新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > LCD上實現(xiàn)數(shù)字時鐘

LCD上實現(xiàn)數(shù)字時鐘

作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
這里使用1602液晶實現(xiàn)數(shù)字時鐘,這里需要注意的是LCD1602液晶的驅(qū)動寫法,可以參考太陽人公司出品的datasheet,具體的程序如下:
#include
# define uchar unsigned char
# define uint unsigned int
sbit rs=P1^0;
sbit rw=P1^1;
sbit e=P1^2;
uchar table[]={0,1,2,3,4,5,6,7,8,9};
uchar num,shi,fen,miao;
void delay(uchar dly)
{
uint x,y;
for(x=0;x<=110;x++)
for(y=0;y
;
}
void write_com(uchar com)//寫命令
{
rs=0;
P2=com;
delay(1);
e=1;
delay(1);
e=0;
}
void write_data(uchar num)//寫數(shù)據(jù)
{
rs=1;
P2=num;
delay(1);
e=1;
delay(1);
e=0;
}
void init()
{
e=0;
rw=0;
num=0;
miao=0;
fen=0;
shi=0;
TMOD=0x01;
EA=1;
TR0=1;
ET0=1;
write_com(0x38);//初始化命令
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80);
}
void time() interrupt 1
{
TH0=(65535-46080)/256;
TL0=(65535-46080)% 256;
num++;
}
void main()
{
init();
write_com(0x80);
write_data(table[0]);
write_com(0x81);
write_data(table[0]);
write_com(0x83);
write_data(table[0]);
write_com(0x84);
write_data(table[0]);
write_com(0x86);
write_data(table[0]);
write_com(0x87);
write_data(table[0]);
write_com(0x82);
write_data(:);
write_com(0x85);
write_data(:);
while(1)
{
if(num==20)
{
miao++;
num=0;
}
if(miao==60)
{
fen++;
miao=0;
write_com(0x83);
write_data(table[fen/10]);
write_com(0x84);
write_data(table[fen ]);// % 10 ,神馬情況,% 咋個寫不進去
}
if(fen==24)
{
shi++;
fen=0;
write_com(0x80);
write_data(table[shi/10]);
write_com(0x81);
write_data(table[shi ]);// % 10
}
write_com(0x86);
write_data(table[miao/10]);
write_com(0x87);
write_data(table[miao ]);// % 10
}
}



關(guān)鍵詞: LCD數(shù)字時

評論


技術(shù)專區(qū)

關(guān)閉