找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2846|回复: 1
收起左侧

STM32红外舵机自动壁障小车源程序

[复制链接]
ID:303826 发表于 2018-4-8 17:37 | 显示全部楼层 |阅读模式
基于STM32的红外舵机自动壁障小车

单片机源程序如下:
  1. #include "stm32f10x_it.h"
  2. #include "stm32f10x_lib.h"
  3. #include "stm32f10x_type.h"
  4. #include "stm32f10x_usart.h"
  5. #include "defines.h"
  6. #include "stm32f10x_flash.h"
  7. #include "cpu.h"

  8. #include <stdio.h>


  9. #define  FLASH_ADDRESS   (0x08000000 + 1024 * 32 - 4096)  /* 存储数据Flash页首地址 */

  10. #define DUTY_WIDTH 25  //占空比最大级数
  11. #define CAR_QIAN_JIN 0 //小车前进
  12. #define CAR_HOU_TUI  1 //小车后退


  13. u8 debug_switch = 0;//调试开关
  14. u32 IR_ref_value_L = 0;//红外感应参考值,开机前将小车置于空旷位置,系统便于识别环境光强度
  15. u32 IR_ref_value_R = 0;//红外感应参考值,开机前将小车置于空旷位置,系统便于识别环境光强度

  16. u8 moto_run = 0;//电机运行标志
  17. u8 moto_R_speed = 0;//电机速度
  18. u8 moto_R_dir   = CAR_QIAN_JIN;//电机方向
  19. u8 moto_L_speed = 0;//电机速度
  20. u8 moto_L_dir   = CAR_QIAN_JIN;//电机方向
  21. u8 moto_speed   = 0;//电机前进的速度
  22. s8 moto_speed_adj = 1;//左右电机速度校正,-3~+3,已左边轮子速度为基准,在右边轮子速度加校正值

  23. //u32 TIME_L_R  = (TIMER_FREQ / 3);//转弯时间,完成后自动归正
  24. u8 moto_L_switch = 0;//左转有效
  25. u8 moto_R_switch = 0;//右转有效


  26. u32 left_turn_cnt = 0;        //转弯时间定时器
  27. u32 right_turn_cnt = 0;        //转弯时间定时器

  28. u32 b_led_cnt = 0;//刹车灯时间定时器
  29. u32 beep_cnt = 0;//喇叭时间定时器,ms

  30. u8 lamp_front_bright = 0; //大灯亮度
  31. u8 lamp_f = 0; //大灯开关切换

  32. void Lamp_front(u8 de);


  33. /***********************************************************************
  34. 函数功能: 写flash,数据长度不超过1扇区
  35. 入口参数:
  36. 出口参数:
  37. ***********************************************************************/
  38. void WriteFlash(u32 byte_addr , u16 len , u8 *dat)
  39. {
  40.         u16 i = 0;

  41.         len = len / 2 * 2 + (len % 2) * 2;

  42.         FLASH_Unlock();
  43.         FLASH_ErasePage(byte_addr);                  /* 擦除页 */
  44.         //FLASH_ProgramWord(FLASH_ADR,0 << 1 | 0);   /* 写16位半字 */
  45.         for(i = 0 ; i < len ; i += 2)
  46.         {
  47.                 FLASH_ProgramHalfWord(byte_addr + i , *(u16*)&dat[i]);   /* 写16位半字 */
  48.         }

  49.         FLASH_Lock();
  50. }
  51. /***********************************************************************
  52. 函数功能:延时_dlytime毫秒
  53. 入口参数:
  54. 出口参数:
  55. ***********************************************************************/
  56. void Delay_ms(u32 _dlytime)
  57. {
  58.         u32 i;
  59.         u32 j;

  60.         for (i = 0; i < _dlytime * 10; i++)
  61.                 for (j = 0; j < 0xff; j++);       
  62. }
  63. /***********************************************************************
  64. 函数功能:延时
  65. 入口参数:
  66. 出口参数:
  67. ***********************************************************************/
  68. void Delay(u32 _dlytime)
  69. {
  70.         u32 i;
  71.         u32 j;

  72.         for (i = 0; i < _dlytime * 1; i++)
  73.                 for (j = 0; j < 0x13; j++);       
  74. }
  75. /***********************************************************************
  76. 函数功能:获取AD值
  77. 入口参数:
  78. 出口参数:
  79. ***********************************************************************/
  80. u16 GetADCVal(u8 ADC_Channel)
  81. {       
  82.         ADC_RegularChannelConfig(ADC1, ADC_Channel, 1, ADC_SampleTime_239Cycles5);
  83.        
  84.         /* Start ADC1 Software Conversion */
  85.         ADC_SoftwareStartConvCmd(ADC1, ENABLE);

  86.         while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);

  87.         return ADC_GetConversionValue(ADC1);
  88. }
  89. /***********************************************************************
  90. 函数功能:判断左侧是否有障碍物
  91. 入口参数:
  92. 出口参数: 1:有障碍,
  93. ***********************************************************************/
  94. u8 CheckHinder_Left()
  95. {
  96.         u16 adc = 0 , avg = 0;
  97.         static u32 adc_temp = 0 , times = 0;

  98.         adc = GetADCVal(ADC_Channel_5);
  99.                
  100.         adc_temp += adc;
  101.         times ++;

  102.         if(adc > IR_ref_value_L + 350)
  103.          return 1;

  104.         avg = (adc_temp / times); //获取平均值

  105.         if(adc > avg + 60)//如果当前值大于平均值较多,也认为是有障碍
  106.                 return 2;

  107.         return 0;
  108. }
  109. /***********************************************************************
  110. 函数功能:判断右侧是否有障碍物
  111. 入口参数:
  112. 出口参数: 1:有障碍,
  113. ***********************************************************************/
  114. u8 CheckHinder_Right()
  115. {
  116.         u16 adc = 0 , avg = 0;
  117.         static u32 adc_temp = 0 , times = 0;

  118.         adc = GetADCVal(ADC_Channel_4);
  119.                
  120.         adc_temp += adc;
  121.         times ++;

  122.         if(adc > IR_ref_value_R + 150)
  123.          return 1;

  124.         avg = (adc_temp / times); //获取平均值

  125.         if(adc > avg + 50)//如果当前值大于平均值较多,也认为是有障碍
  126.                 return 2;

  127.         return 0;
  128. }
  129. /***********************************************************************
  130. 函数功能:向串口发数据
  131. 入口参数:
  132. 出口参数:
  133. ***********************************************************************/
  134. void SendDataToUart(u8 dat)
  135. {
  136.         UART1_SendByte(dat);       
  137. }
  138. /***********************************************************************
  139. 函数功能:发送数据
  140. 入口参数:
  141. 出口参数:
  142. ***********************************************************************/
  143. void SendStrToUart(char*str)
  144. {
  145.         while(*str)
  146.         {
  147.                 SendDataToUart(*str ++);
  148.         }
  149. }
  150. /***********************************************************************
  151. 函数功能:
  152. 入口参数:
  153. 出口参数:
  154. ***********************************************************************/
  155. void Timer2ISR(void)
  156. {
  157.         static u32 cnt = 0 , st = 0 , cnt_t = 0 , beep_freq_cnt = 0 , beep_freq = 1000 ;       
  158.         static u8 b = 0 , l_r_led = 0;
  159.         static u32 l_r_led_cnt = 0;//转弯灯时间定时器
  160.         u32 audio_adc_val = 0;

  161.         //

  162.         if(cnt < DUTY_WIDTH)//占空比计数
  163.         {
  164.                 cnt ++;
  165.         }
  166.         else
  167.         {
  168.                 cnt = 0;
  169.         }


  170.         GPIO_WriteBit(GPIOC , GPIO_Pin_13 , l_r_led); //cpu状态指示灯
  171.         GPIO_WriteBit(GPIOB, GPIO_Pin_2 , l_r_led);


  172.         //刹车灯控制       
  173.                 if(b_led_cnt < TIMER_FREQ / 2)
  174.                 {
  175.                         b_led_cnt ++;
  176.                         GPIO_WriteBit(GPIOB, GPIO_Pin_2 , 1);
  177.                 }
  178.                 else
  179.                 {
  180.                         //GPIO_WriteBit(GPIOB, GPIO_Pin_2 , 0);
  181.                 }


  182.         if(l_r_led_cnt < TIMER_FREQ / 5)
  183.         {
  184.                 l_r_led_cnt ++ ;
  185.         }
  186.         else
  187.         {
  188.                 l_r_led_cnt = 0;
  189.                 l_r_led = !l_r_led;
  190.         }

  191.         //转弯控制
  192.         if(moto_L_switch) //左转
  193.         {
  194.                 if(left_turn_cnt > 0)
  195.                 {
  196.                         left_turn_cnt --;
  197.                         GPIO_WriteBit(GPIOA, GPIO_Pin_1 , l_r_led);
  198.                         GPIO_WriteBit(GPIOA, GPIO_Pin_12 , 0);
  199.                 }
  200.                 else
  201.                 {
  202.                         moto_L_speed = moto_speed;//转弯结束,自动归正
  203.                         moto_R_speed = moto_speed;//转弯结束,自动归正
  204.                         moto_L_switch = 0;
  205.                         moto_L_dir = CAR_QIAN_JIN;
  206.                         moto_R_dir = CAR_QIAN_JIN;
  207.                         GPIO_WriteBit(GPIOA, GPIO_Pin_1 , 0);
  208.                 }
  209.         }
  210.         else
  211.         if(moto_R_switch)  //右转
  212.         {
  213.                 if(right_turn_cnt > 0)
  214.                 {
  215.                         right_turn_cnt --;
  216.                         GPIO_WriteBit(GPIOA, GPIO_Pin_12 , l_r_led);
  217.                         GPIO_WriteBit(GPIOA, GPIO_Pin_1 , 0);
  218.                 }
  219.                 else
  220.                 {
  221.                         moto_L_speed = moto_speed;//转弯结束,自动归正
  222.                         moto_R_speed = moto_speed;//转弯结束,自动归正
  223.                         moto_R_switch = 0;
  224.                         moto_R_dir = CAR_QIAN_JIN;
  225.                         moto_L_dir = CAR_QIAN_JIN;
  226.                         GPIO_WriteBit(GPIOA, GPIO_Pin_12 , 0);
  227.                 }
  228.         }

  229.         //右电机控制,定时器模拟PWM控制
  230.         GPIO_WriteBit(GPIOB, GPIO_Pin_3  , moto_R_speed > 0 ? (cnt <= moto_R_speed + moto_speed_adj ?  (moto_R_dir == CAR_QIAN_JIN ? moto_run & 1 : 0) : 0) : 0);
  231.         GPIO_WriteBit(GPIOA, GPIO_Pin_15 , moto_R_speed > 0 ? (cnt <= moto_R_speed + moto_speed_adj ?  (moto_R_dir == moto_run & 1 ? moto_run & 1 : 0) : 0) : 0);
  232.                
  233.         //左电机控制,定时器模拟PWM控制
  234.         GPIO_WriteBit(GPIOA, GPIO_Pin_2  , moto_L_speed > 0 ? (cnt <= moto_L_speed ?  (moto_L_dir == moto_run & 1 ? moto_run & 1 : 0) : 0) : 0);
  235.         GPIO_WriteBit(GPIOA, GPIO_Pin_3  , moto_L_speed > 0 ? (cnt <= moto_L_speed ?  (moto_L_dir == CAR_QIAN_JIN ? moto_run & 1 : 0) : 0) : 0);       
  236.        
  237.         GPIO_WriteBit(GPIOA, GPIO_Pin_11  , cnt < lamp_front_bright);// 大灯


  238.         if(beep_freq_cnt < TIMER_FREQ / beep_freq / 2)//喇叭频率计数器
  239.                 {
  240.                          beep_freq_cnt ++;
  241.                 }
  242.                 else
  243.                 {
  244.                         beep_freq_cnt = 0;
  245.                         b = !b;
  246.                 }

  247.                 if(beep_cnt > 0)//喇叭响持续时间
  248.                         {                               
  249.                                 beep_cnt --;
  250.                                 GPIO_WriteBit(GPIOB, GPIO_Pin_0 , b);
  251.                         }
  252.                         else
  253.                         {
  254.                                 GPIO_WriteBit(GPIOB, GPIO_Pin_0 , 0);
  255.                         }

  256. }

  257.   
  258. /***********************************************************************
  259. 函数功能:串口接收数据中断程序,处理命令
  260. 入口参数:
  261. 出口参数:
  262. ***********************************************************************/
  263. void Uart1RevISR(u8 dat)
  264. {
  265.         char txt[33];

  266.         switch(dat)
  267.         {
  268.                 case '0': //开关大灯
  269.                         lamp_f = !lamp_f;                       
  270.                 break;
  271.                 case 'a': //查询连接
  272.                         SendStrToUart("b");               
  273.                 break;
  274.                 case 'd': //调试开关
  275.                         debug_switch = !debug_switch;       
  276.                         sprintf(txt , "调试开关:%d\r\n" , debug_switch);
  277.                         SendStrToUart(txt);               
  278.                 break;
  279.                 case '5': //开关喇叭
  280.                         beep_cnt = (TIMER_FREQ / 1000) * 300;
  281.                        
  282.                         sprintf(txt , "beep:%d\r\n" , beep_cnt);
  283.                         SendStrToUart(txt);                       
  284.                 break;
  285.                 case ' ': //开关喇叭
  286.                         beep_cnt = (TIMER_FREQ / 1000) * 300;

  287.                         sprintf(txt , "beep:%d\r\n" , beep_cnt);
  288.                         SendStrToUart(txt);
  289.                 break;
  290.                 case '8': //加速
  291.                         moto_run = 1;

  292.                         if(CAR_QIAN_JIN == moto_L_dir && CAR_QIAN_JIN == moto_R_dir) //
  293.                         {
  294.                                 if(moto_speed < DUTY_WIDTH - 4)
  295.                                         moto_speed += 1;
  296.                         }
  297.                         else
  298.                         if(CAR_HOU_TUI == moto_L_dir && CAR_HOU_TUI == moto_R_dir) //
  299.                         {
  300.                                 if(moto_speed > 0)
  301.                                         moto_speed -= 1;
  302.                                 else
  303.                                 {
  304.                                         moto_speed = 0;
  305.                                         moto_L_dir = CAR_QIAN_JIN; //减速到0时开始后退
  306.                                         moto_R_dir = CAR_QIAN_JIN; //减速到0时开始后退
  307.                                 }
  308.                         }

  309.                         moto_L_speed = moto_speed;
  310.                         moto_R_speed = moto_speed;

  311.                         sprintf(txt , "L:%d , R:%d\r\n" , moto_L_speed , moto_R_speed);
  312.                         SendStrToUart(txt);
  313.                 break;
  314.                 case '2': //减速
  315.                         if(CAR_QIAN_JIN == moto_L_dir && CAR_QIAN_JIN == moto_R_dir) //
  316.                         {
  317.                                 if(moto_speed > 0)
  318.                                         moto_speed -= 1;
  319.                                 else
  320.                                 {
  321.                                         moto_speed = 0;
  322.                                         moto_L_dir = CAR_HOU_TUI; //减速到0时开始后退
  323.                                         moto_R_dir = CAR_HOU_TUI; //减速到0时开始后退
  324.                                 }
  325.                         }
  326.                         else
  327.                         if(CAR_HOU_TUI == moto_L_dir && CAR_HOU_TUI == moto_R_dir) //
  328.                         {
  329.                                 if(moto_speed < DUTY_WIDTH / 2)
  330.                                         moto_speed += 1;
  331.                         }


  332.                         b_led_cnt = 0;

  333.                         moto_L_speed = moto_speed;
  334.                         moto_R_speed = moto_speed;

  335.                         sprintf(txt , "L:%d , R:%d\r\n" , moto_L_speed , moto_R_speed);
  336.                         SendStrToUart(txt);

  337.                 break;
  338.                 case '7': //左转校正
  339.                         if(moto_speed_adj < 3)
  340.                                 moto_speed_adj ++;
  341.                 break;
  342.                 case '9': //右转校正
  343.                         if(moto_speed_adj > -3)
  344.                                 moto_speed_adj --;
  345.                 break;
  346.                 case '4': //左转
  347.                         moto_L_switch = 1;
  348.                         moto_R_switch = 0;
  349.                         moto_L_dir = CAR_QIAN_JIN;
  350.                         moto_R_dir = CAR_QIAN_JIN;

  351.                         left_turn_cnt = (TIMER_FREQ / 5);//转弯时间定时器
  352.                         moto_L_speed = moto_speed / 3;
  353.                         moto_R_speed = moto_speed;

  354.                         sprintf(txt , "L:%d , R:%d\r\n" , moto_L_switch , moto_R_switch);
  355.                         SendStrToUart(txt);
  356.                 break;
  357.                 case '6': //右转
  358.                         moto_R_switch = 1;
  359.                         moto_L_switch = 0;
  360.                         moto_R_dir = CAR_QIAN_JIN;
  361.                         moto_L_dir = CAR_QIAN_JIN;

  362.                         right_turn_cnt = (TIMER_FREQ / 5);//转弯时间定时器
  363.                         moto_R_speed = moto_speed / 3;
  364.                         moto_L_speed = moto_speed;

  365.                         sprintf(txt , "L:%d , R:%d\r\n" , moto_L_switch , moto_R_switch);
  366.                         SendStrToUart(txt);
  367.                 break;
  368.                 case 'l': //左转大弯,并稍微后退,避障用
  369.                         moto_L_switch = 1;
  370.                         moto_R_switch = 0;
  371.                         moto_L_dir = CAR_HOU_TUI;
  372.                         moto_R_dir = CAR_HOU_TUI;

  373.                         left_turn_cnt = (TIMER_FREQ / (moto_speed / 20 + 1) );//转弯时间定时器, 转弯时间与速度相关
  374.                         moto_L_speed = moto_speed;
  375.                         moto_R_speed = moto_speed / 4;

  376.                         //sprintf(txt , "L:%d , R:%d\r\n" , moto_L_switch , moto_R_switch);
  377.                         //SendStrToUart(txt);
  378.                 break;
  379.                 case 'r': //右转大弯,并稍微后退,避障用
  380.                         moto_R_switch = 1;
  381.                         moto_L_switch = 0;
  382.                         moto_R_dir = CAR_HOU_TUI;
  383.                         moto_L_dir = CAR_HOU_TUI;

  384.                         right_turn_cnt = (TIMER_FREQ / (moto_speed / 20 + 1) );//转弯时间定时器, 转弯时间与速度相关
  385.                         moto_R_speed = moto_speed;
  386.                         moto_L_speed = moto_speed / 4;

  387.                         //sprintf(txt , "L:%d , R:%d\r\n" , moto_L_switch , moto_R_switch);
  388.                         //SendStrToUart(txt);
  389.                 break;
  390.         }
  391. }
  392. /***********************************************************************
  393. 函数功能:串口接收数据中断程序,处理命令
  394. 入口参数:
  395. 出口参数:
  396. ***********************************************************************/
  397. void Uart2RevISR(u8 dat)
  398. {       
  399.         u8 n = 0 , i = 0 , len = 0 , ch = 0;
  400.         float val = 0.0;
  401.         static float current_adj = 1.0;
  402.        
  403. }


  404. /***********************************************************************
  405. 函数功能:大灯控制
  406. 入口参数:
  407. 出口参数:
  408. ***********************************************************************/
  409. void Lamp_front(u8 de)
  410. {
  411.         u8 i = 0;

  412.         if(de == 1)//灯渐亮
  413.         {
  414.                 if(lamp_front_bright == 0)
  415.                 {       
  416.                         for(i = 0 ; i < DUTY_WIDTH ; i ++)
  417.                                 {
  418.                                         lamp_front_bright = i;
  419.                                         Delay_ms(20);
  420.                                 }
  421.                 }
  422.         }
  423.         else //灯渐暗
  424.         {
  425.                 if(lamp_front_bright == DUTY_WIDTH - 1)
  426.                 {       
  427.                         for(i = 0 ; i < DUTY_WIDTH ; i ++)
  428.                                 {
  429.                                         lamp_front_bright = DUTY_WIDTH - i - 1;          
  430.                                         Delay_ms(20);
  431.                                 }
  432.                 }
  433.         }
  434. }

  435. /***********************************************************************
  436. 函数功能:
  437. 入口参数:
  438. 出口参数:
  439. ***********************************************************************/
  440. int main(void)
  441. {
  442.         char txt[44];
  443.         int i = 0 , ls = 0 , rs = 0 , t = 0;
  444.         s32 ad = 0;

  445.         STM32_Board_Init();

  446.         //SendStrToUart("AT+BAUD8");//设置波特率为115200

  447.         moto_speed = 18; //
  448.         moto_run = 1;

  449.         moto_R_speed = moto_speed;
  450.         moto_R_dir   = CAR_QIAN_JIN;//电机方向

  451.         moto_L_speed = moto_speed;
  452.         moto_L_dir   = CAR_QIAN_JIN ;//电机方向

  453.         Delay_ms(200);

  454.         //自动识别环境光强度
  455.         for(i = 0 ; i < 20 ; i ++)
  456.         {
  457.                 t += GetADCVal(ADC_Channel_5);
  458.         }
  459.         t /= 20;
  460.         IR_ref_value_L = t;

  461.         t = 0;
  462.         for(i = 0 ; i < 20 ; i ++)
  463.         {
  464.                 t += GetADCVal(ADC_Channel_4);
  465.         }
  466.         t /= 20;
  467.         IR_ref_value_R = t;

  468.         //FlashData=*(vu32*)(FLASH_ADR);         /* 读取地址中的16位数据 */       
  469.         //SendDataToUart('A');

  470.         lamp_front_bright = 0; //大灯亮度
  471.         beep_cnt = (TIMER_FREQ / 1000) * 100;//喇叭叫

  472.         while(1)
  473.                 {
  474.                         if(debug_switch == 0)
  475.                         {
  476.                                 if(lamp_front_bright == 0)
  477.                                 {
  478.                                         if(lamp_f == 1)
  479.                                         {
  480.                                                 Lamp_front(lamp_f);
  481.                                         }
  482.                                 }
  483.                                 else
  484.                                 {
  485.                                         if(lamp_f == 0)
  486.                                         {
  487.                                                 Lamp_front(lamp_f);
  488.                                         }
  489.                                 }
  490.        
  491.                                 rs = CheckHinder_Right();
  492.        
  493.                                 if( rs )        //判断右侧是否有障碍物 , 如有则左转
  494.                                 {
  495.                                         if(moto_L_switch == 0)
  496.                                         {
  497.                                                 Uart1RevISR('l');      //发送左转指令
  498.                                                
  499.                                                 if(lamp_f == 0)        //如果大灯没开,这里打开大灯
  500.                                                         lamp_front_bright = (rs - 0 ) * 10 + 0;
  501.                
  502.                                                 if(beep_cnt == 0)       
  503.                                                         beep_cnt = (TIMER_FREQ / 1000) * 50;  //喇叭叫一声
  504.                                                 //SendStrToUart("<<<\r\n");
  505.                                         }
  506.                                 }
  507.                                 else
  508.                                 {
  509.                                         ls = CheckHinder_Left();
  510.                                                                                          //判断左侧是否有障碍物 , 如有则右转
  511.                                         if(ls)
  512.                                         {
  513.                                                 if(moto_R_switch == 0)
  514.                                                 {
  515.                                                         Uart1RevISR('r');      //发送右转指令
  516.                        
  517.                                                         if(lamp_f == 0)        //如果大灯没开,这里打开大灯
  518.                                                                 lamp_front_bright = (ls - 0 ) * 10 + 0;
  519.                        
  520.                                                         if(beep_cnt == 0)       
  521.                                                                 beep_cnt = (TIMER_FREQ / 1000) * 10;  //喇叭叫一声
  522.                                                         //SendStrToUart(">>>\r\n");
  523.                                                 }
  524.                                         }
  525.                                         else
  526.                                         {
  527.                                                 if(lamp_f == 0 && lamp_front_bright > 0)
  528.                                                         lamp_front_bright = 0;
  529.                                         }
  530.                                 }       

  531.                                 Delay_ms(10);
  532.        
  533.                                 if(GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_9) == 0)        //key1按下 ,开车和停车切换
  534.                                 {
  535.                                         moto_run = !moto_run;
  536.        
  537.                                         while(GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_9) == 0);
  538.                                         Delay_ms(20);
  539.                                 }

  540.                                 #if 0
  541.                                 if(lamp_f == 0)        //如果大灯没开,这里打开大灯
  542.                                 {
  543.                                         ad = GetADCVal(ADC_Channel_6);
  544.                                         ad -= 2000;
  545.                                         if(ad > 0)
  546.                                                 ad = 0;
  547.                                         ad = 0 - ad;

  548.                                         ad /= 200;
  549.                                         lamp_front_bright = ad;
  550.                                 }
  551.                                 #endif
  552.                         }

  553.                         //GPIO_WriteBit(GPIOC , GPIO_Pin_13 , 0);//led
  554.                         //Delay_ms(200);
  555.                         //GPIO_WriteBit(GPIOC , GPIO_Pin_13 , 1);//led

  556.                         if(debug_switch)
  557.                         {
  558.                                 Delay_ms(50);
  559.                                 sprintf(txt , "右侧红外感应AD4:%4d,左侧红外感应AD5:%4d,音频:%4d\r\n" , GetADCVal(ADC_Channel_4) , GetADCVal(ADC_Channel_5) , GetADCVal(ADC_Channel_6) );
  560.                                 SendStrToUart(txt);
  561.                         }
  562.                 }

  563.         return 0;
  564. }
复制代码

所有资料51hei提供下载:
stm32 Car V1.0.zip (603.16 KB, 下载次数: 23)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:500602 发表于 2019-4-7 19:22 | 显示全部楼层
下载学习一下。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表