Home Article stm32f107vct6实现串口定时器呼吸灯

stm32f107vct6实现串口定时器呼吸灯

Release time:2021-03-30 14:24:53 Author:一蓑烟雨 Reading volume:339

最近整了一个f107的开发板,可惜没有原理图,只能自己拿万用表慢慢量了。

目前已知串口是用的USART2  PD5-- TX   PD6-- RX

LED: D3-- PE1    D4 -- PE0   D5-- PB9  D6 --PB8

引脚图:


用的神舟IV号开发板的例程:工程文件下载


/* Includes ------------------------------------------------------------------*/
#include "SZ_STM32F107VC_LIB.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/


/**-------------------------------------------------------
  * @函数名 main
  * @功能   主函数
  * @参数   无
  * @返回值 无
***------------------------------------------------------*/
int main(void)
{
    /*!< At this stage the microcontroller clock setting is already configured, 
         this is done through SystemInit() function which is called from startup
         file (startup_stm32f10x_xx.s) before to branch to application main.
         To reconfigure the default setting of SystemInit() function, refer to
         system_stm32f10x.c file
       */ 
    /*!< 在系统启动文件(startup_stm32f10x_xx.s)中已经调用SystemInit()初始化了时钟, 
         所以main函数不需要再次重复初始化时钟。默认初始化系统主时钟为72MHz。
         SystemInit()函数的实现位于system_stm32f10x.c文件中。
       */ 
    uint32_t PwmValue = 0;
    uint32_t DirValue = 0;
      
    /* 初始化板载LED指示灯 */
    SZ_STM32_LEDInit(LED1);
    SZ_STM32_LEDInit(LED2);
    SZ_STM32_LEDInit(LED3);
    SZ_STM32_LEDInit(LED4);
    
    /* 注意串口2使用Printf时"SZ_STM32F107VC_LIB.c"文件中fputc定义中设备改为SZ_STM32_COM2 */
    /* 串口2初始化 */
    SZ_STM32_COMInit(COM2, 115200);
    printf(" ARMJISHU.COM-->TIM3定时器PWM实验

");

    TIM3_PWM_Init();
    
    /* Infinite loop 主循环 */
    while (1)
    {
        /* 延迟 */
        delay(6000);
              
        if(DirValue == 0)
        {
            TIM_SetCompare1(TIM3, PwmValue++);                    

            if(PwmValue >= 1000)
            {
							 printf("--------------
");
                DirValue = 1;
                PwmValue = 999;
            }                    
        }
        else
        {
            TIM_SetCompare1(TIM3, PwmValue--);                    

            if(PwmValue == 0)
            {
                DirValue = 0;        
            }                    
        }
            
        /* 此处可以添加用户的程序 */
    }    
}


/**-------------------------------------------------------
  * @函数名 SysTick_Handler_User
  * @功能   系统节拍定时器服务请求用户处理函数
  * @参数   无
  * @返回值 无
***------------------------------------------------------*/
void SysTick_Handler_User(void)
{
    static uint32_t TimeIncrease = 0;

    if((TimeIncrease%200) == 0)
    {
        if((TimeIncrease%1000) == 0) //每2秒亮100毫秒
        {
          LED1OBB = 0;
					LED2OBB = 0;
					LED3OBB = 0;
					LED4OBB = 0;
        }
        else
        {
          LED1OBB = 1;
					LED2OBB = 1;
					LED3OBB = 1;
					LED4OBB = 1;
        }
    }
    TimeIncrease++;
}


  
I want to comment

Search

classification

Leave a message
http://blog.rjxj513.com/index.php/
User login
You have not written any reviews yet!
You have commented!
Can only praise once!
You have a collection!