//本机晶振11.0592,选用stc89c51单片机,P3.2 P3.3两个按键操控方波发生器的输出频率.
#include
#define uchar unsigned char
#define uint unsigned int
sbit output=P1^7; //输出点
sbit oneset=P3^2; //设置100HZ
sbit twoset=P3^3; //设置200HZ
uint number1=0; //定时器0高8位
uint number2=0; //定时器0低8位
void main()
{
TMOD=0x01;
TH0=0xee;//恣意设定初值
TL0=0x0b;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(oneset==0)//键值判别 oneset为100HZ 实践是100.027HZ略有差错
{number1=0xee;
number2=0x0b;
}
if(twoset==0) //键值判别twoset为200HZ 实践是200.143HZ略有差错
{
number1=0xf7;
number2=0x0b;
}
}
}
void init()interrupt 1
{
TH0=number1;
TL0=number2;
output=~output;
TR0=1;
}