My attempt at using the mbed without the mbed libraries.
Here is a main.cpp, that uses the registers library.
main.cpp
- Committer:
- elevatorguy
- Date:
- 2013-01-03
- Revision:
- 4:6ed8900881e8
- Parent:
- 3:88da6c0412b0
- Child:
- 6:d40cd917854d
File content as of revision 4:6ed8900881e8:
#include "registers.h" DigitalOut led1(p20); DigitalOut led2(p19); DigitalOut led3(LED3); DigitalOut led4(LED4); DigitalIn switch1(p21); Serial pc(115200); Timer t(1000); //ms resolution for a serial stopwatch demo Timeout tock; Ticker tock2; extern "C" void isr(void) { led1 = !led1; } extern "C" void isr2(void) { led2 = !led2; } int main() { //Timer and Ticker demonstration switch1.mode(PULLDOWN); t.start(); tock.attach(&isr, 2); tock2.attach(&isr2, 0.5); while(1) { double time = t; int h = 0; int m = 0; while(time > 3600) { time = time - 3600; h = h + 1; } while(time > 60) { time = time - 60; m = m + 1; } if(h < 10.0) { pc.putc('0'); } if(h != 0) { pc.printf(h); } else { pc.putc('0'); } pc.putc(':'); if(m < 10.0) { pc.putc('0'); } if(m != 0) { pc.printf(m); } else { pc.putc('0'); } pc.putc(':'); if(time < 10.0) { pc.putc('0'); } if(time < 1.0) { pc.putc('0'); } pc.printf(time, 100); int timeAsInt = time; if((time-timeAsInt)*100 < 10.0) { pc.putc('0'); } if((time-timeAsInt)*100 < 1.0) { pc.putc('0'); } pc.printf("\r\n"); } }