#include <at89x52.h>
#define key_mode 0x20 //增加一個按鍵P3.5
#define key_start 0x40
#define key_pause 0x80
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 count=0;
char k=0;
int time=0;
char Trg;
char Cont;
unsigned char zero_cnt;
sbit buzzer = P3^2;
bit mode_flag;
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 KeyRead()
{
unsigned char ReadData = P3^0xff; // 1
ReadData &= 0xe0; //按鍵只讀取 P3.6 及 P3.7
/*
11000000 11000000
&)10000000 &01000000
10000000 01000000
*/
Trg = ReadData & (ReadData ^ Cont); // 2
Cont = ReadData; // 3
/*
不是0x80不然就是0x40
*/
}
void KeyProc()
{
if(Trg & key_mode)
{
mode_flag=~mode_flag;
if( mode_flag){TR0=1;TR1=1;}
else {TR0=0;TR1=0;P1=0xfe;P0=0xc0;}
}
if(Trg & key_start) TR1=1;
/*按一次開始計數 P3.6 0x40 & 0x40 =0x40*/
if(Trg & key_pause)
/*按一次開始計數 P3.7 0x80 & 0x80=0x80*/
{ //短按兩次停止計數
TR1=1;
k++;
if(k == 2)
TR1=0;
}
if(!Trg & !Cont) //按一次放開後 k 為零
{
zero_cnt++;
if(zero_cnt>10)
{
zero_cnt=0;
k=0;;
}
}
if (Cont & key_pause)
{
zero_cnt++;
if(zero_cnt>50)
{
zero_cnt=0;
TR1=0;
count=0;
bcd[1]=0;
bcd[0]=0;
}
}
}
void main()
{
init();
P3=0xFF;
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)
{
delay_1ms(80); //防止按鍵彈跳,delay時間配合短按兩下的時間調整
KeyRead();
KeyProc();
}
}
}
2019年11月17日 星期日
訂閱:
張貼留言 (Atom)
algorithm
#include <iostream> #include <string.h> using namespace std; int main(int argc, char** argv) { for(int j=2;j<=100;j++)//j...
-
本文旨在補充《 超圖解Arduino互動設計入門 》第18章「RFID無線識別裝置與問答遊戲製作」單元,書本採用的RFID讀卡機模組是採用9600bps, TTL序列通訊介面,RFID的通訊頻率為125KHz。這種模組的接線和程式都很簡單,每當感測到RFID卡,讀卡機就把...
-
3.Keil C 幫我們寫好 程式:#include <reg51.h> vs c語言 #include <stdio.h> //幫您宣告 P0=0x80 有相對的記憶體以十六進位表示,它定義定reg51.h,我們直接拿來用他的代碼即可 P1=0...
-
/* 多重按鈕開關 */ //==宣告區================================ #include // 定義8051暫存器之標頭檔,P2-17~19 #include "myio.h" // 自己寫的I/O程式庫 sbit PB...
沒有留言:
張貼留言