单片机使用12MHz晶振,用C51编写,实现用P2.0产生周期为2ms的方波信号

如题所述

第1个回答  2016-06-19
#include<reg51.h>
#define uchar unsigned char
sbit pluse=P2^0;
uchar num;
void t0isr() interrupt 1
{
num++;
num%=5;
if(num==0)pluse=~pluse;
}
main()
{
TMOD=0x02;
TH1=TL1=56;
TR0=1;
ET0=1;
EA=1;
while(1);
}本回答被网友采纳
第2个回答  2016-06-18
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit kai=P1^0;
int num;
void Timer0Init(void) //2ms@11.0592MHz
{
TMOD &= 0xF0; //???????
TMOD |= 0x01; //???????
TL1 = 0xcd;
TH1 = 0xf8;
TF0 = 0; //??TF0??
TR0 = 1;
}

void main()
{
Timer0Init();
EA=1;
ET0=1;
kai=0;
while(1)
{

}

}
void t0_() interrupt 1
{
TL1 = 0xcd;
TH1 = 0xf8;

}
相似回答