STC12C5A60S2
日期:2011-10-11
//1602 四线制驱动程序,根据需要自己改端口定义和延时
#define LINE1 0
#define LINE2 1
#define LINE1_HEAD 0x80
#define LINE2_HEAD 0xC0
#define CLEARSCREEN LCD_en_com(0x01);LCD_delay(30)
/*************************************/
//change this part at different board
sbit DB7=P2^7;
sbit DB6=P2^6;
sbit DB5=P2^5;
sbit DB4=P2^4;
sbit LCD1602_RS=P2^1; //data command select 1 data 0 command pin 4
sbit LCD1602_RW=P2^2; //read write select 1 read 0 write pin 5
sbit LCD1602_EN=P2^3; //LCD enable signal pin 6
/********************************************************************/
void LCD_delay(unsigned int n)
{
unsigned int i=0,j=0;
for (i=n;i>0;i--)
for (j=0;j<12;j++);
}
void LCD_en_com(unsigned char command)
{
DB7=(command>>7)%2;
DB6=(command>>6)%2;
DB5=(command>>5)%2;
DB4=(command>>4)%2;
LCD1602_RS = 0; //RS 0
LCD1602_RW = 0; //RW 0
LCD1602_EN = 1; //EN --\|/__ Write command
LCD_delay(2);
LCD1602_EN = 0;
DB7=(command>>3)%2;
DB6=(command>>2)%2;
DB5=(command>>1)%2;
DB4=(command>>0)%2;
LCD1602_RS = 0; //RS 0