#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P2^5;
sbit s1=P3^0;
sbit s2=P3^1;
sbit s3=P3^2;
sbit rd=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
void write_com(uchar com);
void write_date(uchar date);
uchar code table[]=" 2013-9-13 FIR";
uchar code table1[]=" 00:00:00";
uchar num,t;
char shi,fen,miao;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
en=0;
P0=com;
delay(5);
en=1;
delay(5);
en=0;
}
void write_date(uchar date)
{
rs=1;
en=0;
P0=date;
delay(5);
en=1;
delay(5);
en=0;
}
void init()
{
TMOD=0X01;
EA=1;
ET0=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
dula=0;
wela=0;
rw=0;
write_com(0x38);
write_com(0x0e);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<16;num++)
{
write_date(table[num]);
delay(100);
}
write_com(0x80+0x40);
for(num=0;num<12;num++)
{
write_date(table1[num]);
delay(100);
}
}
void write_sfm(uchar add,uchar date)
{
uchar sh,g;
sh=date/10;
g=date%10;
write_com(0x80+0x40+add);
write_date(0x30+sh);
write_date(0x30+g);
}
void time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
void main()
{
init();
while(1)
{
if(t==20)
{
t=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
write_sfm(4,shi);
}
write_sfm(7,fen);
}
write_sfm(10,miao);
}
}
}
此帖出自
小平头技术问答
这是写完不准备修改和看第二遍的节奏~~~~
一周热门 更多>