#include <at89x52.h>
int P2table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x10,0x20,0x40};
char const P0table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char bdata flag;
sbit Mode0_flag=flag^0;
sbit Mode1_flag=flag^1;
sbit up_flag=flag^2;
int task;
int anti_cck_i;
int pili_led_i;
int i=2;
int ii;
int j=0;
int L_btn_f1=0;
int count=0;
char k=0;
int time=0;
unsigned char zero_cnt;
sbit L_btn=P3^6;//5.按下按鈕開始上數
sbit R_btn=P3^7;//6.短按兩下按鈕暫停上數char count=0
sbit buzzer = P3^5;
char bcd[2]={0,0};
char P1table[]={0xFE,0xfD,0xFF};
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<110;j++)
;
}
void task1_seg7_rotate3_cck()//逆時針左旋三次
{
for(anti_cck_i=0;anti_cck_i<3;anti_cck_i++)
{
P1=0XFE;P0=0XFE;delay_1ms(50);//亮a 個位數
P1=0XFD;P0=0XFE;delay_1ms(50); //亮a十位數
P1=0XFB;P0=0XFE;delay_1ms(50); //亮a百位數
P1=0XF7;P0=0XFE;delay_1ms(50); //亮a千位數
P1=0XF7;P0=0XDF;delay_1ms(50); //亮f千位數
P1=0XF7;P0=0XEF;delay_1ms(50); //亮e千位數
P1=0XF7;P0=0XF7;delay_1ms(50); //亮d千位數
P1=0XFB;P0=0XF7;delay_1ms(50); //亮d百位數
P1=0XFD;P0=0XF7;delay_1ms(50); //亮d十位數
P1=0XFE;P0=0XF7;delay_1ms(50); //亮d個位數
P1=0XFE;P0=0XFB;delay_1ms(50); //亮c個位數
P1=0XFE;P0=0XFD;delay_1ms(50); //亮b個位數
}
P1=0XFE;P0=0XFE;delay_1ms(500); //亮a個位數
}
void task2_8LED_rotate3()
{
for(ii=0;ii<3;ii++)
{
for(pili_led_i=0;pili_led_i<14;pili_led_i++)
{
P2=~P2table[pili_led_i];delay_1ms(50);
}
}
}
void task3_buzzer_beep3(int count,int TH,int TL)
{
int i;
for(i=0;i<count;i++)
{
buzzer=0;
delay_1ms(TL);
buzzer=1;
delay_1ms(TH);
}
}
void init()
{
int task=1;//接龍
if(task==1)
{
P0=~0xFF;P1=0XFF;
task1_seg7_rotate3_cck();//逆時針轉三圈
P0=~0xFF;P1=0XFF;//結束把七段及掃瞄OFF
task=2;
}
if(task==2)
{
task2_8LED_rotate3();
P2=~0x80;delay_1ms(500);P2=0xFF;
task=3;
}
if(task==3)
{
int i;
for(i=0;i<3;i++)
{
task3_buzzer_beep3(100,1,1);delay_1ms(10);
}
}
}
void T0_int(void) interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
P0=P0table[ bcd[j] ];
P1=P1table[j];
j++;
if(j==2) j=0;
}
void T1_int(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
time++;
if(time %2==0)
{
count++;
if(count==100) count=0;
bcd[1]=count/10;
bcd[0]=count%10;
}
}
void main()
{
init();
IE=0x8A;
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
Mode0_flag=1;
TR0=1; TR1=0;
while(1)
{
if(Mode0_flag==1)
{
if(L_btn==0)
{
TR1=1;
zero_cnt++;
if(zero_cnt>200) //200增減可改變長按時間
{
zero_cnt=0;
TR1=0;
count=0;
bcd[1]=0;
bcd[0]=0;
}
else if(zero_cnt<200)
{
k++;delay_1ms(20);
if(k==2)k=0;
}
}
if(k%1==1){TR1=1;}
if(k%2 ==0 ) { TR1=0; }
}
}
}
沒有留言:
張貼留言