单片机课程设计,《基于89C51控制的LCD时钟》

《基于89C51控制的LCD时钟》课程设计题目不要用C语言写啊!
2024-12-15 13:45:27
推荐回答(2个)
回答1:

用的是实时时钟DS12887做的,很准确的液晶是1602
#include
#define uint unsigned int
#define uchar unsigned char

sbit up=P2^6;
sbit down=P2^7;
sbit lcdrs=P2^3;
sbit lcden=P2^4;
sbit light=P2^1;
sbit lc=P3^7;
sbit dscs=P3^6;
sbit dsas=P3^5;
sbit dsrw=P3^4;
sbit dsds=P3^3;
uchar code table3[]="0123456789";
uchar code table4[8][3]={" ","SUN","MON","TUE","WED","THU","FRI","SAT",};
uchar num,num1,sun,sun1,sun2;
uchar year,mon,day,hour,min,sec,sss;
uchar tflag;
void delay(uint z);
void init();
void write_com(uchar com);
void write_data(uchar date);
void getto(uchar i,uchar j,uchar da);
void write_ds(uchar add,uchar date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P1=add;
dsas=0;
dsrw=0;
P1=date;
dsrw=1;
dsas=1;
dscs=1;
}

uchar read_ds(uchar add)
{
uchar ds_date;
dsas=1;
dsds=1;
dsrw=1;
dscs=0;
P1=add;
dsas=0;
dsds=0;
P1=0xff;
ds_date=P1;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
/*void set_time()
{
write_ds(9,9);
write_ds(8,3);
write_ds(7,7);
write_ds(6,7);
write_ds(4,19);
write_ds(2,47);
write_ds(0,10);

}*/
void main()
{
init();
while(1)
{
if(lc==0)
{
delay(10);
if(lc==0)
{
TR0=1;
tflag=1;
light=0;
while(~lc);
}
}
if(up==0&&tflag==1)
{
delay(10);
if(up==0)
{
min++;
if(min==60)
{
hour++;
min=0;
}
sec=0;
write_ds(4,hour);
write_ds(2,min);
write_ds(0,sec);
while(~up);
}
}
if(down==0&&tflag==1)
{
delay(10);
if(down==0)
{
min--;
sec=0;
write_ds(2,min);
write_ds(0,sec);
while(~down);
}
}
year=read_ds(9);
mon=read_ds(8);
day=read_ds(7);
sss=read_ds(6);
hour=read_ds(4);
min=read_ds(2);
if((min%10==0)&&(sec==0))
{
TR0=1;
light=0;
}
sec=read_ds(0);
sun1=read_ds(0x30);
sun2=read_ds(0x31);
sun=100*sun1+sun2;
getto(2,10,sec);
getto(2,7,min);
getto(2,4,hour);
getto(1,4,year);
getto(1,7,mon);
getto(1,10,day);
write_com(0x80+12);
write_data(table4[sss][0]);
write_data(table4[sss][1]);
write_data(table4[sss][2]);
write_com(0x80+0x40+12);
write_data('2');
write_data((sun-200)/10+0x30);
write_data((sun-200)%10+0x30);
}
}

void timer0() interrupt 1 using 1
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
num1++;
if(num1==120)
{
TR0=0;
num1=0;
light=1;
tflag=0;
}
}
void init()
{
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
EA=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
EX0=1;
IT0=1;
EA=1;
light=1;
num1=0;
tflag=0;
// sun=204;
// write_ds(0x30,sun/100);
// write_ds(0x31,sun%100);
getto(1,2,20);
write_com(0x80+5);
write_data('-');
write_com(0x80+8);
write_data('-');
write_com(0x80+0x40+5);
write_data(':');
write_com(0x80+0x40+8);
write_data(':');
// write_ds(0x0b,0x26);
// set_time();
// write_ds(7,26);
write_ds(1,0);
write_ds(3,0);
write_ds(5,0);
}

void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}

void write_com(uchar com)
{
lcdrs=0;
lcden=1;
P0=com;
delay(5);
lcden=0;
}

void write_data(uchar date)
{
lcdrs=1;
lcden=1;
P0=date;
delay(5);
lcden=0;
}

void getto(uchar i,uchar j,uchar da)
{
uchar h,l;
h=da/10;
l=da%10;
switch(i)
{
case 1:
write_com(0x80+j-1);
break;
case 2:
write_com(0x80+0x40+j-1);
break;
}
write_data(table3[h]);
write_data(table3[l]);
}
void exter() interrupt 0
{ uchar c;
//做闹铃的中断
c=read_ds(0x0c);
}

回答2:

可以用keil自动生成汇编代码吧?