V09 / V09_01h

Dependencies:   MODSERIAL USBDevice USBMSD_SD V09_01h

Dependents:   V09_01h

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBMSD_SD.h"
00003 #include "SDFileSystem.h"
00004 #include "MODSERIAL.h"
00005 #include "mon.h"
00006 #include "com.h"
00007 #include "menu.h"
00008 #include "myTextLCD.h"
00009 #include "timer0.h"
00010 
00011 #define LED_OFF 1
00012 #define LED_ON  0
00013 #define COM_LINE_LEN 128              // maximale Länge der Eingabezeile  
00014 #define TEL_SIZE 10
00015 
00016 #define TIMER0_NUM_COUNTDOWNTIMERS  25
00017    
00018 // LCD's für Anzeige
00019 DigitalOut led1(PTB18);
00020 DigitalOut led2(PTB19);
00021 DigitalOut led3(PTB17);
00022 
00023 // Taster für die Eingabe
00024 DigitalIn S1(PTC7);
00025 DigitalIn S2(PTC8);
00026 DigitalIn S3(PTC9);
00027 DigitalIn S4(PTC10);
00028 DigitalIn S5(PTC11);
00029 
00030 timer0 down_timer;          // Timer für Zeitsteuerung
00031 
00032 MODSERIAL pc(USBTX,USBRX); 
00033 
00034 SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd"); 
00035 
00036 menu menu_var;
00037 
00038 //MODSERIAK uart1(PTC4, PTC3, 512); // tx, rx
00039 MODSERIAL uart1(PTC4, PTC3); // tx, rx
00040 
00041 TextLCD lcd(PTE24, PTE25, PTE20, PTE21, PTE22, PTE23); // rs, e, d4-d7
00042 PwmOut lcd_kontrast(PTA5); // Kontrast wird über PWM gesteuert
00043 DigitalOut lcd_bl(PTE29);  // Hintergrundbeleuchtung
00044 
00045 monitor mon;
00046 
00047 uint8_t tasten, tasten_old;
00048 
00049 //-----------------------------------------------------------------------------
00050 // main
00051 //
00052 //
00053 int main() 
00054 {
00055     tasten = 0; 
00056     tasten_old = 0; 
00057     
00058     S1.mode(PullUp);
00059     S2.mode(PullUp);
00060     S3.mode(PullUp);
00061     S4.mode(PullUp);
00062     S5.mode(PullUp);
00063        
00064     // pc.printf("\ntimer0::set_t = %s", buffer); 
00065     
00066     lcd_bl = 6;         // Hintergrundbeleuchtung LCD Anzeige einschalten
00067 
00068     // die Zeiten müssen so kurz sein, da die LCD Anzeige sonst flackert
00069     lcd_kontrast.period_us(100);          // 100µs Periode
00070     lcd_kontrast.pulsewidth_us(30);       // 30 µs Pulszeit    
00071  
00072     // pc ist die USB Schnittstelle des Debuggers
00073     pc.baud(56700);    
00074     pc.printf("\nSD_USB_FS V09.01g");   
00075     pc.printf("\n V08 was compiled on %s  %s \n", __DATE__,__TIME__);
00076        
00077     // auf USB Mode umschalten
00078     S5.mode(PullUp);
00079     
00080     if (S5 == 0)
00081     {
00082         //          0123456789012345
00083         lcd.printf(" -- USB Mode -- ");
00084         lcd.writeLCD();
00085         
00086         USBMSD_SD msd(PTD2, PTD3, PTD1, PTD0);
00087         while(1);
00088     }
00089       
00090     //          0123456789012345
00091     lcd.printf(" - nomal Mode - ");  
00092     lcd.writeLCD();
00093     pc.printf("\nnormal SD mode\n");
00094 
00095     // uart1 ist die Schnittstelle zur microSPS    
00096     uart1.baud(115200);
00097     com_init();
00098         
00099     down_timer.SetCountdownTimer(0,1,50);  // Timer für Tasten
00100     down_timer.SetCountdownTimer(1,1,500); // Timer für LED
00101     down_timer.SetCountdownTimer(2,1,1000);// Timer für die Ausgabe der Daten
00102  
00103     while(1)
00104     {
00105         mon.monPC();
00106         com_line();
00107         
00108         //--------------------------------------------------------------------------
00109         // LED für Statusanzeige              
00110        
00111         if (down_timer.GetTimerStatus(1) == 0)
00112         {
00113             down_timer.SetCountdownTimer(1,1,500);    // alle 500ms                                          
00114             led1 = !led1;           // blaue oder gründe LED
00115             //led2 = !led2;
00116         }    
00117         
00118         //--------------------------------------------------------------------------
00119         // Die Tasten alle 10ms abfragen und Telegramm senden falls Tasten gedrückt            
00120 
00121         if (down_timer.GetTimerStatus(0) == 0)
00122         {
00123             down_timer.SetCountdownTimer(0,1,10);  // alle 10ms
00124             // Tasten abfragen
00125             if (S1 == 0) tasten |= 0x01; else tasten &= ~0x01;
00126             if (S2 == 0) tasten |= 0x02; else tasten &= ~0x02;
00127             if (S3 == 0) tasten |= 0x04; else tasten &= ~0x04;
00128             if (S4 == 0) tasten |= 0x08; else tasten &= ~0x08;
00129             if (S5 == 0) tasten |= 0x10; else tasten &= ~0x10;
00130             
00131             //---------------------------------------------------------------------------
00132             // Tastatur auswerten und Ergebnis senden
00133             if (tasten != tasten_old)
00134             {
00135               uart1.putc(0xE5);
00136               uart1.putc(0x02);
00137               uart1.putc(0x05);         // Telegramm für Tasten 
00138               uart1.putc(0x01);         // Anzahl der Nutzdaten
00139               uart1.putc(tasten);       // Tasteninformation
00140               uart1.putc(0x00);         // Abschlusszeichen
00141               
00142               tasten_old = tasten; 
00143               pc.printf("\nTaste %02x",tasten);
00144             }
00145         } 
00146         
00147         //--------------------------------------------------------------------------
00148         // Uhrzeit abfragen            
00149         
00150         if (down_timer.GetTimerStatus(2) == 0)
00151         {
00152             down_timer.SetCountdownTimer(2,2,60);    // alle 60s                                          
00153             
00154             uart1.putc(0xE5);         // Startzeichen
00155             uart1.putc(0x02);         // Startzeichen
00156             uart1.putc(0x06);         // Telegramm für Zeitabfrage 
00157             uart1.putc(0x00);         // Anzahl der Nutzdaten
00158             uart1.putc(0x00);         // Abschlusszeichen
00159         }
00160                 
00161     } // while[1]
00162 }