Jovica D.
/
FeuerwehrStoppuhr0805
stoppuhr s
Fork of FeuerwehrStoppuhr by
main.cpp@3:6f6ee868bf8c, 2013-05-08 (annotated)
- Committer:
- joca89
- Date:
- Wed May 08 13:59:35 2013 +0000
- Revision:
- 3:6f6ee868bf8c
- Parent:
- 2:9c7ca5717309
Feuerwehrprojekt
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 | 3:6f6ee868bf8c | 25 | //int volatile send=0; |
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 | // send = 1; |
joca89 | 3:6f6ee868bf8c | 40 | t.stop(); |
joca89 | 3:6f6ee868bf8c | 41 | if(sblock==1) |
joca89 | 3:6f6ee868bf8c | 42 | { |
joca89 | 3:6f6ee868bf8c | 43 | lcd.cls(); |
joca89 | 3:6f6ee868bf8c | 44 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 3:6f6ee868bf8c | 45 | wait(1); |
joca89 | 3:6f6ee868bf8c | 46 | } |
joca89 | 3:6f6ee868bf8c | 47 | pc.printf("Gesamtzeit: %s\n", buffer); |
joca89 | 3:6f6ee868bf8c | 48 | pc.printf("Zwischenzeit: %s\n", zwischenzeit); |
joca89 | 3:6f6ee868bf8c | 49 | pc.printf("Zwischenzeit: %s\n", zwischenzeit1); |
joca89 | 3:6f6ee868bf8c | 50 | sblock=1; |
joca89 | 3:6f6ee868bf8c | 51 | lcd.printf("%c\n", hm.getc()); |
joca89 | 3:6f6ee868bf8c | 52 | return; |
joca89 | 3:6f6ee868bf8c | 53 | } |
joca89 | 3:6f6ee868bf8c | 54 | |
joca89 | 3:6f6ee868bf8c | 55 | void konfiguration(void) |
joca89 | 3:6f6ee868bf8c | 56 | { |
joca89 | 3:6f6ee868bf8c | 57 | config = 0; |
joca89 | 3:6f6ee868bf8c | 58 | enable = 0; |
joca89 | 3:6f6ee868bf8c | 59 | hm.printf("AA FA F0"); |
joca89 | 3:6f6ee868bf8c | 60 | wait(0.1); |
joca89 | 3:6f6ee868bf8c | 61 | config = 1; |
joca89 | 3:6f6ee868bf8c | 62 | return; |
joca89 | 3:6f6ee868bf8c | 63 | } |
joca89 | 3:6f6ee868bf8c | 64 | |
joca89 | 1:3ed42298abc3 | 65 | void stoppuhr(void) |
joca89 | 1:3ed42298abc3 | 66 | { |
joca89 | 1:3ed42298abc3 | 67 | ms = t.read_ms(); //hole mir den TimerWert in ms |
joca89 | 1:3ed42298abc3 | 68 | sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec |
joca89 | 1:3ed42298abc3 | 69 | ms = ms - (sec*1000); //stelle meine ms richtig |
joca89 | 1:3ed42298abc3 | 70 | min = (sec/60); //erzeuge mir Minuten |
joca89 | 1:3ed42298abc3 | 71 | sec = sec - (min*60); //stelle Sekunden richtig |
joca89 | 1:3ed42298abc3 | 72 | ms = (ms/10); |
joca89 | 1:3ed42298abc3 | 73 | ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma |
joca89 | 1:3ed42298abc3 | 74 | sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer |
joca89 | 1:3ed42298abc3 | 75 | return; |
joca89 | 1:3ed42298abc3 | 76 | } |
joca89 | 1:3ed42298abc3 | 77 | |
joca89 | 1:3ed42298abc3 | 78 | void reset_halten( void ) |
joca89 | 3:6f6ee868bf8c | 79 | { |
joca89 | 1:3ed42298abc3 | 80 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 81 | { |
joca89 | 1:3ed42298abc3 | 82 | t.stop(); |
joca89 | 1:3ed42298abc3 | 83 | t.reset(); |
joca89 | 1:3ed42298abc3 | 84 | stoppuhr(); |
joca89 | 1:3ed42298abc3 | 85 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 86 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 87 | resetcnt=0; |
joca89 | 1:3ed42298abc3 | 88 | count=0; |
joca89 | 1:3ed42298abc3 | 89 | zz1=0; |
joca89 | 1:3ed42298abc3 | 90 | zz2=0; |
joca89 | 1:3ed42298abc3 | 91 | sblock=0; |
joca89 | 1:3ed42298abc3 | 92 | D++; |
joca89 | 1:3ed42298abc3 | 93 | if(D>99){D=0;} |
joca89 | 1:3ed42298abc3 | 94 | } |
joca89 | 1:3ed42298abc3 | 95 | } |
fox46 | 0:48f4880c730b | 96 | |
fox46 | 0:48f4880c730b | 97 | // Callback routine is interrupt activated by a debounced pb1 hit |
fox46 | 0:48f4880c730b | 98 | void pb1_hit_callback (void) { |
joca89 | 1:3ed42298abc3 | 99 | |
joca89 | 1:3ed42298abc3 | 100 | ++count; //erhöhe die Variable count nach jedem drücken des Startbuttoms um 1 |
joca89 | 1:3ed42298abc3 | 101 | |
joca89 | 1:3ed42298abc3 | 102 | if ((resetcnt==0) && (count <= 1)&& (sblock==0)) |
joca89 | 1:3ed42298abc3 | 103 | { |
joca89 | 1:3ed42298abc3 | 104 | t.reset(); //restiere Timer |
joca89 | 1:3ed42298abc3 | 105 | t.start(); //starte Timer |
joca89 | 1:3ed42298abc3 | 106 | resetcnt=1; |
joca89 | 1:3ed42298abc3 | 107 | } |
joca89 | 1:3ed42298abc3 | 108 | else if ((resetcnt==1) && (count <= 2) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 109 | { |
joca89 | 1:3ed42298abc3 | 110 | zz1=1; |
joca89 | 1:3ed42298abc3 | 111 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 112 | resetcnt=2; |
joca89 | 1:3ed42298abc3 | 113 | } |
joca89 | 1:3ed42298abc3 | 114 | else if ((resetcnt==2) && (count <= 3) && (sblock==0)) |
joca89 | 1:3ed42298abc3 | 115 | { |
joca89 | 1:3ed42298abc3 | 116 | zz2=1; |
joca89 | 1:3ed42298abc3 | 117 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
joca89 | 1:3ed42298abc3 | 118 | } |
joca89 | 1:3ed42298abc3 | 119 | else |
joca89 | 1:3ed42298abc3 | 120 | { |
joca89 | 1:3ed42298abc3 | 121 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 122 | // wait(0.05); |
joca89 | 1:3ed42298abc3 | 123 | lcd.locate(1, 0); |
joca89 | 1:3ed42298abc3 | 124 | if(sblock==0) |
joca89 | 1:3ed42298abc3 | 125 | { |
joca89 | 1:3ed42298abc3 | 126 | |
joca89 | 1:3ed42298abc3 | 127 | lcd.printf("STOPP DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 128 | wait(1); |
joca89 | 1:3ed42298abc3 | 129 | } |
joca89 | 1:3ed42298abc3 | 130 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 131 | { |
joca89 | 1:3ed42298abc3 | 132 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 133 | wait(1); |
joca89 | 1:3ed42298abc3 | 134 | } |
joca89 | 1:3ed42298abc3 | 135 | } |
joca89 | 1:3ed42298abc3 | 136 | resetcnt=resetcnt++; |
fox46 | 0:48f4880c730b | 137 | } |
joca89 | 3:6f6ee868bf8c | 138 | /* |
fox46 | 0:48f4880c730b | 139 | // Callback routine is interrupt activated by a debounced pb2 hit |
fox46 | 0:48f4880c730b | 140 | void pb2_hit_callback (void) { |
fox46 | 0:48f4880c730b | 141 | t.stop(); |
joca89 | 1:3ed42298abc3 | 142 | if(sblock==1) |
joca89 | 1:3ed42298abc3 | 143 | { |
joca89 | 1:3ed42298abc3 | 144 | lcd.cls(); |
joca89 | 1:3ed42298abc3 | 145 | // wait(0.05); |
joca89 | 1:3ed42298abc3 | 146 | lcd.printf("RESET: START LANGE DRUEKEN!"); |
joca89 | 1:3ed42298abc3 | 147 | wait(1); |
joca89 | 1:3ed42298abc3 | 148 | } |
joca89 | 1:3ed42298abc3 | 149 | pc.printf("Gesamtzeit: %s\n", buffer); |
joca89 | 1:3ed42298abc3 | 150 | pc.printf("Zwischenzeit: %s\n", zwischenzeit); |
joca89 | 1:3ed42298abc3 | 151 | pc.printf("Zwischenzeit: %s\n", zwischenzeit1); |
joca89 | 1:3ed42298abc3 | 152 | sblock=1; |
fox46 | 0:48f4880c730b | 153 | } |
joca89 | 3:6f6ee868bf8c | 154 | */ |
fox46 | 0:48f4880c730b | 155 | int main() { |
joca89 | 3:6f6ee868bf8c | 156 | |
joca89 | 3:6f6ee868bf8c | 157 | konfiguration(); |
joca89 | 3:6f6ee868bf8c | 158 | hm.attach(&empfangen); |
joca89 | 3:6f6ee868bf8c | 159 | |
fox46 | 0:48f4880c730b | 160 | // Setup Interrupt callback functions for a pb hit |
fox46 | 0:48f4880c730b | 161 | pb1.attach_deasserted(&pb1_hit_callback); |
joca89 | 1:3ed42298abc3 | 162 | pb1.attach_deasserted_held(&reset_halten); |
joca89 | 3:6f6ee868bf8c | 163 | // pb2.attach_deasserted(&pb2_hit_callback); |
joca89 | 1:3ed42298abc3 | 164 | |
fox46 | 0:48f4880c730b | 165 | // Start sampling pb inputs using interrupts |
fox46 | 0:48f4880c730b | 166 | pb1.setSampleFrequency(); |
joca89 | 3:6f6ee868bf8c | 167 | // pb2.setSampleFrequency(); |
joca89 | 3:6f6ee868bf8c | 168 | |
joca89 | 3:6f6ee868bf8c | 169 | |
fox46 | 0:48f4880c730b | 170 | while (1) { |
joca89 | 1:3ed42298abc3 | 171 | wait(.1); |
joca89 | 1:3ed42298abc3 | 172 | lcd.cls(); |
joca89 | 3:6f6ee868bf8c | 173 | // if(send=1){ |
joca89 | 3:6f6ee868bf8c | 174 | |
joca89 | 3:6f6ee868bf8c | 175 | //} |
joca89 | 1:3ed42298abc3 | 176 | myled = !myled; // LED1 blickt |
joca89 | 1:3ed42298abc3 | 177 | stoppuhr(); //rufe Funktion stoppuhr auf |
joca89 | 1:3ed42298abc3 | 178 | lcd.locate(0, 0); //setze den curser auf Zeihen 0 Reihe 1 |
joca89 | 1:3ed42298abc3 | 179 | lcd.printf("D%02d", D); //Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) |
joca89 | 1:3ed42298abc3 | 180 | lcd.locate(4, 0); |
joca89 | 1:3ed42298abc3 | 181 | lcd.printf("ZE:%s", buffer); |
joca89 | 1:3ed42298abc3 | 182 | if(zz1==1) |
joca89 | 1:3ed42298abc3 | 183 | { |
joca89 | 1:3ed42298abc3 | 184 | lcd.locate(0, 1); |
joca89 | 1:3ed42298abc3 | 185 | lcd.printf("A%s", zwischenzeit); |
joca89 | 1:3ed42298abc3 | 186 | } |
joca89 | 1:3ed42298abc3 | 187 | if(zz2==1) |
joca89 | 1:3ed42298abc3 | 188 | { |
joca89 | 1:3ed42298abc3 | 189 | lcd.locate(8, 1); |
joca89 | 1:3ed42298abc3 | 190 | lcd.printf("B%s", zwischenzeit1); |
joca89 | 1:3ed42298abc3 | 191 | } |
joca89 | 3:6f6ee868bf8c | 192 | |
fox46 | 0:48f4880c730b | 193 | } |
fox46 | 0:48f4880c730b | 194 | |
joca89 | 1:3ed42298abc3 | 195 | } |