My attempt at using the mbed without the mbed libraries.

Dependencies:   ARM registers

Here is a main.cpp, that uses the registers library.

Committer:
elevatorguy
Date:
Thu Jan 03 03:57:07 2013 +0000
Revision:
4:6ed8900881e8
Parent:
3:88da6c0412b0
Child:
6:d40cd917854d
Timeout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elevatorguy 2:e26c096f1946 1 #include "registers.h"
elevatorguy 3:88da6c0412b0 2 DigitalOut led1(p20);
elevatorguy 3:88da6c0412b0 3 DigitalOut led2(p19);
elevatorguy 2:e26c096f1946 4 DigitalOut led3(LED3);
elevatorguy 2:e26c096f1946 5 DigitalOut led4(LED4);
elevatorguy 0:5fa5046f2ff5 6 DigitalIn switch1(p21);
elevatorguy 0:5fa5046f2ff5 7
elevatorguy 3:88da6c0412b0 8 Serial pc(115200);
elevatorguy 2:e26c096f1946 9 Timer t(1000); //ms resolution for a serial stopwatch demo
elevatorguy 2:e26c096f1946 10
elevatorguy 4:6ed8900881e8 11 Timeout tock;
elevatorguy 3:88da6c0412b0 12 Ticker tock2;
elevatorguy 3:88da6c0412b0 13
elevatorguy 3:88da6c0412b0 14 extern "C" void isr(void) {
elevatorguy 3:88da6c0412b0 15 led1 = !led1;
elevatorguy 3:88da6c0412b0 16 }
elevatorguy 3:88da6c0412b0 17
elevatorguy 3:88da6c0412b0 18 extern "C" void isr2(void) {
elevatorguy 3:88da6c0412b0 19 led2 = !led2;
elevatorguy 3:88da6c0412b0 20 }
elevatorguy 3:88da6c0412b0 21
elevatorguy 3:88da6c0412b0 22 int main() { //Timer and Ticker demonstration
elevatorguy 0:5fa5046f2ff5 23 switch1.mode(PULLDOWN);
elevatorguy 2:e26c096f1946 24 t.start();
elevatorguy 3:88da6c0412b0 25
elevatorguy 4:6ed8900881e8 26 tock.attach(&isr, 2);
elevatorguy 4:6ed8900881e8 27 tock2.attach(&isr2, 0.5);
elevatorguy 2:e26c096f1946 28 while(1)
elevatorguy 2:e26c096f1946 29 {
elevatorguy 2:e26c096f1946 30 double time = t;
elevatorguy 2:e26c096f1946 31 int h = 0;
elevatorguy 2:e26c096f1946 32 int m = 0;
elevatorguy 2:e26c096f1946 33 while(time > 3600)
elevatorguy 2:e26c096f1946 34 {
elevatorguy 2:e26c096f1946 35 time = time - 3600;
elevatorguy 2:e26c096f1946 36 h = h + 1;
elevatorguy 2:e26c096f1946 37 }
elevatorguy 2:e26c096f1946 38 while(time > 60)
elevatorguy 2:e26c096f1946 39 {
elevatorguy 2:e26c096f1946 40 time = time - 60;
elevatorguy 2:e26c096f1946 41 m = m + 1;
elevatorguy 2:e26c096f1946 42 }
elevatorguy 2:e26c096f1946 43 if(h < 10.0)
elevatorguy 2:e26c096f1946 44 {
elevatorguy 2:e26c096f1946 45 pc.putc('0');
elevatorguy 2:e26c096f1946 46 }
elevatorguy 2:e26c096f1946 47 if(h != 0)
elevatorguy 2:e26c096f1946 48 {
elevatorguy 2:e26c096f1946 49 pc.printf(h);
elevatorguy 2:e26c096f1946 50 }
elevatorguy 2:e26c096f1946 51 else
elevatorguy 2:e26c096f1946 52 {
elevatorguy 2:e26c096f1946 53 pc.putc('0');
elevatorguy 2:e26c096f1946 54 }
elevatorguy 2:e26c096f1946 55 pc.putc(':');
elevatorguy 2:e26c096f1946 56 if(m < 10.0)
elevatorguy 2:e26c096f1946 57 {
elevatorguy 2:e26c096f1946 58 pc.putc('0');
elevatorguy 2:e26c096f1946 59 }
elevatorguy 2:e26c096f1946 60 if(m != 0)
elevatorguy 2:e26c096f1946 61 {
elevatorguy 2:e26c096f1946 62 pc.printf(m);
elevatorguy 2:e26c096f1946 63 }
elevatorguy 2:e26c096f1946 64 else
elevatorguy 2:e26c096f1946 65 {
elevatorguy 2:e26c096f1946 66 pc.putc('0');
elevatorguy 2:e26c096f1946 67 }
elevatorguy 2:e26c096f1946 68 pc.putc(':');
elevatorguy 2:e26c096f1946 69 if(time < 10.0)
elevatorguy 2:e26c096f1946 70 {
elevatorguy 2:e26c096f1946 71 pc.putc('0');
elevatorguy 2:e26c096f1946 72 }
elevatorguy 2:e26c096f1946 73 if(time < 1.0)
elevatorguy 2:e26c096f1946 74 {
elevatorguy 2:e26c096f1946 75 pc.putc('0');
elevatorguy 2:e26c096f1946 76 }
elevatorguy 2:e26c096f1946 77 pc.printf(time, 100);
elevatorguy 2:e26c096f1946 78 int timeAsInt = time;
elevatorguy 2:e26c096f1946 79 if((time-timeAsInt)*100 < 10.0)
elevatorguy 2:e26c096f1946 80 {
elevatorguy 2:e26c096f1946 81 pc.putc('0');
elevatorguy 2:e26c096f1946 82 }
elevatorguy 2:e26c096f1946 83 if((time-timeAsInt)*100 < 1.0)
elevatorguy 2:e26c096f1946 84 {
elevatorguy 2:e26c096f1946 85 pc.putc('0');
elevatorguy 2:e26c096f1946 86 }
elevatorguy 2:e26c096f1946 87 pc.printf("\r\n");
elevatorguy 0:5fa5046f2ff5 88 }
elevatorguy 0:5fa5046f2ff5 89 }