附上C语言程序,大神帮我看看哪里出错了:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P3^1;
sbit wela=P3^2;
uint bb=0;
sbit led1=P3^3;
uint x=0,t0=0;
uchar num,temp,ch=1;
uchar shi=17,fen=13,miao=25,shi1,shi2,fen1,fen2,miao1,miao2;
uint nian=2019,yue=7,ri=9,nian1,nian2,yue1,yue2,ri1,ri2,year=00,month=00,day=00,year1,year2,month1,month2,day1,day2;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f,0};
void delay(uint z)
{
uint t1,y;
for(t1=z;t1>0;t1--)
for(y=110;y>0;y--);
}
void display(uchar shi1,uchar shi2,uchar fen1,uchar fen2,uchar miao1,uchar miao2)
{
wela=1;
P2=0xfe;
wela=0;
dula=1;
P2=table[shi1];
delay(5);
dula=0;
wela=1;
P2=0xfd;
wela=0;
dula=1;
P2=table[shi2];
delay(5);
dula=0;
wela=1;
P2=0xfb;
wela=0;
dula=1;
P2=table[fen1];
delay(5);
dula=0;
wela=1;
P2=0xf7;
wela=0;
dula=1;
P2=table[fen2];
delay(5);
dula=0;
wela=1;
P2=0xef;
wela=0;
dula=1;
P2=table[miao1];
delay(5);
dula=0;
wela=1;
P2=0xdf;
wela=0;
dula=1;
P2=table[miao2];
delay(5);
dula=0;
}
void init()
{
TMOD=0x11;
TH0=(65536-50000)/256; //定时器初始化
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR1=1;
}
uchar keyscan()
{
P3=0xfe;//检测第一行
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=1;
break;
case 0xd0:num=2;
break;
case 0xb0:num=3;
break;
case 0x70:num=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
return shi,fen;
}
void jisuan()
{
if(num==1)
{
ch++;
if(ch==4)
ch=1;
num=0;
}
if(num==2)
{
if(ch==1)
shi++;
if(ch==2)
nian++;
if(ch==3)
year++;
num=0;
}
if(num==3)
{
if(ch==1)
fen++;
if(ch==2)
yue++;
if(ch==3)
month++;
num=0;
}
if(num==4)
{
if(ch==1)
miao++;
if(ch==2)
ri++;
if(ch==3)
day++;
num=0;
}
}
void shijian()
{
shi1=shi/10;
shi2=shi%10;
fen1=fen/10;
fen2=fen%10;
miao1=miao/10;
miao2=miao%10;
if(fen==0&miao==0)/*
当时间为整时时灯灭,否则灯亮
*/
{
led1=0;
}else{
led1=1;
}
if(shi==24)
{
shi=0;
ri++;
}
if(fen==60)
{
fen=0;
shi++;
}
if(miao==60)
{
miao=0;
fen++;
}
}
void riqi()
{
nian1=nian/10;
nian2=nian%10;
yue1=yue/10;
yue2=yue%10;
ri1=ri/10;
ri2=ri%10;
if(yue==12)
{
nian++;
yue=1;
}
switch(yue)//判断月份大小
{
case 1:case 3:case 5:case 7:case 8:case 10:case 12:
if(ri==32)
{
ri=1;
yue++;
}
break;
case 4:case 6:case 9:case 11:
if(ri==31)
{
ri=1;
yue++;
}
break;
case 2: //判断闰年
if((nian%4==0&nian%100!=0)||nian%400==0)
{
yue++;
ri=1;
}
else if(nian%400!=0&ri==29)
{
yue++;
ri=1;
}
break;
}
}
void naozhong() //闹钟
{
year1=year/10;
year2=year%10;
month1=month/10;
month2=month%10;
day1=day/10;
day2=day%10;
if(year==24)
{
year=0;
}
if(month==60)
{
month=0;
year++;
}
if(day==60)
{
day=0;
month++;
}
}
void main() //shi代表当前时间 year代表闹钟时间
{
init();
P1=0x00; //P1四个灯 初始化为灭
while(1)
{
jisuan();
keyscan();
shijian();
riqi();
naozhong();
if(shi==year&fen==month&miao==day)
TR0=1;
if(ch==1)
display(shi1, shi2, fen1, fen2, miao1, miao2);
if(ch==2)
display(nian1,nian2,yue1,yue2,ri1,ri2);
if(ch==3)
display(year1,year2,month1,month2,day1,day2);
}
}
void time1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
x++;
if(x==20)
{
x=0;
miao++;
if(miao==60)
{
miao=0;
fen++;
if(fen==60)
{
fen=0;
shi++;
if(shi==24)
{
shi=0;
}
}
}
}
}
void timer0() interrupt 1 //定时器0中断
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(t0<1200)
{
bb++; //增加_b 拖延时间增加闪烁时间
if(bb<15){
P1=0xff;
}
if(bb>15){
P1=0xf0;
if(bb>30){bb=0;}
}
if(t0==1200)
{
TR0=0; //60秒后关闭定时器0,关闭灯
P1=0x00;
}
}
}
|