Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PinDetect TextLCD
Fork of FWFSU_Start_28102013 by
main.cpp
00001 #include "mbed.h" 00002 #include "PinDetect.h" 00003 #include "stdlib.h" 00004 #include "TextLCD.h" 00005 00006 #define ulow 3.3 //definiere Symbolische Konstante für ulow mit dem Wert xx 00007 #define u_shutdown 3.1 //Konstante für shutdown bei zu geringer Akkuspannung muss immer kleiner als charge4 sein!!! 00008 #define charge1 4 00009 #define charge2 3.7 00010 #define charge3 3.4 00011 #define charge4 3.2 00012 00013 Timer timer1; 00014 Timer t; 00015 TextLCD lcd(p34, p23, p36, p15, p16, p35); // rs, e, d0-d3 für 130110-1P1 00016 PinDetect pb1(p18); //Buzzer 00017 PinDetect pb2(p19); //LED-Button 00018 DigitalIn dip0(p26); //Hex-Schalter Pin 1 LSB 00019 DigitalIn dip1(p27); //Hex-schalter Pin 2 00020 DigitalIn dip2(p28); //Hex-schalter Pin 3 00021 DigitalIn dip3(p29); //Hex-Schalter Pin 4 MSB 00022 //Serial hm(p13, p14); // definiere UART fuer HM-TPR433 Modul LPC1768 00023 Serial hm(p9, p10); // definiere UART fr HM-TPR433 Modul LPC11U24 00024 DigitalOut config(p22); 00025 DigitalOut enable(p21); 00026 DigitalOut stoppled(p25); //LED-Button 00027 DigitalOut kill(p8); 00028 DigitalOut suspend_charge(p7); //enables LION Charger suspend mode 00029 DigitalOut highpower_charge(p6); // high- 100% charge current, low- 20% charge current 00030 DigitalOut ChargeLed1(LED1); 00031 DigitalOut ChargeLed2(LED2); 00032 DigitalOut ChargeLed3(LED3); 00033 DigitalOut ChargeLed4(LED4); 00034 AnalogIn ubat(p17); 00035 AnalogIn charge_current(p20); 00036 00037 Ticker time1; 00038 Ticker timelong; 00039 00040 int volatile count=0; 00041 int volatile resetcnt=0; 00042 int volatile zz1=0; 00043 int volatile zz2=0; 00044 int volatile sblock=0; 00045 int volatile reset=0; 00046 int volatile D=1; 00047 int volatile j=0; 00048 00049 int ms; 00050 int sec; 00051 int min; 00052 int ms1; 00053 00054 int firsthit=1; 00055 00056 int empfangi=0; 00057 00058 int debug=0; 00059 int timerwert=0; 00060 00061 float u_akku=0; 00062 00063 00064 00065 char buffer[9]; 00066 char buffer1[9]; 00067 char temp[20]; 00068 00069 char zwischenzeit[9]; 00070 char zwischenzeit1[9]; 00071 00072 char transmit=0; 00073 00074 00075 /*Funktions Dekleration*/ 00076 00077 void konfiguration(void) 00078 { 00079 config = 0; 00080 enable = 0; 00081 wait(0.1); 00082 00083 /*******Standardkonfiguration laden*******/ 00084 hm.putc(0xAA); /******/ 00085 hm.putc(0xFA); /******/ 00086 hm.putc(0xF0); /******/ 00087 /*****************************************/ 00088 00089 wait(0.1); 00090 00091 if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) 00092 { 00093 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xCF); hm.putc(0xD1); hm.putc(0x90); //HEX-Schalter 0 00094 } 00095 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) 00096 { 00097 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD1); hm.putc(0x58); hm.putc(0x30); //HEX-Schalter 1 00098 } 00099 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) 00100 { 00101 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD2); hm.putc(0xDE); hm.putc(0xD0); //HEX-Schalter 2 00102 } 00103 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) 00104 { 00105 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD4); hm.putc(0x65); hm.putc(0x70); //HEX-Schalter 3 00106 } 00107 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) 00108 { 00109 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD5); hm.putc(0xEC); hm.putc(0x10); //HEX-Schalter 4 00110 } 00111 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) 00112 { 00113 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD7); hm.putc(0x72); hm.putc(0xB0); //HEX-Schalter 5 00114 } 00115 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) 00116 { 00117 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD8); hm.putc(0xF9); hm.putc(0x50); //HEX-Schalter 6 00118 } 00119 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) 00120 { 00121 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDA); hm.putc(0x7F); hm.putc(0xF0); //HEX-Schalter 7 00122 } 00123 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) 00124 { 00125 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDC); hm.putc(0x06); hm.putc(0x90); //HEX-Schalter 8 00126 } 00127 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) 00128 { 00129 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDD); hm.putc(0x8D); hm.putc(0x30); //HEX-Schalter 9 00130 } 00131 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) 00132 { 00133 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDF); hm.putc(0x13); hm.putc(0xD0); //HEX-Schalter A 00134 } 00135 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) 00136 { 00137 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE0); hm.putc(0x9A); hm.putc(0x70); //HEX-Schalter B 00138 } 00139 else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) 00140 { 00141 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE2); hm.putc(0x21); hm.putc(0x10); //HEX-Schalter C 00142 } 00143 else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) 00144 { 00145 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE3); hm.putc(0xA7); hm.putc(0xB0); //HEX-Schalter D 00146 } 00147 else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) 00148 { 00149 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE5); hm.putc(0x2E); hm.putc(0x50); //HEX-Schalter E 00150 } 00151 else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) 00152 { 00153 hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE6); hm.putc(0xB4); hm.putc(0xF0); //HEX-Schalter F 00154 } 00155 else 00156 { 00157 stoppled=1; 00158 } 00159 wait(0.1); 00160 00161 /*******Reading the current Config parameter*******/ 00162 /*hm.putc(0xAA); 00163 hm.putc(0xFA); 00164 hm.putc(0xE1); 00165 */ 00166 // wait(0.1); 00167 config = 1; 00168 enable = 0; 00169 return; 00170 } 00171 00172 void stoppuhr(void) 00173 { 00174 ms = t.read_ms(); //hole mir den TimerWert in ms 00175 sec = (ms/1000); //erzeuge mir durch division eine sekunde - aktueller Timerwert/1000 - z.b: 2548/1000=2sec 00176 ms = ms - (sec*1000); //stelle meine ms richtig 00177 min = (sec/60); //erzeuge mir Minuten 00178 sec = sec - (min*60); //stelle Sekunden richtig 00179 ms = (ms/10); 00180 ms1 = (ms/10); 00181 //erzeuge mir zwei Stellen nach komma 00182 sprintf(buffer, "%02d:%02d:%02d", min, sec, ms); //schreibe in den buffer 00183 return; 00184 } 00185 00186 void starten(void) // Callback routine is interrupt activated by a debounced pb1 hit 00187 { 00188 00189 if ((resetcnt==0) && (sblock==0)) { 00190 t.reset(); //restiere Timer 00191 t.start(); //starte Timer 00192 resetcnt=1; 00193 enable = 0; //schalte das RF-Modul ein 00194 firsthit=0; //verhindert ein erhöhen der Variable sblock durch wiederholtes drücken des Buzzers. 00195 } else if ((resetcnt==1) && (sblock==0)) { 00196 zz1=1; 00197 sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00198 lcd.locate(0, 1); 00199 lcd.printf("A%s", zwischenzeit); 00200 resetcnt=2; 00201 } else if ((resetcnt==2) && (sblock==0)) { 00202 zz2=1; 00203 sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00204 lcd.locate(8, 1); 00205 lcd.printf("B%s", zwischenzeit1); 00206 resetcnt=3; 00207 } else { //nach hundert mal drueken wieder auf restcnt auf 3 setzen - SIcherheitsmechanismus um Integerüberlauf zu vermeiden 00208 resetcnt=resetcnt++; 00209 if(resetcnt==100) { 00210 resetcnt=3; 00211 } 00212 } 00213 resetcnt=resetcnt++; 00214 } 00215 00216 void sendkill (void) 00217 { 00218 enable=0; 00219 wait(0.1); 00220 hm.putc(0); 00221 wait(0.1); 00222 hm.putc('s'); 00223 wait(0.1); 00224 hm.putc('s'); 00225 wait(0.1); 00226 hm.putc('q'); 00227 wait(0.1); 00228 hm.putc(0); 00229 } 00230 00231 void sendreset(){ 00232 enable=0; 00233 wait(0.1); 00234 hm.putc(0); 00235 wait(0.1); 00236 hm.putc('s'); 00237 wait(0.1); 00238 hm.putc('s'); 00239 wait(0.1); 00240 hm.putc('x'); 00241 wait(0.1); 00242 hm.putc(0); 00243 enable=0; 00244 return; 00245 } 00246 00247 void sendstart(){ 00248 starten(); 00249 transmit=1; 00250 enable=0; 00251 wait(0.1); 00252 hm.putc(0); 00253 wait(0.1); 00254 hm.putc('s'); 00255 wait(0.1); 00256 hm.putc('s'); 00257 wait(0.1); 00258 hm.putc('g'); 00259 wait(0.1); 00260 hm.putc(0); 00261 enable=0; 00262 transmit=0; 00263 return; 00264 } 00265 00266 void sendstop(){ 00267 enable=0; 00268 wait(0.1); 00269 hm.putc(0); 00270 wait(0.1); 00271 hm.putc('s'); 00272 wait(0.1); 00273 hm.putc('s'); 00274 wait(0.1); 00275 hm.putc('s'); 00276 wait(0.1); 00277 hm.putc(0); 00278 enable=0; 00279 return; 00280 } 00281 00282 void kill_modul(void) 00283 { 00284 lcd.cls(); 00285 lcd.printf(" shut down"); 00286 00287 sendkill(); 00288 00289 wait(3); 00290 kill=0; 00291 wait (0.1); 00292 return; 00293 } 00294 00295 void reset_startbutton( void ) 00296 { 00297 if(sblock==1) { // Reset für Durchgang erhöhen 00298 t.stop(); 00299 t.reset(); 00300 memset(buffer1,0,19); 00301 stoppuhr(); 00302 //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00303 //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00304 resetcnt=0; 00305 zz1=0; 00306 zz2=0; 00307 sblock=0; 00308 D++; 00309 firsthit=1; 00310 lcd.cls(); 00311 00312 sendreset(); 00313 00314 if(D>99) { 00315 D=1; 00316 } 00317 } 00318 } 00319 00320 void totalreset_local (void) 00321 { 00322 t.stop(); 00323 t.reset(); 00324 stoppuhr(); 00325 memset(buffer1,0,19); 00326 //sprintf(zwischenzeit,"%01d:%02d:%1d", min, sec, ms1); 00327 //sprintf(zwischenzeit1,"%01d:%02d:%1d", min, sec, ms1); 00328 resetcnt=0; 00329 zz1=0; 00330 zz2=0; 00331 sblock=0; 00332 D=1; 00333 firsthit=1; 00334 time1.detach(); 00335 lcd.cls(); 00336 } 00337 00338 void stoppen (void) //Stoppen des Timers ohne Funk 00339 { 00340 t.stop(); 00341 if (firsthit==0){ 00342 sblock=1; 00343 } 00344 } 00345 00346 void stoppled_blink() { 00347 stoppled=!stoppled; 00348 return; 00349 } 00350 00351 void akkucheck() 00352 { 00353 if (transmit==0){ 00354 float i=0; 00355 00356 for(int t=0; t<100; t++) { 00357 i=i+ubat.read(); 00358 } 00359 // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen 00360 00361 u_akku=((i/100)*4.364); 00362 00363 //lcd.locate(0, 1); //debug Ausgabe 00364 //lcd.printf("Akkucheck %3.2fV", u_akku); //debug Ausgabe 00365 //wait(0.1); //debug Ausgabe 00366 00367 if(u_akku<=ulow) { //wenn Batteriespannung kleiner als ulow dann Akku laden am LCD ausgeben 00368 lcd.cls(); 00369 00370 lcd.locate(6,0); 00371 lcd.printf("%3.2fV", u_akku); 00372 lcd.locate(3,1); 00373 lcd.printf("Akku laden!"); 00374 wait(3); 00375 lcd.cls(); 00376 } 00377 /*if(u_akku>ulow) { 00378 time1.attach(&stoppled_blink,2); 00379 00380 00381 } 00382 if(u_akku<=ulow) { 00383 time1.attach(&stoppled_blink,0.5); 00384 00385 }*/ 00386 if(u_akku>=charge1) { 00387 ChargeLed1=1; 00388 ChargeLed2=1; 00389 ChargeLed3=1; 00390 ChargeLed4=1; 00391 time1.attach(&stoppled_blink,2); 00392 } 00393 00394 else if(u_akku>=charge2) { 00395 ChargeLed1=1; 00396 ChargeLed2=1; 00397 ChargeLed3=1; 00398 ChargeLed4=0; 00399 time1.attach(&stoppled_blink,2); 00400 } 00401 else if(u_akku>=charge3) { 00402 ChargeLed1=1; 00403 ChargeLed2=1; 00404 ChargeLed3=0; 00405 ChargeLed4=0; 00406 time1.attach(&stoppled_blink,2); 00407 } 00408 else if(u_akku>=charge4) { 00409 ChargeLed1=1; 00410 ChargeLed2=0; 00411 ChargeLed3=0; 00412 ChargeLed4=0; 00413 time1.attach(&stoppled_blink,0.5); 00414 } 00415 else if (u_akku<=u_shutdown) { 00416 time1.detach(); 00417 stoppled=0; 00418 wait(3); 00419 kill_modul(); 00420 } 00421 00422 } 00423 00424 00425 return; 00426 // } 00427 } 00428 00429 void empfangen() 00430 { 00431 //Funktion wird aufgerufen sobald das RF-Modul Daten an TX hat - über die Interruptroutine hm.attach(&empfangen) springe ich in die Funktion 00432 //Beim konfigurieren des Funkmoduls werden Uart Interrupts ausgelöst, diese werden durch die folgende while schleife abgefangen 00433 //Funkmodul schickt anscheinend 4 char nach der Konfiguration 00434 00435 /* while (j<4) { 00436 j=j+1; 00437 hm.getc(); 00438 return; 00439 }*/ 00440 int i=0; 00441 00442 if (hm.readable()) { 00443 temp[empfangi] = hm.getc(); 00444 empfangi++; 00445 00446 if (temp[empfangi-1]==0) { 00447 temp[empfangi]=0; 00448 empfangi=0; 00449 i=0; 00450 00451 if (temp[0]=='s' && temp[1]=='s' && temp[2]=='q') { //Kommandos werden mit zwei 's' characters eingeleitet der dritte character definiert das Kommando 00452 kill_modul(); 00453 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='s') { 00454 stoppen(); 00455 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='x') { 00456 reset_startbutton(); 00457 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='t') { 00458 totalreset_local(); 00459 } else if (temp[0]=='s' && temp[1]=='s' && temp[2]=='e') { //mit Kommando 'e' kann Text übertragen werden 00460 00461 00462 for (int z=3; temp[z]!=0; z++) 00463 // lcd.printf("%c", temp[z]); 00464 {buffer1[i]=temp[z]; 00465 i++; 00466 } 00467 buffer1[i]=0; 00468 00469 //lcd.locate(4,1); 00470 //lcd.printf("Z1:%s",buffer1); 00471 memset(temp,0,19); 00472 //lcd.locate(4,0); 00473 //lcd.printf("Zx:%s",buffer1); 00474 } 00475 } 00476 00477 } 00478 return; 00479 } 00480 00481 /*Funktion zur Anzeige der Batteriespannung am LCD.****** 00482 **Unterhalb der Spannung "ulow" wird eine Aufforderung*** 00483 ** zum Batterietausch ausgegeben.************************/ 00484 void lowbatt() 00485 { 00486 float i=0; 00487 00488 for(int t=0; t<100; t++) { 00489 i=i+ubat.read(); 00490 } // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen 00491 00492 u_akku=((i/100)*4.364); 00493 if(u_akku>=ulow) { 00494 lcd.cls(); 00495 00496 //lcd.setUDC(unsigned char udc_Bat_Hi[],{0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}); 00497 00498 lcd.printf(" Akkuspannung"); 00499 lcd.locate(5,1); 00500 lcd.printf("%3.2fV",u_akku); // Ausgabe der Akkuspannung 00501 wait(2); 00502 lcd.cls(); 00503 00504 } 00505 if(u_akku<=ulow) { //wenn Batteriespannung kleiner als ulow dann Akku laden am LCD ausgeben 00506 lcd.cls(); 00507 00508 lcd.locate(6,0); 00509 lcd.printf("%3.2fV", u_akku); 00510 lcd.locate(3,1); 00511 lcd.printf("Akku laden!"); 00512 wait(3); 00513 lcd.cls(); 00514 00515 } 00516 if (u_akku<=u_shutdown) { 00517 kill_modul(); 00518 } 00519 return; 00520 } 00521 00522 int main() 00523 { 00524 kill=1; 00525 suspend_charge=0; 00526 highpower_charge=1; 00527 00528 00529 pb1.mode(PullDown); // Use internal pulldown for pushbutton 00530 pb2.mode(PullNone); // keinen Modus verwenden 00531 dip0.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor 00532 dip1.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor 00533 dip2.mode(PullUp); // Use internal pullup for heX-switch - on LPC1768 you need also hardware pull up resistor 00534 dip3.mode(PullUp); // Use internal pullup for pushbutton - on LPC1768 you need also hardware pull up resistor 00535 00536 wait(0.01); // Delay for initial pullup to take effect 00537 00538 konfiguration(); //RF Modul konfigurieren 00539 00540 lowbatt(); //Batteriespannung beim Start abfragen 00541 00542 pb1.attach_asserted(&sendstart); 00543 pb1.attach_asserted_held(&reset_startbutton); 00544 00545 pb2.attach_asserted(&sendstop); 00546 pb2.attach_deasserted_held(&kill_modul); // Setup Interrupt callback functions for a pb hit 00547 00548 pb1.setSampleFrequency(); 00549 00550 pb2.setSampleFrequency(); 00551 00552 pb2.setSamplesTillHeld( 200 ); 00553 00554 hm.attach(&empfangen,Serial::RxIrq); // Setup Interrupt callback functions for Datareceive 00555 timelong.attach(&akkucheck,60); //Akkutest wird alle 60sec. gestartet 00556 00557 lcd.cls(); //debug Ausgabe 00558 lcd.printf(" Starttaster"); //debug Ausgabe 00559 wait(2); 00560 00561 time1.attach(&stoppled_blink,2); 00562 timer1.start(); 00563 lcd.cls(); 00564 00565 memset (buffer,0,19); 00566 memset (buffer1,0,19); 00567 while (1) { 00568 wait(.1); 00569 //lcd.cls(); 00570 stoppuhr(); //rufe Funktion stoppuhr auf 00571 lcd.locate(0, 0); //setze den Cursor auf Zeichen 0 Reihe 1 00572 lcd.printf("D%02d", D); // Ausgabe der Durchgänge, Formatiere mein LCD-Ausgabe nach D00 (zwei stellen) 00573 lcd.locate(4, 0); 00574 if (buffer1[1]!=0) { 00575 // if (strlen(buffer1)>0) { 00576 //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]); 00577 lcd.printf("ZE:%s",buffer1); 00578 //} else { 00579 // lcd.printf("pussy %d ",debug); 00580 // } 00581 } else if (buffer[1]!=0){ 00582 lcd.printf("ZE:%s",buffer); 00583 } 00584 00585 //lcd.locate(4, 1); 00586 //lcd.printf("ZE:%s", temp); 00587 00588 } 00589 00590 }
Generated on Tue Jul 19 2022 09:08:07 by
1.7.2
