#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit relay=P1^0; //继电器由P1.0控制
sbit add=P1^1; //申明按键
sbit sub=P1^2;
sbit start=P1^3;
sbit LED_shi=P2^1; //申明数码管位选
sbit LED_ge=P2^2;
uchar code table[]={ 0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71 };//数码管共阴极编码
uchar n,num;//
void delay_ms(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void init()
{
num=5;
TMOD=0x01;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
EA=1;
ET0=1;
}
void display(uchar number)
{
uchar ge,shi;
shi=number/10;
ge=number%10;
LED_shi=0;
P0=table[shi];
delay_ms(5);
LED_shi=1;
LED_ge=0;
P0=table[ge];
delay_ms(5);
LED_ge=1;
}
void keyscan()
{
if(add==1)
{
delay_ms(10);
if(add==1)
{
num++;
if(num==60)
num=0;
while(!add);
}
}
if(sub==1)
{
delay_ms(10);
if(sub==1)
{
num--;
if(num==0)
num=59;
while(!sub);
}
}
if(start==1)
{
delay_ms(10);
if(start==1)
{
while(!start);
TR0=~TR0;
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num);
if(n==20num)
{
n=0;
relay=0;
delay_ms(50);
relay=1;
}
}
}
void time0() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
n++;
}
各位前辈,能不能帮我看下程序出了什么问题,编译完总是说有语法错误,在主程序的的if语句那块,已经标成红色了,我是想让数码管显示一个两位数,表示设定的时间是多少秒,可以由按键加减,等到时间到了就让继电器短暂吸合,定时器是50ms中断一次,谢谢各位了! |