?? lcd.h
字號:
// 16x2 HD44780 based LCD Module functions for SDCC / P89V51RD2
/* Original Code by:
* Author : sci-3d@hotmail.com
* Date : 2006-08-01 (yyyy-mm-dd)
*/
/* Modified for ucmicrosys UNI-51-SDK (www.ucmicrosys.com) by
* Author(s) : Anurag Chugh (anurag@ucmicrosys.com) and Ranjit Puri (ranjit.puri@gmail.com)
* Date : 2006-12-15 (yyyy-mm-dd)
*/
//NOTES:
//1: This code may be distributed and modified freely .
//2: External Crystal of 11.0592 MHz is assumed.
//3. 16x2 LCD Modules is being operated in Nibble Mode.
//4: Connections to the LCD are assumed as followed:
// RS -> P0.0
// RW -> P0.1
// E -> P0.2
// D4,D5,D6,D7 -> P0.4,P0.5,P0.6,P0.7
#ifndef __p89v51rd2_h__
#include <p89v51rd2.h>
#define __p89v51rd2_h__
#endif
#define LCD_DATA P0
#define LCD_en P0_2
#define LCD_rs P0_0
#define LCD_rw P0_1 //Must Always be low to allow data to be sent to LCD
#define LCD_DELAY 100 //Delay for allowing the LCD to execute the Command Sent to it
#define LCD_clear() LCD_command(0x1) //Clear display LCD
#define LCD_origin() LCD_command(0x2) //Set to origin LCD
#define LCD_row1() LCD_command(0x80) //Begin at Line 1
#define LCD_row2() LCD_command(0xC0) //Begin at Line 2
void LCD_gotoxy(char position, char line);
void LCD_delay(unsigned char ms);
void LCD_enable();
void LCD_command(unsigned char command);
void LCD_putc(unsigned char ascii);
void LCD_puts(unsigned char *lcd_string); //Function to put a string on LCD
void LCD_init(); //Function to initialize the LCD module
void LCD_delay(unsigned char ms)
{
unsigned char n;
unsigned int i;
for (n=0; n<ms; n++)
{
for (i=0; i<LCD_DELAY; i++);
}
}
void LCD_enable()
{
LCD_en = 0; //High to low transition
LCD_delay(1);
LCD_en = 1; //Back to default state
}
void LCD_command(unsigned char command)
{
LCD_rs = 0; //Command Mode
LCD_DATA = ((command & 0xF0)|0x04);
LCD_enable();
LCD_DATA = (((command<<4) & 0xF0)|0x04);
LCD_enable();
LCD_delay(1);
}
void LCD_putc(unsigned char ascii)
{
LCD_rs = 1; //Data Mode
LCD_DATA = ((ascii & 0xF0)|0x05);
LCD_enable();
LCD_DATA = (((ascii<<4) & 0xF0)|0x05);
LCD_enable();
LCD_delay(1);
}
void LCD_puts(unsigned char *lcd_string)
{
while (*lcd_string)
{
LCD_putc(*lcd_string++);
}
}
void LCD_init()
{
LCD_delay(20); //Let LCD Driver stabilize
P0=0x00;
LCD_en = 1;
LCD_rs = 0;
LCD_rw = 0;
LCD_command(0x33); //8 bit mode, 8 bit mode
LCD_command(0x33); //8 bit mode, 8 bit mode
LCD_command(0x32); //8 bit mode, 4 bit mode
LCD_command(0x28); //4 bit mode, 2 line mode
LCD_command(0x0F); //Display Cursor (Underline and Blink)
LCD_command(0x03); //Display and Cursor Home
LCD_delay(20); //Display and Cursor Home requres more time
LCD_command(0x01); //Clear Display
LCD_delay(20); //Clear Display requires more time
}
void LCD_gotoxy(char position, char line)
{
if(line == 0)
{
LCD_command(0x80 + position);
}
else if(line == 1)
{
LCD_command(0x80 + 0x40 + position);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -