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 05:25:38 2013 +0000
Revision:
7:411ae6b21c9b
Parent:
6:d40cd917854d
off by 1 error

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 7:411ae6b21c9b 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 7:411ae6b21c9b 13 Ticker tock3;
elevatorguy 3:88da6c0412b0 14
elevatorguy 6:d40cd917854d 15 extern "C" void turnOff(void) {
elevatorguy 6:d40cd917854d 16 led1 = 0;
elevatorguy 3:88da6c0412b0 17 }
elevatorguy 3:88da6c0412b0 18
elevatorguy 6:d40cd917854d 19 extern "C" void turnOn(void) {
elevatorguy 6:d40cd917854d 20 led1 = 1;
elevatorguy 7:411ae6b21c9b 21 tock.attach(&turnOff, 0.0001);
elevatorguy 7:411ae6b21c9b 22 }
elevatorguy 7:411ae6b21c9b 23
elevatorguy 7:411ae6b21c9b 24 extern "C" void led2flip(void)
elevatorguy 7:411ae6b21c9b 25 {
elevatorguy 7:411ae6b21c9b 26 led2 = !led2;
elevatorguy 3:88da6c0412b0 27 }
elevatorguy 3:88da6c0412b0 28
elevatorguy 3:88da6c0412b0 29 int main() { //Timer and Ticker demonstration
elevatorguy 0:5fa5046f2ff5 30 switch1.mode(PULLDOWN);
elevatorguy 2:e26c096f1946 31 t.start();
elevatorguy 7:411ae6b21c9b 32 tock2.attach(&turnOn, 0.005);
elevatorguy 7:411ae6b21c9b 33 tock3.attach(&led2flip, 0.0025);
elevatorguy 2:e26c096f1946 34 while(1)
elevatorguy 2:e26c096f1946 35 {
elevatorguy 2:e26c096f1946 36 double time = t;
elevatorguy 2:e26c096f1946 37 int h = 0;
elevatorguy 2:e26c096f1946 38 int m = 0;
elevatorguy 2:e26c096f1946 39 while(time > 3600)
elevatorguy 2:e26c096f1946 40 {
elevatorguy 2:e26c096f1946 41 time = time - 3600;
elevatorguy 2:e26c096f1946 42 h = h + 1;
elevatorguy 2:e26c096f1946 43 }
elevatorguy 2:e26c096f1946 44 while(time > 60)
elevatorguy 2:e26c096f1946 45 {
elevatorguy 2:e26c096f1946 46 time = time - 60;
elevatorguy 2:e26c096f1946 47 m = m + 1;
elevatorguy 2:e26c096f1946 48 }
elevatorguy 2:e26c096f1946 49 if(h < 10.0)
elevatorguy 2:e26c096f1946 50 {
elevatorguy 2:e26c096f1946 51 pc.putc('0');
elevatorguy 2:e26c096f1946 52 }
elevatorguy 2:e26c096f1946 53 if(h != 0)
elevatorguy 2:e26c096f1946 54 {
elevatorguy 2:e26c096f1946 55 pc.printf(h);
elevatorguy 2:e26c096f1946 56 }
elevatorguy 2:e26c096f1946 57 else
elevatorguy 2:e26c096f1946 58 {
elevatorguy 2:e26c096f1946 59 pc.putc('0');
elevatorguy 2:e26c096f1946 60 }
elevatorguy 2:e26c096f1946 61 pc.putc(':');
elevatorguy 2:e26c096f1946 62 if(m < 10.0)
elevatorguy 2:e26c096f1946 63 {
elevatorguy 2:e26c096f1946 64 pc.putc('0');
elevatorguy 2:e26c096f1946 65 }
elevatorguy 2:e26c096f1946 66 if(m != 0)
elevatorguy 2:e26c096f1946 67 {
elevatorguy 2:e26c096f1946 68 pc.printf(m);
elevatorguy 2:e26c096f1946 69 }
elevatorguy 2:e26c096f1946 70 else
elevatorguy 2:e26c096f1946 71 {
elevatorguy 2:e26c096f1946 72 pc.putc('0');
elevatorguy 2:e26c096f1946 73 }
elevatorguy 2:e26c096f1946 74 pc.putc(':');
elevatorguy 2:e26c096f1946 75 if(time < 10.0)
elevatorguy 2:e26c096f1946 76 {
elevatorguy 2:e26c096f1946 77 pc.putc('0');
elevatorguy 2:e26c096f1946 78 }
elevatorguy 2:e26c096f1946 79 if(time < 1.0)
elevatorguy 2:e26c096f1946 80 {
elevatorguy 2:e26c096f1946 81 pc.putc('0');
elevatorguy 2:e26c096f1946 82 }
elevatorguy 2:e26c096f1946 83 pc.printf(time, 100);
elevatorguy 2:e26c096f1946 84 int timeAsInt = time;
elevatorguy 2:e26c096f1946 85 if((time-timeAsInt)*100 < 10.0)
elevatorguy 2:e26c096f1946 86 {
elevatorguy 2:e26c096f1946 87 pc.putc('0');
elevatorguy 2:e26c096f1946 88 }
elevatorguy 2:e26c096f1946 89 if((time-timeAsInt)*100 < 1.0)
elevatorguy 2:e26c096f1946 90 {
elevatorguy 2:e26c096f1946 91 pc.putc('0');
elevatorguy 2:e26c096f1946 92 }
elevatorguy 2:e26c096f1946 93 pc.printf("\r\n");
elevatorguy 0:5fa5046f2ff5 94 }
elevatorguy 0:5fa5046f2ff5 95 }