Display zeigt merkwürdige Zeichen

Dependencies:   mbed PinDetect TextLCD

Fork of FWFSU_Start_28102013 by KX-ONE

Committer:
fox46
Date:
Wed Aug 24 13:12:18 2016 +0000
Branch:
oldschool
Revision:
35:1fcb3101c2f9
Parent:
34:71b726a58856
Display zeigt merkw?rdige zeichen;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fox46 35:1fcb3101c2f9 1 #include "mbed.h"
fox46 35:1fcb3101c2f9 2 #include "PinDetect.h"
fox46 35:1fcb3101c2f9 3 #include "stdlib.h"
fox46 35:1fcb3101c2f9 4 #include "TextLCD.h"
joca89 0:097b334e1077 5
fox46 35:1fcb3101c2f9 6 #define ulow 3.3 //definiere Symbolische Konstante für ulow mit dem Wert xx
fox46 35:1fcb3101c2f9 7 #define u_shutdown 3.1 //Konstante für shutdown bei zu geringer Akkuspannung muss immer kleiner als charge4 sein!!!
fox46 35:1fcb3101c2f9 8 #define charge1 4
fox46 35:1fcb3101c2f9 9 #define charge2 3.7
fox46 35:1fcb3101c2f9 10 #define charge3 3.4
fox46 35:1fcb3101c2f9 11 #define charge4 3.2
manuelfederanko 20:e809ca4de724 12
fox46 35:1fcb3101c2f9 13 Timer timer1;
fox46 35:1fcb3101c2f9 14 Timer t;
fox46 35:1fcb3101c2f9 15 TextLCD lcd(p34, p23, p36, p15, p16, p35); // rs, e, d0-d3 für 130110-1P1
fox46 35:1fcb3101c2f9 16 PinDetect pb1(p18); //Buzzer
fox46 35:1fcb3101c2f9 17 PinDetect pb2(p19); //LED-Button
fox46 35:1fcb3101c2f9 18 DigitalIn dip0(p26); //Hex-Schalter Pin 1 LSB
fox46 35:1fcb3101c2f9 19 DigitalIn dip1(p27); //Hex-schalter Pin 2
fox46 35:1fcb3101c2f9 20 DigitalIn dip2(p28); //Hex-schalter Pin 3
fox46 35:1fcb3101c2f9 21 DigitalIn dip3(p29); //Hex-Schalter Pin 4 MSB
fox46 35:1fcb3101c2f9 22 //Serial hm(p13, p14); // definiere UART fuer HM-TPR433 Modul LPC1768
fox46 35:1fcb3101c2f9 23 Serial hm(p9, p10); // definiere UART fr HM-TPR433 Modul LPC11U24
fox46 35:1fcb3101c2f9 24 DigitalOut config(p22);
fox46 35:1fcb3101c2f9 25 DigitalOut enable(p21);
fox46 35:1fcb3101c2f9 26 DigitalOut stoppled(p25); //LED-Button
fox46 35:1fcb3101c2f9 27 DigitalOut kill(p8);
fox46 35:1fcb3101c2f9 28 DigitalOut suspend_charge(p7); //enables LION Charger suspend mode
fox46 35:1fcb3101c2f9 29 DigitalOut highpower_charge(p6); // high- 100% charge current, low- 20% charge current
fox46 35:1fcb3101c2f9 30 DigitalOut ChargeLed1(LED1);
fox46 35:1fcb3101c2f9 31 DigitalOut ChargeLed2(LED2);
fox46 35:1fcb3101c2f9 32 DigitalOut ChargeLed3(LED3);
fox46 35:1fcb3101c2f9 33 DigitalOut ChargeLed4(LED4);
fox46 35:1fcb3101c2f9 34 AnalogIn ubat(p17);
fox46 35:1fcb3101c2f9 35 AnalogIn charge_current(p20);
joca89 0:097b334e1077 36
fox46 35:1fcb3101c2f9 37 Ticker time1;
fox46 35:1fcb3101c2f9 38 Ticker timelong;
manuelfederanko 34:71b726a58856 39
fox46 35:1fcb3101c2f9 40 int volatile count=0;
fox46 35:1fcb3101c2f9 41 int volatile resetcnt=0;
fox46 35:1fcb3101c2f9 42 int volatile zz1=0;
fox46 35:1fcb3101c2f9 43 int volatile zz2=0;
fox46 35:1fcb3101c2f9 44 int volatile sblock=0;
fox46 35:1fcb3101c2f9 45 int volatile reset=0;
fox46 35:1fcb3101c2f9 46 int volatile D=1;
fox46 35:1fcb3101c2f9 47 int volatile j=0;
manuelfederanko 13:a45461fbb77f 48
fox46 35:1fcb3101c2f9 49 int ms;
fox46 35:1fcb3101c2f9 50 int sec;
fox46 35:1fcb3101c2f9 51 int min;
fox46 35:1fcb3101c2f9 52 int ms1;
manuelfederanko 13:a45461fbb77f 53
fox46 35:1fcb3101c2f9 54 int firsthit=1;
fox46 35:1fcb3101c2f9 55
fox46 35:1fcb3101c2f9 56 int empfangi=0;
fox46 35:1fcb3101c2f9 57
fox46 35:1fcb3101c2f9 58 int debug=0;
fox46 35:1fcb3101c2f9 59 int timerwert=0;
fox46 35:1fcb3101c2f9 60
fox46 35:1fcb3101c2f9 61 float u_akku=0;
fox46 35:1fcb3101c2f9 62
manuelfederanko 19:a06d764e4f64 63
fox46 35:1fcb3101c2f9 64
fox46 35:1fcb3101c2f9 65 char buffer[9];
fox46 35:1fcb3101c2f9 66 char buffer1[9];
fox46 35:1fcb3101c2f9 67 char temp[20];
manuelfederanko 19:a06d764e4f64 68
fox46 35:1fcb3101c2f9 69 char zwischenzeit[9];
fox46 35:1fcb3101c2f9 70 char zwischenzeit1[9];
fox46 35:1fcb3101c2f9 71
fox46 35:1fcb3101c2f9 72 char transmit=0;
manuelfederanko 19:a06d764e4f64 73
manuelfederanko 19:a06d764e4f64 74
fox46 35:1fcb3101c2f9 75 /*Funktions Dekleration*/
manuelfederanko 19:a06d764e4f64 76
fox46 35:1fcb3101c2f9 77 void konfiguration(void)
fox46 35:1fcb3101c2f9 78 {
fox46 35:1fcb3101c2f9 79 config = 0;
fox46 35:1fcb3101c2f9 80 enable = 0;
fox46 35:1fcb3101c2f9 81 wait(0.1);
fox46 35:1fcb3101c2f9 82
fox46 35:1fcb3101c2f9 83 /*******Standardkonfiguration laden*******/
fox46 35:1fcb3101c2f9 84 hm.putc(0xAA); /******/
fox46 35:1fcb3101c2f9 85 hm.putc(0xFA); /******/
fox46 35:1fcb3101c2f9 86 hm.putc(0xF0); /******/
fox46 35:1fcb3101c2f9 87 /*****************************************/
fox46 35:1fcb3101c2f9 88
fox46 35:1fcb3101c2f9 89 wait(0.1);
manuelfederanko 19:a06d764e4f64 90
fox46 35:1fcb3101c2f9 91 if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1))
fox46 35:1fcb3101c2f9 92 {
fox46 35:1fcb3101c2f9 93 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xCF); hm.putc(0xD1); hm.putc(0x90); //HEX-Schalter 0
fox46 35:1fcb3101c2f9 94 }
fox46 35:1fcb3101c2f9 95 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1))
fox46 35:1fcb3101c2f9 96 {
fox46 35:1fcb3101c2f9 97 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD1); hm.putc(0x58); hm.putc(0x30); //HEX-Schalter 1
fox46 35:1fcb3101c2f9 98 }
fox46 35:1fcb3101c2f9 99 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1))
fox46 35:1fcb3101c2f9 100 {
fox46 35:1fcb3101c2f9 101 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD2); hm.putc(0xDE); hm.putc(0xD0); //HEX-Schalter 2
fox46 35:1fcb3101c2f9 102 }
fox46 35:1fcb3101c2f9 103 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1))
fox46 35:1fcb3101c2f9 104 {
fox46 35:1fcb3101c2f9 105 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD4); hm.putc(0x65); hm.putc(0x70); //HEX-Schalter 3
fox46 35:1fcb3101c2f9 106 }
fox46 35:1fcb3101c2f9 107 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1))
fox46 35:1fcb3101c2f9 108 {
fox46 35:1fcb3101c2f9 109 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD5); hm.putc(0xEC); hm.putc(0x10); //HEX-Schalter 4
fox46 35:1fcb3101c2f9 110 }
fox46 35:1fcb3101c2f9 111 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1))
fox46 35:1fcb3101c2f9 112 {
fox46 35:1fcb3101c2f9 113 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD7); hm.putc(0x72); hm.putc(0xB0); //HEX-Schalter 5
fox46 35:1fcb3101c2f9 114 }
fox46 35:1fcb3101c2f9 115 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1))
fox46 35:1fcb3101c2f9 116 {
fox46 35:1fcb3101c2f9 117 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD8); hm.putc(0xF9); hm.putc(0x50); //HEX-Schalter 6
fox46 35:1fcb3101c2f9 118 }
fox46 35:1fcb3101c2f9 119 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1))
fox46 35:1fcb3101c2f9 120 {
fox46 35:1fcb3101c2f9 121 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDA); hm.putc(0x7F); hm.putc(0xF0); //HEX-Schalter 7
fox46 35:1fcb3101c2f9 122 }
fox46 35:1fcb3101c2f9 123 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0))
fox46 35:1fcb3101c2f9 124 {
fox46 35:1fcb3101c2f9 125 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDC); hm.putc(0x06); hm.putc(0x90); //HEX-Schalter 8
fox46 35:1fcb3101c2f9 126 }
fox46 35:1fcb3101c2f9 127 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0))
fox46 35:1fcb3101c2f9 128 {
fox46 35:1fcb3101c2f9 129 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDD); hm.putc(0x8D); hm.putc(0x30); //HEX-Schalter 9
fox46 35:1fcb3101c2f9 130 }
fox46 35:1fcb3101c2f9 131 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0))
fox46 35:1fcb3101c2f9 132 {
fox46 35:1fcb3101c2f9 133 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDF); hm.putc(0x13); hm.putc(0xD0); //HEX-Schalter A
fox46 35:1fcb3101c2f9 134 }
fox46 35:1fcb3101c2f9 135 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0))
fox46 35:1fcb3101c2f9 136 {
fox46 35:1fcb3101c2f9 137 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE0); hm.putc(0x9A); hm.putc(0x70); //HEX-Schalter B
fox46 35:1fcb3101c2f9 138 }
fox46 35:1fcb3101c2f9 139 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0))
fox46 35:1fcb3101c2f9 140 {
fox46 35:1fcb3101c2f9 141 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE2); hm.putc(0x21); hm.putc(0x10); //HEX-Schalter C
fox46 35:1fcb3101c2f9 142 }
fox46 35:1fcb3101c2f9 143 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0))
fox46 35:1fcb3101c2f9 144 {
fox46 35:1fcb3101c2f9 145 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE3); hm.putc(0xA7); hm.putc(0xB0); //HEX-Schalter D
fox46 35:1fcb3101c2f9 146 }
fox46 35:1fcb3101c2f9 147 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0))
fox46 35:1fcb3101c2f9 148 {
fox46 35:1fcb3101c2f9 149 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE5); hm.putc(0x2E); hm.putc(0x50); //HEX-Schalter E
fox46 35:1fcb3101c2f9 150 }
fox46 35:1fcb3101c2f9 151 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0))
fox46 35:1fcb3101c2f9 152 {
fox46 35:1fcb3101c2f9 153 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE6); hm.putc(0xB4); hm.putc(0xF0); //HEX-Schalter F
fox46 35:1fcb3101c2f9 154 }
fox46 35:1fcb3101c2f9 155 else
fox46 35:1fcb3101c2f9 156 {
fox46 35:1fcb3101c2f9 157 stoppled=1;
fox46 35:1fcb3101c2f9 158 }
fox46 35:1fcb3101c2f9 159 wait(0.1);
manuelfederanko 19:a06d764e4f64 160
fox46 35:1fcb3101c2f9 161 /*******Reading the current Config parameter*******/
fox46 35:1fcb3101c2f9 162 /*hm.putc(0xAA);
fox46 35:1fcb3101c2f9 163 hm.putc(0xFA);
fox46 35:1fcb3101c2f9 164 hm.putc(0xE1);
fox46 35:1fcb3101c2f9 165 */
fox46 35:1fcb3101c2f9 166 // wait(0.1);
fox46 35:1fcb3101c2f9 167 config = 1;
fox46 35:1fcb3101c2f9 168 enable = 0;
fox46 35:1fcb3101c2f9 169 return;
manuelfederanko 19:a06d764e4f64 170 }
manuelfederanko 19:a06d764e4f64 171
fox46 35:1fcb3101c2f9 172 void stoppuhr(void)
fox46 35:1fcb3101c2f9 173 {
fox46 35:1fcb3101c2f9 174 ms = t.read_ms(); //hole mir den TimerWert in ms
fox46 35:1fcb3101c2f9 175 sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec
fox46 35:1fcb3101c2f9 176 ms = ms - (sec*1000); //stelle meine ms richtig
fox46 35:1fcb3101c2f9 177 min = (sec/60); //erzeuge mir Minuten
fox46 35:1fcb3101c2f9 178 sec = sec - (min*60); //stelle Sekunden richtig
fox46 35:1fcb3101c2f9 179 ms = (ms/10);
fox46 35:1fcb3101c2f9 180 ms1 = (ms/10);
fox46 35:1fcb3101c2f9 181 //erzeuge mir zwei Stellen nach komma
fox46 35:1fcb3101c2f9 182 sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer
fox46 35:1fcb3101c2f9 183 return;
manuelfederanko 19:a06d764e4f64 184 }
manuelfederanko 19:a06d764e4f64 185
fox46 35:1fcb3101c2f9 186 void starten(void) // Callback routine is interrupt activated by a debounced pb1 hit
fox46 35:1fcb3101c2f9 187 {
fox46 35:1fcb3101c2f9 188
fox46 35:1fcb3101c2f9 189 if ((resetcnt==0) && (sblock==0)) {
fox46 35:1fcb3101c2f9 190 t.reset(); //restiere Timer
fox46 35:1fcb3101c2f9 191 t.start(); //starte Timer
fox46 35:1fcb3101c2f9 192 resetcnt=1;
fox46 35:1fcb3101c2f9 193 enable = 0; //schalte das RF-Modul ein
fox46 35:1fcb3101c2f9 194 firsthit=0; //verhindert ein erhöhen der Variable sblock durch wiederholtes drücken des Buzzers.
fox46 35:1fcb3101c2f9 195 } else if ((resetcnt==1) && (sblock==0)) {
fox46 35:1fcb3101c2f9 196 zz1=1;
fox46 35:1fcb3101c2f9 197 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 198 lcd.locate(0, 1);
fox46 35:1fcb3101c2f9 199 lcd.printf("A%s", zwischenzeit);
fox46 35:1fcb3101c2f9 200 resetcnt=2;
fox46 35:1fcb3101c2f9 201 } else if ((resetcnt==2) && (sblock==0)) {
fox46 35:1fcb3101c2f9 202 zz2=1;
fox46 35:1fcb3101c2f9 203 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 204 lcd.locate(8, 1);
fox46 35:1fcb3101c2f9 205 lcd.printf("B%s", zwischenzeit1);
fox46 35:1fcb3101c2f9 206 resetcnt=3;
fox46 35:1fcb3101c2f9 207 } else { //nach hundert mal drueken wieder auf restcnt auf 3 setzen - SIcherheitsmechanismus um Integerüberlauf zu vermeiden
fox46 35:1fcb3101c2f9 208 resetcnt=resetcnt++;
fox46 35:1fcb3101c2f9 209 if(resetcnt==100) {
fox46 35:1fcb3101c2f9 210 resetcnt=3;
fox46 35:1fcb3101c2f9 211 }
manuelfederanko 24:9c0151db1f98 212 }
fox46 35:1fcb3101c2f9 213 resetcnt=resetcnt++;
manuelfederanko 19:a06d764e4f64 214 }
manuelfederanko 19:a06d764e4f64 215
fox46 35:1fcb3101c2f9 216 void sendkill (void)
fox46 35:1fcb3101c2f9 217 {
fox46 35:1fcb3101c2f9 218 enable=0;
fox46 35:1fcb3101c2f9 219 wait(0.1);
fox46 35:1fcb3101c2f9 220 hm.putc(0);
fox46 35:1fcb3101c2f9 221 wait(0.1);
fox46 35:1fcb3101c2f9 222 hm.putc('s');
fox46 35:1fcb3101c2f9 223 wait(0.1);
fox46 35:1fcb3101c2f9 224 hm.putc('s');
fox46 35:1fcb3101c2f9 225 wait(0.1);
fox46 35:1fcb3101c2f9 226 hm.putc('q');
fox46 35:1fcb3101c2f9 227 wait(0.1);
fox46 35:1fcb3101c2f9 228 hm.putc(0);
manuelfederanko 19:a06d764e4f64 229 }
manuelfederanko 19:a06d764e4f64 230
fox46 35:1fcb3101c2f9 231 void sendreset(){
fox46 35:1fcb3101c2f9 232 enable=0;
fox46 35:1fcb3101c2f9 233 wait(0.1);
fox46 35:1fcb3101c2f9 234 hm.putc(0);
fox46 35:1fcb3101c2f9 235 wait(0.1);
fox46 35:1fcb3101c2f9 236 hm.putc('s');
fox46 35:1fcb3101c2f9 237 wait(0.1);
fox46 35:1fcb3101c2f9 238 hm.putc('s');
fox46 35:1fcb3101c2f9 239 wait(0.1);
fox46 35:1fcb3101c2f9 240 hm.putc('x');
fox46 35:1fcb3101c2f9 241 wait(0.1);
fox46 35:1fcb3101c2f9 242 hm.putc(0);
fox46 35:1fcb3101c2f9 243 enable=0;
fox46 35:1fcb3101c2f9 244 return;
manuelfederanko 19:a06d764e4f64 245 }
manuelfederanko 19:a06d764e4f64 246
fox46 35:1fcb3101c2f9 247 void sendstart(){
fox46 35:1fcb3101c2f9 248 starten();
fox46 35:1fcb3101c2f9 249 transmit=1;
fox46 35:1fcb3101c2f9 250 enable=0;
fox46 35:1fcb3101c2f9 251 wait(0.1);
fox46 35:1fcb3101c2f9 252 hm.putc(0);
fox46 35:1fcb3101c2f9 253 wait(0.1);
fox46 35:1fcb3101c2f9 254 hm.putc('s');
fox46 35:1fcb3101c2f9 255 wait(0.1);
fox46 35:1fcb3101c2f9 256 hm.putc('s');
fox46 35:1fcb3101c2f9 257 wait(0.1);
fox46 35:1fcb3101c2f9 258 hm.putc('g');
fox46 35:1fcb3101c2f9 259 wait(0.1);
fox46 35:1fcb3101c2f9 260 hm.putc(0);
fox46 35:1fcb3101c2f9 261 enable=0;
fox46 35:1fcb3101c2f9 262 transmit=0;
fox46 35:1fcb3101c2f9 263 return;
manuelfederanko 19:a06d764e4f64 264 }
manuelfederanko 19:a06d764e4f64 265
fox46 35:1fcb3101c2f9 266 void sendstop(){
fox46 35:1fcb3101c2f9 267 enable=0;
fox46 35:1fcb3101c2f9 268 wait(0.1);
fox46 35:1fcb3101c2f9 269 hm.putc(0);
fox46 35:1fcb3101c2f9 270 wait(0.1);
fox46 35:1fcb3101c2f9 271 hm.putc('s');
fox46 35:1fcb3101c2f9 272 wait(0.1);
fox46 35:1fcb3101c2f9 273 hm.putc('s');
fox46 35:1fcb3101c2f9 274 wait(0.1);
fox46 35:1fcb3101c2f9 275 hm.putc('s');
fox46 35:1fcb3101c2f9 276 wait(0.1);
fox46 35:1fcb3101c2f9 277 hm.putc(0);
fox46 35:1fcb3101c2f9 278 enable=0;
fox46 35:1fcb3101c2f9 279 return;
fox46 35:1fcb3101c2f9 280 }
manuelfederanko 19:a06d764e4f64 281
fox46 35:1fcb3101c2f9 282 void kill_modul(void)
fox46 35:1fcb3101c2f9 283 {
fox46 35:1fcb3101c2f9 284 lcd.cls();
fox46 35:1fcb3101c2f9 285 lcd.printf(" shut down");
manuelfederanko 26:5c92d4036a4f 286
fox46 35:1fcb3101c2f9 287 sendkill();
manuelfederanko 19:a06d764e4f64 288
fox46 35:1fcb3101c2f9 289 wait(3);
fox46 35:1fcb3101c2f9 290 kill=0;
fox46 35:1fcb3101c2f9 291 wait (0.1);
fox46 35:1fcb3101c2f9 292 return;
fox46 35:1fcb3101c2f9 293 }
manuelfederanko 19:a06d764e4f64 294
fox46 35:1fcb3101c2f9 295 void reset_startbutton( void )
fox46 35:1fcb3101c2f9 296 {
fox46 35:1fcb3101c2f9 297 if(sblock==1) { // Reset für Durchgang erhöhen
fox46 35:1fcb3101c2f9 298 t.stop();
fox46 35:1fcb3101c2f9 299 t.reset();
fox46 35:1fcb3101c2f9 300 memset(buffer1,0,19);
fox46 35:1fcb3101c2f9 301 stoppuhr();
fox46 35:1fcb3101c2f9 302 //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 303 //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 304 resetcnt=0;
fox46 35:1fcb3101c2f9 305 zz1=0;
fox46 35:1fcb3101c2f9 306 zz2=0;
fox46 35:1fcb3101c2f9 307 sblock=0;
fox46 35:1fcb3101c2f9 308 D++;
fox46 35:1fcb3101c2f9 309 firsthit=1;
fox46 35:1fcb3101c2f9 310 lcd.cls();
fox46 35:1fcb3101c2f9 311
fox46 35:1fcb3101c2f9 312 sendreset();
fox46 35:1fcb3101c2f9 313
fox46 35:1fcb3101c2f9 314 if(D>99) {
fox46 35:1fcb3101c2f9 315 D=1;
fox46 35:1fcb3101c2f9 316 }
manuelfederanko 20:e809ca4de724 317 }
fox46 35:1fcb3101c2f9 318 }
fox46 35:1fcb3101c2f9 319
fox46 35:1fcb3101c2f9 320 void totalreset_local (void)
fox46 35:1fcb3101c2f9 321 {
fox46 35:1fcb3101c2f9 322 t.stop();
fox46 35:1fcb3101c2f9 323 t.reset();
fox46 35:1fcb3101c2f9 324 stoppuhr();
fox46 35:1fcb3101c2f9 325 memset(buffer1,0,19);
fox46 35:1fcb3101c2f9 326 //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 327 //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1);
fox46 35:1fcb3101c2f9 328 resetcnt=0;
fox46 35:1fcb3101c2f9 329 zz1=0;
fox46 35:1fcb3101c2f9 330 zz2=0;
fox46 35:1fcb3101c2f9 331 sblock=0;
fox46 35:1fcb3101c2f9 332 D=1;
fox46 35:1fcb3101c2f9 333 firsthit=1;
fox46 35:1fcb3101c2f9 334 time1.detach();
fox46 35:1fcb3101c2f9 335 lcd.cls();
fox46 35:1fcb3101c2f9 336 }
manuelfederanko 20:e809ca4de724 337
fox46 35:1fcb3101c2f9 338 void stoppen (void) //Stoppen des Timers ohne Funk
fox46 35:1fcb3101c2f9 339 {
fox46 35:1fcb3101c2f9 340 t.stop();
fox46 35:1fcb3101c2f9 341 if (firsthit==0){
fox46 35:1fcb3101c2f9 342 sblock=1;
fox46 35:1fcb3101c2f9 343 }
manuelfederanko 20:e809ca4de724 344 }
manuelfederanko 20:e809ca4de724 345
fox46 35:1fcb3101c2f9 346 void stoppled_blink() {
fox46 35:1fcb3101c2f9 347 stoppled=!stoppled;
fox46 35:1fcb3101c2f9 348 return;
fox46 35:1fcb3101c2f9 349 }
fox46 35:1fcb3101c2f9 350
fox46 35:1fcb3101c2f9 351 void akkucheck()
fox46 35:1fcb3101c2f9 352 {
fox46 35:1fcb3101c2f9 353 if (transmit==0){
fox46 35:1fcb3101c2f9 354 float i=0;
fox46 35:1fcb3101c2f9 355
fox46 35:1fcb3101c2f9 356 for(int t=0; t<100; t++) {
fox46 35:1fcb3101c2f9 357 i=i+ubat.read();
fox46 35:1fcb3101c2f9 358 }
fox46 35:1fcb3101c2f9 359 // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen
fox46 35:1fcb3101c2f9 360
fox46 35:1fcb3101c2f9 361 u_akku=((i/100)*4.364);
fox46 35:1fcb3101c2f9 362
fox46 35:1fcb3101c2f9 363 //lcd.locate(0, 1); //debug Ausgabe
fox46 35:1fcb3101c2f9 364 //lcd.printf("Akkucheck %3.2fV", u_akku); //debug Ausgabe
fox46 35:1fcb3101c2f9 365 //wait(0.1); //debug Ausgabe
fox46 35:1fcb3101c2f9 366
fox46 35:1fcb3101c2f9 367 if(u_akku<=ulow) { //wenn Batteriespannung kleiner als ulow dann Akku laden am LCD ausgeben
fox46 35:1fcb3101c2f9 368 lcd.cls();
fox46 35:1fcb3101c2f9 369
fox46 35:1fcb3101c2f9 370 lcd.locate(6,0);
fox46 35:1fcb3101c2f9 371 lcd.printf("%3.2fV", u_akku);
fox46 35:1fcb3101c2f9 372 lcd.locate(3,1);
fox46 35:1fcb3101c2f9 373 lcd.printf("Akku laden!");
fox46 35:1fcb3101c2f9 374 wait(3);
fox46 35:1fcb3101c2f9 375 lcd.cls();
manuelfederanko 21:5fb0832693d1 376 }
fox46 35:1fcb3101c2f9 377 /*if(u_akku>ulow) {
fox46 35:1fcb3101c2f9 378 time1.attach(&stoppled_blink,2);
fox46 35:1fcb3101c2f9 379
fox46 35:1fcb3101c2f9 380
fox46 35:1fcb3101c2f9 381 }
fox46 35:1fcb3101c2f9 382 if(u_akku<=ulow) {
fox46 35:1fcb3101c2f9 383 time1.attach(&stoppled_blink,0.5);
fox46 35:1fcb3101c2f9 384
fox46 35:1fcb3101c2f9 385 }*/
fox46 35:1fcb3101c2f9 386 if(u_akku>=charge1) {
fox46 35:1fcb3101c2f9 387 ChargeLed1=1;
fox46 35:1fcb3101c2f9 388 ChargeLed2=1;
fox46 35:1fcb3101c2f9 389 ChargeLed3=1;
fox46 35:1fcb3101c2f9 390 ChargeLed4=1;
fox46 35:1fcb3101c2f9 391 time1.attach(&stoppled_blink,2);
fox46 35:1fcb3101c2f9 392 }
fox46 35:1fcb3101c2f9 393
fox46 35:1fcb3101c2f9 394 else if(u_akku>=charge2) {
fox46 35:1fcb3101c2f9 395 ChargeLed1=1;
fox46 35:1fcb3101c2f9 396 ChargeLed2=1;
fox46 35:1fcb3101c2f9 397 ChargeLed3=1;
fox46 35:1fcb3101c2f9 398 ChargeLed4=0;
fox46 35:1fcb3101c2f9 399 time1.attach(&stoppled_blink,2);
fox46 35:1fcb3101c2f9 400 }
fox46 35:1fcb3101c2f9 401 else if(u_akku>=charge3) {
fox46 35:1fcb3101c2f9 402 ChargeLed1=1;
fox46 35:1fcb3101c2f9 403 ChargeLed2=1;
fox46 35:1fcb3101c2f9 404 ChargeLed3=0;
fox46 35:1fcb3101c2f9 405 ChargeLed4=0;
fox46 35:1fcb3101c2f9 406 time1.attach(&stoppled_blink,2);
fox46 35:1fcb3101c2f9 407 }
fox46 35:1fcb3101c2f9 408 else if(u_akku>=charge4) {
fox46 35:1fcb3101c2f9 409 ChargeLed1=1;
fox46 35:1fcb3101c2f9 410 ChargeLed2=0;
fox46 35:1fcb3101c2f9 411 ChargeLed3=0;
fox46 35:1fcb3101c2f9 412 ChargeLed4=0;
fox46 35:1fcb3101c2f9 413 time1.attach(&stoppled_blink,0.5);
fox46 35:1fcb3101c2f9 414 }
fox46 35:1fcb3101c2f9 415 else if (u_akku<=u_shutdown) {
fox46 35:1fcb3101c2f9 416 time1.detach();
fox46 35:1fcb3101c2f9 417 stoppled=0;
fox46 35:1fcb3101c2f9 418 wait(3);
fox46 35:1fcb3101c2f9 419 kill_modul();
fox46 35:1fcb3101c2f9 420 }
fox46 35:1fcb3101c2f9 421
fox46 35:1fcb3101c2f9 422 }
fox46 35:1fcb3101c2f9 423
fox46 35:1fcb3101c2f9 424
fox46 35:1fcb3101c2f9 425 return;
fox46 35:1fcb3101c2f9 426 // }
fox46 35:1fcb3101c2f9 427 }
fox46 35:1fcb3101c2f9 428
fox46 35:1fcb3101c2f9 429 void empfangen()
fox46 35:1fcb3101c2f9 430 {
fox46 35:1fcb3101c2f9 431 //Funktion wird aufgerufen sobald das RF-Modul Daten an TX hat - über die Interruptroutine hm.attach(&empfangen) springe ich in die Funktion
fox46 35:1fcb3101c2f9 432 //Beim konfigurieren des Funkmoduls werden Uart Interrupts ausgelöst, diese werden durch die folgende while schleife abgefangen
fox46 35:1fcb3101c2f9 433 //Funkmodul schickt anscheinend 4 char nach der Konfiguration
fox46 35:1fcb3101c2f9 434
fox46 35:1fcb3101c2f9 435 /* while (j<4) {
fox46 35:1fcb3101c2f9 436 j=j+1;
fox46 35:1fcb3101c2f9 437 hm.getc();
fox46 35:1fcb3101c2f9 438 return;
fox46 35:1fcb3101c2f9 439 }*/
fox46 35:1fcb3101c2f9 440 int i=0;
fox46 35:1fcb3101c2f9 441
fox46 35:1fcb3101c2f9 442 if (hm.readable()) {
fox46 35:1fcb3101c2f9 443 temp[empfangi] = hm.getc();
fox46 35:1fcb3101c2f9 444 empfangi++;
fox46 35:1fcb3101c2f9 445
fox46 35:1fcb3101c2f9 446 if (temp[empfangi-1]==0) {
fox46 35:1fcb3101c2f9 447 temp[empfangi]=0;
fox46 35:1fcb3101c2f9 448 empfangi=0;
fox46 35:1fcb3101c2f9 449 i=0;
fox46 35:1fcb3101c2f9 450
fox46 35:1fcb3101c2f9 451 if (temp[0]=='s' && temp[1]=='s' && temp[2]=='q') { //Kommandos werden mit zwei 's' characters eingeleitet der dritte character definiert das Kommando
fox46 35:1fcb3101c2f9 452 kill_modul();
fox46 35:1fcb3101c2f9 453 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='s') {
fox46 35:1fcb3101c2f9 454 stoppen();
fox46 35:1fcb3101c2f9 455 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='x') {
fox46 35:1fcb3101c2f9 456 reset_startbutton();
fox46 35:1fcb3101c2f9 457 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='t') {
fox46 35:1fcb3101c2f9 458 totalreset_local();
fox46 35:1fcb3101c2f9 459 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='e') { //mit Kommando 'e' kann Text übertragen werden
fox46 35:1fcb3101c2f9 460
fox46 35:1fcb3101c2f9 461
fox46 35:1fcb3101c2f9 462 for (int z=3; temp[z]!=0; z++)
fox46 35:1fcb3101c2f9 463 // lcd.printf("%c", temp[z]);
fox46 35:1fcb3101c2f9 464 {buffer1[i]=temp[z];
fox46 35:1fcb3101c2f9 465 i++;
fox46 35:1fcb3101c2f9 466 }
fox46 35:1fcb3101c2f9 467 buffer1[i]=0;
fox46 35:1fcb3101c2f9 468
fox46 35:1fcb3101c2f9 469 //lcd.locate(4,1);
fox46 35:1fcb3101c2f9 470 //lcd.printf("Z1:%s",buffer1);
fox46 35:1fcb3101c2f9 471 memset(temp,0,19);
fox46 35:1fcb3101c2f9 472 //lcd.locate(4,0);
fox46 35:1fcb3101c2f9 473 //lcd.printf("Zx:%s",buffer1);
fox46 35:1fcb3101c2f9 474 }
fox46 35:1fcb3101c2f9 475 }
fox46 35:1fcb3101c2f9 476
manuelfederanko 19:a06d764e4f64 477 }
fox46 35:1fcb3101c2f9 478 return;
manuelfederanko 13:a45461fbb77f 479 }
manuelfederanko 13:a45461fbb77f 480
fox46 35:1fcb3101c2f9 481 /*Funktion zur Anzeige der Batteriespannung am LCD.******
fox46 35:1fcb3101c2f9 482 **Unterhalb der Spannung "ulow" wird eine Aufforderung***
fox46 35:1fcb3101c2f9 483 ** zum Batterietausch ausgegeben.************************/
fox46 35:1fcb3101c2f9 484 void lowbatt()
fox46 35:1fcb3101c2f9 485 {
fox46 35:1fcb3101c2f9 486 float i=0;
fox46 35:1fcb3101c2f9 487
fox46 35:1fcb3101c2f9 488 for(int t=0; t<100; t++) {
fox46 35:1fcb3101c2f9 489 i=i+ubat.read();
fox46 35:1fcb3101c2f9 490 } // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen
fox46 35:1fcb3101c2f9 491
fox46 35:1fcb3101c2f9 492 u_akku=((i/100)*4.364);
fox46 35:1fcb3101c2f9 493 if(u_akku>=ulow) {
fox46 35:1fcb3101c2f9 494 lcd.cls();
fox46 35:1fcb3101c2f9 495
fox46 35:1fcb3101c2f9 496 //lcd.setUDC(unsigned char udc_Bat_Hi[],{0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00});
fox46 35:1fcb3101c2f9 497
fox46 35:1fcb3101c2f9 498 lcd.printf(" Akkuspannung");
fox46 35:1fcb3101c2f9 499 lcd.locate(5,1);
fox46 35:1fcb3101c2f9 500 lcd.printf("%3.2fV",u_akku); // Ausgabe der Akkuspannung
fox46 35:1fcb3101c2f9 501 wait(2);
fox46 35:1fcb3101c2f9 502 lcd.cls();
fox46 35:1fcb3101c2f9 503
fox46 35:1fcb3101c2f9 504 }
fox46 35:1fcb3101c2f9 505 if(u_akku<=ulow) { //wenn Batteriespannung kleiner als ulow dann Akku laden am LCD ausgeben
fox46 35:1fcb3101c2f9 506 lcd.cls();
fox46 35:1fcb3101c2f9 507
fox46 35:1fcb3101c2f9 508 lcd.locate(6,0);
fox46 35:1fcb3101c2f9 509 lcd.printf("%3.2fV", u_akku);
fox46 35:1fcb3101c2f9 510 lcd.locate(3,1);
fox46 35:1fcb3101c2f9 511 lcd.printf("Akku laden!");
fox46 35:1fcb3101c2f9 512 wait(3);
fox46 35:1fcb3101c2f9 513 lcd.cls();
fox46 12:3f53322a5270 514
fox46 35:1fcb3101c2f9 515 }
fox46 35:1fcb3101c2f9 516 if (u_akku<=u_shutdown) {
fox46 35:1fcb3101c2f9 517 kill_modul();
fox46 35:1fcb3101c2f9 518 }
fox46 35:1fcb3101c2f9 519 return;
fox46 35:1fcb3101c2f9 520 }
fox46 35:1fcb3101c2f9 521
fox46 35:1fcb3101c2f9 522 int main()
fox46 35:1fcb3101c2f9 523 {
fox46 35:1fcb3101c2f9 524 kill=1;
fox46 35:1fcb3101c2f9 525 suspend_charge=0;
fox46 35:1fcb3101c2f9 526 highpower_charge=1;
fox46 35:1fcb3101c2f9 527
fox46 35:1fcb3101c2f9 528
fox46 35:1fcb3101c2f9 529 pb1.mode(PullDown); // Use internal pulldown for pushbutton
fox46 35:1fcb3101c2f9 530 pb2.mode(PullNone); // keinen Modus verwenden
fox46 35:1fcb3101c2f9 531 dip0.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor
fox46 35:1fcb3101c2f9 532 dip1.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor
fox46 35:1fcb3101c2f9 533 dip2.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor
fox46 35:1fcb3101c2f9 534 dip3.mode(PullUp); // Use internal pullup for pushbutton - on LPC1768 you need also hardware pull up resistor
manuelfederanko 17:ce5a80e8fc8e 535
fox46 35:1fcb3101c2f9 536 wait(0.01); // Delay for initial pullup to take effect
fox46 35:1fcb3101c2f9 537
fox46 35:1fcb3101c2f9 538 konfiguration(); //RF Modul konfigurieren
fox46 35:1fcb3101c2f9 539
fox46 35:1fcb3101c2f9 540 lowbatt(); //Batteriespannung beim Start abfragen
fox46 35:1fcb3101c2f9 541
fox46 35:1fcb3101c2f9 542 pb1.attach_asserted(&sendstart);
fox46 35:1fcb3101c2f9 543 pb1.attach_asserted_held(&reset_startbutton);
fox46 35:1fcb3101c2f9 544
fox46 35:1fcb3101c2f9 545 pb2.attach_asserted(&sendstop);
fox46 35:1fcb3101c2f9 546 pb2.attach_deasserted_held(&kill_modul); // Setup Interrupt callback functions for a pb hit
fox46 35:1fcb3101c2f9 547
fox46 35:1fcb3101c2f9 548 pb1.setSampleFrequency();
fox46 35:1fcb3101c2f9 549
manuelfederanko 17:ce5a80e8fc8e 550 pb2.setSampleFrequency();
manuelfederanko 17:ce5a80e8fc8e 551
fox46 35:1fcb3101c2f9 552 pb2.setSamplesTillHeld( 200 );
manuelfederanko 19:a06d764e4f64 553
fox46 35:1fcb3101c2f9 554 hm.attach(&empfangen,Serial::RxIrq); // Setup Interrupt callback functions for Datareceive
fox46 35:1fcb3101c2f9 555 timelong.attach(&akkucheck,60); //Akkutest wird alle 60sec. gestartet
manuelfederanko 19:a06d764e4f64 556
fox46 35:1fcb3101c2f9 557 lcd.cls(); //debug Ausgabe
fox46 35:1fcb3101c2f9 558 lcd.printf(" Starttaster"); //debug Ausgabe
fox46 35:1fcb3101c2f9 559 wait(2);
manuelfederanko 17:ce5a80e8fc8e 560
fox46 35:1fcb3101c2f9 561 time1.attach(&stoppled_blink,2);
fox46 35:1fcb3101c2f9 562 timer1.start();
fox46 35:1fcb3101c2f9 563 lcd.cls();
manuelfederanko 19:a06d764e4f64 564
fox46 35:1fcb3101c2f9 565 memset (buffer,0,19);
fox46 35:1fcb3101c2f9 566 memset (buffer1,0,19);
fox46 35:1fcb3101c2f9 567 while (1) {
fox46 35:1fcb3101c2f9 568 wait(.1);
fox46 35:1fcb3101c2f9 569 //lcd.cls();
fox46 35:1fcb3101c2f9 570 stoppuhr(); //rufe Funktion stoppuhr auf
fox46 35:1fcb3101c2f9 571 lcd.locate(0, 0); //setze den Cursor auf Zeichen 0 Reihe 1
fox46 35:1fcb3101c2f9 572 lcd.printf("D%02d", D); // Ausgabe der Durchgänge, Formatiere mein LCD-Ausgabe nach D00 (zwei stellen)
fox46 35:1fcb3101c2f9 573 lcd.locate(4, 0);
fox46 35:1fcb3101c2f9 574 if (buffer1[1]!=0) {
fox46 35:1fcb3101c2f9 575 // if (strlen(buffer1)>0) {
fox46 35:1fcb3101c2f9 576 //lcd.printf("ZE:%c%c%c%c%c%c%c%c",buffer1[0],buffer1[1],buffer1[2],buffer1[3],buffer1[4],buffer1[5],buffer1[6],buffer1[7]);
fox46 35:1fcb3101c2f9 577 lcd.printf("ZE:%s",buffer1);
fox46 35:1fcb3101c2f9 578 //} else {
fox46 35:1fcb3101c2f9 579 // lcd.printf("pussy %d ",debug);
fox46 35:1fcb3101c2f9 580 // }
fox46 35:1fcb3101c2f9 581 } else if (buffer[1]!=0){
fox46 35:1fcb3101c2f9 582 lcd.printf("ZE:%s",buffer);
fox46 35:1fcb3101c2f9 583 }
manuelfederanko 17:ce5a80e8fc8e 584
fox46 35:1fcb3101c2f9 585 //lcd.locate(4, 1);
fox46 35:1fcb3101c2f9 586 //lcd.printf("ZE:%s", temp);
fox46 35:1fcb3101c2f9 587
fox46 35:1fcb3101c2f9 588 }
fox46 35:1fcb3101c2f9 589
fox46 35:1fcb3101c2f9 590 }