?? 99秒.c
字號:
/*
1、程序目的:使用定時器學習計時
2、硬件要求:數碼管、晶振12M
*/
#include <reg52.h>
code unsigned char tab[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
//共陰數碼管 0-9
unsigned char Dis_Shiwei;//定義十位
unsigned char Dis_Gewei; //定義個位
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
TMOD |=0x01;//定時器設置 10ms in 12M crystal
TH0=0xd8;
TL0=0xf0;
IE= 0x82; //打開中斷
TR0=1;
while(1)
{
P0=Dis_Shiwei;//顯示十位
P2=0;
delay(300);//短暫延時
P0=Dis_Gewei; //顯示個位
P2=1;
delay(300);
}
}
/********************************/
/* 定時中斷 */
/********************************/
void tim(void) interrupt 1 using 1
{
static unsigned char second,count;
TH0=0xd8;//重新賦值
TL0=0xf0;
count++;
if (count==100)
{
count=0;
second++;//秒加1
if(second==100)
second=0;
Dis_Shiwei=tab[second/10];//十位顯示值處理
Dis_Gewei=tab[second%10]; //個位顯示處理
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -