1602液晶 1602液晶显示
本帖最后由 Tolerantfree 于 2017-8-3 12:47 编辑
#include
typedef unsigned char uchar;
typedef unsigned int uint;
uchar date[]="2017-06-02"; //10 4-7
uchar sfm[]="00-00-00"; //8 2-5
***it lcden=P2^2;
***it lcdrs=P2^1;
***it lcdrw=P2^0;
***it dula=P2^6;
***it wela=P2^7;
***it D1=P3^3;
uint i;
uint tt=0;
uint j=7;
uint flag=0;
uint shi,fen,miao;
uint shi =22 ; //change 小时
uint fen =59 ; //change 分钟
uint miao =55 ; //change 秒钟
void firstshow()
{
sfm[6]=(miao/10)+0x30;
sfm[7]=(miao%10)+0x30;
sfm[3]=(fen/10)+0x30;
sfm[4]=(fen%10)+0x30;
sfm[0]=(shi/10)+0x30;
sfm[1]=(shi%10)+0x30;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void timeinit()
{
TMOD=0x01;
EA=1;
ET0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void write_com(uchar com) //写指令
{
lcdrs=0;
lcdrw=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date) //写数据
{
lcdrs=1;
lcdrw=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
dula=0;
wela=0;
lcden=0;
write_com(0x38);
write_com(0x0c); //开显示,显示光标;
write_com(0x06); //读或写一个字符后地址指针加1;
write_com(0x01); //关显示,不显示光标,光标不闪烁;
// write_com(0x80);
}
void main()
{
init();
timeinit();
firstshow();
write_com(0x80+0x02);
for(i=0;i<10;i++)
{
write_date(year);
delay(10);
D1=1;
}
while(1)
{
write_com(0x80+0x42);
for(i=0;i<8;i++) {
TR0=1;
if(tt==20){
tt=0;
miao++;
if(miao==60){ //miao -----------------------------------------
miao=0;
fen++;
if(fen==60){ //fen-------------------------------
fen=0;
shi++;
if(shi==24){ //shi --------------
shi=0;
} //shi---------------
sfm[0]=(shi/10)+0x30;
sfm[1]=(shi%10)+0x30;
} //fen ------------------------------------
sfm[3]=(fen/10)+0x30;
sfm[4]=(fen%10)+0x30;
} //miao ----------------------------------------------
sfm[6]=(miao/10)+0x30;
sfm[7]=(miao%10)+0x30;
}
write_date(sfm);
delay(5);
}
}
}
void time0() interrupt 1
{
D1=0;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
tt++;
}
更多回帖