#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
sbit dula=P2^6;
sbit wela=P2^7;
sbit output=P1^0;
uchar PERCENT=50;
uchar FLAG_F=0,FLAG_W=0;
uchar TIMER0_H,TIMER0_L,TIMER1_H,TIMER1_L;
uint FREQ=5000;
void time(uint sec)
{
uint i,j;
for(i=sec;i>0;i--)
for(j=110;j>0;j--);
}
void calculate_F()
{
TIMER0_H = (uint)(66536-10^6/FREQ)/256;
TIMER0_L = (uint)(65536-10^6/FREQ)%256;
}
void calculate_W()
{
float TEMP;
TEMP = 66536-(10^6*PERCENT)/(FREQ*100);
TIMER1_H = (uint)TEMP/256;
TIMER1_L = (uint)TEMP%256;
}
void keyscan()
{
if(key1==0)
{
time(10);//去抖
if(key1==0)
{
FLAG_F=1;
if(FREQ<1000)
FREQ+=10;
else
FREQ=1000;
}
}
if(key3==0)
{
time(10);//去抖
if(key3==0)
{
FLAG_F=1;
if(FREQ>100)
FREQ-=10;
else
FREQ=100;
}
}
if(key2==0)
{
time(10);
if(key2==0)
{
FLAG_W=1;
if(PERCENT<100)
PERCENT+=5;
else
PERCENT=100;
}
}
if(key4==0)
{
time(10);
if(key4==0)
{
FLAG_W=1;
if(PERCENT>0)
PERCENT-=5;
else
PERCENT=0;
}
}
}
void init() //设定初值
{
TMOD=0x11;
calculate_F();
calculate_W();
TH0=TIMER0_H;
TL0=TIMER0_L;
TH1=TIMER1_H;
TL1=TIMER1_L;
EA=1;
ET1=1;
ET0=1;
TR0=1;
TR1=1;
}
void main()
{
init();
while(1)
{
keyscan();
if(FLAG_F)
{
calculate_F();
calculate_W();
FLAG_F=0;
}
if(FLAG_W)
{
calculate_W();
FLAG_W=0;
}
}
}
void brea() interrupt 1
{
TH0=TIMER0_H;
TL0=TIMER0_L;
TR1=1;
output=1;
}
void brea_() interrupt 3
{
TH1=TIMER1_H;
TL1=TIMER1_L;
TR1=0;
output=0;
}
——————————————————————————————
这个在示波器上连频率都出不来咋整啊?
此帖出自
小平头技术问答
一周热门 更多>