標(biāo)題:
51單片機(jī)PWM呼吸燈
[打印本頁(yè)]
作者:
wj159357
時(shí)間:
2019-11-21 08:48
標(biāo)題:
51單片機(jī)PWM呼吸燈
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit PWM=P0^0;
bit DIR;
uint count,value,timer1;
void Timer1Init()
{
TMOD|=0x01;
TH1=0xff;
TL1=0xff;
EA=1;
ET1=1;
TR1=1;
}
void main()
{
Timer1Init();
while(1)
{
if(count>100)
{
count=0;
if(DIR==1)
{
value++;
}
if(DIR==0)
{
value--;
}
}
if(value==1000)
{
DIR=0;
}
if(value==0)
{
DIR=1;
}
if(timer1>1000)
{
timer1=0;
}
if(timer1<value)
{
PWM=1;
}
else
{
PWM=0;
}
}
}
void Time1(void) interrupt 3
{
TH1=0xff;
TL1=0xff;
timer1++;
count++;
}
作者:
2972905150ttp
時(shí)間:
2024-2-7 12:02
太快了,閃爍得慢一些怎么調(diào)
作者:
紅了腳丫
時(shí)間:
2024-4-29 08:29
2972905150ttp 發(fā)表于 2024-2-7 12:02
太快了,閃爍得慢一些怎么調(diào)
調(diào)count值方便點(diǎn)
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1