Proteus運(yùn)行Keil編寫的51單片機(jī)C語(yǔ)言步驟
本文引用地址:http://m.butianyuan.cn/article/201611/323961.htm
#include
#define uchar unsigned char
#define uint unsigned int
#define DB P1
sbit RS=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
uchar code ttt[]="Tel:123456789";
uchar code ggg[]="address:Xian dianziyuan";
/******************************************************
1602液晶顯示必須的幾個(gè)函數(shù):
1.初始化函數(shù),清屏,設(shè)置從頭顯示,字符狀態(tài),光標(biāo)狀態(tài)等
2.寫命令函數(shù),顯示的位置,方式
3.寫數(shù)據(jù)函數(shù),要顯示的內(nèi)容
4.延遲函數(shù)
5主函數(shù)
****************************************************/
void LCDinit(void);
void delay(uchar x);
void writecom(uchar com);
void writedat(uchar dat);
void LCDinit(void)
{
writecom(0x38);
writecom(0x0c);
writecom(0x06);
writecom(0x01);
delay(100);
}
void writecom(uchar com)
{
DB=com;
RS=0;
rw=0;
en=1;
delay(5);
en=0;
}
void writedata(uchar dat)
{
RS=1;
rw=0;
en=0;
DB=dat;
en=1;
delay(5);
en=0;
}
void delay(uchar x)
{
uint i=0;
while(x--)
{
for (i=0;i<100;i++);
};
}
void main(void)
{
LCDinit();
while(1)
{
uint i=0;
writecom(0x80+10);
for (i=0;i<9;i++)
{
writedata(ttt[i]);
delay(1000);
}
writecom(0xC0+5);
for(i=0;i<24;i++)
{
writedata(ggg[i]);
delay(1000);
}
}
評(píng)論