利用定时⼀计数器T0从P1.0输出周期为100ms,脉宽为20ms的正脉冲信号,晶振频率为12MH

2025-04-28 06:38:46
推荐回答(1个)
回答1:

#include "reg51.h"

//timer init
void initTimer(void)
{
TMOD=0x1;
TH0=0xff;
TL0=0xec;
}

//timer0/counter0 interrupt
void timer0(void) interrupt 1
{
TH0=0xff;
TL0=0xec;
//add your code here.
P1^=1;
}

//the main fun
void main(void)
{
initTimer();
TR0=1;
ET0=1;
EA=1;
while(1)
{;}
}