Wesley Schon
/
ECE4180Lab1Part2
Lab 1 Parts 1 and 2, and watchdog timer EC
Diff: main.cpp
- Revision:
- 0:38ede70f5c4d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jan 23 20:15:24 2016 +0000 @@ -0,0 +1,70 @@ +#include "mbed.h" + +PwmOut myled(p21); +DigitalIn button1(p30); +DigitalIn button2(p29); +DigitalIn switch1(p8); +DigitalOut myled4(LED4); +DigitalOut myled3(LED3); +float intensity = 0.5f; + + +class Watchdog { +public: +// Load timeout value in watchdog timer and enable + void kick(float s) { + LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK + uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 + LPC_WDT->WDTC = s * (float)clk; + LPC_WDT->WDMOD = 0x3; // Enabled and Reset + kick(); + } +// "kick" or "feed" the dog - reset the watchdog timer +// by writing this required bit pattern + void kick() { + LPC_WDT->WDFEED = 0xAA; + LPC_WDT->WDFEED = 0x55; + } +}; + +// Setup the watchdog timer +Watchdog wdt; + + +int main() { + + int count = 0; + wdt.kick(5.0); + if ((LPC_WDT->WDMOD >> 2) & 1) + myled4 = 1; else myled3 = 1; + wait(2); + myled4 = 0; + myled3 = 0; + + + + while(1) { + if (button1 == 0) { + if (intensity <= 1.0f) { + intensity += 0.07f; + } + } + if (button2 == 0) { + if (intensity >= 0.0f) { + intensity -= 0.07f; + } + } + if (switch1 == 0) { + myled = intensity; + } + else { + myled = 0.0f; + } + wait(0.1); + count++; + if (count == 70) { + wait(11); + } + wdt.kick(); //kick the watchdog timer + } +}