?? 99秒倒計(jì)時(shí).c
字號(hào):
/*-----------------------------------------------
名稱:99秒倒計(jì)時(shí)器
日期:2009.5
修改:無(wú)
內(nèi)容:通過(guò)定時(shí)器倒計(jì)時(shí)
------------------------------------------------*/
#include<reg52.h> //包含頭文件,一般情況不需要改動(dòng),頭文件包含特殊功能寄存器的定義
code unsigned char tab[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共陰數(shù)碼管 0-9
unsigned char Dis_Shiwei;//定義十位
unsigned char Dis_Gewei; //定義個(gè)位
/******************************************************************/
/* 延時(shí)函數(shù) */
/******************************************************************/
void delay(unsigned int cnt)
{
while(--cnt);
}
/******************************************************************/
/* 主函數(shù) */
/******************************************************************/
main()
{
TMOD |=0x01;//定時(shí)器設(shè)置 10ms in 12M crystal,工作在模式1,16位定時(shí)
TH0=0xd8;
TL0=0xf0;
IE= 0x82; //打開(kāi)中斷
TR0=1; //打開(kāi)定時(shí)開(kāi)關(guān)
while(1)
{
P0=Dis_Shiwei;//顯示十位
P2=0;
delay(300); //短暫延時(shí)
P0=Dis_Gewei; //顯示個(gè)位
P2=1;
delay(300);
}
}
/******************************************************************/
/* 定時(shí)器中斷函數(shù) */
/******************************************************************/
void tim(void) interrupt 1 using 1
{
static unsigned char second=99,count; //初值99
TH0=0xd8; //重新賦值
TL0=0xf0;
count++;
if (count==100)
{
count=0;
second--;//秒減1
if(second==0)
{ //這里添加定時(shí)到0的代碼 ,可以是燈電路,繼電器吸合等,或者執(zhí)行一個(gè)程序
second=99; //減到0是重新賦值99
}
Dis_Shiwei=tab[second/10];//十位顯示值處理
Dis_Gewei=tab[second%10]; //個(gè)位顯示處理
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -