新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 99秒计时+99秒倒计时(中断触发定时器)

99秒计时+99秒倒计时(中断触发定时器)

作者:时间:2012-09-04来源:网络收藏

主函数中的关于的控制位:

TMOD |=0x01; //模式选择
TH0=0xd8; //高8位
TL0=0xf0; //低8位
IE= 0x82; //打开
TR0=1; //打开定时开关(运行控制位,置“1”启动0)

TMOD |= 0x01; //使用模式1,16位定时器
TH0=0x00;
TL0=0x00;
EA=1; //总打开
ET0=1; //定时器中断打开
TR0=1; //定时器开关打开


*/

______________________________________________

功能:99秒

时间:2010—7—18

______________________________________________


#includereg52.h>


code unsigned char tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

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=99,count;
TH0=0xd8;
TL0=0xf0;
count++;
if (count==100)
{
count=0;
second--;
if(second==0)
{
second=99;
}
Dis_Shiwei=tab[second/10];
Dis_Gewei=tab[second%10];

}
}

红外遥控器相关文章:红外遥控器原理

上一页 1 2 下一页

评论


相关推荐

技术专区

关闭