找回密码
 立即注册

只需一步,快速开始

搜索

【FM33LG0系列开发板测评】02.基础工程(LED、KEY、LPUART、LPTIM、SHELL)

1
回复
1977
查看
[复制链接]

177

主题

354

帖子

3121

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3121
QQ
2021-12-31 17:07:55 显示全部楼层 |阅读模式
【FM33LG0系列开发板测评】02.基础工程(LED、KEY、LPUART、LPTIM、SHELL)





在准备好开发资料和搭建好开发环境后,我们就要来准备一个基础工程了;好的基础建设是搭建高楼大厦的关键,所以在基础工程中使用的原创的TASK任务管理调试方式,为了方便后期程序的调试、测试和演示,我们又添加了NR_MICRO_SHELL开源代码,可以使用串口终端方便的对接正在运行的程序;


本次的基础工程包含从零开始新建工程、LED、KEY、LPUART、LPTIM、SHELL等多个方面,所以篇幅有些长,但满满的都是干货,有启发和帮助哦……


从零开始新建立工程:

我们使用KEIL开发环境进行开发,所以提前安装好了芯片支持包;打开KEIL软件,点击菜单栏Project->New uVision Project...在弹出的对话框中选择工程存放的路径及工程名,点击保存,如下图所示:


在Select Device for Target窗口中选择芯片型FM33LG04X,然后在弹出的Manage Run-Time Environment窗口直接点击OK,新建的空工程就完成啦;如下图所示:


接下来我们需要往新建的空工程中划分程序结构以及添加程序源代码,点击工具栏上的Manage Project Items按钮,在弹出的窗口中进行操作,完成后点击OK,就完成啦;如下图所示:


最后就是对工程进行相应的配置了,点击工具栏上的Configure target options按钮,以弹出的窗口中进行相应的配置,如下图所示:


至此我们一个完整的工程就创建OK啦;对于官方的程序,我们提取了Device文件夹和MF-config文件夹使用,其它的文件夹以及程序源文件都是后期创建的。接下来就是对各个部分进行代码编写了。


程序就的大体功能就是创建LED任务,每间隔250ms闪烁一次,可以通过SHELL命令来控制时行闪烁和停止闪烁;创建KEY任务,进行按键识别,并打印出相应的按键事件/状态;使用LPTIM32作为TASK的定时器,写成任务的调度;通过LPUART0作为SHELL的调试接口,并进行SHELL程序移植;


LED原理图:


LED头文件:

  1. /*******************************************************************************
  2. * @file    LED.h
  3. * @author  King
  4. * @version V1.00
  5. * @date 27-Nov-2021
  6. * @brief ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __LED_H__
  10. #define __LED_H__


  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif


  14. #undef  EXTERN


  15. #ifdef  __LED_C__
  16. #define EXTERN
  17. #else
  18. #define EXTERN extern
  19. #endif


  20. /* Includes ------------------------------------------------------------------*/
  21. #include "config.h"


  22. /* Exported constants --------------------------------------------------------*/
  23. #define LED_NUMBER  4

  24. #define LED1_GPIO   GPIOC
  25. #define LED1_PIN    FL_GPIO_PIN_1

  26. #define LED2_GPIO   GPIOC
  27. #define LED2_PIN    FL_GPIO_PIN_0

  28. #define LED3_GPIO   GPIOD
  29. #define LED3_PIN    FL_GPIO_PIN_12

  30. #define LED4_GPIO   GPIOB
  31. #define LED4_PIN    FL_GPIO_PIN_15


  32. /* Exported types ------------------------------------------------------------*/
  33. typedef struct
  34. {
  35.     GPIO_Type *GPIOx;
  36.     uint32_t   pin;
  37. } LED_TypeDef;


  38. /* Exported macro ------------------------------------------------------------*/


  39. /* Exported functions --------------------------------------------------------*/
  40. EXTERN void LED_Init(void);
  41. EXTERN void LED_Toggle(void);
  42. EXTERN void LED_SHELL_Handler(uint8_t Enable);


  43. #ifdef __cplusplus
  44. }
  45. #endif


  46. #endif


  47. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

复制代码

