设MCS-51的单片机时钟频率为12Mhz请编写程序在P1.7脚输出周期为1s,脉宽为1ms的脉

设MCS-51的单片机时钟频率为12Mhz,y用定时/计数器T0编制在P1.7引脚上产生周期为1s,占空比为50%的连续方波信号的程序

第1个回答  2018-12-21
#include<reg51.h>
#define uchar unsigned chr
#define uint unsigned int
uint cnt;
sbit pluse=P1^7;
void t0isr() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
cnt++;
cnt%=1000;
if(cnt<1)pluse=1;
else pluse=0;
}
main()
{
TMOD=0x01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
ET0=1;
EA=1;
while(1);
}

本回答被网友采纳
第2个回答  2018-12-20
153