#include <reg52.h>
#define uchar unsigned char
sbit p11=P1^1;
code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar shiwei;
uchar gewei;
void delay(unsigned int cnt)
{
while(--cnt);
}
void main()
{
TMOD|=0x01;
TH0=0xd8;
TL0=0xf0;
IE=0x82; //這里是中斷優先級控制EA=1(開總中斷),ET0=1(定時器0允許中斷),這里用定時器0來定時
TR0=1; //開定時器0
while(1)
{
P0=shiwei; //99的十位
P2=0; //99的個位,
delay(300); //動態掃描數碼管延時
P0=gewei;
P2=1;
delay(300);
}
}
void tim(void) interrupt 1 using 1 //定時器0中斷
{
static uchar second=99,count; //99只是一個數,可以任意改,因為這里只學習怎樣實現倒計時
TH0=0xd8; //定時10毫秒
TL0=0xf0;
count++;
if(count==100) //10毫秒定時,10*100=1000(毫秒)=1秒
{
count=0;
second--;
if(second==0)
{
p11=0; //這里讓繼電器動作,當然動作之后,要復位才能等下次倒定時再動作。
second=99; //回到99再循環來,當然,可以做其他的控制,
}
shiwei=tab[second/10]; //數碼管10位
gewei=tab[second%10]; //數碼管個位
}
}
大神們 我想在開發板上做一個倒計時 網上找的這個程序 運行也沒問題 可是連線不會。。。開發板用的是東方藍芯 程序其實看的的也不懂 真心希望有大神能夠給給我講講
|