源程序如下:
#include<reg51.h>
#include"24c02.h"
#define uc unsigned char
#define ui unsigned int
uc code table[]=
{
0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e//共阳极
};
int num_qian,
time_qian,num_bai,time_bai,num_shi,time_shi,num_ge,time_ge,sum_qian,sum_bai,sum_shi,sum_ge,tiao,mode,time,num;
long sum;
ui i,j ;
sbit move=P1^7;
sbit add=P1^6;
sbit set=P1^5;
sbit jiejin=P1^4;
sbit yuan=P1^3;
sbit ping=P1^2;
sbit led=P1^1;
sbit guangqian=P3^2;
sbit al
ARM=P1^1;
void delay(ui z)
{
ui x,y;
for(x=z;x--;x>0)
for(y=12;y--;y>0);
}
void system_ini ( void)
{
ping=1;
yuan=1;
led =1;
EA=1;
EX0=1;
IT0=1;
x24c02_init();
num_qian=x24c02_read(1);
num_bai=x24c02_read(2);
num_shi=x24c02_read(3);
num_ge=x24c02_read(4);
sum_qian=x24c02_read(5);
sum_bai=x24c02_read(6);
sum_shi=x24c02_read(7);
sum_ge=x24c02_read(8);
time_qian=x24c02_read(9);
time_bai=x24c02_read(10);
time_shi=x24c02_read(11);
time_ge=x24c02_read(12);
num=num_ge+num_shi*10+num_bai*100+num_qian*1000;
sum=sum_ge+sum_shi*10+sum_bai*100+sum_qian*1000;
time=time_ge+time_shi*10+time_bai*100+time_qian*1000;
}
void system_led (led)
{
//P2=0xff ;
P2=0xf7;
P0=0X00
P0=table[sum_ge];
;
delay(15);
//P2=0xf0;
P2=0xff ;
P2=0xfb;
P0=0x00;
P0=table[sum_shi];
delay(15);
//P2=0xf0;
P2=0xff ;
P2=0xfd;
P0=0x00;
P0=table[sum_bai];
delay(15);
//P2=0xf0;
P2=0xff ;
P2=0xfe;
P0=0x00;
P0=table[sum_qian];
delay(15);
//P2=0xf0;
P2=0xff ;
}
void system_set ( void )
{
if(set==0)
{
delay(1000);
if(set==0)
{
EA=0;
tiao=1;
mode++;
if(mode==3)
{
mode=0;
EA=1;
}
}
}
if(mode==0)
{
if(move==0)
{
delay(100);
if(move==0)
{
sum_ge=0;
sum_shi=0;
sum_bai=0;
sum_qian=0;
x24c02_write(5,sum_qian);
delay(10);
x24c02_write(6,sum_bai);
delay(10);
x24c02_write(7,sum_shi);
delay(10);
x24c02_write(8,sum_ge);
delay(10);
}
}
system_led (led);
if(sum_ge==10)
{
sum_ge=0;
sum_shi++;
if(sum_shi==10)
{
sum_shi=0;
sum_bai++;
if(sum_bai==10)
{
sum_bai=0;
sum_qian++;
if(sum_qian==10)
sum_qian=0;
}
}
}
x24c02_write(5,sum_qian);
delay(10);
x24c02_write(6,sum_bai);
delay(10);
x24c02_write(7,sum_shi);
delay(10);
x24c02_write(8,sum_ge);
delay(10);
sum=sum_ge+sum_shi*10+sum_bai*100+sum_qian*1000;
if((sum>=num)&(num>1))
{
if(sum_ge==10)
{
sum_ge=0;
sum_shi++;
if(sum_shi==10)
{
sum_shi=0;
sum_bai++;
if(sum_bai==10)
{
sum_bai=0;
sum_qian++;
if(sum_qian==10)
sum_qian=0;
}
}
}
yuan=1;
P2=0xf0;
for(i=1;i<=time;i++)
{
for(j=1;j<200;j++)
{
system_led (led);
}
}
ping=1;
while(jiejin==1)
{
led=1;
for(j=1;j<100;j++)
{
system_led (led) ;
}
led=0;
for(j=1;j<100;j++)
{
system_led (led);
}
}
led=1;
sum_ge=0;
sum_shi=0;
sum_bai=0;
sum_qian=0;
}
}
if(mode==1)
{
if(move==0)
{
delay(1000);
if(move==0)
{
tiao++;
if(tiao==5)
tiao=1;
}
}
if(tiao==1)
{
delay(10);
P2=0xf7;
P0=table[time_ge];
if(add==0)
{
delay(1000);
if(add==0)
{
time_ge++;
if(time_ge==10)
time_ge=0;
}
}
}
if(tiao==2)
{
delay(10);
P2=0xfb;
P0=table[time_shi];
if(add==0)
{
delay(1000);
if(add==0)
{
time_shi++;
if(time_shi==10)
time_shi=0;
}
}
}
if(tiao==3)
{
delay(10);
P2=0xfd;
P0=table[time_bai];
if(add==0)
{
delay(1000);
if(add==0)
{
time_bai++;
if(time_bai==10)
time_bai=0;
}
}
}
if(tiao==4)
{
delay(10);
P2=0xfe;
P0=table[time_qian];
if(add==0)
{
delay(1000);
if(add==0)
{
time_qian++;
if(time_qian==10)
time_qian=0;
}
}
}
x24c02_write(9,time_qian);
delay(10);
x24c02_write(10,time_bai);
delay(10);
x24c02_write(11,time_shi);
delay(10);
x24c02_write(12,time_ge);
delay(10);
time=time_ge+time_shi*10+time_bai*100+time_qian*1000;
}
if(mode==2)
{
if(move==0)
{
delay(1000);
if(move==0)
{
tiao++;
if(tiao==5)
tiao=1;
}
}
if(tiao==1)
{
delay(10);
P2=0xf7;
P0=table[num_ge];
if(add==0)
{
delay(1000);
if(add==0)
{
num_ge++;
if(num_ge==10)
num_ge=0;
}
}
}
if(tiao==2)
{
delay(10);
P2=0xfb;
P0=table[num_shi];
if(add==0)
{
delay(1000);
if(add==0)
{
num_shi++;
if(num_shi==10)
num_shi=0;
}
}
}
if(tiao==3)
{
delay(10);
P2=0xfd;
P0=table[num_bai];
if(add==0)
{
delay(1000);
if(add==0)
{
num_bai++;
if(num_bai==10)
num_bai=0;
}
}
}
if(tiao==4)
{
delay(10);
P2=0xfe;
P0=table[num_qian];
if(add==0)
{
delay(1000);
if(add==0)
{
num_qian++;
if(num_qian==10)
num_qian=0;
}
}
}
x24c02_write(1,num_qian);
delay(10);
x24c02_write(2,num_bai);
delay(10);
x24c02_write(3,num_shi);
delay(10);
x24c02_write(4,num_ge);
delay(10);
num=num_ge+num_shi*10+num_bai*100+num_qian*1000;
}
}
main()
{
system_ini ( ) ;
if (jiejin==0) //接近开关拿
{
ping=1; //
yuan=1; //
led =1; //
}
while(1)
{
if(jiejin==1)
{
ping=0;
yuan=0;
led =1;
}
system_set ( ) ;
}
}
void int0(void) interrupt 0 using 0
{
sum_ge++;
}
计数到一定时,为什么会出现数码管会乱码呢。。
一周热门 更多>