kevin ollivier / Mbed 2 deprecated LCD_clavier

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kevin_38
Date:
Tue May 29 09:30:20 2012 +0000
Commit message:

Changed in this revision

TextLCD_4x40/TextLCD_4x40.cpp Show annotated file Show diff for this revision Revisions of this file
TextLCD_4x40/TextLCD_4x40.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD_4x40/TextLCD_4x40.cpp	Tue May 29 09:30:20 2012 +0000
@@ -0,0 +1,131 @@
+/*Modification de :" mbed TextLCD Library, for a 4-bit LCD based on HD44780........"
+  pour la commande d'un afficheur 4x40 (M4024)
+ */
+#include "TextLCD_4x40.h"
+#include "mbed.h"
+
+TextLCD_4x40::TextLCD_4x40(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3) :
+                        _rs(rs),_e(e), _d(d0, d1, d2, d3) {
+
+//-------------------------------------
+char  euro_v1[8]={0x06,0x09,0x1c,0x08,0x1C,0x09,0x06,0}//symbole euro
+     ,e_aigu[8] ={0x02,0x04,0x0e,0x11,0x1f,0x10,0x0e,0}//e accent aigu
+       ;
+//-------------------------------------
+char i;
+    _e  = 1;
+    _rs = 0;            // command mode
+
+    wait_ms(15);        // Wait 15ms to ensure powered up
+
+    // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus)
+    for (char i=0; i<3; i++) {
+        writeByte(0x3);
+        wait_us(1640);  // this command takes 1.64ms, so wait for it
+    }
+    writeByte(0x2);     // 4-bit mode
+    wait_us(40);    // most instructions take 40us
+
+    writeCommand(0x28); // Function set 001 BW N F - -
+    writeCommand(0x0C);
+    writeCommand(0x6);  // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes
+    cls();
+wait_ms(6);
+
+////////////////////// Generateur de caracteres ////////////////////////////////
+//........ chargement du 1er caractere .........
+   for(i=0;i<=7;i++){
+         writeCommand(0x40+i);
+         writeData(e_aigu[i]);
+                        }
+//........ chargement du 2eme caractere .........
+   for(i=0;i<=7;i++){
+         writeCommand(0x48+i);
+         writeData(euro_v1[i]);
+                        }
+/////////////////////// Fin du generateur de caracteres ///////////////////////
+
+writeCommand(2);// "home" pour que l'afficheur soit pret a afficher,
+                // pour sortir du generateur de caracteres
+}
+
+void TextLCD_4x40::character(char column, char row, char c) {
+    char a = address(column, row);
+    writeCommand(a);
+    writeData(c);
+}
+
+void TextLCD_4x40::cls() {
+    writeCommand(0x01); // cls, and set cursor to 0
+    wait_us(1640);     // This command takes 1.64 ms
+//    locate(0, 0);
+}
+
+void TextLCD_4x40::locate(char column, char row) {
+    _column = column;
+    _row = row;
+}
+
+//-----------------------------
+int TextLCD_4x40::_putc(int value) {
+ switch(value)
+   {
+    case '\f':
+      cls();
+      break;
+
+    case '\n':
+         _column = 0;
+        _row++;
+        if (_row >= 2) {
+            _row = 0;
+        }
+       break;
+
+    case '\b':
+       writeCommand(0x10);
+       break;
+
+    case '\1':
+       writeData(0);
+       break;
+    case '\2':
+       writeData(1);
+       break;
+    default:
+       writeData(value);
+       break;    
+   }
+ return value;
+}
+//-----------------------------
+int TextLCD_4x40::_getc() {
+    return -1;
+}
+
+void TextLCD_4x40::writeByte(char value) {
+    _d = value >> 4;
+    wait_us(40); // most instructions take 40us
+    _e = 0;
+    wait_us(40);
+    _e = 1;
+    _d = value >> 0;
+    wait_us(40);
+    _e = 0;
+    wait_us(40);  // most instructions take 40us
+    _e = 1;
+}
+
+void TextLCD_4x40::writeCommand(char command) {
+    _rs = 0;
+    writeByte(command);
+}
+
+void TextLCD_4x40::writeData(char data) {
+    _rs = 1;
+    writeByte(data);
+}
+
+char TextLCD_4x40::address(char column, char row) {   
+            return 0x80 + (row * 0x40) + column;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD_4x40/TextLCD_4x40.h	Tue May 29 09:30:20 2012 +0000
@@ -0,0 +1,79 @@
+/*Modification de : mbed TextLCD Library, for a 4-bit LCD based on HD44780
+  pour la commande d'un afficheur 4x40
+ */
+
+#ifndef MBED_TEXTLCD_H
+#define MBED_TEXTLCD_H
+
+#include "mbed.h"
+
+/** A TextLCD interface for driving 4-bit HD44780-based LCDs
+ *
+ *
+ * @code
+ * #include "mbed.h"
+ * #include "TextLCD.h"
+ * 
+ * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3
+ * 
+ * int main() {
+ *     lcd.printf("Hello World!\n");
+ * }
+ * @endcode
+ */
+class TextLCD_4x40 : public Stream {
+public:
+
+    /** Create a TextLCD interface
+     *
+     * @param rs    Instruction/data control line
+     * @param e     Enable line (clock)
+     * @param d0-d3 Data lines
+     */
+    TextLCD_4x40(PinName rs, PinName e, PinName d0, PinName d1, PinName d2, PinName d3);
+    
+#if DOXYGEN_ONLY
+    /** Write a character to the LCD
+     *
+     * @param c The character to write to the display
+     */
+    int putc(char c);
+
+    /** Write a formated string to the LCD
+     *
+     * @param format A printf-style format string, followed by the
+     *               variables to use in formating the string.
+     */
+    char printf(const char* format, ...);
+#endif
+
+    /** Locate to a screen column and row
+     *
+     * @param column  The horizontal position from the left, indexed from 0
+     * @param row     The vertical position from the top, indexed from 0
+     */
+    void locate(char column, char row);
+
+    /** Clear the screen and locate to 0,0 */
+    void cls();
+
+protected:
+
+    // Stream implementation functions
+    virtual int _putc(int value);
+    virtual int _getc();
+
+    char address(char column, char row);
+    void character(char column, char row, char c);
+    void writeByte(char value);
+    void writeCommand(char command);
+    void writeData(char data);
+
+    DigitalOut _rs, _e;
+    BusOut _d;
+
+    char _column;
+    char _row;
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 29 09:30:20 2012 +0000
@@ -0,0 +1,291 @@
+#include "mbed.h"
+#include "TextLCD_4x40.h"
+
+DigitalOut led1(LED1);
+AnalogIn analog(p15);
+//Serial pc(USBTX, USBRX); // tx, rx
+//Serial xbee1(p28, p27); // creation du port serie sur les broches 28 et 27
+TextLCD_4x40 lcd1(p6, p7, p8, p9, p10, p11); // rs, e1, d4-d7 -> les 2 lignes du haut
+TextLCD_4x40 lcd2(p6, p5, p8, p9, p10, p11); // rs, e2, d4-d7 -> les 2 lignes du bas
+
+
+
+
+
+void menu1() {
+
+             lcd1.cls();
+             lcd2.cls();
+             lcd1.printf("\f --->   Module Radar                   \n");
+             lcd1.printf("         Communication PC                 ");
+             lcd2.printf("\f        Affichage des donn\1es          \n");
+             lcd2.printf("                                          ");
+        
+             }
+
+void menu2()  {
+
+             lcd1.cls();
+             lcd2.cls();
+             lcd1.printf("\f        Module Radar                   \n");
+             lcd1.printf("  --->   Communication PC                 ");
+             lcd2.printf("\f        Affichage des donn\1es          \n");
+             lcd2.printf("                                          ");
+          
+          
+               }
+                            
+void menu3()  {
+
+             lcd1.cls();
+             lcd2.cls();
+             lcd1.printf("\f        Module Radar                   \n");
+             lcd1.printf("         Communication PC                 ");
+             lcd2.printf("\f --->   Affichage des donn\1es          \n");
+             lcd2.printf("                                          ");
+               }
+                             
+void menu10() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\fModule -->  R\1cup\1ration des donn\1es\n");
+            lcd1.printf("    Radar       Effacement des donn\1es      ");
+            lcd2.printf("\f            R\1glage seuil de vitesse     \n");
+            lcd2.printf("           R\1glage horloge, date         ");
+              }
+              
+void menu11() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\fModule      R\1cup\1ration des donn\1es \n");
+            lcd1.printf("   Radar  -->  Effacement des donn\1es     ");
+            lcd2.printf("\f            R\1glage seuil de vitesse     \n");
+            lcd2.printf("           R\1glage horloge, date         ");
+              }
+              
+void menu12() {
+
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\fModule      R\1cup\1ration des donn\1es \n");
+            lcd1.printf("   Radar       Effacement des donn\1es     ");
+            lcd2.printf("\f       -->  R\1glage seuil de vitesse     \n");
+            lcd2.printf("           R\1glage horloge, date         ");
+              }
+              
+void menu13() {
+
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\fModule      R\1cup\1ration des donn\1es \n");
+            lcd1.printf("   Radar       Effacement des donn\1es     ");
+            lcd2.printf("\f            R\1glage seuil de vitesse     \n");
+            lcd2.printf("      -->  R\1glage horloge, date         ");
+             
+              }
+            
+void menu20() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f  Communication PC                     \n");
+            lcd1.printf("                                           ");
+            lcd2.printf("\f    --->  Transfert des donn\1es        \n");
+            lcd2.printf("           Effacement donn\1es du boitier ");
+              }
+              
+void menu21() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f  Communication PC                     \n");
+            lcd1.printf("                                           ");
+            lcd2.printf("\f          Transfert des donn\1es        \n");
+            lcd2.printf("     --->  Effacement donn\1es du boitier ");
+              }    
+              
+void menu30() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f    Affichage des donn\1es              \n");
+            lcd1.printf("                                           ");
+            lcd2.printf("\f                                        \n");
+            lcd2.printf("                                          ");
+              }    
+                
+/* void menu22() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f //    Fonction 2                       \n");
+            lcd1.printf("            Fonction 2.1                  ");
+            lcd2.printf("\f            Fonction 2.2                \n");
+            lcd2.printf("      --->  Fonction 2.3                  ");
+              }          
+                
+void menu30() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f //    Fonction 3                       \n");
+            lcd1.printf("      --->  Fonction 3.1                  ");
+            lcd2.printf("\f            Fonction 3.2                \n");
+            lcd2.printf("            Fonction 3.3                  ");
+              }
+      
+void menu31() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f //    Fonction 3                       \n");
+            lcd1.printf("            Fonction 3.1                  ");
+            lcd2.printf("\f      --->  Fonction 3.2                \n");
+            lcd2.printf("            Fonction 3.3                  ");
+              }
+              
+void menu32() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f //    Fonction 3                       \n");
+            lcd1.printf("            Fonction 3.1                  ");
+            lcd2.printf("\f            Fonction 3.2                \n");
+            lcd2.printf("      --->  Fonction 3.3                  ");
+               }    
+                    
+void menu40() {
+            lcd1.cls();
+            lcd2.cls();
+            lcd1.printf("\f //    Fonction 4                       \n");
+            lcd1.printf("            Fonction 3.1                  ");
+            lcd2.printf("\f            Fonction 3.2                \n");
+            lcd2.printf("      --->  Fonction 3.3                  ");
+               }  */      
+
+///////////// Fonction clavier \\\\\\\\\\\\\\\\         
+               
+void clavier(int *menu)  
+ {
+   float mesure, tension;
+   
+  do {
+      
+     do {
+          mesure = analog.read();
+          tension = mesure * 3.3;  
+        
+        }   while ( tension < 3.25 );  // attente retour clavier au repos
+          
+          wait_ms(30); 
+          mesure = analog.read();                     
+          tension = mesure * 3.3;
+       
+      
+          if (tension > 0.86  & tension < 0.95)       {
+      
+                (*menu)--;     
+          
+                if (*menu == 0) { *menu = 4; }  
+                else if (*menu == 9) { *menu = 13; }
+                else if (*menu == 19) { *menu = 21;}       
+                                                      }
+      
+          else if (tension > 1.32 & tension < 1.41)   {
+      
+               *menu = (*menu) /10;
+                                                      }
+
+          else if (tension > 2.05 & tension < 2.14)   {
+     
+               *menu = (*menu) * 10; 
+          
+             //  if (*menu >= 100 & *menu < 200 )     { *menu = 10; }
+              // else if (*menu >= 200 & *menu < 300) { *menu = 20; }
+                                                      }
+ 
+          else  if (tension > 2.57 & tension < 2.65)  {
+      
+               (*menu)++;
+               
+               if (*menu == 4)  { *menu = 1; }
+               else if (*menu == 14) { *menu = 10; }
+               
+          else if (*menu == 22) { *menu = 20; } 
+                                                      }
+                                                      
+    } while( *menu == 0);             
+}         
+                      
+////////////////  Main \\\\\\\\\\\\\\\\\          
+                
+int main()                
+{
+    int menu = 0;
+    int old_menu = 0;
+
+    while(1) {
+
+     //   wait_ms(20);
+        
+        clavier(&menu);
+        
+        if( menu == old_menu ) continue;
+        
+       // led1 = 1;
+
+        switch(menu)    {
+        
+        case 1:
+            menu1();
+            break;
+            
+        case 2:
+             menu2(); 
+             break;
+        case 3:
+             menu3(); 
+             break;
+                               
+        case 10:
+             menu10(); 
+             break;
+                   
+        case 11:
+             menu11();
+             break;
+                  
+        case 12:
+             menu12();
+             break;
+             
+        case 13:
+             menu13();
+             break;           
+                   
+        case 20:
+             menu20();
+             break;
+             
+        case 21:
+             menu21();
+             break;
+             
+       // case 22:
+         //    menu22();
+           //  break;
+              
+        case 30:
+             menu30();
+             break;
+             
+      /*  case 31:
+             menu31();
+             break;
+             
+        case 32:
+             menu32();
+             break;    */
+             
+            default: 
+            break;
+                     
+                           }
+         old_menu = menu;
+        // led1 = 0;
+        
+         }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 29 09:30:20 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479