|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
- #include "reg52.h"
- typedef unsigned char u8;
- typedef unsigned int u16;
- ***it LED = P2^0;
- u16 timer1, count, value;
- bit flag;
- void TimeInit()//¶¨Ê±1us
- {
- TMOD |= 0x10;
- TH1 = 0xFF;
- TL1 = 0xFF;
- TR1 = 1;
- EA = 1;
- ET1 = 1;
- }
- void main()
- {
- LED = 1;
- timer1 = 0;
- count = 0;
- value = 0;
- flag = 0;
- TimeInit();
- while(1);
- }
- void Time() interrupt 2
- {
- TH1 = 0xFF;
- TL1 = 0xFF;
- //while(1)
- // {
- timer1++;
- count++;
- if(timer1 == 1000)
- {
- timer1 = 0;
- LED = 1;
- }
- if(count == 100)
- {
- count = 0;
- if(flag == 0)
- {
- value++;
- }
- if(flag == 1)
- {
- value--;
- }
- }
- if(value == 1000)
- {
- flag = 1;
- }
- if(value == 0)
- {
- flag = 0;
- }
- if(value > timer1)
- {
- LED = 0;
- }
- else
- {
- LED = 1;
- }
- // }
- }
! h& o! {# w7 Z9 ~7 D: [# l. [& | ) L" t) j e* G+ y( P" x3 i
复制代码" F/ Q4 p/ g) q y! v6 D, }1 M
& _2 }! \- c) b- ~9 \. n3 \ 这是我编写的PWM呼吸灯程序,但是只有在中断里面加上while(1)循环他才能呼吸。没有这个while直接就不亮了,但我看别人的呼吸灯函数中断内没有while循环也能呼吸,这是为什么?
, ^; C6 u% ^! Z7 ? 还有一个问题,加上while循环后的呼吸灯在逐渐变暗的时候“灯亮灭的抖动”明显,怎么能让他看起来流畅一点。0 W. b& A3 S* V4 `9 a O9 ^8 T
|
|