89C51單片機(jī)40s倒記時(shí)數(shù)碼管動(dòng)態(tài)顯示
sbit buzz = P2^2;
sbit clear = P2^0;
sbit start = P2^1;
分別是喇叭,清除和開始 與gnd相連即可.
#include < reg51.h >
#include < intrins.h >
const unsigned char LED7Code[]={
0xC0, // 0
0xF9, // 1
0xA4, // 2
0xB0, // 3
0x99, // 4
0x92, // 5
0x82, // 6
0xF8, // 7
0x80, // 8
0x90, // 9
0x88, // A
0x83, // B
0xC6, // C
0xA1, // D
0x86, // E
0x8E // F
};
sbit buzz = P2^2;
sbit clear = P2^0;
sbit start = P2^1;
unsigned char count = 0;
unsigned char timer1s_flag;
unsigned char hw,lw;
unsigned char flag;
unsigned char clear_flag;
unsigned char start_flag;
//函數(shù)申明
void key_scna(void);
/*********************************************************/
void main()
{
TMOD=0x01 ;
TH0=0xed ;
TL0=0xff ;
EA=1;
ET0=1;
TR0=1 ;
while(1)
{
if(timer1s_flag>=200){
timer1s_flag = 0;
if((count>0)&&(count<=40)){
//count--;
hw=count/10;
lw=count%10;
P0=0XFF;
buzz=0;
}
else if(count==0){
hw=count/10;
lw=count%10;
count=42;
P0=0X00;
buzz=1;
}
count--;
}//500ms
//key_scan();
}
}
/*********************************************************/
// 定時(shí)器0中斷服務(wù)程序.
/*********************************************************/
void timer0() interrupt 1 using 2
{
TH0=0xee ;
TL0=0x04 ;
timer1s_flag++;
if(flag==0){
P3=0X40;
P1=LED7Code[hw];
flag = 1;
}
else{
P3=0X80;
P1=LED7Code[lw];
flag = 0;
}
}
/*********************************************************/
//按鍵掃描程序.
/*********************************************************/
void key_scna(void)
{
;
}
評論