|
就是逐漸流水速度慢到快,現(xiàn)在只會(huì)用delay固定速度,無法做到開始由慢逐漸到快,PWM不知道怎么取值,想的效果是開始的時(shí)候慢到快暗道亮, 關(guān)的時(shí)候才會(huì)快到慢亮到暗,現(xiàn)在學(xué)寫的PWM只能控制一個(gè)燈無法融入到流水效果里面,同時(shí)速度也是 不知道怎么讓它慢到快并且保持住快,關(guān)的時(shí)候才會(huì)快到慢
#include <reg51.h>
sbit LED = P0;
unsigned char CYCLE;
unsigned char PWM_ON ;
void delay(unsigned int cnt)
{
while(--cnt);
}
main()
{
bit Flag;
TMOD |=0x01;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
IE= 0x82;
TR0=1;
CYCLE = 10;
while(!Flag)
{
delay(20000);
PWM_ON++;
if(PWM_ON == CYCLE)
}
void tim(void) interrupt 1 using 1
{
static unsigned char count;
TH0=(65536-100)/256;
TL0=(65536-100)%256;
if (count==PWM_ON)
{
LED = 1;
}
count++;
if(count == CYCLE)
{
count=0;
if(PWM_ON!=0)
LED = 0;
}
} |
|