📄 main.c
字号:
#include "LED.h"
#include "Key.h"
#include "LCD.h"
#include <ucos_ii.h>
#define STKSIZE 128
OS_STK Stack1[STKSIZE], Stack2[STKSIZE], Stack3[STKSIZE];
OS_STK StackCount[STKSIZE];
void Task1(void *arg)
{
while(1)
{
LED_Set(0, LED_TOGGLE);
OSTimeDly(128);
}
}
void Task2(void *arg)
{
while(1)
{
LED_Set(1, LED_TOGGLE);
OSTimeDly(256);
}
}
void Task3(void *arg)
{
while(1)
{
LED_Set(2, LED_TOGGLE);
OSTimeDly(512);
}
}
void TaskCount(void *arg)
{
unsigned hh = 0, mm = 0, ss = 0, ms = 0;
RTC_PrescalerConfig(256);
RTC_FlagClear(RTC_OWIR);
RTC_FlagClear(RTC_AIR);
RTC_FlagClear(RTC_SIR);
RTC_FlagClear(RTC_GIR);
EIC_IRQChannelConfig(RTC_IRQChannel, ENABLE);
EIC_IRQChannelPriorityConfig(RTC_IRQChannel, 1);
EIC_IRQConfig(ENABLE);
RTC_ITConfig(RTC_SIT | RTC_GIT, ENABLE);
OSTimeDly(1);
OSStatInit();
OSTaskCreate(Task1, 0, Stack1 + (STKSIZE - 1), 1);
OSTaskCreate(Task2, 0, Stack2 + (STKSIZE - 1), 2);
OSTaskCreate(Task3, 0, Stack3 + (STKSIZE - 1), 3);
LCD_Goto(0, 0);
LCD_Puts("00:00:00:00");
LCD_Goto(1, 0);
LCD_Puts("CPU Usage:");
while(1)
{
OSTimeDly(1);
if(++ms >= OS_TICKS_PER_SEC)
{
ms = 0;
if(++ss >= 60)
{
ss = 0;
if(++mm >= 60)
{
mm = 0;
++hh;
LCD_Goto(0, 0);
LCD_Printf("%02u", hh);
}
LCD_Goto(0, 3);
LCD_Printf("%02u", mm);
}
LCD_Goto(0, 6);
LCD_Printf("%02u", ss);
}
LCD_Goto(0, 9);
LCD_Printf("%02u", ms * 100 / OS_TICKS_PER_SEC);
LCD_Goto(1, 10);
LCD_Printf("%3d%%", OSCPUUsage);
}
}
void __main(void)
{
#ifdef DEBUG
debug();
#endif
RCCU_Div2Config(ENABLE); // Enable DIV2
RCCU_MCLKConfig(RCCU_DEFAULT); // Configure MCLK = RCLK
RCCU_FCLKConfig(RCCU_RCLK_8); // Configure FCLK = RCLK / 8
RCCU_PCLKConfig(RCCU_RCLK_8); // Configure PCLK = RCLK / 8
RCCU_PLL1Config(RCCU_PLL1_Mul_12 , RCCU_Div_2) ; // Configure the PLL1 ( * 12 , / 2 )
while(RCCU_FlagStatus(RCCU_PLL1_LOCK) == RESET);// Wait PLL to lock
RCCU_RCLKSourceConfig(RCCU_PLL1_Output); // Select PLL1_Output as RCLK clock
// at this step the CKOUT signal should be equal to 48 Mhz
EIC_Init();
LED_Init();
Key_Init();
LCD_Init();
LED_Set(0, LED_ON);
LED_Set(1, LED_ON);
LED_Set(2, LED_ON);
OSInit();
OSTaskCreate(TaskCount, 0, StackCount + (STKSIZE - 1), 4);
OSStart();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -