pwm控制的流水灯!很不错
时间:10-02
整理:3721RD
点击:
- #include
- #include
- #define LED_PORT P1
- #define TIMER_BEGIN 0xe333; //4ms
- const int inc_timer_count=0x001d;
- unsigned char code game[16]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x18,0x24,0x42,0x81,0x03,0x0c,0x30,0xc0};
- volatile unsigned int pre_time_set=0;
- void init_timer0();
- void modi_timer0();
- void main()
- {
- init_timer0();
- while (1);
- }
- void init_timer0()
- {
- TR0=0;
- EA=0;
- TMOD=0x01;
- TL0=0x33;
- TH0=0XE3;
-
- ET0=1;
- EA=1;
- TR0=1;
- }
- void modi_timer0()
- { static bit c_state=0;//当前状态
- static unsigned int proc_count=0; //处理次数
- static unsigned int timer0_high=0;
- static unsigned int timer0_low=0;
- static unsigned char cur_proc_led=0;
- TR0=0;
- if (!proc_count)
- {
- timer0_high=TIMER_BEGIN;
- timer0_low=0x0ffff;
- }
- if (c_state) //高电平
- {
- timer0_high=timer0_high+inc_timer_count;
- TH0=(timer0_high )>>8;
- TL0=(timer0_high)&0x00ff;
- LED_PORT=0xff;
- }
- else
- {
- timer0_low=timer0_low-inc_timer_count;
- TH0=(timer0_low )>>8;
- TL0=(timer0_low)&0x00ff;
- LED_PORT=game[cur_proc_led];
- }
- TR0=1;
- c_state=~c_state;
- if (++proc_count==500)
- { proc_count=0;
- if (++cur_proc_led==16)
- cur_proc_led=0;
- }
- }
- void time0(void ) interrupt 1 using 1//定时器T0中断。
- {
- modi_timer0();
- }
PWM亮度控制!
![](../imgqa/ele/mcu/mcu-3721rd.com-34383e41j0drnglc.gif)
很好,很强大
很好,牛x呀
pwm 也能这样玩,学习
我也想学习一下昂。多谢了。