stm32 oled显示呼吸灯- #include "stm32f10x.h"
- #include "led.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "timer.h"
- #include "oled.h"
- int main(void)
- {
- u16 led0pwmval=0;
- u8 dir=1;
- delay_init(); //延时函数初始化
- OLED_Init();
- LED_Init(); //LED端口初始化
- TIM3_PWM_Init(899,0); //不分频。PWM频率=72000000/900=80Khz
- OLED_ColorTurn(0);//0正常显示,1 反色显示
- OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示
- while(1)
- {
- delay_ms(10);
- if(dir)led0pwmval++;
- else led0pwmval--;
- if(led0pwmval>300)dir=0;
- if(led0pwmval==0)dir=1;
- TIM_SetCompare2(TIM3,led0pwmval);
- OLED_Refresh();
- delay_ms(500);
- OLED_Clear();
- OLED_ShowString(0,0,"PWM:",16,1);
- OLED_ShowNum(40,0,led0pwmval,3,16,1);
- }
- }
复制代码
下载:
OLED显示呼吸灯.7z
(193.38 KB, 下载次数: 24)
|