LED源程序:

  1. /*******************************************************************************
  2. * @file    LED.c
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #define __LED_C__


  10. /* Includes ------------------------------------------------------------------*/
  11. #include "LED.h"


  12. /* Private typedef -----------------------------------------------------------*/
  13. /* Private define ------------------------------------------------------------*/
  14. /* Private macro -------------------------------------------------------------*/


  15. /* Private variables ---------------------------------------------------------*/
  16. LED_TypeDef LED[LED_NUMBER] =
  17. {
  18.     {LED1_GPIO, LED1_PIN},
  19.     {LED2_GPIO, LED2_PIN},
  20.     {LED3_GPIO, LED3_PIN},
  21.     {LED4_GPIO, LED4_PIN},
  22. };

  23. uint8_t LED_ToggleEnable = 1;


  24. /* Private function prototypes -----------------------------------------------*/
  25. /* Private functions ---------------------------------------------------------*/


  26. /* Exported variables --------------------------------------------------------*/
  27. /* Exported function prototypes ----------------------------------------------*/


  28. /*******************************************************************************
  29. * @brief      
  30. * @param      
  31. * @retval      
  32. * @attention *******************************************************************************/
  33. void LED_Init(void)
  34. {
  35.     FL_GPIO_InitTypeDef GPIO_InitStruct;

  36.     for(uint8_t i = 0; i < LED_NUMBER; i++)
  37.     {
  38.         FL_GPIO_StructInit(&GPIO_InitStruct);
  39.         GPIO_InitStruct.pin        = LED.pin;
  40.         GPIO_InitStruct.mode       = FL_GPIO_MODE_OUTPUT;
  41.         GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
  42.         FL_GPIO_Init(LED.GPIOx, &GPIO_InitStruct);

  43.         FL_GPIO_SetOutputPin(LED.GPIOx, LED.pin);
  44.     }


  45.     TASK_Append(TASK_ID_LED, LED_Toggle, 250);
  46. }


  47. /*******************************************************************************
  48. * @brief      
  49. * @param      
  50. * @retval      
  51. * @attention   
  52. *******************************************************************************/
  53. void LED_Toggle(void)
  54. {
  55.     if(LED_ToggleEnable)
  56.     {
  57.         for(uint8_t i = 0; i < LED_NUMBER; i++)
  58.         {
  59.             FL_GPIO_ToggleOutputPin(LED.GPIOx, LED.pin);
  60.         }
  61.     }
  62. }


  63. /*******************************************************************************
  64. * @brief      
  65. * @param      
  66. * @retval      
  67. * @attention   
  68. *******************************************************************************/
  69. void LED_SHELL_Handler(uint8_t Enable)
  70. {
  71.     LED_ToggleEnable = Enable;
  72. }


  73. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
复制代码

KEY原理图:


KEY头文件:

  1. /*******************************************************************************
  2. * @file    KEY.h
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __KEY_H__
  10. #define __KEY_H__


  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif


  14. #undef  EXTERN


  15. #ifdef  __KEY_C__
  16. #define EXTERN
  17. #else
  18. #define EXTERN extern
  19. #endif


  20. /* Includes ------------------------------------------------------------------*/
  21. #include "config.h"


  22. /* Exported constants --------------------------------------------------------*/
  23. #define KEY_NUMBER  4

  24. #define KEY1_GPIO   GPIOD
  25. #define KEY1_PIN    FL_GPIO_PIN_9   /* WKUP8 */

  26. #define KEY2_GPIO   GPIOE
  27. #define KEY2_PIN    FL_GPIO_PIN_6   /* WKUP9 */

  28. #define KEY3_GPIO   GPIOE
  29. #define KEY3_PIN    FL_GPIO_PIN_7

  30. #define KEY4_GPIO   GPIOC
  31. #define KEY4_PIN    FL_GPIO_PIN_6   /* WKUP4 */


  32. /* Exported types ------------------------------------------------------------*/
  33. typedef struct
  34. {
  35.     GPIO_Type *GPIOx;
  36.     uint32_t   pin;
  37. } KEY_TypeDef;


  38. /* Exported macro ------------------------------------------------------------*/


  39. /* Exported functions --------------------------------------------------------*/
  40. EXTERN void KEY_Init(void);
  41. EXTERN void KEY_Scan(void);


  42. #ifdef __cplusplus
  43. }
  44. #endif


  45. #endif


  46. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

复制代码

