Display zeigt merkwürdige Zeichen
Dependencies: mbed PinDetect TextLCD
Fork of FWFSU_Start_28102013 by
main.cpp
- Committer:
- fox46
- Date:
- 2014-02-03
- Revision:
- 9:5c871d235f31
- Parent:
- 8:9eccc5d25e8f
- Child:
- 10:27b3acc95b8f
File content as of revision 9:5c871d235f31:
#include "mbed.h" #include "PinDetect.h" #include "stdlib.h" #include "TextLCD.h" #define ulow 3.3 //definiere Symbolische Konstante für ulow mit dem Wert xx #define u_shutdown 3 //Konstante für shutdown bei zu geringer Akkuspannung Timer timer1; TextLCD lcd(p34, p23, p36, p15, p16, p35); // rs, e, d0-d3 für 130110-1P1 PinDetect pb1(p18); //Buzzer PinDetect pb2(p19); //LED-Button DigitalIn dip0(p26); //Hex-Schalter Pin 1 LSB DigitalIn dip1(p27); //Hex-schalter Pin 2 DigitalIn dip2(p28); //Hex-schalter Pin 3 DigitalIn dip3(p29); //Hex-Schalter Pin 4 MSB //Serial hm(p13, p14); // definiere UART fuer HM-TPR433 Modul LPC1768 Serial hm(p9, p10); // definiere UART fr HM-TPR433 Modul LPC11U24 DigitalOut config(p22); DigitalOut enable(p21); DigitalOut stoppled(p25); //LED-Button DigitalOut kill(p8); DigitalOut suspend_charge(p7); //enables LION Charger suspend mode DigitalOut highpower_charge(p6); // high- 100% charge current, low- 20% charge current AnalogIn ubat(p17); AnalogIn charge_current(p20); Ticker time1; Ticker timelong; float u_akku=0; int timerwert=0; int j=0; char transmit=0; /*Funktions Dekleration*/ void konfiguration(void) { config = 0; enable = 0; wait(0.1); /*******Standardkonfiguration laden*******/ hm.putc(0xAA); /******/ hm.putc(0xFA); /******/ hm.putc(0xF0); /******/ /*****************************************/ wait(0.1); if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xCF); hm.putc(0xD1); hm.putc(0x90); //HEX-Schalter 0 } else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD1); hm.putc(0x58); hm.putc(0x30); //HEX-Schalter 1 } else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD2); hm.putc(0xDE); hm.putc(0xD0); //HEX-Schalter 2 } else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD4); hm.putc(0x65); hm.putc(0x70); //HEX-Schalter 3 } else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD5); hm.putc(0xEC); hm.putc(0x10); //HEX-Schalter 4 } else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD7); hm.putc(0x72); hm.putc(0xB0); //HEX-Schalter 5 } else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xD8); hm.putc(0xF9); hm.putc(0x50); //HEX-Schalter 6 } else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 1)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDA); hm.putc(0x7F); hm.putc(0xF0); //HEX-Schalter 7 } else if((dip0 == 1) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDC); hm.putc(0x06); hm.putc(0x90); //HEX-Schalter 8 } else if((dip0 == 0) && (dip1 == 1) && (dip2 == 1) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDD); hm.putc(0x8D); hm.putc(0x30); //HEX-Schalter 9 } else if((dip0 == 1) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xDF); hm.putc(0x13); hm.putc(0xD0); //HEX-Schalter A } else if((dip0 == 0) && (dip1 == 0) && (dip2 == 1) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE0); hm.putc(0x9A); hm.putc(0x70); //HEX-Schalter B } else if((dip0 == 1) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE2); hm.putc(0x21); hm.putc(0x10); //HEX-Schalter C } else if((dip0 == 0) && (dip1 == 1) && (dip2 == 0) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE3); hm.putc(0xA7); hm.putc(0xB0); //HEX-Schalter D } else if((dip0 == 1) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE5); hm.putc(0x2E); hm.putc(0x50); //HEX-Schalter E } else if((dip0 == 0) && (dip1 == 0) && (dip2 == 0) && (dip3 == 0)) { hm.putc(0xAA);hm.putc(0xFA);hm.putc(0xD2);hm.putc(0x19); hm.putc(0xE6); hm.putc(0xB4); hm.putc(0xF0); //HEX-Schalter F } else { stoppled=1; } wait(0.1); /*******Reading the current Config parameter*******/ /*hm.putc(0xAA); hm.putc(0xFA); hm.putc(0xE1); */ // wait(0.1); config = 1; enable = 0; return; } void sendstart(){ transmit=1; enable=0; wait(0.1); hm.putc('g'); wait(0.1); enable=0; transmit=0; return; } void sendreset(){ enable=0; wait(0.1); hm.putc('x'); wait(0.1); enable=0; return; } void sendstop(){ transmit=1; enable=0; wait(0.1); hm.putc('s'); wait(0.1); enable=0; transmit=0; return; } void kill_modul(){ lcd.cls(); lcd.printf(" shut down"); wait(3); kill=0; return; } void stoppled_blink() { stoppled=!stoppled; return; } void akkucheck() { if (transmit==0){ float i=0; for(int t=0; t<100; t++) { i=i+ubat.read(); } // 100x ubat ADC Wert abfragen und in i aufsummieren um mittels Mittelwertbildung genaueres Ergebnis zu erziehlen u_akku=((i/100)*4.364); //lcd.locate(0, 1); //debug Ausgabe //lcd.printf("Akkucheck %3.2fV", u_akku); //debug Ausgabe //wait(0.1); //debug Ausgabe if(u_akku>ulow) { time1.attach(&stoppled_blink,2); } if(u_akku<=ulow) { time1.attach(&stoppled_blink,0.5); } if (u_akku<=u_shutdown) { time1.detach(); stoppled=0; wait(3); kill_modul(); } return; } } void empfangen() { //Funktion wird aufgerufen sobald das RF-Modul Daten an TX hat - über die Interruptroutine hm.attach(&empfangen) springe ich in die Funktion //Beim konfigurieren des Funkmoduls werden Uart Interrupts ausgelöst, diese werden durch die folgende while schleife abgefangen //Funkmodul schickt anscheinend 4 char nach der Konfiguration while (j<4) { j=j+1; hm.getc(); return; } if (hm.readable()) { char rxd = hm.getc(); if (rxd=='q') { kill_modul(); } } return; } int main() { kill=1; suspend_charge=0; highpower_charge=1; // Use internal pullup for pushbutton pb1.mode(PullDown); pb2.mode(PullNone); // keinen Modus verwenden dip0.mode(PullUp); dip1.mode(PullUp); dip2.mode(PullUp); dip3.mode(PullUp); wait(0.01); // Delay for initial pullup to take effect pb1.attach_asserted(&sendstart); pb1.attach_asserted_held(&sendreset); pb2.attach_asserted(&sendstop); pb2.attach_deasserted_held(&kill_modul); // Setup Interrupt callback functions for a pb hit pb1.setSampleFrequency(); pb2.setSampleFrequency(); pb2.setSamplesTillHeld( 200 ); konfiguration(); //RF Modul konfigurieren timelong.attach(&akkucheck,60); //Akkutest wird alle 60sec. gestartet hm.attach(&empfangen,Serial::RxIrq); // Setup Interrupt callback functions for Datarecive //lcd.cls(); //debug Ausgabe //lcd.printf(" Starttaster"); //debug Ausgabe time1.attach(&stoppled_blink,2); timer1.start(); while (1) { } }