|
#include <stc11.h>
#include <intrins.h>
sbit LED=P3^1;
void Timer0Init(void);
void main(void)
{
P3M0|=0x02; P3M1&=0xfd;
LED=1;
EA=1;
Timer0Init();
while(1);
}
void Timer0Init(void) //1毫秒@24MHz
{
AUXR &= 0x7F; //定時(shí)器時(shí)鐘12T模式
TMOD &= 0xF0; //清零T0的控制位
TMOD |= 0x01; //配置T0為模式1
TL0 = 0x30; //設(shè)置定時(shí)初值
TH0 = 0xF8; //設(shè)置定時(shí)初值
ET0=1;
TR0 = 1; //定時(shí)器0開始計(jì)時(shí)
}
void interruptTimer0() interrupt 1
{
static unsigned char cnt=0;
TL0 = 0x30; //設(shè)置定時(shí)初值
TH0 = 0xF8; //設(shè)置定時(shí)初
if(cnt<20)
{
LED=0;
cnt++;
}
else if(cnt<50)
{
LED=1;
cnt++;
}
else if(cnt==50)
{
cnt=0;
}
}
|
|