stoppuhr s
Dependencies: PinDetect TextLCD mbed
Fork of FeuerwehrStoppuhr0805 by
main.cpp@4:8c274febf3b0, 2013-05-21 (annotated)
- Committer:
- joca89
- Date:
- Tue May 21 08:47:20 2013 +0000
- Revision:
- 4:8c274febf3b0
- Parent:
- 3:6f6ee868bf8c
- Child:
- 5:9772a9e2c7e9
Neuer Stand
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fox46 | 0:48f4880c730b | 1 | #include "mbed.h" |
fox46 | 0:48f4880c730b | 2 | #include "PinDetect.h" |
joca89 | 1:3ed42298abc3 | 3 | #include "stdlib.h" |
fox46 | 0:48f4880c730b | 4 | #include "TextLCD.h" |
joca89 | 3:6f6ee868bf8c | 5 | |
fox46 | 0:48f4880c730b | 6 | |
fox46 | 0:48f4880c730b | 7 | DigitalOut myled(LED1); |
fox46 | 0:48f4880c730b | 8 | Timer t; |
joca89 | 3:6f6ee868bf8c | 9 | TextLCD lcd(p36, p34, p24, p23, p15, p16); // rs, e, d0-d3 |
fox46 | 0:48f4880c730b | 10 | PinDetect pb1(p18); |
fox46 | 0:48f4880c730b | 11 | PinDetect pb2(p19); |
joca89 | 1:3ed42298abc3 | 12 | Serial pc(USBTX, USBRX); |
joca89 | 3:6f6ee868bf8c | 13 | Serial hm(p9, p10); // definiere UART für HM-TPR433 Modul |
joca89 | 3:6f6ee868bf8c | 14 | DigitalOut config(p22); |
joca89 | 3:6f6ee868bf8c | 15 | DigitalOut enable(p21); |
fox46 | 0:48f4880c730b | 16 | |
fox46 | 0:48f4880c730b | 17 | // Global count variable |
fox46 | 0:48f4880c730b | 18 | int volatile count=0; |
fox46 | 0:48f4880c730b | 19 | int volatile resetcnt=0; |
joca89 | 1:3ed42298abc3 | 20 | int volatile zz1=0; |
joca89 | 1:3ed42298abc3 | 21 | int volatile zz2=0; |
joca89 | 1:3ed42298abc3 | 22 | int volatile sblock=0; |
joca89 | 1:3ed42298abc3 | 23 | int volatile reset=0; |
joca89 | 1:3ed42298abc3 | 24 | int volatile D=0; |
joca89 | 4:8c274febf3b0 | 25 | |
joca89 | 1:3ed42298abc3 | 26 | int ms; |
joca89 | 1:3ed42298abc3 | 27 | int sec; |
joca89 | 1:3ed42298abc3 | 28 | int min; |
joca89 | 1:3ed42298abc3 | 29 | int ms1; |
joca89 | 1:3ed42298abc3 | 30 | char buffer[9]; |
joca89 | 1:3ed42298abc3 | 31 | char zwischenzeit[9]; |
joca89 | 1:3ed42298abc3 | 32 | char zwischenzeit1[9]; |
joca89 | 1:3ed42298abc3 | 33 | |
joca89 | 1:3ed42298abc3 | 34 | /*Funktions Dekleration*/ |
joca89 | 3:6f6ee868bf8c | 35 | |
joca89 | 3:6f6ee868bf8c | 36 | void empfangen() { |
joca89 | 3:6f6ee868bf8c | 37 | // Note: you need to actually read from the serial to clear the RX interrupt |
joca89 | 3:6f6ee868bf8c | 38 | |
joca89 | 3:6f6ee868bf8c | 39 | t.stop(); |
joca89 | 3:6f6ee868bf8c | 40 | pc.printf("Gesamtzeit: %s\n", buffer); |
joca89 | 3:6f6ee868bf8c | 41 | pc.printf("Zwischenzeit: %s\n", zwischenzeit); |
joca89 | 3:6f6ee868bf8c | 42 | pc.printf("Zwischenzeit: %s\n", zwischenzeit1); |
joca89 | 3:6f6ee868bf8c | 43 | sblock=1; |
joca89 | 4:8c274febf3b0 | 44 | lcd.printf("%c\n", hm.getc()); // um RX Interrupt zu löschen, Zeichen auslesen |
joca89 | 3:6f6ee868bf8c | 45 | return; |
joca89 | 3:6f6ee868bf8c | 46 | } |
joca89 | 3:6f6ee868bf8c | 47 | |
joca89 | 3:6f6ee868bf8c | 48 | void konfiguration(void) |
joca89 | 3:6f6ee868bf8c | 49 | { |
joca89 | 3:6f6ee868bf8c | 50 | config = 0; |
joca89 | 3:6f6ee868bf8c | 51 | enable = 0; |
joca89 | 4:8c274febf3b0 | 52 | hm.printf("AA FA F0"); //Standardkonfiguration laden |
joca89 | 3:6f6ee868bf8c | 53 | wait(0.1); |
joca89 | 3:6f6ee868bf8c | 54 | config = 1; |
joca89 | 3:6f6ee868bf8c | 55 | return; |
joca89 | 3:6f6ee868bf8c | 56 | } |
joca89 | 3:6f6ee868bf8c | 57 | |
joca89 | 1:3ed42298abc3 | 58 | void stoppuhr(void) |
joca89 | 1:3ed42298abc3 | 59 | { |
joca89 | 1:3ed42298abc3 | 60 | ms = t.read_ms(); //hole mir den TimerWert in ms |
joca89 | 1:3ed42298abc3 | 61 | sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec |
joca89 | 1:3ed42298abc3 | 62 | ms = ms - (sec*1000); //stelle meine ms richtig |
joca89 | 1:3ed42298abc3 | 63 | min = (sec/60); //erzeuge mir Minuten |
joca89 | 1:3ed42298abc3 | 64 | sec = sec - (min*60); //stelle Sekunden richtig |
joca89 | 1:3ed42298abc3 | 65 | ms = (ms/10); |
joca89 | 1:3ed42298abc3 | 66 | ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma |
joca89 | 1:3ed42298abc3 | 67 | sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer |
joca89 | 1:3ed42298abc3 | 68 | return; |
joca89 | 1:3ed42298abc3 | 69 | } |
joca89 | 1:3ed42298abc3 | 70 | |
joca89 | 1:3ed42298abc3 | 71 | void reset_halten( void ) |
joca89 | 3:6f6ee868bf8c | 72 | { |
joca89 | 1:3ed42298abc3 | 73 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 74 | { |
joca89 | 1:3ed42298abc3 | 75 | t.stop(); |
joca89 | 1:3ed42298abc3 | 76 | t.reset(); |
joca89 | 1:3ed42298abc3 | 77 | stoppuhr(); |
joca89 | 1:3ed42298abc3 | 78 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 79 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 80 | resetcnt=0; |
joca89 | 1:3ed42298abc3 | 81 | count=0; |
joca89 | 1:3ed42298abc3 | 82 | zz1=0; |
joca89 | 1:3ed42298abc3 | 83 | zz2=0; |
joca89 | 1:3ed42298abc3 | 84 | sblock=0; |
joca89 | 1:3ed42298abc3 | 85 | D++; |
joca89 | 1:3ed42298abc3 | 86 | if(D>99){D=0;} |
joca89 | 1:3ed42298abc3 | 87 | } |
joca89 | 1:3ed42298abc3 | 88 | } |
fox46 | 0:48f4880c730b | 89 | |
fox46 | 0:48f4880c730b | 90 | // Callback routine is interrupt activated by a debounced pb1 hit |
fox46 | 0:48f4880c730b | 91 | void pb1_hit_callback (void) { |
joca89 | 1:3ed42298abc3 | 92 | |
joca89 | 1:3ed42298abc3 | 93 | ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 |
joca89 | 1:3ed42298abc3 | 94 | |
joca89 | 1:3ed42298abc3 | 95 | if ((resetcnt==0) && (count <= 1)&& (sblock==0)) |
joca89 | 1:3ed42298abc3 | 96 | { |
joca89 | 1:3ed42298abc3 | 97 | t.reset(); //restiere Timer |
joca89 | 1:3ed42298abc3 | 98 | t.start(); //starte Timer |
joca89 | 1:3ed42298abc3 | 99 | resetcnt=1; |
joca89 | 1:3ed42298abc3 | 100 | } |
joca89 | 1:3ed42298abc3 | 101 | else if ((resetcnt==1) && (count <= 2) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 102 | { |
joca89 | 1:3ed42298abc3 | 103 | zz1=1; |
joca89 | 1:3ed42298abc3 | 104 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 105 | resetcnt=2; |
joca89 | 1:3ed42298abc3 | 106 | } |
joca89 | 1:3ed42298abc3 | 107 | else if ((resetcnt==2) && (count <= 3) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 108 | { |
joca89 | 1:3ed42298abc3 | 109 | zz2=1; |
joca89 | 1:3ed42298abc3 | 110 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 111 | } |
joca89 | 1:3ed42298abc3 | 112 | else |
joca89 | 1:3ed42298abc3 | 113 | { |
joca89 | 1:3ed42298abc3 | 114 | lcd.cls(); |
joca89 | 4:8c274febf3b0 | 115 | |
joca89 | 1:3ed42298abc3 | 116 | lcd.locate(1, 0); |
joca89 | 1:3ed42298abc3 | 117 | if(sblock==0) |
joca89 | 1:3ed42298abc3 | 118 | { |
joca89 | 1:3ed42298abc3 | 119 | |
joca89 | 1:3ed42298abc3 | 120 | lcd.printf("STOPP DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 121 | wait(1); |
joca89 | 1:3ed42298abc3 | 122 | } |
joca89 | 1:3ed42298abc3 | 123 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 124 | { |
joca89 | 1:3ed42298abc3 | 125 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 126 | wait(1); |
joca89 | 4:8c274febf3b0 | 127 | } |
joca89 | 1:3ed42298abc3 | 128 | } |
joca89 | 1:3ed42298abc3 | 129 | resetcnt=resetcnt++; |
fox46 | 0:48f4880c730b | 130 | } |
joca89 | 4:8c274febf3b0 | 131 | |
fox46 | 0:48f4880c730b | 132 | int main() { |
joca89 | 3:6f6ee868bf8c | 133 | |
joca89 | 4:8c274febf3b0 | 134 | konfiguration(); |
joca89 | 3:6f6ee868bf8c | 135 | hm.attach(&empfangen); |
joca89 | 3:6f6ee868bf8c | 136 | |
fox46 | 0:48f4880c730b | 137 | // Setup Interrupt callback functions for a pb hit |
fox46 | 0:48f4880c730b | 138 | pb1.attach_deasserted(&pb1_hit_callback); |
joca89 | 4:8c274febf3b0 | 139 | pb1.attach_deasserted_held(&reset_halten); |
fox46 | 0:48f4880c730b | 140 | // Start sampling pb inputs using interrupts |
fox46 | 0:48f4880c730b | 141 | pb1.setSampleFrequency(); |
joca89 | 3:6f6ee868bf8c | 142 | |
fox46 | 0:48f4880c730b | 143 | while (1) { |
joca89 | 1:3ed42298abc3 | 144 | wait(.1); |
joca89 | 1:3ed42298abc3 | 145 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 146 | myled = !myled; // LED1 blickt |
joca89 | 1:3ed42298abc3 | 147 | stoppuhr(); //rufe Funktion stoppuhr auf |
joca89 | 1:3ed42298abc3 | 148 | lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 |
joca89 | 1:3ed42298abc3 | 149 | lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) |
joca89 | 1:3ed42298abc3 | 150 | lcd.locate(4, 0); |
joca89 | 1:3ed42298abc3 | 151 | lcd.printf("ZE:%s", buffer); |
joca89 | 1:3ed42298abc3 | 152 | if(zz1==1) |
joca89 | 1:3ed42298abc3 | 153 | { |
joca89 | 1:3ed42298abc3 | 154 | lcd.locate(0, 1); |
joca89 | 1:3ed42298abc3 | 155 | lcd.printf("A%s", zwischenzeit); |
joca89 | 1:3ed42298abc3 | 156 | } |
joca89 | 1:3ed42298abc3 | 157 | if(zz2==1) |
joca89 | 1:3ed42298abc3 | 158 | { |
joca89 | 1:3ed42298abc3 | 159 | lcd.locate(8, 1); |
joca89 | 1:3ed42298abc3 | 160 | lcd.printf("B%s", zwischenzeit1); |
joca89 | 1:3ed42298abc3 | 161 | } |
joca89 | 3:6f6ee868bf8c | 162 | |
fox46 | 0:48f4880c730b | 163 | } |
fox46 | 0:48f4880c730b | 164 | |
joca89 | 1:3ed42298abc3 | 165 | } |