📄 液晶时钟.c
字号:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit rs=P3^5;
sbit lcden=P3^4;
sbit s1=P1^0;
sbit s2=P1^1;
sbit s3=P1^2;
uchar count,count1;
char shi,fen,miao;
uchar table[]=" 2008-4-09 wen";
uchar table1[]=" 00:00:00";
void keyscan();
void delay(uint z)
{ uchar i;
for(;z>0;z--)
for(i=0;i<110;i++);
}
void write_com(uchar com)
{
rs=0;
lcden=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void write_date(uchar date)
{
rs=1;
lcden=0;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
uchar num;
lcden=0;
delay(10);
write_com(0x38);
write_com(0x0C);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_date(table[num]);
delay(20);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(20);
}
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
write_sfm(uchar add,uchar date)
{
uchar sh,ge;
sh=date/10;
ge=date%10;
write_com(0x80+0x40+add);
write_date(sh+0x30);
write_date(ge+0x30);
}
void main()
{
init();
while(1)
{
keyscan();
}
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(3,shi);
}
write_sfm(6,fen);
}
write_sfm(9,miao);
}
}
void keyscan()
{
if(s1==0)
{
delay(10);
if(s1==0)
{
count1++;
while(!s1);
if(count1==1)
{
TR0=0;
write_com(0x80+0x40+9);
write_com(0x0f);
}
if(count1==2)
{
write_com(0x80+0x40+6);
}
if(count1==3)
{
write_com(0x80+0x40+3);
}
if(count1==4)
{
count1=0;
TR0=1;
write_com(0x0c);
}
}
}
if(count1!=0)
{
if(s2==0)
{
delay(10);
if(s2==0)
{
while(!s2);
if(count1==1)
{
miao++;
if(miao==60)
miao=0;
write_sfm(9,miao);
write_com(0x80+0x40+9);
}
if(count1==2)
{
fen++;
if(fen==60)
fen=0;
write_sfm(6,fen);
write_com(0x80+0x40+6);
}
if(count1==3)
{
shi++;
if(shi==24)
shi=0;
write_sfm(3,shi);
write_com(0x80+0x40+3);
}
}
}
if(s3==0)
{
delay(10);
if(s3==0)
{
while(!s3);
if(count1==1)
{
miao--;
if(miao==-1)
miao=59;
write_sfm(9,miao);
write_com(0x80+0x40+9);
}
if(count1==2)
{
fen--;
if(fen==-1)
fen=59;
write_sfm(6,fen);
write_com(0x80+0x40+6);
}
if(count1==3)
{
shi--;
if(shi==-1)
shi=23;
write_sfm(3,shi);
write_com(0x80+0x40+3);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -