本帖最后由 比神乐 于 2022-11-21 07:07 编辑
用易码魔盒生成了一个模板,用定时器0中断定时使LED灯闪烁。
代码:
- //************************************************************
- // Copyright (c)
- // FileName : main.c
- // Module Function :
- // Instructions : Contains the MCU initialization function and its H file
- //************************************************************
- /********************Includes************************************************************************/
- #include "SC_Init.h" //MCU Init header,Include all IC resource headers
- #include "SC_it.h"
- #include "..\Drivers\SCDriver_list.h"
- #include "HeadFiles\SysFunVarDefine.h"
- /**************************************Generated by EasyCodeCube*************************************/
- /*************************************.Generated by EasyCodeCube.************************************/
- /*****************************************************************************************************
- * Function Name: main
- * Description : This function implements main function.
- * Arguments : None
- * Return Value : None
- ******************************************************************************************************/
- void main(void)
- {
- /*<Generated by EasyCodeCube begin>*/
- /*<UserCodeStart>*//*<SinOne-Tag><3>*/
- SC_Init(); /*** MCU init***/
- /*<UserCodeEnd>*//*<SinOne-Tag><3>*/
- /*<UserCodeStart>*//*<SinOne-Tag><4>*/
- /*****MainLoop*****/
- while(1)
- {
- /*<UserCodeStart>*//*<SinOne-Tag><5>*/
- /*****User program*****/
- /*<UserCodeEnd>*//*<SinOne-Tag><5>*/
- /*<Begin-Inserted by EasyCodeCube for Condition>*/
- }
- /*<UserCodeEnd>*//*<SinOne-Tag><4>*/
- /*<Generated by EasyCodeCube end>*/
- }
- /*****************************************************
- *函数名称: SC_Init
- *函数功能: MCU初始化函数
- *入口参数:void
- *出口参数:void
- *****************************************************/
- void SC_Init(void)
- {
- SC_GPIO_Init();
- SC_OPTION_Init();
- SC_TIM0_Init();
- /*write initial function here*/
- EA = 1;
- }
- void Timer0Interrupt() interrupt 1
- {
- /*TIM0_it write here begin*/
- TIM0_Mode1SetReloadCounter(1000);
-
- if(cnt>=1000)
- {
- cnt=0;
- GPIO_TogglePin(GPIO0,GPIO_PIN_1);
- }
- cnt++;
- /*TIM0_it write here*/
- /*<Generated by EasyCodeCube begin>*/
- /*<UserCodeStart>*//*<SinOne-Tag><6>*/
- //Timer0Interrupt
- {
- /*<UserCodeStart>*//*<SinOne-Tag><7>*/
- /*****User program*****/
- /*<UserCodeEnd>*//*<SinOne-Tag><7>*/
- /*<Begin-Inserted by EasyCodeCube for Condition>*/
- }
- /*<UserCodeEnd>*//*<SinOne-Tag><6>*/
- /*<Generated by EasyCodeCube end>*/
- /*Timer0Interrupt Flag Clear begin*/
- /*Timer0Interrupt Flag Clear end*/
- }
效果图
|