void longdelay(uchar s) //長延時
{
while(s--)
{
delay(80);
}
}
void delay(uchar ms)
{ // 延時子程序
uchar i;
while(ms--)
{
for(i = 0; i< 250; i++);
}
}
BOOL lcd_bz()
{ // 測試LCD忙碌狀態(tài)
BOOL result;
rs = 0;
rw = 1;
ep = 1;
result = (BOOL)(P0 & 0x80);
ep = 0;
return result;
}
void lcd_wcmd(uchar cmd)
{ // 寫入指令數(shù)據(jù)到LCD
while(lcd_bz());
rs = 0;
rw = 0;
ep = 0;
P0 = cmd;
ep = 1;
ep = 0;
}
void lcd_pos(uchar pos)
{ //設(shè)定顯示位置
lcd_wcmd(pos | 0x80);
}
void lcd_wdat(uchar dat)
{ //寫入字符顯示數(shù)據(jù)到LCD
while(lcd_bz());
rs = 1;
rw = 0;
ep = 0;
P0 = dat;
ep = 1;
ep = 0;
}
void lcd_init()
{ //LCD初始化設(shè)定
lcd_wcmd(0x38); //function set
delay(1);
lcd_wcmd(0x38); //function set
delay(1);
lcd_wcmd(0x08); //display on/off
delay(1);
lcd_wcmd(0x01); //清除LCD的顯示內(nèi)容
delay(1);
lcd_wcmd(0x06); //entry mode set
delay(1);
lcd_wcmd(0x0d); //開顯示,并顯示光標(biāo)
delay(1);
}
/*---------------
函數(shù)名稱:display()
功能 :在LCD上顯示數(shù)組的數(shù)據(jù) ,打印模式
說明 :先寫顯示地址,后寫顯示數(shù)據(jù)
調(diào)用 :lcd_wcmd(), lcd_pos()
入口參數(shù):pos 寫入的位置,q指向要寫入的數(shù)據(jù)所在的數(shù)組
返回值 :無
----------------*/
void display(uchar pos, uchar *q)
{
// uchar i;
//lcd_wcmd(0x01); //clear
delay(10);
lcd_pos(pos);
while(*q != '\0')
{
lcd_wdat(*q);
q++;
longdelay(2);
}
}
main()
{
lcd_init(); // 初始化LCD
delay(10);
display(0x00,dis1);
display(0x42,dis2);
display(0x14,dis1);
lcd_wcmd(0x07); //entry mode set
delay(1);
while(1)
{
}
}