移植实操
国民技术提供大量程序,在\Nationstech.N32G4FR_Library.2.1.0\projects\n32g4fr_EVAL\examples\RT_Thread\RT_Thread17_Finsh基础简单增加就很容易编程修改。
原来代码led亮度软件pwm
//GPIO模拟PWM的实体
1. void pwm_entry(void* p) {
1. uint8_t count;
1. while(1) {
1. //设定脉宽200ms
1. count++;
1. count %=10;
1. rt_thread_mdelay(1);
1. //模拟pwm比较
1. //红色的pwm输出
1. if (a_v==5) {
1. if( count>=a) {
1. rt_pin_write(pin_r, PIN_LOW);
1. }
1. else {
1. rt_pin_write(pin_r,PIN_HIGH);
1. }
1. } else {
1. rt_pin_write(pin_r,PIN_HIGH);
1. }
1.
1. //绿色的PWM输出
1. if (b_v==5) {
1. if(count>=b)
1. {
1. rt_pin_write(pin_g, PIN_LOW);
1. }
1. else {
1. rt_pin_write(pin_g,PIN_HIGH);
1. }
1. } else {
1. rt_pin_write(pin_g,PIN_HIGH);
1. }
1.
1. //蓝色的pwm输出
1. if (c_v==5) {
1. if(count>=c)
1. {
1. rt_pin_write(pin_b, PIN_LOW);
1. }
1. else {
1. rt_pin_write(pin_b,PIN_HIGH);
1. }
1. } else {
1. rt_pin_write(pin_b,PIN_HIGH);
1. }
1. }
1. }
现在用TIM1,TIM3,硬件pwm_
void pwm_entry(void* p) {
while(1) {
for (int var1 = 0; var1 < 4; ++var1) {
a_v=((rgb1>>var1 ) & 1) * 5;
b_v=((rgb1>>var1 + 4 ) & 1) * 5;
c_v=((rgb1>>var1+8 ) & 1) * 5;
if (a_v==5) {TIM_Intial(TIM1,a,'r');
} else {TIM_Intial(TIM1,0,'r');
}
if (b_v==5) {TIM_Intial(TIM3,b,'g');
} else {TIM_Intial(TIM3,0,'g');
}
if (c_v==5) {TIM_Intial(TIM3,c,'b');
} else {TIM_Intial(TIM3,0,'b');
}
rt_thread_mdelay(25);
}
}
RTC_增加RTC_ConfigSmoothCalib(SMOOTH_CALIB_32SEC,
RTC_SMOOTH_CALIB_PLUS_PULSES_SET,
use)校准。
软I2C显示lcd
ADC显示value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
UART系统调试
新旧文件:*附件:新.rar
(P E.0)输出,( ADC1 的第 11(2)个通道, 18 PA2 (Pa1 17)脚 )模拟输入,)模拟输入,板(Pa8 Pb5 Pb4)输出LED,OLED_I2C1输出GPIOB GPIO_PIN_8 GPIO_PIN_9,板(Pa4-6)button,P E.0来通过光耦中间继电器控制加热设备。 pin_r Pa8 pin_g =Pb5 pin_b Pb4
线程:
pwm_entry
key_thread_entry
DF_A
DF_B
test1_thread_entry