另外一种 主要看 LCD_set_xy( uchar x, uchar y )
void LCD_init(void) //液晶初始化
{
P1=0xFF;
P3=0xff; //输出
LCD_RS=0; //
del_ms(50);
LCD_write_char(0x30,0);
del_ms(6);
LCD_write_char(0x30,0); //
del_ms(1);
LCD_write_char(0x30,0); //上电即显示正常,无需复位
del_ms(1);
LCD_write_char(0x02,0);
del_ms(1);
LCD_write_char(0x28,0); //4bit test显示模式设置(不检测忙信号)
del_ms(1);
LCD_write_char(0x08,0); // 显示关闭
del_ms(1);
LCD_write_char(0x01,0); // 显示清屏
del_ms(1);
LCD_write_char(0x06,0); // 显示光标移动设置
del_ms(1);
LCD_write_char(0x0C,0); // 显示开及光标设置
del_ms(10);
}
//---------------------------------------------
void LCD_write_str(uchar X,uchar Y,uchar *s)
{
LCD_set_xy( X, Y ); //写地址
while (*s) // 写显示字符
{
LCD_write_char( 0, *s );
s ++;
}
}
void LCD_set_xy( uchar x, uchar y ) //写地址函数
{
uchar address;
if (y == 0) address = 0x80 + x;
else
address = 0xc0 + x;
LCD_write_char( address, 0 );
}
//------------------------------------------------
void LCD_en_write(void) //液晶使能
{
_nop_();
LCD_E=1;//EN=1
_nop_();
LCD_E=0;//EN=0
}
//------------------------------------------------
void LCD_write_char(uchar cd,uchar ab) // 写数据
{
delay_nus(20);
if(cd==0)
{
LCD_RS=1; //RS=1,写显示内容
LCD_byte(ab);
}
else
{
LCD_RS=0; //RS=0,写命令
LCD_byte(cd);
}
}
//-----------------------------------------------
void LCD_byte(uchar abc)//
{
delay_nus(50);
if(((abc<<0)&0x80)==0) //MSB is output first
LCD_D7=0; //abc=0
else LCD_D7=1; //abc=1
if(((abc<<1)&0x80)==0) //MSB is output first
LCD_D6=0; //abc=0
else LCD_D6=1; //abc=1
if(((abc<<2)&0x80)==0) //MSB is output first
LCD_D5=0; //abc=0
else LCD_D5=1; //abc=1
if(((abc<<3)&0x80)==0) //MSB is output first
LCD_D4=0; //abc=0
else LCD_D4=1; //abc=1
LCD_en_write();
if(((abc<<4)&0x80)==0) //MSB is output first
LCD_D7=0; //abc=0
else LCD_D7=1; //abc=1
if(((abc<<5)&0x80)==0) //MSB is output first
LCD_D6=0; //abc=0
else LCD_D6=1; //abc=1
if(((abc<<6)&0x80)==0) //MSB is output first
LCD_D5=0; //abc=0
else LCD_D5=1; //abc=1
if(((abc<<7)&0x80)==0) //MSB is output first
LCD_D4=0; //abc=0
else LCD_D4=1; //abc=1
LCD_en_write();
} |