#include <htc.h>
#include "buttons.h"
+#include "timer.h"
void buttons_sleep()
{
+ /* If the rocker is on, sleep until it is placed in the off position */
+ IOCBN4 = 0; IOCBP4 = 1;
+ IOCBN5 = 0; IOCBP5 = 1;
+ while ((buttons_read() & (IN_ROCKERA | IN_ROCKERB))) {
+ IOCIE = 1;
+ SLEEP();
+ IOCIE = 0;
+ timer_mwait(50); /* debounce */
+ }
+
+ /* Now that the rocker is off, sleep until it is turned on */
+ IOCBN4 = 1; IOCBP4 = 0; IOCBF4 = 0;
+ IOCBN5 = 1; IOCBP5 = 0; IOCBF5 = 0;
if ((buttons_read() & (IN_ROCKERA | IN_ROCKERB)) == 0) {
- IOCBF4 = 0;
- IOCBF5 = 0;
IOCIE = 1;
SLEEP();
IOCIE = 0;