KEY源程序:

  1. /*******************************************************************************
  2. * @file    KEY.c
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #define __KEY_C__


  10. /* Includes ------------------------------------------------------------------*/
  11. #include "KEY.h"


  12. /* Private typedef -----------------------------------------------------------*/
  13. /* Private define ------------------------------------------------------------*/
  14. /* Private macro -------------------------------------------------------------*/


  15. /* Private variables ---------------------------------------------------------*/
  16. KEY_TypeDef KEY[KEY_NUMBER] =
  17. {
  18.     {KEY1_GPIO, KEY1_PIN},
  19.     {KEY2_GPIO, KEY2_PIN},
  20.     {KEY3_GPIO, KEY3_PIN},
  21.     {KEY4_GPIO, KEY4_PIN},
  22. };


  23. /* Private function prototypes -----------------------------------------------*/
  24. /* Private functions ---------------------------------------------------------*/


  25. /* Exported variables --------------------------------------------------------*/
  26. /* Exported function prototypes ----------------------------------------------*/


  27. /*******************************************************************************
  28. * @brief      
  29. * @param      
  30. * @retval      
  31. * @attention   
  32. *******************************************************************************/
  33. void KEY_Init(void)
  34. {
  35.     FL_GPIO_InitTypeDef GPIO_InitStruct;

  36.     for(uint8_t i = 0; i < KEY_NUMBER; i++)
  37.     {
  38.         FL_GPIO_StructInit(&GPIO_InitStruct);
  39.         GPIO_InitStruct.pin  = KEY.pin;
  40.         GPIO_InitStruct.mode = FL_GPIO_MODE_INPUT;
  41.         GPIO_InitStruct.pull = FL_ENABLE;
  42.         FL_GPIO_Init(KEY.GPIOx, &GPIO_InitStruct);
  43.     }

  44.     TASK_Append(TASK_ID_KEY, KEY_Scan, 10);
  45. }


  46. /*******************************************************************************
  47. * @brief      
  48. * @param      
  49. * @retval      
  50. * @attention   
  51. *******************************************************************************/
  52. void KEY_SubScan(uint8_t *State, uint8_t *Count, uint32_t Value, char *Name)
  53. {
  54.     if(*State == 0)
  55.     {
  56.         if(Value == 0)
  57.         {
  58.             *Count += 1;

  59.             if(*Count > 5)
  60.             {
  61.                 *Count = 0; *State = 1;

  62.                 printf("\r\n%s Pressed...", Name);
  63.             }
  64.         }
  65.         else
  66.         {
  67.             *Count = 0;
  68.         }
  69.     }
  70.     else
  71.     {
  72.         if(Value != 0)
  73.         {
  74.             *Count += 1;

  75.             if(*Count > 5)
  76.             {
  77.                 *Count = 0; *State = 0;

  78.                 printf("\r\n%s Release\r\n", Name);
  79.             }
  80.         }
  81.         else
  82.         {
  83.             *Count = 0;
  84.         }
  85.     }
  86. }


  87. /*******************************************************************************
  88. * @brief      
  89. * @param      
  90. * @retval      
  91. * @attention   
  92. *******************************************************************************/
  93. void KEY_Scan(void)
  94. {
  95.     static uint8_t KEY1_State = 0, KEY1_Count = 0;
  96.     static uint8_t KEY2_State = 0, KEY2_Count = 0;
  97.     static uint8_t KEY3_State = 0, KEY3_Count = 0;
  98.     static uint8_t KEY4_State = 0, KEY4_Count = 0;

  99.     KEY_SubScan(&KEY1_State, &KEY1_Count,
  100.                 FL_GPIO_GetInputPin(KEY[0].GPIOx, KEY[0].pin),
  101.                 "KEY1");

  102.     KEY_SubScan(&KEY2_State, &KEY2_Count,
  103.                 FL_GPIO_GetInputPin(KEY[1].GPIOx, KEY[1].pin),
  104.                 "KEY2");

  105.     KEY_SubScan(&KEY3_State, &KEY3_Count,
  106.                 FL_GPIO_GetInputPin(KEY[2].GPIOx, KEY[2].pin),
  107.                 "KEY3");

  108.     KEY_SubScan(&KEY4_State, &KEY4_Count,
  109.                 FL_GPIO_GetInputPin(KEY[3].GPIOx, KEY[3].pin),
  110.                 "KEY4");
  111. }


  112. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
复制代码

