標(biāo)題:
51單片機(jī)LCD1602顯示程序源碼
[打印本頁(yè)]
作者:
lyczli
時(shí)間:
2020-9-18 09:45
標(biāo)題:
51單片機(jī)LCD1602顯示程序源碼
LCD EN 用P3.4;LCD RS用P3.5;
LCD R/W在仿真的硬件電路上接地;
仿真電路參考圖片;
C51_1602.png
(30.42 KB, 下載次數(shù): 35)
下載附件
2020-9-18 09:45 上傳
單片機(jī)源程序如下:
#include <reg52.h>
#include <intrins.h>
sbit lcden=P3^4;
sbit lcdrs=P3^5;
unsigned int const ad1=0x80;
unsigned int const ad2=0x80+0x40;
void delay(unsigned char j)
{
unsigned char i=60;
for(;j>0;j--)
{
while(--i); i=59;
while(--i); i=60;
}
}
void w_date(unsigned char date)
{
lcden=0;
lcdrs=1;
P0=date;
delay(5);
lcden=1;
_nop_();
lcden=0;
delay(1);
}
void w_com(unsigned char com)
{
lcden=0;
lcdrs=0;
P0=com;
delay(5);
lcden=1;
_nop_();
lcden=0;
delay(1);
}
void string(unsigned char ad,unsigned char *s)
{
w_com(ad);
while(*s>0)
{
w_date(*s++);delay(100);
}
}
void lcd_ini()
{
w_com(0x38);//16*2顯示;5*7點(diǎn)陣;8位數(shù)據(jù)口
w_com(0x0c);//開(kāi)顯示,不顯示光標(biāo)
w_com(0x06);//寫(xiě)一個(gè)字符后地址加1;
w_com(0x01);//clear screen
delay(1);
}
unsigned char code table1[]={"hellow "};
unsigned char code table2[]={"hellow word"};
int main()
{
lcd_ini();
while(1)
{
string(0x80,table1);
string(0x80+0x40,table2);
delay(100);
}
}
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1