Display zeigt merkwürdige Zeichen
Dependencies: mbed PinDetect TextLCD
Fork of FWFSU_Start_28102013 by
main.cpp@11:3d21939eb9bd, 2016-06-24 (annotated)
- Committer:
- fox46
- Date:
- Fri Jun 24 10:56:09 2016 +0000
- Revision:
- 11:3d21939eb9bd
- Parent:
- 10:27b3acc95b8f
- Child:
- 12:3f53322a5270
first working version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joca89 | 0:097b334e1077 | 1 | #include "mbed.h" |
joca89 | 0:097b334e1077 | 2 | #include "PinDetect.h" |
joca89 | 0:097b334e1077 | 3 | #include "stdlib.h" |
joca89 | 0:097b334e1077 | 4 | #include "TextLCD.h" |
joca89 | 0:097b334e1077 | 5 | |
fox46 | 7:016281ea7be6 | 6 | #define ulow 3.3 //definiere Symbolische Konstante für ulow mit dem Wert xx |
fox46 | 10:27b3acc95b8f | 7 | #define u_shutdown 3.1 //Konstante für shutdown bei zu geringer Akkuspannung muss immer kleiner als charge4 sein!!! |
fox46 | 10:27b3acc95b8f | 8 | #define charge1 4 |
fox46 | 10:27b3acc95b8f | 9 | #define charge2 3.7 |
fox46 | 10:27b3acc95b8f | 10 | #define charge3 3.4 |
fox46 | 10:27b3acc95b8f | 11 | #define charge4 3.2 |
fox46 | 4:165fc296f7f5 | 12 | |
fox46 | 7:016281ea7be6 | 13 | Timer timer1; |
fox46 | 11:3d21939eb9bd | 14 | Timer t; |
fox46 | 3:def65a960118 | 15 | TextLCD lcd(p34, p23, p36, p15, p16, p35); // rs, e, d0-d3 für 130110-1P1 |
fox46 | 3:def65a960118 | 16 | PinDetect pb1(p18); //Buzzer |
fox46 | 3:def65a960118 | 17 | PinDetect pb2(p19); //LED-Button |
fox46 | 3:def65a960118 | 18 | DigitalIn dip0(p26); //Hex-Schalter Pin 1 LSB |
fox46 | 3:def65a960118 | 19 | DigitalIn dip1(p27); //Hex-schalter Pin 2 |
fox46 | 3:def65a960118 | 20 | DigitalIn dip2(p28); //Hex-schalter Pin 3 |
fox46 | 3:def65a960118 | 21 | DigitalIn dip3(p29); //Hex-Schalter Pin 4 MSB |
joca89 | 2:8d12fef6cc0e | 22 | //Serial hm(p13, p14); // definiere UART fuer HM-TPR433 Modul LPC1768 |
joca89 | 2:8d12fef6cc0e | 23 | Serial hm(p9, p10); // definiere UART fr HM-TPR433 Modul LPC11U24 |
joca89 | 0:097b334e1077 | 24 | DigitalOut config(p22); |
joca89 | 0:097b334e1077 | 25 | DigitalOut enable(p21); |
fox46 | 4:165fc296f7f5 | 26 | DigitalOut stoppled(p25); //LED-Button |
fox46 | 4:165fc296f7f5 | 27 | DigitalOut kill(p8); |
fox46 | 7:016281ea7be6 | 28 | DigitalOut suspend_charge(p7); //enables LION Charger suspend mode |
fox46 | 7:016281ea7be6 | 29 | DigitalOut highpower_charge(p6); // high- 100% charge current, low- 20% charge current |
fox46 | 10:27b3acc95b8f | 30 | DigitalOut ChargeLed1(LED1); |
fox46 | 10:27b3acc95b8f | 31 | DigitalOut ChargeLed2(LED2); |
fox46 | 10:27b3acc95b8f | 32 | DigitalOut ChargeLed3(LED3); |
fox46 | 10:27b3acc95b8f | 33 | DigitalOut ChargeLed4(LED4); |
fox46 | 3:def65a960118 | 34 | AnalogIn ubat(p17); |
fox46 | 7:016281ea7be6 | 35 | AnalogIn charge_current(p20); |
joca89 | 0:097b334e1077 | 36 | |
fox46 | 6:79bc3888c88c | 37 | Ticker time1; |
fox46 | 6:79bc3888c88c | 38 | Ticker timelong; |
fox46 | 6:79bc3888c88c | 39 | |
fox46 | 11:3d21939eb9bd | 40 | int volatile count=0; |
fox46 | 11:3d21939eb9bd | 41 | int volatile resetcnt=0; |
fox46 | 11:3d21939eb9bd | 42 | int volatile zz1=0; |
fox46 | 11:3d21939eb9bd | 43 | int volatile zz2=0; |
fox46 | 11:3d21939eb9bd | 44 | int volatile sblock=0; |
fox46 | 11:3d21939eb9bd | 45 | int volatile reset=0; |
fox46 | 11:3d21939eb9bd | 46 | int volatile D=1; |
fox46 | 11:3d21939eb9bd | 47 | int firsthit=1; |
fox46 | 11:3d21939eb9bd | 48 | |
fox46 | 5:832cc1bf7eba | 49 | float u_akku=0; |
fox46 | 7:016281ea7be6 | 50 | int timerwert=0; |
fox46 | 8:9eccc5d25e8f | 51 | int j=0; |
fox46 | 11:3d21939eb9bd | 52 | int ms; |
fox46 | 11:3d21939eb9bd | 53 | int sec; |
fox46 | 11:3d21939eb9bd | 54 | int min; |
fox46 | 11:3d21939eb9bd | 55 | int ms1; |
fox46 | 11:3d21939eb9bd | 56 | char buffer[6]; |
fox46 | 11:3d21939eb9bd | 57 | char zwischenzeit[6]; |
fox46 | 11:3d21939eb9bd | 58 | char zwischenzeit1[6]; |
fox46 | 9:5c871d235f31 | 59 | char transmit=0; |
fox46 | 5:832cc1bf7eba | 60 | |
fox46 | 5:832cc1bf7eba | 61 | |
joca89 | 0:097b334e1077 | 62 | /*Funktions Dekleration*/ |
joca89 | 0:097b334e1077 | 63 | |
joca89 | 0:097b334e1077 | 64 | void konfiguration(void) |
joca89 | 0:097b334e1077 | 65 | { |
joca89 | 0:097b334e1077 | 66 | config = 0; |
joca89 | 0:097b334e1077 | 67 | enable = 0; |
joca89 | 0:097b334e1077 | 68 | wait(0.1); |
joca89 | 0:097b334e1077 | 69 | |
joca89 | 0:097b334e1077 | 70 | /*******Standardkonfiguration laden*******/ |
joca89 | 0:097b334e1077 | 71 | hm.putc(0xAA); /******/ |
joca89 | 0:097b334e1077 | 72 | hm.putc(0xFA); /******/ |
joca89 | 0:097b334e1077 | 73 | hm.putc(0xF0); /******/ |
joca89 | 0:097b334e1077 | 74 | /*****************************************/ |
joca89 | 0:097b334e1077 | 75 | |
joca89 | 0:097b334e1077 | 76 | wait(0.1); |
joca89 | 0:097b334e1077 | 77 | |
joca89 | 0:097b334e1077 | 78 | if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 79 | { |
joca89 | 0:097b334e1077 | 80 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xCF); hm.putc(0xD1); hm.putc(0x90); //HEX-Schalter 0 |
joca89 | 0:097b334e1077 | 81 | } |
joca89 | 0:097b334e1077 | 82 | else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 83 | { |
joca89 | 0:097b334e1077 | 84 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD1); hm.putc(0x58); hm.putc(0x30); //HEX-Schalter 1 |
joca89 | 0:097b334e1077 | 85 | } |
joca89 | 0:097b334e1077 | 86 | else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 87 | { |
joca89 | 0:097b334e1077 | 88 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD2); hm.putc(0xDE); hm.putc(0xD0); //HEX-Schalter 2 |
joca89 | 0:097b334e1077 | 89 | } |
joca89 | 0:097b334e1077 | 90 | else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 91 | { |
joca89 | 0:097b334e1077 | 92 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD4); hm.putc(0x65); hm.putc(0x70); //HEX-Schalter 3 |
joca89 | 0:097b334e1077 | 93 | } |
joca89 | 0:097b334e1077 | 94 | else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 95 | { |
joca89 | 0:097b334e1077 | 96 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD5); hm.putc(0xEC); hm.putc(0x10); //HEX-Schalter 4 |
joca89 | 0:097b334e1077 | 97 | } |
joca89 | 0:097b334e1077 | 98 | else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 99 | { |
joca89 | 0:097b334e1077 | 100 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD7); hm.putc(0x72); hm.putc(0xB0); //HEX-Schalter 5 |
joca89 | 0:097b334e1077 | 101 | } |
joca89 | 0:097b334e1077 | 102 | else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 103 | { |
joca89 | 0:097b334e1077 | 104 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD8); hm.putc(0xF9); hm.putc(0x50); //HEX-Schalter 6 |
joca89 | 0:097b334e1077 | 105 | } |
joca89 | 0:097b334e1077 | 106 | else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) |
joca89 | 0:097b334e1077 | 107 | { |
joca89 | 0:097b334e1077 | 108 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDA); hm.putc(0x7F); hm.putc(0xF0); //HEX-Schalter 7 |
joca89 | 0:097b334e1077 | 109 | } |
joca89 | 0:097b334e1077 | 110 | else if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 111 | { |
joca89 | 0:097b334e1077 | 112 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDC); hm.putc(0x06); hm.putc(0x90); //HEX-Schalter 8 |
joca89 | 0:097b334e1077 | 113 | } |
joca89 | 0:097b334e1077 | 114 | else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 115 | { |
joca89 | 0:097b334e1077 | 116 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDD); hm.putc(0x8D); hm.putc(0x30); //HEX-Schalter 9 |
joca89 | 0:097b334e1077 | 117 | } |
joca89 | 0:097b334e1077 | 118 | else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 119 | { |
joca89 | 0:097b334e1077 | 120 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDF); hm.putc(0x13); hm.putc(0xD0); //HEX-Schalter A |
joca89 | 0:097b334e1077 | 121 | } |
joca89 | 0:097b334e1077 | 122 | else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 123 | { |
joca89 | 0:097b334e1077 | 124 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE0); hm.putc(0x9A); hm.putc(0x70); //HEX-Schalter B |
joca89 | 0:097b334e1077 | 125 | } |
joca89 | 0:097b334e1077 | 126 | else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 127 | { |
joca89 | 0:097b334e1077 | 128 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE2); hm.putc(0x21); hm.putc(0x10); //HEX-Schalter C |
joca89 | 0:097b334e1077 | 129 | } |
joca89 | 0:097b334e1077 | 130 | else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 131 | { |
joca89 | 0:097b334e1077 | 132 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE3); hm.putc(0xA7); hm.putc(0xB0); //HEX-Schalter D |
joca89 | 0:097b334e1077 | 133 | } |
joca89 | 0:097b334e1077 | 134 | else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 135 | { |
joca89 | 0:097b334e1077 | 136 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE5); hm.putc(0x2E); hm.putc(0x50); //HEX-Schalter E |
joca89 | 0:097b334e1077 | 137 | } |
joca89 | 0:097b334e1077 | 138 | else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) |
joca89 | 0:097b334e1077 | 139 | { |
joca89 | 0:097b334e1077 | 140 | hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE6); hm.putc(0xB4); hm.putc(0xF0); //HEX-Schalter F |
joca89 | 0:097b334e1077 | 141 | } |
joca89 | 0:097b334e1077 | 142 | else |
joca89 | 0:097b334e1077 | 143 | { |
fox46 | 4:165fc296f7f5 | 144 | stoppled=1; |
joca89 | 0:097b334e1077 | 145 | } |
joca89 | 0:097b334e1077 | 146 | wait(0.1); |
joca89 | 0:097b334e1077 | 147 | |
joca89 | 0:097b334e1077 | 148 | /*******Reading the current Config parameter*******/ |
fox46 | 4:165fc296f7f5 | 149 | /*hm.putc(0xAA); |
joca89 | 0:097b334e1077 | 150 | hm.putc(0xFA); |
joca89 | 0:097b334e1077 | 151 | hm.putc(0xE1); |
fox46 | 4:165fc296f7f5 | 152 | */ |
fox46 | 4:165fc296f7f5 | 153 | // wait(0.1); |
joca89 | 0:097b334e1077 | 154 | config = 1; |
fox46 | 8:9eccc5d25e8f | 155 | enable = 0; |
joca89 | 0:097b334e1077 | 156 | return; |
joca89 | 0:097b334e1077 | 157 | } |
joca89 | 0:097b334e1077 | 158 | |
fox46 | 11:3d21939eb9bd | 159 | void stoppuhr(void) |
fox46 | 11:3d21939eb9bd | 160 | { |
fox46 | 11:3d21939eb9bd | 161 | ms = t.read_ms(); //hole mir den TimerWert in ms |
fox46 | 11:3d21939eb9bd | 162 | sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec |
fox46 | 11:3d21939eb9bd | 163 | ms = ms - (sec*1000); //stelle meine ms richtig |
fox46 | 11:3d21939eb9bd | 164 | min = (sec/60); //erzeuge mir Minuten |
fox46 | 11:3d21939eb9bd | 165 | sec = sec - (min*60); //stelle Sekunden richtig |
fox46 | 11:3d21939eb9bd | 166 | ms = (ms/10); |
fox46 | 11:3d21939eb9bd | 167 | ms1 = (ms/10); //erzeuge mir zwei Stellen nach komma |
fox46 | 11:3d21939eb9bd | 168 | sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer |
fox46 | 4:165fc296f7f5 | 169 | return; |
joca89 | 0:097b334e1077 | 170 | } |
joca89 | 0:097b334e1077 | 171 | |
fox46 | 11:3d21939eb9bd | 172 | void starten(void) |
fox46 | 11:3d21939eb9bd | 173 | { |
fox46 | 11:3d21939eb9bd | 174 | |
fox46 | 11:3d21939eb9bd | 175 | if ((resetcnt==0) && (sblock==0)) { |
fox46 | 11:3d21939eb9bd | 176 | t.reset(); //restiere Timer |
fox46 | 11:3d21939eb9bd | 177 | t.start(); //starte Timer |
fox46 | 11:3d21939eb9bd | 178 | resetcnt=1; |
fox46 | 11:3d21939eb9bd | 179 | enable = 0; //schalte das RF-Modul ein |
fox46 | 11:3d21939eb9bd | 180 | firsthit=0; //verhindert ein erhöhen der Variable sblock durch wiederholtes drücken des Buzzers. |
fox46 | 11:3d21939eb9bd | 181 | } else if ((resetcnt==1) && (sblock==0)) { |
fox46 | 11:3d21939eb9bd | 182 | zz1=1; |
fox46 | 11:3d21939eb9bd | 183 | sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 184 | lcd.locate(0, 1); |
fox46 | 11:3d21939eb9bd | 185 | lcd.printf("A%s", zwischenzeit); |
fox46 | 11:3d21939eb9bd | 186 | resetcnt=2; |
fox46 | 11:3d21939eb9bd | 187 | } else if ((resetcnt==2) && (sblock==0)) { |
fox46 | 11:3d21939eb9bd | 188 | zz2=1; |
fox46 | 11:3d21939eb9bd | 189 | sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 190 | lcd.locate(8, 1); |
fox46 | 11:3d21939eb9bd | 191 | lcd.printf("B%s", zwischenzeit1); |
fox46 | 11:3d21939eb9bd | 192 | resetcnt=3; |
fox46 | 11:3d21939eb9bd | 193 | } else { //nach hundert mal drueken wieder auf restcnt auf 3 setzen - SIcherheitsmechanismus um Integerüberlauf zu vermeiden |
fox46 | 11:3d21939eb9bd | 194 | resetcnt=resetcnt++; |
fox46 | 11:3d21939eb9bd | 195 | if(resetcnt==100) { |
fox46 | 11:3d21939eb9bd | 196 | resetcnt=3; |
fox46 | 11:3d21939eb9bd | 197 | } |
fox46 | 11:3d21939eb9bd | 198 | } |
fox46 | 11:3d21939eb9bd | 199 | resetcnt=resetcnt++; |
fox46 | 11:3d21939eb9bd | 200 | } |
fox46 | 11:3d21939eb9bd | 201 | |
fox46 | 11:3d21939eb9bd | 202 | void stoppen (void) //Stoppen des Timers ohne Funk |
fox46 | 11:3d21939eb9bd | 203 | { |
fox46 | 11:3d21939eb9bd | 204 | t.stop(); |
fox46 | 11:3d21939eb9bd | 205 | if (firsthit==0){ |
fox46 | 11:3d21939eb9bd | 206 | sblock=1; |
fox46 | 11:3d21939eb9bd | 207 | } |
fox46 | 11:3d21939eb9bd | 208 | } |
fox46 | 11:3d21939eb9bd | 209 | |
fox46 | 4:165fc296f7f5 | 210 | void sendreset(){ |
fox46 | 4:165fc296f7f5 | 211 | enable=0; |
fox46 | 4:165fc296f7f5 | 212 | wait(0.1); |
fox46 | 4:165fc296f7f5 | 213 | hm.putc('x'); |
fox46 | 4:165fc296f7f5 | 214 | wait(0.1); |
fox46 | 8:9eccc5d25e8f | 215 | enable=0; |
fox46 | 4:165fc296f7f5 | 216 | return; |
fox46 | 4:165fc296f7f5 | 217 | } |
fox46 | 7:016281ea7be6 | 218 | |
fox46 | 11:3d21939eb9bd | 219 | void reset_startbutton( void ) |
fox46 | 11:3d21939eb9bd | 220 | { |
fox46 | 11:3d21939eb9bd | 221 | if(sblock==1) { // Reset für Durchgang erhöhen |
fox46 | 11:3d21939eb9bd | 222 | t.stop(); |
fox46 | 11:3d21939eb9bd | 223 | t.reset(); |
fox46 | 11:3d21939eb9bd | 224 | stoppuhr(); |
fox46 | 11:3d21939eb9bd | 225 | //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 226 | //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 227 | resetcnt=0; |
fox46 | 11:3d21939eb9bd | 228 | zz1=0; |
fox46 | 11:3d21939eb9bd | 229 | zz2=0; |
fox46 | 11:3d21939eb9bd | 230 | sblock=0; |
fox46 | 11:3d21939eb9bd | 231 | D++; |
fox46 | 11:3d21939eb9bd | 232 | firsthit=1; |
fox46 | 11:3d21939eb9bd | 233 | lcd.cls(); |
fox46 | 11:3d21939eb9bd | 234 | sendreset(); |
fox46 | 11:3d21939eb9bd | 235 | |
fox46 | 11:3d21939eb9bd | 236 | if(D>99) { |
fox46 | 11:3d21939eb9bd | 237 | D=1; |
fox46 | 11:3d21939eb9bd | 238 | } |
fox46 | 11:3d21939eb9bd | 239 | } |
fox46 | 11:3d21939eb9bd | 240 | } |
fox46 | 11:3d21939eb9bd | 241 | |
fox46 | 11:3d21939eb9bd | 242 | void totalreset_local (void) |
fox46 | 11:3d21939eb9bd | 243 | { |
fox46 | 11:3d21939eb9bd | 244 | // if (pb2==0) { |
fox46 | 11:3d21939eb9bd | 245 | t.stop(); |
fox46 | 11:3d21939eb9bd | 246 | t.reset(); |
fox46 | 11:3d21939eb9bd | 247 | stoppuhr(); |
fox46 | 11:3d21939eb9bd | 248 | //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 249 | //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); |
fox46 | 11:3d21939eb9bd | 250 | resetcnt=0; |
fox46 | 11:3d21939eb9bd | 251 | zz1=0; |
fox46 | 11:3d21939eb9bd | 252 | zz2=0; |
fox46 | 11:3d21939eb9bd | 253 | sblock=0; |
fox46 | 11:3d21939eb9bd | 254 | D=1; |
fox46 | 11:3d21939eb9bd | 255 | firsthit=1; |
fox46 | 11:3d21939eb9bd | 256 | time1.detach(); |
fox46 | 11:3d21939eb9bd | 257 | lcd.cls(); |
fox46 | 11:3d21939eb9bd | 258 | // } |
fox46 | 11:3d21939eb9bd | 259 | } |
fox46 | 11:3d21939eb9bd | 260 | void sendstart(){ |
fox46 | 11:3d21939eb9bd | 261 | starten(); |
fox46 | 11:3d21939eb9bd | 262 | transmit=1; |
fox46 | 11:3d21939eb9bd | 263 | enable=0; |
fox46 | 11:3d21939eb9bd | 264 | wait(0.1); |
fox46 | 11:3d21939eb9bd | 265 | hm.putc('g'); |
fox46 | 11:3d21939eb9bd | 266 | wait(0.1); |
fox46 | 11:3d21939eb9bd | 267 | enable=0; |
fox46 | 11:3d21939eb9bd | 268 | transmit=0; |
fox46 | 11:3d21939eb9bd | 269 | return; |
fox46 | 11:3d21939eb9bd | 270 | } |
fox46 | 11:3d21939eb9bd | 271 | |
fox46 | 7:016281ea7be6 | 272 | void sendstop(){ |
fox46 | 11:3d21939eb9bd | 273 | stoppen(); |
fox46 | 9:5c871d235f31 | 274 | transmit=1; |
fox46 | 7:016281ea7be6 | 275 | enable=0; |
fox46 | 7:016281ea7be6 | 276 | wait(0.1); |
fox46 | 7:016281ea7be6 | 277 | hm.putc('s'); |
fox46 | 7:016281ea7be6 | 278 | wait(0.1); |
fox46 | 8:9eccc5d25e8f | 279 | enable=0; |
fox46 | 9:5c871d235f31 | 280 | transmit=0; |
fox46 | 7:016281ea7be6 | 281 | return; |
fox46 | 7:016281ea7be6 | 282 | } |
fox46 | 7:016281ea7be6 | 283 | |
fox46 | 4:165fc296f7f5 | 284 | void kill_modul(){ |
fox46 | 10:27b3acc95b8f | 285 | //lcd.cls(); |
fox46 | 10:27b3acc95b8f | 286 | //lcd.printf(" shut down"); |
fox46 | 5:832cc1bf7eba | 287 | wait(3); |
fox46 | 4:165fc296f7f5 | 288 | kill=0; |
fox46 | 4:165fc296f7f5 | 289 | return; |
fox46 | 4:165fc296f7f5 | 290 | } |
joca89 | 0:097b334e1077 | 291 | |
fox46 | 6:79bc3888c88c | 292 | void stoppled_blink() { |
fox46 | 6:79bc3888c88c | 293 | stoppled=!stoppled; |
fox46 | 6:79bc3888c88c | 294 | return; |
fox46 | 6:79bc3888c88c | 295 | } |
fox46 | 6:79bc3888c88c | 296 | |
fox46 | 6:79bc3888c88c | 297 | void akkucheck() |
fox46 | 4:165fc296f7f5 | 298 | { |
fox46 | 9:5c871d235f31 | 299 | if (transmit==0){ |
fox46 | 9:5c871d235f31 | 300 | float i=0; |
fox46 | 6:79bc3888c88c | 301 | |
fox46 | 9:5c871d235f31 | 302 | for(int t=0; t<100; t++) { |
fox46 | 9:5c871d235f31 | 303 | i=i+ubat.read(); |
fox46 | 9:5c871d235f31 | 304 | } |
fox46 | 9:5c871d235f31 | 305 | // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen |
fox46 | 9:5c871d235f31 | 306 | |
fox46 | 9:5c871d235f31 | 307 | u_akku=((i/100)*4.364); |
fox46 | 9:5c871d235f31 | 308 | |
fox46 | 9:5c871d235f31 | 309 | //lcd.locate(0, 1); //debug Ausgabe |
fox46 | 9:5c871d235f31 | 310 | //lcd.printf("Akkucheck %3.2fV", u_akku); //debug Ausgabe |
fox46 | 9:5c871d235f31 | 311 | //wait(0.1); //debug Ausgabe |
fox46 | 6:79bc3888c88c | 312 | |
fox46 | 10:27b3acc95b8f | 313 | /*if(u_akku>ulow) { |
fox46 | 9:5c871d235f31 | 314 | time1.attach(&stoppled_blink,2); |
fox46 | 10:27b3acc95b8f | 315 | |
fox46 | 10:27b3acc95b8f | 316 | |
fox46 | 9:5c871d235f31 | 317 | } |
fox46 | 9:5c871d235f31 | 318 | if(u_akku<=ulow) { |
fox46 | 9:5c871d235f31 | 319 | time1.attach(&stoppled_blink,0.5); |
fox46 | 10:27b3acc95b8f | 320 | |
fox46 | 10:27b3acc95b8f | 321 | }*/ |
fox46 | 10:27b3acc95b8f | 322 | if(u_akku>=charge1) { |
fox46 | 10:27b3acc95b8f | 323 | ChargeLed1=1; |
fox46 | 10:27b3acc95b8f | 324 | ChargeLed2=1; |
fox46 | 10:27b3acc95b8f | 325 | ChargeLed3=1; |
fox46 | 10:27b3acc95b8f | 326 | ChargeLed4=1; |
fox46 | 10:27b3acc95b8f | 327 | time1.attach(&stoppled_blink,2); |
fox46 | 10:27b3acc95b8f | 328 | } |
fox46 | 10:27b3acc95b8f | 329 | |
fox46 | 10:27b3acc95b8f | 330 | else if(u_akku>=charge2) { |
fox46 | 10:27b3acc95b8f | 331 | ChargeLed1=1; |
fox46 | 10:27b3acc95b8f | 332 | ChargeLed2=1; |
fox46 | 10:27b3acc95b8f | 333 | ChargeLed3=1; |
fox46 | 10:27b3acc95b8f | 334 | ChargeLed4=0; |
fox46 | 10:27b3acc95b8f | 335 | time1.attach(&stoppled_blink,2); |
fox46 | 10:27b3acc95b8f | 336 | } |
fox46 | 10:27b3acc95b8f | 337 | else if(u_akku>=charge3) { |
fox46 | 10:27b3acc95b8f | 338 | ChargeLed1=1; |
fox46 | 10:27b3acc95b8f | 339 | ChargeLed2=1; |
fox46 | 10:27b3acc95b8f | 340 | ChargeLed3=0; |
fox46 | 10:27b3acc95b8f | 341 | ChargeLed4=0; |
fox46 | 10:27b3acc95b8f | 342 | time1.attach(&stoppled_blink,2); |
fox46 | 10:27b3acc95b8f | 343 | } |
fox46 | 10:27b3acc95b8f | 344 | else if(u_akku>=charge4) { |
fox46 | 10:27b3acc95b8f | 345 | ChargeLed1=1; |
fox46 | 10:27b3acc95b8f | 346 | ChargeLed2=0; |
fox46 | 10:27b3acc95b8f | 347 | ChargeLed3=0; |
fox46 | 10:27b3acc95b8f | 348 | ChargeLed4=0; |
fox46 | 10:27b3acc95b8f | 349 | time1.attach(&stoppled_blink,0.5); |
fox46 | 10:27b3acc95b8f | 350 | } |
fox46 | 10:27b3acc95b8f | 351 | else if (u_akku<=u_shutdown) { |
fox46 | 10:27b3acc95b8f | 352 | time1.detach(); |
fox46 | 10:27b3acc95b8f | 353 | stoppled=0; |
fox46 | 10:27b3acc95b8f | 354 | wait(3); |
fox46 | 10:27b3acc95b8f | 355 | kill_modul(); |
fox46 | 10:27b3acc95b8f | 356 | } |
fox46 | 10:27b3acc95b8f | 357 | |
fox46 | 9:5c871d235f31 | 358 | } |
fox46 | 10:27b3acc95b8f | 359 | |
fox46 | 9:5c871d235f31 | 360 | |
fox46 | 9:5c871d235f31 | 361 | return; |
fox46 | 10:27b3acc95b8f | 362 | // } |
fox46 | 6:79bc3888c88c | 363 | } |
joca89 | 0:097b334e1077 | 364 | |
fox46 | 8:9eccc5d25e8f | 365 | void empfangen() |
fox46 | 8:9eccc5d25e8f | 366 | { |
fox46 | 8:9eccc5d25e8f | 367 | //Funktion wird aufgerufen sobald das RF-Modul Daten an TX hat - über die Interruptroutine hm.attach(&empfangen) springe ich in die Funktion |
fox46 | 8:9eccc5d25e8f | 368 | //Beim konfigurieren des Funkmoduls werden Uart Interrupts ausgelöst, diese werden durch die folgende while schleife abgefangen |
fox46 | 8:9eccc5d25e8f | 369 | //Funkmodul schickt anscheinend 4 char nach der Konfiguration |
fox46 | 8:9eccc5d25e8f | 370 | |
fox46 | 8:9eccc5d25e8f | 371 | while (j<4) { |
fox46 | 8:9eccc5d25e8f | 372 | j=j+1; |
fox46 | 8:9eccc5d25e8f | 373 | hm.getc(); |
fox46 | 8:9eccc5d25e8f | 374 | return; |
fox46 | 8:9eccc5d25e8f | 375 | } |
fox46 | 8:9eccc5d25e8f | 376 | if (hm.readable()) { |
fox46 | 8:9eccc5d25e8f | 377 | char rxd = hm.getc(); |
fox46 | 8:9eccc5d25e8f | 378 | if (rxd=='q') { |
fox46 | 8:9eccc5d25e8f | 379 | kill_modul(); |
fox46 | 11:3d21939eb9bd | 380 | } else if (rxd=='s') { |
fox46 | 11:3d21939eb9bd | 381 | stoppen(); |
fox46 | 11:3d21939eb9bd | 382 | } else if (rxd=='x') { |
fox46 | 11:3d21939eb9bd | 383 | reset_startbutton(); |
fox46 | 11:3d21939eb9bd | 384 | } else if (rxd=='t') { |
fox46 | 11:3d21939eb9bd | 385 | totalreset_local(); |
fox46 | 11:3d21939eb9bd | 386 | } |
fox46 | 11:3d21939eb9bd | 387 | |
fox46 | 8:9eccc5d25e8f | 388 | } |
fox46 | 8:9eccc5d25e8f | 389 | return; |
fox46 | 8:9eccc5d25e8f | 390 | } |
fox46 | 6:79bc3888c88c | 391 | |
fox46 | 4:165fc296f7f5 | 392 | int main() { |
fox46 | 7:016281ea7be6 | 393 | kill=1; |
fox46 | 7:016281ea7be6 | 394 | suspend_charge=0; |
fox46 | 7:016281ea7be6 | 395 | highpower_charge=1; |
fox46 | 7:016281ea7be6 | 396 | |
joca89 | 0:097b334e1077 | 397 | // Use internal pullup for pushbutton |
fox46 | 4:165fc296f7f5 | 398 | pb1.mode(PullDown); |
fox46 | 4:165fc296f7f5 | 399 | pb2.mode(PullNone); // keinen Modus verwenden |
joca89 | 0:097b334e1077 | 400 | dip0.mode(PullUp); |
joca89 | 0:097b334e1077 | 401 | dip1.mode(PullUp); |
joca89 | 0:097b334e1077 | 402 | dip2.mode(PullUp); |
fox46 | 4:165fc296f7f5 | 403 | dip3.mode(PullUp); |
fox46 | 4:165fc296f7f5 | 404 | |
fox46 | 4:165fc296f7f5 | 405 | wait(0.01); // Delay for initial pullup to take effect |
fox46 | 4:165fc296f7f5 | 406 | |
fox46 | 7:016281ea7be6 | 407 | pb1.attach_asserted(&sendstart); |
fox46 | 4:165fc296f7f5 | 408 | pb1.attach_asserted_held(&sendreset); |
fox46 | 4:165fc296f7f5 | 409 | |
fox46 | 7:016281ea7be6 | 410 | pb2.attach_asserted(&sendstop); |
fox46 | 4:165fc296f7f5 | 411 | pb2.attach_deasserted_held(&kill_modul); // Setup Interrupt callback functions for a pb hit |
joca89 | 0:097b334e1077 | 412 | |
fox46 | 4:165fc296f7f5 | 413 | pb1.setSampleFrequency(); |
fox46 | 4:165fc296f7f5 | 414 | pb2.setSampleFrequency(); |
joca89 | 0:097b334e1077 | 415 | |
fox46 | 4:165fc296f7f5 | 416 | pb2.setSamplesTillHeld( 200 ); |
fox46 | 4:165fc296f7f5 | 417 | |
fox46 | 10:27b3acc95b8f | 418 | akkucheck(); |
fox46 | 10:27b3acc95b8f | 419 | |
fox46 | 4:165fc296f7f5 | 420 | konfiguration(); //RF Modul konfigurieren |
fox46 | 6:79bc3888c88c | 421 | timelong.attach(&akkucheck,60); //Akkutest wird alle 60sec. gestartet |
fox46 | 11:3d21939eb9bd | 422 | hm.attach(&empfangen,Serial::RxIrq); // Setup Interrupt callback functions for Datareceive |
fox46 | 8:9eccc5d25e8f | 423 | |
fox46 | 9:5c871d235f31 | 424 | //lcd.cls(); //debug Ausgabe |
fox46 | 9:5c871d235f31 | 425 | //lcd.printf(" Starttaster"); //debug Ausgabe |
joca89 | 0:097b334e1077 | 426 | |
fox46 | 6:79bc3888c88c | 427 | time1.attach(&stoppled_blink,2); |
fox46 | 7:016281ea7be6 | 428 | timer1.start(); |
joca89 | 2:8d12fef6cc0e | 429 | |
fox46 | 6:79bc3888c88c | 430 | while (1) { |
fox46 | 11:3d21939eb9bd | 431 | wait(.1); |
fox46 | 11:3d21939eb9bd | 432 | //lcd.cls(); |
fox46 | 11:3d21939eb9bd | 433 | stoppuhr(); //rufe Funktion stoppuhr auf |
fox46 | 11:3d21939eb9bd | 434 | lcd.locate(0, 0); //setze den Cursor auf Zeichen 0 Reihe 1 |
fox46 | 11:3d21939eb9bd | 435 | lcd.printf("D%02d", D); // Ausgabe der Durchgänge, Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) |
fox46 | 11:3d21939eb9bd | 436 | lcd.locate(4, 0); |
fox46 | 11:3d21939eb9bd | 437 | lcd.printf("ZE:%s", buffer); |
fox46 | 7:016281ea7be6 | 438 | |
fox46 | 6:79bc3888c88c | 439 | |
joca89 | 0:097b334e1077 | 440 | } |
joca89 | 0:097b334e1077 | 441 | |
joca89 | 0:097b334e1077 | 442 | } |