LPUART、SHELL移植头文件:

  1. /*******************************************************************************
  2. * @file    LPUARTx.h
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __LPUARTx_H__
  10. #define __LPUARTx_H__


  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif


  14. #undef  EXTERN


  15. #ifdef  __LPUARTx_C__
  16. #define EXTERN
  17. #else
  18. #define EXTERN extern
  19. #endif


  20. /* Includes ------------------------------------------------------------------*/
  21. #include "config.h"


  22. /* Exported constants --------------------------------------------------------*/
  23. /* Exported types ------------------------------------------------------------*/
  24. /* Exported macro ------------------------------------------------------------*/


  25. /* Exported functions --------------------------------------------------------*/
  26. EXTERN void LPUARTx_Init(LPUART_Type *LPUARTx);


  27. #ifdef __cplusplus
  28. }
  29. #endif


  30. #endif


  31. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
复制代码

LPUART、SHELL移植源程序:LPUART的最大波特率为9600,在SHELL中实现了LED闪烁控制的实现部分

  1. /*******************************************************************************
  2. * @file    LPUARTx.c
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #define __LPUARTx_C__


  10. /* Includes ------------------------------------------------------------------*/
  11. #include "LPUARTx.h"
  12. #include "nr_micro_shell.h"


  13. /* Private typedef -----------------------------------------------------------*/
  14. /* Private define ------------------------------------------------------------*/
  15. /* Private macro -------------------------------------------------------------*/
  16. /* Private variables ---------------------------------------------------------*/
  17. /* Private function prototypes -----------------------------------------------*/
  18. /* Private functions ---------------------------------------------------------*/


  19. /* Exported variables --------------------------------------------------------*/
  20. /* Exported function prototypes ----------------------------------------------*/


  21. /*******************************************************************************
  22. * @brief      
  23. * @param      
  24. * @retval      
  25. * @attention   
  26. *******************************************************************************/
  27. void LPUARTx_Init(LPUART_Type *LPUARTx)
  28. {
  29.     FL_GPIO_InitTypeDef   GPIO_InitStruct;
  30.     FL_LPUART_InitTypeDef LPUART_InitStruct;

  31.     if(LPUARTx == LPUART0)
  32.     {
  33.         FL_GPIO_StructInit(&GPIO_InitStruct);
  34.         GPIO_InitStruct.pin        = FL_GPIO_PIN_13;
  35.         GPIO_InitStruct.mode       = FL_GPIO_MODE_DIGITAL;
  36.         GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
  37.         GPIO_InitStruct.pull       = FL_ENABLE;
  38.         GPIO_InitStruct.remapPin   = FL_ENABLE;
  39.         FL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  40.         FL_GPIO_StructInit(&GPIO_InitStruct);
  41.         GPIO_InitStruct.pin        = FL_GPIO_PIN_14;
  42.         GPIO_InitStruct.mode       = FL_GPIO_MODE_DIGITAL;
  43.         GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
  44.         GPIO_InitStruct.pull       = FL_DISABLE;
  45.         GPIO_InitStruct.remapPin   = FL_ENABLE;
  46.         FL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  47.     }

  48.     if(LPUARTx == LPUART1)
  49.     {
  50.         FL_GPIO_StructInit(&GPIO_InitStruct);
  51.         GPIO_InitStruct.pin        = FL_GPIO_PIN_2;
  52.         GPIO_InitStruct.mode       = FL_GPIO_MODE_DIGITAL;
  53.         GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
  54.         GPIO_InitStruct.pull       = FL_ENABLE;
  55.         GPIO_InitStruct.remapPin   = FL_ENABLE;
  56.         FL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  57.         FL_GPIO_StructInit(&GPIO_InitStruct);
  58.         GPIO_InitStruct.pin        = FL_GPIO_PIN_3;
  59.         GPIO_InitStruct.mode       = FL_GPIO_MODE_DIGITAL;
  60.         GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
  61.         GPIO_InitStruct.pull       = FL_DISABLE;
  62.         GPIO_InitStruct.remapPin   = FL_ENABLE;
  63.         FL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  64.     }

  65.     FL_LPUART_StructInit(&LPUART_InitStruct);
  66.     LPUART_InitStruct.clockSrc          = FL_CMU_LPUART_CLK_SOURCE_LSCLK;   //时钟源LSCLK
  67. //  LPUART_InitStruct.clockSrc          = FL_CMU_LPUART_CLK_SOURCE_RCHF;    //时钟源RCHF
  68. //  LPUART_InitStruct.clockSrc          = FL_CMU_LPUART_CLK_SOURCE_RCLF;    //时钟源RCLF
  69.     LPUART_InitStruct.baudRate          = FL_LPUART_BAUDRATE_9600;
  70.     LPUART_InitStruct.dataWidth         = FL_LPUART_DATA_WIDTH_8B;
  71.     LPUART_InitStruct.stopBits          = FL_LPUART_STOP_BIT_WIDTH_1B;
  72.     LPUART_InitStruct.parity            = FL_LPUART_PARITY_NONE;
  73.     LPUART_InitStruct.transferDirection = FL_LPUART_DIRECTION_TX_RX;
  74.     FL_LPUART_Init(LPUARTx, &LPUART_InitStruct);

  75.     NVIC_DisableIRQ(LPUARTx_IRQn);
  76.     NVIC_SetPriority(LPUARTx_IRQn, 2);
  77.     NVIC_EnableIRQ(LPUARTx_IRQn);

  78.     FL_LPUART_EnableIT_RXBuffFull(LPUARTx);

  79.     printf("\r\n");

  80.     shell_init();

  81.     printf("\r\n");
  82. }


  83. /*******************************************************************************
  84. * @brief      
  85. * @param      
  86. * @retval      
  87. * @attention   
  88. *******************************************************************************/
  89. void LPUARTx_IRQHandler(void)
  90. {
  91.     if((FL_ENABLE == FL_LPUART_IsEnabledIT_RXBuffFull(LPUART0)) &&
  92.        (FL_SET    == FL_LPUART_IsActiveFlag_RXBuffFull(LPUART0)) )
  93.     {
  94.         shell(FL_LPUART_ReadRXBuff(LPUART0));
  95.     }

  96.     if((FL_ENABLE == FL_LPUART_IsEnabledIT_RXBuffFull(LPUART1)) &&
  97.        (FL_SET    == FL_LPUART_IsActiveFlag_RXBuffFull(LPUART1)) )
  98.     {
  99.         FL_LPUART_WriteTXBuff(LPUART1, FL_LPUART_ReadRXBuff(LPUART1));
  100.     }
  101. }


  102. /*******************************************************************************
  103. * @brief      
  104. * @param      
  105. * @retval      
  106. * @attention   
  107. *******************************************************************************/
  108. int fputc(int ch, FILE *f)
  109. {
  110.     FL_LPUART_WriteTXBuff(LPUART0, (uint8_t)ch);

  111.     while(FL_LPUART_IsActiveFlag_TXShiftBuffEmpty(LPUART0) == 0);

  112.     FL_LPUART_ClearFlag_TXShiftBuffEmpty(LPUART0);

  113.     return ch;
  114. }


  115. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/
