📄 main.c
字号:
#include "includes.h"
/*
*********************************************************************************************************
CPU Configuration
*********************************************************************************************************
*/
void MAIN_vInit(void)
{
// USER CODE BEGIN (Init,2)
// USER CODE END
/// -----------------------------------------------------------------------
/// Configuration of the System Clock:
/// -----------------------------------------------------------------------
/// - VCO clock used, input clock is connected
/// - input frequency is 12 MHz
/// - VCO output frequency 100 .. 150 MHz
/// - system clock is 30 MHz
MAIN_vUnlockProtecReg(); // unlock write security
PLLCON = 0x7814; // load PLL control register
//OSTickISRInit(); // RTC initiates as timertick;
PSW_IEN = 1;
}
/*
*********************************************************************************************************
@Function void MAIN_vUnlockProtecReg(void)
---------------------------------------------------------------------------------------------------------
@Description This function makes it possible to write one protected
register. After calling of this function and write on the
protected register is the security level set to low
protected mode.
*********************************************************************************************************
*/
void MAIN_vUnlockProtecReg(void)
{
INT8U ubPASSWORD;
if((SCUSLS & 0x1800) == 0x0800) // if low protected mode
{
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x8E00 | ubPASSWORD; // command 4
} // end if low protected mode
if((SCUSLS & 0x1800) == 0x1800) // if write protected mode
{
SCUSLC = 0xAAAA; // command 0
SCUSLC = 0x5554; // command 1
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x9600 | ubPASSWORD; // command 2
SCUSLC = 0x0800; // command 3; new PASSWOR is 0x00
ubPASSWORD = SCUSLS & 0x00FF;
ubPASSWORD = ~ubPASSWORD;
SCUSLC = 0x8E00 | ubPASSWORD; // command 4
}
}
/*
*********************************************************************************************************
Task's parameters declaration
*********************************************************************************************************
*/
#define TimeTick1Prio 11 /* define task's priority */
#define TimeTick2Prio 12
#define TimeTick1Stk_Num 100 /*define task's stack */
#define TimeTick2Stk_Num 100
OS_STK TimeTick1Stk[TimeTick1Stk_Num];
OS_STK TimeTick2Stk[TimeTick2Stk_Num];
/*
*********************************************************************************************************
@Function void TimeTick1(void *pdata)
----------------------------------------------------------------------------------------------------------
@Description 使P1L=0x0F,并通过OSTimeDly(1)来实现与TimeTick2的切换
*********************************************************************************************************
*/
void TimeTick1(void *pdata)
{
INT32U i;
pdata = pdata;
while (1)
{
P1L = 0x0F; /* cotrol P1L0 */
for(i=0; i<3000000; i++); /* delay time */
OSTimeDly(1); /* Set ticks = 40 , excute OSSched; */
}
}
/*
*********************************************************************************************************
@Function void TimeTick1(void *pdata)
---------------------------------------------------------------------------------------------------------
@Description 使P1L=0xF0,一个时钟节拍后,自动切换到TimeTick1
*********************************************************************************************************
*/
void TimeTick2(void *pdata)
{
pdata = pdata;
while(1)
{
P1L = 0xF0;
}
}
/*
*********************************************************************************************************
@Function void Port1_init(void)
---------------------------------------------------------------------------------------------------------
@Description P1口的初始化,输出方向
*********************************************************************************************************
*/
void Port1_init(void)
{
DP1L = 0x0000; //Port direction : output ;
DP1H = 0x0000;
P1L = 0x00AA;
P1H = 0x00AA;
}
/*
*********************************************************************************************************
@Function void main(void)
---------------------------------------------------------------------------------------------------------
@Description 主函数
*********************************************************************************************************
*/
void main(void)
{
MAIN_vInit();
Port1_init();
OSInit(); /* initiate Ucos-II */
OSTaskCreate(TimeTick1, (void*)0, &TimeTick1Stk[TimeTick1Stk_Num-1], TimeTick1Prio); /* Create TimeTick1 */
OSTaskCreate(TimeTick2, (void*)0, &TimeTick2Stk[TimeTick2Stk_Num-1], TimeTick2Prio); /* Create TimeTick2 */
OSStart(); /* Start Ucso-II */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -