Display zeigt merkwürdige Zeichen

Dependencies:   mbed PinDetect TextLCD

Fork of FWFSU_Start_28102013 by KX-ONE

Committer:
fox46
Date:
Mon Nov 18 14:47:32 2013 +0000
Revision:
8:9eccc5d25e8f
Parent:
7:016281ea7be6
Child:
9:5c871d235f31
Ausschalten des Starttasters ?ber Funk eingebaut

Who changed what in which revision?

UserRevisionLine numberNew 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 5:832cc1bf7eba 7 #define u_shutdown 3 //Konstante für shutdown bei zu geringer Akkuspannung
fox46 4:165fc296f7f5 8
fox46 7:016281ea7be6 9 Timer timer1;
fox46 3:def65a960118 10 TextLCD lcd(p34, p23, p36, p15, p16, p35); // rs, e, d0-d3 für 130110-1P1
fox46 3:def65a960118 11 PinDetect pb1(p18); //Buzzer
fox46 3:def65a960118 12 PinDetect pb2(p19); //LED-Button
fox46 3:def65a960118 13 DigitalIn dip0(p26); //Hex-Schalter Pin 1 LSB
fox46 3:def65a960118 14 DigitalIn dip1(p27); //Hex-schalter Pin 2
fox46 3:def65a960118 15 DigitalIn dip2(p28); //Hex-schalter Pin 3
fox46 3:def65a960118 16 DigitalIn dip3(p29); //Hex-Schalter Pin 4 MSB
joca89 2:8d12fef6cc0e 17 //Serial hm(p13, p14); // definiere UART fuer HM-TPR433 Modul LPC1768
joca89 2:8d12fef6cc0e 18 Serial hm(p9, p10); // definiere UART fr HM-TPR433 Modul LPC11U24
joca89 0:097b334e1077 19 DigitalOut config(p22);
joca89 0:097b334e1077 20 DigitalOut enable(p21);
fox46 4:165fc296f7f5 21 DigitalOut stoppled(p25); //LED-Button
fox46 4:165fc296f7f5 22 DigitalOut kill(p8);
fox46 7:016281ea7be6 23 DigitalOut suspend_charge(p7); //enables LION Charger suspend mode
fox46 7:016281ea7be6 24 DigitalOut highpower_charge(p6); // high- 100% charge current, low- 20% charge current
fox46 3:def65a960118 25 AnalogIn ubat(p17);
fox46 7:016281ea7be6 26 AnalogIn charge_current(p20);
joca89 0:097b334e1077 27
fox46 6:79bc3888c88c 28 Ticker time1;
fox46 6:79bc3888c88c 29 Ticker timelong;
fox46 6:79bc3888c88c 30
fox46 5:832cc1bf7eba 31 float u_akku=0;
fox46 7:016281ea7be6 32 int timerwert=0;
fox46 8:9eccc5d25e8f 33 int j=0;
fox46 5:832cc1bf7eba 34
fox46 5:832cc1bf7eba 35
joca89 0:097b334e1077 36 /*Funktions Dekleration*/
joca89 0:097b334e1077 37
joca89 0:097b334e1077 38 void konfiguration(void)
joca89 0:097b334e1077 39 {
joca89 0:097b334e1077 40 config = 0;
joca89 0:097b334e1077 41 enable = 0;
joca89 0:097b334e1077 42 wait(0.1);
joca89 0:097b334e1077 43
joca89 0:097b334e1077 44 /*******Standardkonfiguration laden*******/
joca89 0:097b334e1077 45 hm.putc(0xAA); /******/
joca89 0:097b334e1077 46 hm.putc(0xFA); /******/
joca89 0:097b334e1077 47 hm.putc(0xF0); /******/
joca89 0:097b334e1077 48 /*****************************************/
joca89 0:097b334e1077 49
joca89 0:097b334e1077 50 wait(0.1);
joca89 0:097b334e1077 51
joca89 0:097b334e1077 52 if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1))
joca89 0:097b334e1077 53 {
joca89 0:097b334e1077 54 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 55 }
joca89 0:097b334e1077 56 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1))
joca89 0:097b334e1077 57 {
joca89 0:097b334e1077 58 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 59 }
joca89 0:097b334e1077 60 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1))
joca89 0:097b334e1077 61 {
joca89 0:097b334e1077 62 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 63 }
joca89 0:097b334e1077 64 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1))
joca89 0:097b334e1077 65 {
joca89 0:097b334e1077 66 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 67 }
joca89 0:097b334e1077 68 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1))
joca89 0:097b334e1077 69 {
joca89 0:097b334e1077 70 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 71 }
joca89 0:097b334e1077 72 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1))
joca89 0:097b334e1077 73 {
joca89 0:097b334e1077 74 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 75 }
joca89 0:097b334e1077 76 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1))
joca89 0:097b334e1077 77 {
joca89 0:097b334e1077 78 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 79 }
joca89 0:097b334e1077 80 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1))
joca89 0:097b334e1077 81 {
joca89 0:097b334e1077 82 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 83 }
joca89 0:097b334e1077 84 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0))
joca89 0:097b334e1077 85 {
joca89 0:097b334e1077 86 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 87 }
joca89 0:097b334e1077 88 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0))
joca89 0:097b334e1077 89 {
joca89 0:097b334e1077 90 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 91 }
joca89 0:097b334e1077 92 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0))
joca89 0:097b334e1077 93 {
joca89 0:097b334e1077 94 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 95 }
joca89 0:097b334e1077 96 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0))
joca89 0:097b334e1077 97 {
joca89 0:097b334e1077 98 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 99 }
joca89 0:097b334e1077 100 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0))
joca89 0:097b334e1077 101 {
joca89 0:097b334e1077 102 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 103 }
joca89 0:097b334e1077 104 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0))
joca89 0:097b334e1077 105 {
joca89 0:097b334e1077 106 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 107 }
joca89 0:097b334e1077 108 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0))
joca89 0:097b334e1077 109 {
joca89 0:097b334e1077 110 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 111 }
joca89 0:097b334e1077 112 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0))
joca89 0:097b334e1077 113 {
joca89 0:097b334e1077 114 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 115 }
joca89 0:097b334e1077 116 else
joca89 0:097b334e1077 117 {
fox46 4:165fc296f7f5 118 stoppled=1;
joca89 0:097b334e1077 119 }
joca89 0:097b334e1077 120 wait(0.1);
joca89 0:097b334e1077 121
joca89 0:097b334e1077 122 /*******Reading the current Config parameter*******/
fox46 4:165fc296f7f5 123 /*hm.putc(0xAA);
joca89 0:097b334e1077 124 hm.putc(0xFA);
joca89 0:097b334e1077 125 hm.putc(0xE1);
fox46 4:165fc296f7f5 126 */
fox46 4:165fc296f7f5 127 // wait(0.1);
joca89 0:097b334e1077 128 config = 1;
fox46 8:9eccc5d25e8f 129 enable = 0;
joca89 0:097b334e1077 130 return;
joca89 0:097b334e1077 131 }
joca89 0:097b334e1077 132
fox46 7:016281ea7be6 133 void sendstart(){
fox46 4:165fc296f7f5 134 enable=0;
fox46 4:165fc296f7f5 135 wait(0.1);
fox46 4:165fc296f7f5 136 hm.putc('g');
fox46 4:165fc296f7f5 137 wait(0.1);
fox46 8:9eccc5d25e8f 138 enable=0;
fox46 4:165fc296f7f5 139 return;
joca89 0:097b334e1077 140 }
joca89 0:097b334e1077 141
fox46 4:165fc296f7f5 142 void sendreset(){
fox46 4:165fc296f7f5 143 enable=0;
fox46 4:165fc296f7f5 144 wait(0.1);
fox46 4:165fc296f7f5 145 hm.putc('x');
fox46 4:165fc296f7f5 146 wait(0.1);
fox46 8:9eccc5d25e8f 147 enable=0;
fox46 4:165fc296f7f5 148 return;
fox46 4:165fc296f7f5 149 }
fox46 7:016281ea7be6 150
fox46 7:016281ea7be6 151 void sendstop(){
fox46 7:016281ea7be6 152 enable=0;
fox46 7:016281ea7be6 153 wait(0.1);
fox46 7:016281ea7be6 154 hm.putc('s');
fox46 7:016281ea7be6 155 wait(0.1);
fox46 8:9eccc5d25e8f 156 enable=0;
fox46 7:016281ea7be6 157 return;
fox46 7:016281ea7be6 158 }
fox46 7:016281ea7be6 159
fox46 4:165fc296f7f5 160 void kill_modul(){
fox46 4:165fc296f7f5 161 lcd.cls();
fox46 4:165fc296f7f5 162 lcd.printf(" shut down");
fox46 5:832cc1bf7eba 163 wait(3);
fox46 4:165fc296f7f5 164 kill=0;
fox46 4:165fc296f7f5 165 return;
fox46 4:165fc296f7f5 166 }
joca89 0:097b334e1077 167
fox46 6:79bc3888c88c 168 void stoppled_blink() {
fox46 6:79bc3888c88c 169 stoppled=!stoppled;
fox46 6:79bc3888c88c 170 return;
fox46 6:79bc3888c88c 171 }
fox46 6:79bc3888c88c 172
fox46 6:79bc3888c88c 173 void akkucheck()
fox46 4:165fc296f7f5 174 {
fox46 4:165fc296f7f5 175 float i=0;
fox46 6:79bc3888c88c 176
fox46 6:79bc3888c88c 177 for(int t=0; t<100; t++) {
fox46 6:79bc3888c88c 178 i=i+ubat.read();
fox46 6:79bc3888c88c 179 }
fox46 6:79bc3888c88c 180 // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen
joca89 0:097b334e1077 181
fox46 6:79bc3888c88c 182 u_akku=((i/100)*4.364);
fox46 6:79bc3888c88c 183
fox46 7:016281ea7be6 184 lcd.locate(0, 1); //debug Ausgabe
fox46 6:79bc3888c88c 185 lcd.printf("Akkucheck %3.2fV", u_akku); //debug Ausgabe
fox46 6:79bc3888c88c 186 wait(0.1); //debug Ausgabe
fox46 6:79bc3888c88c 187
fox46 6:79bc3888c88c 188 if(u_akku>ulow) {
fox46 6:79bc3888c88c 189 time1.attach(&stoppled_blink,2);
fox46 5:832cc1bf7eba 190 }
fox46 6:79bc3888c88c 191 if(u_akku<=ulow) {
fox46 6:79bc3888c88c 192 time1.attach(&stoppled_blink,0.5);
fox46 5:832cc1bf7eba 193 }
fox46 6:79bc3888c88c 194 if (u_akku<=u_shutdown) {
fox46 6:79bc3888c88c 195 time1.detach();
fox46 6:79bc3888c88c 196 stoppled=0;
fox46 6:79bc3888c88c 197 wait(3);
fox46 6:79bc3888c88c 198 kill_modul();
fox46 6:79bc3888c88c 199 }
fox46 6:79bc3888c88c 200
fox46 4:165fc296f7f5 201 return;
fox46 6:79bc3888c88c 202 }
joca89 0:097b334e1077 203
fox46 8:9eccc5d25e8f 204 void empfangen()
fox46 8:9eccc5d25e8f 205 {
fox46 8:9eccc5d25e8f 206 //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 207 //Beim konfigurieren des Funkmoduls werden Uart Interrupts ausgelöst, diese werden durch die folgende while schleife abgefangen
fox46 8:9eccc5d25e8f 208 //Funkmodul schickt anscheinend 4 char nach der Konfiguration
fox46 8:9eccc5d25e8f 209
fox46 8:9eccc5d25e8f 210 while (j<4) {
fox46 8:9eccc5d25e8f 211 j=j+1;
fox46 8:9eccc5d25e8f 212 hm.getc();
fox46 8:9eccc5d25e8f 213 return;
fox46 8:9eccc5d25e8f 214 }
fox46 8:9eccc5d25e8f 215 if (hm.readable()) {
fox46 8:9eccc5d25e8f 216 char rxd = hm.getc();
fox46 8:9eccc5d25e8f 217 if (rxd=='q') {
fox46 8:9eccc5d25e8f 218 kill_modul();
fox46 8:9eccc5d25e8f 219 }
fox46 8:9eccc5d25e8f 220 }
fox46 8:9eccc5d25e8f 221 return;
fox46 8:9eccc5d25e8f 222 }
fox46 6:79bc3888c88c 223
fox46 4:165fc296f7f5 224 int main() {
fox46 7:016281ea7be6 225 kill=1;
fox46 7:016281ea7be6 226 suspend_charge=0;
fox46 7:016281ea7be6 227 highpower_charge=1;
fox46 7:016281ea7be6 228
joca89 0:097b334e1077 229 // Use internal pullup for pushbutton
fox46 4:165fc296f7f5 230 pb1.mode(PullDown);
fox46 4:165fc296f7f5 231 pb2.mode(PullNone); // keinen Modus verwenden
joca89 0:097b334e1077 232 dip0.mode(PullUp);
joca89 0:097b334e1077 233 dip1.mode(PullUp);
joca89 0:097b334e1077 234 dip2.mode(PullUp);
fox46 4:165fc296f7f5 235 dip3.mode(PullUp);
fox46 4:165fc296f7f5 236
fox46 4:165fc296f7f5 237 wait(0.01); // Delay for initial pullup to take effect
fox46 4:165fc296f7f5 238
fox46 7:016281ea7be6 239 pb1.attach_asserted(&sendstart);
fox46 4:165fc296f7f5 240 pb1.attach_asserted_held(&sendreset);
fox46 4:165fc296f7f5 241
fox46 7:016281ea7be6 242 pb2.attach_asserted(&sendstop);
fox46 4:165fc296f7f5 243 pb2.attach_deasserted_held(&kill_modul); // Setup Interrupt callback functions for a pb hit
joca89 0:097b334e1077 244
fox46 4:165fc296f7f5 245 pb1.setSampleFrequency();
fox46 4:165fc296f7f5 246 pb2.setSampleFrequency();
joca89 0:097b334e1077 247
fox46 4:165fc296f7f5 248 pb2.setSamplesTillHeld( 200 );
fox46 4:165fc296f7f5 249
fox46 4:165fc296f7f5 250 konfiguration(); //RF Modul konfigurieren
fox46 6:79bc3888c88c 251 timelong.attach(&akkucheck,60); //Akkutest wird alle 60sec. gestartet
fox46 8:9eccc5d25e8f 252 hm.attach(&empfangen,Serial::RxIrq); // Setup Interrupt callback functions for Datarecive
fox46 8:9eccc5d25e8f 253
fox46 6:79bc3888c88c 254 lcd.cls(); //debug Ausgabe
fox46 6:79bc3888c88c 255 lcd.printf(" Starttaster"); //debug Ausgabe
joca89 0:097b334e1077 256
fox46 6:79bc3888c88c 257 time1.attach(&stoppled_blink,2);
fox46 7:016281ea7be6 258 timer1.start();
joca89 2:8d12fef6cc0e 259
fox46 6:79bc3888c88c 260 while (1) {
fox46 7:016281ea7be6 261
fox46 6:79bc3888c88c 262
joca89 0:097b334e1077 263 }
joca89 0:097b334e1077 264
joca89 0:097b334e1077 265 }