复制代码

LPTIM、TASK移植头文件:

  1. /*******************************************************************************
  2. * @file    LPTIMxx.h
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #ifndef __LPTIMxx_H__
  10. #define __LPTIMxx_H__


  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif


  14. #undef  EXTERN


  15. #ifdef  __LPTIMxx_C__
  16. #define EXTERN
  17. #else
  18. #define EXTERN extern
  19. #endif


  20. /* Includes ------------------------------------------------------------------*/
  21. #include "config.h"


  22. /* Exported constants --------------------------------------------------------*/
  23. /* Exported types ------------------------------------------------------------*/
  24. /* Exported macro ------------------------------------------------------------*/


  25. /* Exported functions --------------------------------------------------------*/
  26. EXTERN void LPTIM32_Init(void);


  27. #ifdef __cplusplus
  28. }
  29. #endif


  30. #endif


  31. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

复制代码

LPTIM、TASK移植源程序:使用的官方程序库中已经使用SysTick定时器作为Delay函数的实现,所以我们需要重新初始化一个定时器来实现TASK的功能实现;

  1. /*******************************************************************************
  2. * @file    LPTIMxx.c
  3. * @author  King
  4. * @version V1.00
  5. * @date    27-Nov-2021
  6. * @brief   ......
  7. *******************************************************************************/


  8. /* Define to prevent recursive inclusion -------------------------------------*/
  9. #define __LPTIMxx_C__


  10. /* Includes ------------------------------------------------------------------*/
  11. #include "LPTIMxx.h"


  12. /* Private typedef -----------------------------------------------------------*/
  13. /* Private define ------------------------------------------------------------*/
  14. /* Private macro -------------------------------------------------------------*/


  15. /* Private variables ---------------------------------------------------------*/
  16. volatile uint32_t LPTIM32_Tick = 0;


  17. /* Private function prototypes -----------------------------------------------*/
  18. /* Private functions ---------------------------------------------------------*/


  19. /* Exported variables --------------------------------------------------------*/
  20. /* Exported function prototypes ----------------------------------------------*/


  21. /*******************************************************************************
  22. * @brief      
  23. * @param      
  24. * @retval      
  25. * @attention   
  26. *******************************************************************************/
  27. void LPTIM32_Init(void)
  28. {
  29.     FL_LPTIM32_InitTypeDef LPTIM32_InitStruct;

  30.     FL_LPTIM32_StructInit(&LPTIM32_InitStruct);
  31.     LPTIM32_InitStruct.clockSource          = FL_CMU_LPTIM32_CLK_SOURCE_APBCLK;
  32.     LPTIM32_InitStruct.mode                 = FL_LPTIM32_OPERATION_MODE_NORMAL;
  33.     LPTIM32_InitStruct.prescalerClockSource = FL_LPTIM32_CLK_SOURCE_INTERNAL;
  34.     LPTIM32_InitStruct.prescaler            = FL_LPTIM32_PSC_DIV8;
  35.     LPTIM32_InitStruct.autoReload           = 1000 - 1;
  36.     LPTIM32_InitStruct.onePulseMode         = FL_LPTIM32_ONE_PULSE_MODE_CONTINUOUS;
  37.     LPTIM32_InitStruct.triggerEdge          = FL_LPTIM32_ETR_TRIGGER_EDGE_RISING;
  38.     LPTIM32_InitStruct.countEdge            = FL_LPTIM32_ETR_COUNT_EDGE_RISING;
  39.     FL_LPTIM32_Init(LPTIM32, &LPTIM32_InitStruct);

  40.     FL_LPTIM32_ClearFlag_Update(LPTIM32);
  41.     FL_LPTIM32_EnableIT_Update(LPTIM32);

  42.     NVIC_DisableIRQ(LPTIMx_IRQn);
  43.     NVIC_SetPriority(LPTIMx_IRQn, 2);
  44.     NVIC_EnableIRQ(LPTIMx_IRQn);

  45.     FL_LPTIM32_Enable(LPTIM32);
  46. }


  47. /*******************************************************************************
  48. * @brief      
  49. * @param      
  50. * @retval      
  51. * @attention   
  52. *******************************************************************************/
  53. void LPTIM_IRQHandler(void)
  54. {
  55.     if(FL_LPTIM32_IsEnabledIT_Update(LPTIM32) &&
  56.        FL_LPTIM32_IsActiveFlag_Update(LPTIM32) )
  57.     {
  58.         LPTIM32_Tick++;
  59.         TASK_TimeSlice(LPTIM32_Tick);

  60.         FL_LPTIM32_ClearFlag_Update(LPTIM32);
  61.     }
  62. }


  63. /******************* (C) COPYRIGHT 2021 *************************END OF FILE***/

