/****************************************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: WAKEUP_IRQHandler ** Descriptions: 唤醒中断服务函数 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void WAKEUP_IRQHandler (void) { uint32 regVal; regVal = STARTSRP0; if (regVal != 0) { STARTRSRP0CLR = regVal; /* 清除唤醒中断标志 */ } regVal = STARTSRP1; if (regVal != 0) { STARTRSRP1CLR = regVal; /* 清除唤醒中断标志 */ } __NOP(); } /********************************************************************************************************* ** Function name: PMU_Init ** Descriptions: 唤醒配置 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ void PMU_Init (void) { INT32U err; PDRUNCFG &= ~(WDT_OSC_PD | SYS_OSC_PD | ADC_PD); err = zyIsrSet(WAKEUP_PIO0_6, (unsigned long)WAKEUP_IRQHandler, PRIO_TWO); if (err != ZY_OK) { while(1); } IOCON_PIO0_6 &= ~0x07; IOCON_PIO0_6 |= 0x20; GPIO0DIR &= ~(1ul << 6); /* 设置PIO0_6为GPIO输入 */ STARTAPRP0 = (1ul << 6); /* 设置PIO0_6为GPIO输入 */ STARTRSRP0CLR = (1ul << 6); STARTERP0 = (1ul << 6); /* 使能PIO0_6为唤醒源 */ } /********************************************************************************************************* ** Function name: main ** Descriptions: 当硬件硬件基于EasyCotex M3-1300时,需要短接JP8中的P2.7与BEEP,P2.8与LED1,用跳线将 ** P0.6与KEY1相连。程序开始运行蜂鸣器响一声后进入睡眠模式,当KEY1按下时,CPU被唤醒, ** LED1不断闪烁。 ** 用户也可以根据自己的底板设计自行连接。 ** input parameters: 无 ** output parameters: 无 ** Returned value: 无 *********************************************************************************************************/ int main (void) { volatile INT32U regVal; targetInit(); /* 初始化目标板,切勿删除 */ pinInit(); /* 引脚初始化 */ SYSAHBCLKCTRL |= (1ul << 6); /* 使能GPIO模块时钟 */ GPIO2DIR |= BEEP | LED1; /* 设置BEEP引脚为输出 */ BEEPON(); myDelay(400); BEEPOFF(); /* * 睡眠模式 */ PMU_Init(); regVal = SYS_PLL_PD | WDT_OSC_PD | ADC_PD | BOD_PD; PDAWAKECFG = PDRUNCFG; PDSLEEPCFG = regVal; __WFI(); /* 进入睡眠模式 */ while (1) { LED1ON(); myDelay(200); LED1OFF(); myDelay(200); } } /********************************************************************************************************* End Of File *********************************************************************************************************/