#include <at89x52.h>
int P1table[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x02,0x04,0x08,0x10,0x20,0x40};
static const char P0table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int task;
int i,ii;
int anti_cck_i;
int pili_led_i;
int i=2;
int j=0;
int x=1;
int count;
int long_press=0;
int add=0;
sbit btn1=0xb2;//5.按下按鈕開始上數
sbit btn2=0xb3;//6.短按兩下按鈕暫停上數char count=0
sbit buzzer = 0XB7;
char bcd[2]={0,0};
char P2table[]={1,2};
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++)
{
P2=0XFE;P0=0XFE;delay_1ms(50);//亮a 個位數
P2=0XFD;P0=0XFE;delay_1ms(50); //亮a十位數
P2=0XFB;P0=0XFE;delay_1ms(50); //亮a百位數
P2=0XF7;P0=0XFE;delay_1ms(50); //亮a千位數
P2=0XF7;P0=0XDF;delay_1ms(50); //亮f千位數
P2=0XF7;P0=0XEF;delay_1ms(50); //亮e千位數
P2=0XF7;P0=0XF7;delay_1ms(50); //亮d千位數
P2=0XFB;P0=0XF7;delay_1ms(50); //亮d百位數
P2=0XFD;P0=0XF7;delay_1ms(50); //亮d十位數
P2=0XFE;P0=0XF7;delay_1ms(50); //亮d個位數
P2=0XFE;P0=0XFB;delay_1ms(50); //亮c個位數
P2=0XFE;P0=0XFD;delay_1ms(50); //亮b個位數
}
P2=0XFE;P0=0XFE;delay_1ms(50); //亮a個位數
}
void task2_8LED_rotate3()
{
for(ii=0;ii<3;ii++)
{
for(pili_led_i=0;pili_led_i<14;pili_led_i++)
{
P1=~P1table[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 task4_mode0()
{
while(1)
{
P0=P0table[0];P2=~P2table[0];
P0=P0table[0];P2=~P2table[1];
if(btn1==0) break;
}
}
void task5_increase_counter()
{
TR0=1;
TR1=1;
}
void task6_pasuse()
{
TR1=0;
}
void main()
{
int task=1;
IE=0x8a;
TMOD=0x10;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=0;
TR1=0;
while(1)
{
if(task==1)
{
P0=~0xFF;P2=0XFF;
task1_seg7_rotate3_cck();
P0=~0xFF;P2=0XFF;
task=2;
}
else if(task==2)
{
task2_8LED_rotate3();
P1=~0x80;delay_1ms(500);P1=0xFF;
task=3;
}
else if(task==3)
{
int i;
for(i=0;i<3;i++)
{
task3_buzzer_beep3(100,1,1);delay_1ms(10);
}
task=4;
}
else if(task==4)
{
task4_mode0();
task=5;
}
else if(task==5)
{
if(btn1==0)
task5_increase_counter();//按下第1個按鈕, 決定上數
//task=100;//設100是因為壓按鍵2,再壓按鍵1沒有作用
}
else if(task==6)
{
TR1=0;
//task6_pasuse();
}
}
}
void T0_int(void) interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
if(btn2==0) //按下第2個按鈕, 要判斷 2短按 1短按, 表示 Pause 還是 Resume
{
add++;
delay_1ms(50);while(btn2==0);
if(add % 2==0){TR1=0;}//取mod奇數為繼續數,偶數為暫停
if(add % 2==1){TR1=1;}
}
P0=P0table[ bcd[j] ];
P2=~P2table[j];
j++;
if(j==2)
j=0;
}
void T1_int(void) interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
i = i-1;
if(i==0)
{
i=2;
count++;
if(count==100)
count=0;
bcd[1]=count/10;
bcd[0]=count%10;
}
}
沒有留言:
張貼留言