/****************************************Copyright (c)**************************************************** ** Guangzhou ZHIYUAN electronics Co.,LTD. ** ** http://www.embedtools.com ** **--------------File Info--------------------------------------------------------------------------------- ** File name: main.c ** Last modified Date: 2010-02-04 ** Last Version: V1.0 ** Descriptions: The main() function example template ** **-------------------------------------------------------------------------------------------------------- ** Created by: Lanwuqiang ** Created date: 2010-02-05 ** Version: V1.0 ** Descriptions: 添加用户应用程序 ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ZhangNingbo ** Modified date: 2010-02-25 ** Version: V1.0 ** Descriptions: 深度掉电示例程序 ** **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: ** Version: ** Descriptions: ** ** Rechecked by: *********************************************************************************************************/ #include "..\config.h" /********************************************************************************************************* 宏定义 *********************************************************************************************************/ #define BEEP (1ul << 7) /* 蜂鸣器P2.7 */ #define BEEPOFF() GPIO2DATA |= BEEP /* 蜂鸣器关 */ #define BEEPON() GPIO2DATA &=~BEEP /* 蜂鸣器开 */ #define LED1 (1ul << 8) /* LED1 P2.8 */ #define LED1OFF() GPIO2DATA |= LED1 /* LED1 关 */ #define LED1ON() GPIO2DATA &=~LED1 /* LED1 开 */ #define IRC_OUT_PD (0x1 << 0) #define IRC_PD (0x1 << 1) #define FLASH_PD (0x1 << 2) #define BOD_PD (0x1 << 3) #define ADC_PD (0x1 << 4) #define SYS_OSC_PD (0x1 << 5) #define WDT_OSC_PD (0x1 << 6) #define SYS_PLL_PD (0x1 << 7) /********************************************************************************************************* ** Function name: myDelay ** Descriptions: 软件延时 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void myDelay (INT32U ulTime) { INT32U i; i = 0; while (ulTime--) { for (i = 0; i < 5000; i++); } } /********************************************************************************************************* ** Function name: SWD_Wait ** Descriptions: 防止调试接口失效 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void SWD_Wait (void) { GPIO3DIR &= ~(0x02); /* 使用PIO3_1接口,按键KEY2 */ if ((GPIO3DATA & 0x02) == 0) { while(1); } } /********************************************************************************************************* ** Function name: PMU_PowerDown ** Descriptions: 芯片进入深度掉电模式 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void PMU_PowerDown (void) { uint32 regVal; if ((PCON & ((0x01 << 8) | (0x01 << 11))) != 0x0) { /* * 检查睡眠模式和深度睡眠模式下的标志位,如果进入睡眠模式或深度睡眠模式,清除PCON的标志位 */ regVal = PCON; regVal |= ((0x01 << 8) | (0x01 << 11)); PCON = regVal; if ((GPREG0 != 0x12345678) || (GPREG1 != 0x87654321) ||(GPREG2 != 0x56781234) ||(GPREG3 != 0x43218765)) { while (1); } } else { /* 如果没有进入睡眠或深度睡眠模式,进入掉电模式*/ GPREG0 = 0x12345678; GPREG1 = 0x87654321; GPREG2 = 0x56781234; GPREG3 = 0x43218765; SCR |= 0x04; PCON = 0x2; __WFI(); } } /********************************************************************************************************* ** Function name: main ** Descriptions: 当硬件基于EasyCortex M3-1300开发板时,使用跳线帽短接JP8中的P2.7与BEEP,P2.8与LED1 ** P3.1与KEY2,P1.4与KEY1用杜邦线连接。程序开始运行蜂鸣器响一声后进入掉电模式,当KEY1 ** 按下时,CPU被唤醒,蜂鸣器响一声(程序重新执行),LED1不断闪烁。 ** 注意:使用该程序后,会导致下次程序烧写的时候检测不到芯片(由于芯片进入掉电模式将 ** SWD调试模式关闭),因此添加SWD_Wait()函数,下载时按住KEY2不松手,即可正常下载调试 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ int main(void) { volatile INT32U regVal; targetInit(); /* 初始化目标板,切勿删除 */ pinInit(); /* 引脚初始化 */ SYSAHBCLKCTRL |= (1ul << 6); /* 使能GPIO模块时钟 */ GPIO2DIR |= BEEP | LED1; /* 设置BEEP引脚为输出 */ SWD_Wait(); /* 防止调试接口SWD失效 */ BEEPON(); myDelay(400); BEEPOFF(); /* * 掉电模式 */ PMU_PowerDown(); /* CPU进入掉电模式 */ while (1) { LED1ON(); myDelay(500); LED1OFF(); myDelay(500); } } /********************************************************************************************************* End Of File *********************************************************************************************************/