找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1621|回复: 0
打印 上一主题 下一主题
收起左侧

STM32F103C8单片机GP8401 PAC调电压_5MV分度源程序

[复制链接]
跳转到指定楼层
楼主
1.这个例子是用于光学器件中,MEMS加电压调转镜角度的工程例子;
2.此例中,用到的技术点有: STM32F103C8, 国内先进的调压芯片GP8401,PWM,FLASH,USART;
3.电路图中有使用MP2359降压芯片(12VL转5V),与LTC3872升压芯片(5V转60V),GP8401的PAC应用;
4.供学习参考,也推荐一下,上海益客电子;

电路原理图如下:


单片机源程序如下:
  1. /********************************* MDK-ARM Project ****************************
  2.    *   Project Name:
  3.    *   Firmware Library version: V3.5.0
  4.    *   Author:  
  5.    *   Date:  
  6.    *   Brief: (mcu--64kflash,20kram,72mhz,26IO)
  7.          *   使用内部时钟,64M,   APB1_PCLK1=32M                                         
  8. ******************************************************************************/

  9. //----------------------project header flie  ------------------------------------------
  10. #include "stm32f10x.h"
  11. #include "userconfig.h"
  12. //#include <string.h>



  13. //*************************  project functions  *********************************


  14. /*******************************************************************************
  15. * Function Name  :  Variables_Init(void)
  16. * Description    : This function .
  17. * Input          : None
  18. * Output         : None
  19. * Return         : None
  20. * Attention      : None
  21. *******************************************************************************/
  22. static void Variables_Init(void)
  23. { u8 cnt=0;
  24.         
  25.         GPIO_InitTypeDef GPIO_InitStructure;
  26.         
  27.   //IO口控制MEMS切换的端口初始化        
  28.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_12;
  29.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  30.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  31.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  32.         GPIO_ResetBits(GPIOA,GPIO_Pin_6|GPIO_Pin_12);


  33.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1;
  34.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  35.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  36.   GPIO_Init(GPIOB, &GPIO_InitStructure);
  37.         GPIO_ResetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1);        
  38.         
  39.         
  40.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3| GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_7| GPIO_Pin_8| GPIO_Pin_11;
  41.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  42.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  43.   GPIO_Init(GPIOA, &GPIO_InitStructure);
  44.         GPIO_ResetBits(GPIOA,GPIO_Pin_3|GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_7| GPIO_Pin_11);        
  45.         GPIO_SetBits(GPIOA,GPIO_Pin_8);
  46.         
  47.         
  48.          //变量初始化        
  49.         for(cnt=0;cnt<12;cnt++)        usart1_rx_buffer[cnt]=0;
  50.         usart1_rx_point=0;sign_rxn_cnt=0;
  51.         usart1_rx_count=0;
  52.         data_usart1_rx=0;
  53.         sign_rxn_usart1=0;

  54.         for(cnt=0;cnt<12;cnt++) usart1_tx_buffer[cnt]=0;
  55.         usart1_tx_point=0;
  56.         usart1_tx_count=0;
  57.         
  58.         sign_debug=0;
  59.         sign_clear_all_correct_vol=0;
  60.         sign_x_correct_vol=0;

  61.         set_vol_XZ=0;  //最高65.535V
  62.         set_vol_XF=0;
  63.         set_vol_YZ=0;
  64.         set_vol_YF=0;
  65.         current_vol_XZ=0;
  66.         current_vol_XF=0;
  67.         current_vol_YZ=0;
  68.         current_vol_YF=0;        
  69.         
  70.         current_ch=0; //开机默认为通道0 各通道电压为0MV        
  71.         current_xz=0;
  72.         current_xf=0;
  73.         current_yz=0;
  74.         current_yf=0;        
  75.         
  76.         
  77. //  //每次上电将在MCU的FLASH中的各通道及电数MV读取SRAM中,以方使快速切换通道时输出电压到加电端子上                                
  78. //  if(read_CHx_VOLx_to_SRAMx()) ;            
  79. //        else
  80. //                {
  81. //                        usart1_tx_buffer[0]='e';
  82. //                        usart1_tx_buffer[1]='r';        
  83. //                        usart1_tx_buffer[2]='r';
  84. //                        usart1_tx_buffer[3]='o';
  85. //                        usart1_tx_buffer[4]='r';
  86. //                        usart1_tx_ptr(usart1_tx_buffer,5);//返回ERROR信息
  87. //          }
  88. //               
  89. //        
  90. //   //最大通道               
  91. //         max_ch=STMFLASH_ReadHalfWord(MAX_CH_FLASH_ADDR);               
  92. //        
  93.         
  94. //        //定时器PWM初始
  95. //        TIM_SelectOCxM(TIM4, TIM_Channel_1, TIM_OCMode_PWM1);  //初始中强置低后,要再重恢复到PWM
  96. //        TIM_SelectOCxM(TIM4, TIM_Channel_2, TIM_OCMode_PWM1);        
  97. //        TIM_CCxCmd(TIM4, TIM_Channel_1, TIM_CCx_Enable);
  98. //        TIM_CCxCmd(TIM4, TIM_Channel_2, TIM_CCx_Enable);

  99.         TIM_Cmd(TIM4, ENABLE);                                 //开启PWM输出波形

  100.         flag_mems_busy=IDLE;        
  101. }



  102. /*******************************************************************************
  103. * Function Name  : int main(void)
  104. * Description    : This function .
  105. * Input          : None
  106. * Output         : None
  107. * Return         : None
  108. * Attention      : None
  109. *******************************************************************************/
  110. int main(void)
  111. {
  112.                 //u8 i;
  113.                 //uint32_t n=0;
  114.         
  115.           MemsReset:
  116.     NVIC_Configuration();

  117.                 RCC_Configuration();   
  118.                 GPIO_Configuration();
  119.           EXTI_Configuration();
  120.                 TIM_Configuration();    //在PB.7上有上升沿时,将在PB.6上产生一个脉冲;        
  121.                 USART_Configuration();
  122.                 USART_ClearFlag(USART1,USART_FLAG_RXNE);               
  123.     Variables_Init();//状态初始
  124.          



  125. mems_IDLE();               
  126. TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable); //立即生效
  127. TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Disable); //立即生效        
  128.         
  129. while(1)
  130.         {   
  131.                 //IWDG_Feed();               
  132.                 //if(mems_ALARM );                 
  133.                 //if(!mems_RESET()) goto MemsReset;
  134.                                  
  135.                 if(sign_rxn_usart1==1)          // 标记接收到了1帧数据
  136.                         {
  137.                                 receive_info();
  138.                                 sign_rxn_usart1=0;
  139.                                 mems_IDLE();
  140.                         }
  141.           }                                                                                
  142. }


  143. #ifdef  USE_FULL_ASSERT

  144. /*******************************************************************************
  145. * Function Name  : assert_failed(uint8_t* file, uint32_t line)
  146. * Description    : This function .Reports the name of the source file and
  147.                    the source line number where the assert_param error has
  148.                    occurred
  149. * Input          : file: pointer to the source file name
  150.                    line: assert_param error line source number
  151. * Output         : None
  152. * Return         : None
  153. * Attention      : None
  154. *******************************************************************************/
  155. void assert_failed(uint8_t* file, uint32_t line)
  156. {
  157.   /* User can add his own implementation to report the file name and line number,
  158.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  159.   /* Infinite loop */
  160.   while (1)
  161.   {
  162.   }
  163. }

  164. #endif
复制代码

Keil5代码下载(仅供参考):
代码.7z (369.96 KB, 下载次数: 15)


评分

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

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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