复制代码

主程序:

  1. /*******************************************************************************
  2. * @brief      
  3. * @param      
  4. * @retval      
  5. * @attention   
  6. *******************************************************************************/
  7. int main(void)
  8. {
  9.     MCU_Init();

  10.     KEY_Init();

  11.     LED_Init();

  12.     printf("\r\nDEMO V1.1 FM33LG0xx %s %s\r\n", __DATE__, __TIME__);

  13.     while(1)
  14.     {
  15.         TASK_Scheduling();
  16.     }
  17. }
复制代码

MCU初始化:

  1. /*******************************************************************************
  2. * @brief      
  3. * @param      
  4. * @retval      
  5. * @attention   
  6. *******************************************************************************/
  7. void MCU_Init(void)
  8. {
  9.     MF_Clock_Init();

  10.     MF_SystemClock_Config();

  11.     FL_Init();

  12.     MF_Config_Init();

  13.     LPTIM32_Init();

  14.     LPUARTx_Init(LPUART0);
  15. }
复制代码

调试运行:

将编写完成的程序进行编译,确认无误后下载程序;打开串口调试终端,配置为9600,N,8,1;程序在启动运行后,可以看到如下图的打印消息;然后依次按下KEY1~KEY4按键,并可看终端打印的消息;最后输入led 0和led 1来控制LED灯停止闪烁和恢复闪烁功能;如下图所示:


至此基础工程就完成了,后期可以在此工程的基础上添加、验证其它的功能了……


FM33LG048_xld0932.zip (356.05 KB, 下载次数: 213)

回复

使用道具 举报

0

主题

1

帖子

48

积分

初级工程师

Rank: 1

积分
48
2022-1-4 11:47:56 显示全部楼层
感谢感谢 最近新学正缺学习基础的资料
回复

使用道具 举报

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

返回顶部