#include <at89x52.h>
char P0table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
char P2table[]={0xfe,0xfd};
char pili_led[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};//0-14
char bcd[]={0,0};
char bdata flag;
sbit up_flag=flag^0;
sbit down_flag=flag^1;
int j;
int time=20;
int count=0;
sbit btn1=P3^0;
sbit bz=P3^1;
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
for(j=0;j<114;j++)
;
}
void beep(int count,int TH,int TL)
{
int i;
for(i=0;i<count;i++)
{
bz=0;delay_1ms(TH);
bz=1;delay_1ms(TL);
}
}
void init()
{
int i;
int j;
for(j=0;j<3;j++)
{
for(i=0;i<16;i++)
{
P1=~pili_led[i];delay_1ms(50);
}
}
for(i=0;i<3;i++)
{
beep(100,1,1);delay_1ms(1000);
}
}
main()
{
init();
IE=0x8A;
TMOD=0x10;
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
TR0=1;
TR1=0;
up_flag=0;
down_flag=1;
while(1)
{
if(btn1==0)
{
delay_1ms(20);while(btn1!=1);delay_1ms(20);
TR1=1;up_flag=~up_flag;down_flag=~down_flag;
}
}
}
void T0_int(void) interrupt 1
{
TH0=(8192-5000)/32;
TL0=(8192-5000)%32;
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;
time--;
if(time==0)
{
time=20;
if(up_flag)
{
count++;
if(count>99) count=0;
}
else if(down_flag)
{
count--;
if(count<0) count=99;
}
bcd[0]=count%10;
bcd[1]=count/10;
}
}
2020年7月1日 星期三
訂閱:
張貼留言 (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...
沒有留言:
張貼留言