/* 遗憾的是不能产生标准38kHz频率的方波,有点误差*/
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit Waveout=P1^0; //P1.0口输出方波
uchar
void main()
{
TMOD=0x01; //定时器0方式1
TH0=0xFF; ///由于晶振是11.0592MHz,每个机器周期约是1.09us,38kHz是26.3us产生一个方波,26.3/1.09需要计数24次,因而TH0=(65536-24)/256=255,即0xff
TL0=0xE8; //TL0=(65536-24)%256=232,即E8
EA=1;
ET0=1;
TR0=1;
while(1);
}
void T0_time() interrupt 1
{
TH0=0xFF;
TL0=0xE8;
Waveout=!Waveout;
}
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit Waveout=P1^0; //P1.0口输出方波
uchar
void main()
{
TMOD=0x01; //定时器0方式1
TH0=0xFF; ///由于晶振是11.0592MHz,每个机器周期约是1.09us,38kHz是26.3us产生一个方波,26.3/1.09需要计数24次,因而TH0=(65536-24)/256=255,即0xff
TL0=0xE8; //TL0=(65536-24)%256=232,即E8
EA=1;
ET0=1;
TR0=1;
while(1);
}
void T0_time() interrupt 1
{
TH0=0xFF;
TL0=0xE8;
Waveout=!Waveout;
}