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.
main.cpp
00001 #include "mbed.h" 00002 00003 DigitalIn sw(p5); 00004 DigitalOut led(p10); 00005 DigitalOut myled1(LED1); 00006 DigitalOut myled2(LED2); 00007 DigitalOut myled3(LED3); 00008 DigitalOut myled4(LED4); 00009 00010 class Watchdog { 00011 public: 00012 // Load timeout value in watchdog timer and enable 00013 void kick(float s) { 00014 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK 00015 uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 00016 LPC_WDT->WDTC = s * (float)clk; 00017 LPC_WDT->WDMOD = 0x3; // Enabled and Reset 00018 kick(); 00019 } 00020 // "kick" or "feed" the dog - reset the watchdog timer 00021 // by writing this required bit pattern 00022 void kick() { 00023 LPC_WDT->WDFEED = 0xAA; 00024 LPC_WDT->WDFEED = 0x55; 00025 } 00026 }; 00027 00028 // Setup the watchdog timer 00029 Watchdog wdt; 00030 00031 int main() { 00032 int count = 0; 00033 if ((LPC_WDT->WDMOD >> 2) & 1) 00034 myled4 = 1; else myled3 = 1; 00035 00036 wdt.kick(10.0); 00037 00038 while(1) { 00039 if (sw == 1) { 00040 led = 1; 00041 myled1 = 1; 00042 wait(0.2); 00043 } else { 00044 if (count >= 20) while(1) {}; 00045 led = 0; 00046 myled1 = 0; 00047 wait(0.2); 00048 } 00049 count++; 00050 wdt.kick(); 00051 } 00052 00053 }
Generated on Sat Jul 16 2022 01:42:55 by
1.7.2