51單片機(jī)方波發(fā)生器程序100HZ和200HZ按鍵控制
#include
#define uchar unsigned char
#define uint unsigned int
sbit output=P1^7; //輸出點(diǎn)
sbit oneset=P3^2; //設(shè)置100HZ
sbit twoset=P3^3; //設(shè)置200HZ
uint number1=0; //定時器0高8位
uint number2=0; //定時器0低8位
void main()
{
TMOD=0x01;
TH0=0xee;//任意設(shè)定初值
TL0=0x0b;
EA=1;
ET0=1;
TR0=1;
while(1)
{
if(oneset==0)//鍵值判斷 oneset為100HZ 實(shí)際是100.027HZ略有誤差
{number1=0xee;
number2=0x0b;
}
if(twoset==0) //鍵值判斷twoset為200HZ 實(shí)際是200.143HZ略有誤差
{
number1=0xf7;
number2=0x0b;
}
}
}
void init()interrupt 1
{
TH0=number1;
TL0=number2;
output=~output;
TR0=1;
}
評論