//
#include <at89x52.h>
char seg_7_table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xff};
char scan_line[]={0xfe,0xfd,0xfb,0xf7};
char bcd[]={4,0,7,0};
char bdata flag;
sbit cck_flag=flag^0;
sbit anti_cck_flag=flag^1;
sbit up_flag=flag^2;
sbit down_flag=flag^3;
sbit sw1=P3^0;
sbit sw2=P3^1;
int cck_cnt=-1;
int time=20,j;
int up_cnt=-1;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++)
;
}
void main()
{
int i;
IE=0x8A;
TMOD=0x10;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
for(i=0;i<2;i++)
{
TR0=1;//先開啟掃描線
bcd[3]=0;bcd[2]=7;bcd[1]=0;bcd[0]=4; delay_1ms(1000);
TR0=0;P2=0xff;delay_1ms(1000);//再關閉掃描線
}
TR0=1;
TR1=1;
cck_flag=1;
anti_cck_flag=0;
up_flag=1;
down_flag=0;
while(1)
{
if(sw1==0)
{
cck_flag=~cck_flag;
anti_cck_flag=~anti_cck_flag;
delay_1ms(50); while(sw1!=1); delay_1ms(50);
}
if(sw2==0)
{
up_flag=~up_flag;
down_flag=~down_flag;
delay_1ms(50); while(sw2!=1); delay_1ms(50);
}
}
}
void T0_int(void) interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
P1=seg_7_table[bcd[j]];
P2=scan_line[j];
j++;
if(j==4)
{
j=0;
}
}
void T1_int(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
time--;
if(time==0)
{
time=20;
if(cck_flag==1)
{
cck_cnt++;
if(cck_cnt>7){ cck_cnt=0;}
}
else if(anti_cck_flag==1)
{
cck_cnt--;
if(cck_cnt<0){cck_cnt=7; }
}
if(up_flag==1)
{
up_cnt++;
if(up_cnt>99)
{
up_cnt=0;
}
}
else if(down_flag==1)
{
up_cnt--;
if(up_cnt<0)
{
up_cnt=99;
}
}
bcd[3]=up_cnt/10;
bcd[2]=up_cnt%10;
if(cck_cnt==0){ bcd[1]=10 ; bcd[0]=16; }
if(cck_cnt==1){ bcd[1]=16 ; bcd[0]=10; }
if(cck_cnt==2){ bcd[1]=16 ; bcd[0]=11; }
if(cck_cnt==3){ bcd[1]=16 ; bcd[0]=12; }
if(cck_cnt==4){ bcd[1]=16 ; bcd[0]=13; }
if(cck_cnt==5){ bcd[1]=13 ; bcd[0]=16; }
if(cck_cnt==6){ bcd[1]=14 ; bcd[0]=16; }
if(cck_cnt==7){ bcd[1]=15 ; bcd[0]=16; }
}
}
沒有留言:
張貼留言