51 單片機(jī)綜合學(xué)習(xí)系統(tǒng)之 1602字符型液晶顯示篇
10.8.3.2 程序流程圖
圖10-61 軟件流程圖
10.8.3.3 軟件代碼
#include
#include
sbit rs= P2^0;
sbit rw = P2^1;
sbit ep = P2^2;
unsigned char code dis1[] = {"www.hificat.com"};
unsigned char code dis2[] = {"0571-85956028"};
void delay(unsigned char ms)
{
unsigned char i;
while(ms--)
{
for(i = 0; i< 250; i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
bit lcd_bz()
{
bit result;
rs = 0;
rw = 1;
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (bit)(P0 & 0x80);
ep = 0;
return result;
}
void lcd_wcmd(unsigned char cmd)
{
while(lcd_bz());//判斷LCD是否忙碌
rs = 0;
rw = 0;
ep = 0;
_nop_();
_nop_();
P0 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 0;
}
void lcd_pos(unsigned char pos)
{
lcd_wcmd(pos | 0x80);
}
void lcd_wdat(unsigned char dat)
{
while(lcd_bz());//判斷LCD是否忙碌
rs = 1;
rw = 0;
ep = 0;
P0 = dat;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 1;
_nop_();
_nop_();
_nop_();
_nop_();
ep = 0;
}
void lcd_init()
{
lcd_wcmd(0x38);
delay(1);
lcd_wcmd(0x0c);
delay(1);
lcd_wcmd(0x06);
delay(1);
lcd_wcmd(0x01);
delay(1);
}
void main(void)
{
unsigned char i;
lcd_init();// 初始化LCD
delay(10);
lcd_pos(0x01);//設(shè)置顯示位置
i = 0;
while(dis1[i] != /0)
{
lcd_wdat(dis1[i]);//顯示字符
i++;
}
lcd_pos(0x42);// 設(shè)置顯示位置
i = 0;
while(dis2[i] != /0)
{
lcd_wdat(dis2[i]);// 顯示字符
i++;
}
while(1);
}
評論