- void sleep() {
- u8 i = 0;
- if "condition" {
- ...
- ...
- ...
- if(i == NUM_OF_CMD) { // no task should be invoked
- if "condition1" {
- WKTCL = 0x11;
- WKTCH = 0xAB;
- sendDataByUartx(UART1, i-1);
- sendDataByUartx(UART1, WKTCH); // 写完直接读发现是0xFF
- sendDataByUartx(UART1, WKTCL); // 写完直接读发现是0xFF
-
- } else if "condation2" {
- sendDataByUartx(UART1, i-1);
- sendDataByUartx(UART1, WKTCH); // condition2是由中断进来的
- sendDataByUartx(UART1, WKTCL); // 此处读到的值是随机的,忽大忽小,正常在一个计数周期内向上计数应该越来越大,向下计数应该越来越小才对,且此处没有修改休眠值,从这里开始到下次休眠启动却还是5s,不是接续计时而像是重新计时
- }
- else {
- WKTCH = 0x00; // 情况3不需要启动定时唤醒
- }
- PCON |= 0x02; // 休眠
- _nop_();_nop_();
- _nop_();_nop_();
- _nop_();_nop_();
- sendDataByUartx(UART1, i+2); // 如果外部中断唤醒,此处的值随机,如果定时器唤醒
- sendDataByUartx(UART1, WKTCH); // 前几次计时满读出来是0xFF,最后一次是0x7F
- sendDataByUartx(UART1, WKTCL); // 除外部中断唤醒外每次读出来都是0xFF
- if(WKTCL == 0xFF && WKTCH == 0xFF) {
- "定时器唤醒后的代码"
- }
- }
- }
- }
复制代码
|