Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 0:d1018730bb52, committed 2015-02-18
- Comitter:
- lzzcd001
- Date:
- Wed Feb 18 14:47:35 2015 +0000
- Commit message:
- Extra problem 1 for HW 1
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Feb 18 14:47:35 2015 +0000 @@ -0,0 +1,53 @@ +#include "mbed.h" + +DigitalIn sw(p5); +DigitalOut led(p10); +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +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; + if ((LPC_WDT->WDMOD >> 2) & 1) + myled4 = 1; else myled3 = 1; + + wdt.kick(10.0); + + while(1) { + if (sw == 1) { + led = 1; + myled1 = 1; + wait(0.2); + } else { + if (count >= 20) while(1) {}; + led = 0; + myled1 = 0; + wait(0.2); + } + count++; + wdt.kick(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 18 14:47:35 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file