#include<reg51.h>
unsigned char pwhh,pwhl,pwlh,pwll
bit flag
sbit pwm=P1^0
void t0isr() interrupt 1
{
if(flag)
{
TH0=pwhh
TL0=pwhl
}
else
{
TH0=pwlh
TL0=pwll
}
pwm=~pwm
}
main()
{
TMOD=0x01
pwhh=(65536-1000)/256
pwhl=(65536-1000)%256
pwlh=(65536-500)/256
pwll=(65536-500)%256
TH0=pwhh
L0=pwhl
TR0=1
ET0=1
EA=1
while(1)
}
#include <reg52.h >#define uchar unsigned char
#define uint unsigned int
sbit s2=P3^7
sbit s3=P3^6
sbit fm=P2^3
uchar pwm,num
void delay(uint ms)
{
uchar i
while(ms--)
{
for(i=0i<120i++)
}
}
void keyscan()
{
if(s2==0)
{
delay(80)
if(s2==0)
{
if(pwm<32)
{
pwm++
delay(150)
}
else //如果禅纳冲大于32 蜂鸣器想茄桐
{
bee( )
}
}
}
if(s3==0)
{
delay(80)
if(s3==0)
{
if(pwm>1)
{
pwm--
delay(50)
}
else //如贺歼果小于1 蜂鸣器想
{
bee( )
}
}
}
}
void init_t0( )
{
TMOD=0x01
TH0=(65536-500)/256 //500ms
TL0=(65536-500)%256
EA=1
ET0=1
TR0=1
}
void t0( ) interrupt 1
{
TR0=0//关计时器
TH0=(65536-500)/256
TL0=(65536-500)%256
num++
if(num>32)
{
num=0
}
if(num<=pwm )
{
P1=0xff
}
else
{
P1=0x00
}
TR0=1
}
void main( )
{
init_t0( )
num=0
pwm=0
while(1)
{
keyscan()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)