|
#include
#define uchar unsigned char
#define unit unsigned int
char DATA_7SEG[10]={0xC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};
uchar FFW[4]={0xfe,0xfd,0xfb,0xf7}; /*正转*/
uchar REV[4]={0xf7,0xfb,0xfd,0xfe}; /*反转*/
int i=0;
uchar hour=0,min=0,sec=0;
uchar deda=0;
uchar set=0;
void delay();
void conv();
void disp();
void init_timer()
{
TMOD=0X01;
TH0=0XEC;
TL0=0X78;
IE=1;
TR0=1;
}
void TO_SRV(void) interrupt 1
{
TH0=0XEC;
TL0=0X78;
deda++;
}
void conv()
{
if(deda>=200)
{
sec++;
deda=0;
}
if(sec==60)
{
min++;
sec=0;
}
if(min==60)
{
hour++;
min=0;
}
if(hour==24)
{
hour=0;
}
}
void disp()
{
P0=DATA_7SEG[hour/10];P2=0XFE;
P0=DATA_7SEG[hour%10];P2=0XFD;
P0=DATA_7SEG[min/10]; P2=0XFB;
P0=DATA_7SEG[min%10]; P2=0XF7;
P0=DATA_7SEG[sec/10]; P2=0XFE;
P0=DATA_7SEG[sec%10]; P2=0XDF;
}
void set_time()
{
if(P3_0==0)/*设置小时*/
delay();
if(P3_0==0)
hour++;
if(hour==24)
hour=0;
if(P3_1==0)/*设置分钟*/
delay();
if(P3_1==0)
min++;
if(min==60)
min=0;
if(P3_6==0)/*设置秒针*/
delay();
if(P3_6==0)
sec++;
if(sec==60)
sec=0;
}
void totime()
{
if(hour==12&&min==10&&sec==0)
{
for(;sec<=3;)
{
P1=FFW;
i++;
delay();
if(i>=4)
i=0;
}
P1=0xff;
}
if(hour==12&&min==50&&sec==0)
{
for(;sec<=3;)
{
P1=REV;
i++;
delay();
if(i>=4)
i=0;
}
P1=0xff;
}
}
void time()
{
conv();
disp();
totime();
}
void scan_key()
{if(P3_7==0)
set++;
if(set>=2)
set=0;
F0:if(P3_7==0)
goto F0;
}
void delay()
{
unit j;
for(j=0;j<2;j++)
{;}
}
void main()
{
init_timer();
while(1)
{
if(P3_7==0)
scan_key();
switch(set)
{
case 0: time();break;
case 1: set_time();break;
default: break;
}
}
}
这是我的程序,用keil没有错误,但是用proteus仿真出不了结果,不知道到底时怎么回事,麻烦各位高手帮忙看一下
|
|