ABDELALI Benmiloud / Mbed 2 deprecated GLCD128128

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /*******************************************************************************
00004 * Module:     BUSI2C.cpp
00005 * Function:   Controleur de bus I2C por un driver de glcd128x128
00006 * Author:     Belloula AbdelMalek [31.10.2010]
00007 *******************************************************************************/
00008 #include "mbed.h"
00009 
00010 I2C i2c(p9, p10); // sda, scl
00011 //char RD_CMD = 0xF9;
00012 //char WR_CMD = 0xFA;
00013 //char RD_DATA = 0xF1;
00014 //char WR_DATA = 0xF7;
00015 //char SET = 0xFF;
00016 //char RESET = 0xEF;
00017 
00018 unsigned int adress_PCFcmd = 0x40;
00019 unsigned int adress_PCFdata = 0x42;
00020 
00021 char cmd[10]={0xF7,0xFA,0xF9,0xF1,0xF2,0xFF,0xEF};
00022 char data[5];
00023 
00024 Serial pc(USBTX, USBRX); // tx, rx
00025 
00026 
00027 void reset_lcd_chip(void) /* reset the LCD controller chip */
00028     {       
00029         i2c.write(adress_PCFcmd,cmd+6, 1); // cmd [1] = 0xEF
00030         wait(0.05);
00031         i2c.write(adress_PCFdata,cmd+5, 1);    // cmd [0] = 0xFF
00032     }
00033 
00034 void lcd_busy_wait(void)// status check
00035  {       
00036     do
00037     {
00038         i2c.write(adress_PCFcmd,cmd+2, 1);  // cmd [2] = 0xF9
00039         i2c.read(adress_PCFdata,data, 1);   // data 
00040         i2c.write(adress_PCFcmd,cmd+5, 1);  // cmd [0] = 0xFF
00041     }
00042     while((data[0] & 0x03) != 0x03);        /* wait till STA1=1 && STA0=1 */
00043     
00044  }
00045 
00046  void  write_data_byte (void) // Procedure for sending a data
00047     {
00048         lcd_busy_wait();                        // status check
00049         i2c.write(adress_PCFcmd,cmd, 1);        // cmd [2] = 0xF7
00050         i2c. write (adress_PCFdata,data, 1);    // data 
00051         i2c.write(adress_PCFcmd,cmd+4, 1);      // cmd [2] = 0xF2
00052         i2c.write(adress_PCFcmd,cmd, 1);        // cmd [2] = 0xF7
00053         i2c.write(adress_PCFcmd,cmd+5, 1);      // cmd [2] = 0xFF
00054     }
00055 
00056  void  write_cmd_byte (void) // Procedure for sending a command;
00057     {
00058         lcd_busy_wait(); // status check
00059         i2c. write (adress_PCFdata,data, 1);   //data  (commande)
00060         i2c.write(adress_PCFcmd,cmd+4, 1);  // cmd [x] = 0xF2
00061         i2c.write(adress_PCFcmd,cmd, 1);  // cmd [x] = 0xF7
00062         i2c.write(adress_PCFcmd,cmd+5, 1);  // cmd [x] = 0xFF
00063     }
00064 
00065 
00066 
00067 int main() 
00068 {
00069     int count = 0;
00070     //Scan for I2C slave devices (0 => no slave found !0 => address of the slaved device found )
00071     printf("I2CU! Searching for I2C devices...\n");
00072     for (int address=0; address<256; address+=2)   
00073     {
00074         if (!i2c.write(address, NULL, 0)) 
00075             { // 0 returned is ok
00076                 printf(" - I2C device found at address 0x%02X\n", address);
00077                 count++;
00078             }
00079     }
00080     printf("%d devices found\n", count);
00081     
00082     reset_lcd_chip();
00083     
00084     lcd_busy_wait();
00085     data[0]= 0x00;
00086     write_data_byte();
00087    
00088     lcd_busy_wait();
00089     data[0]= 0x00;
00090     write_data_byte();
00091     
00092     lcd_busy_wait();
00093     data[0]= 0x42;
00094     write_cmd_byte();
00095     
00096     lcd_busy_wait();
00097     data[0]= 0x00;
00098     write_data_byte();
00099    
00100     lcd_busy_wait();
00101     data[0]= 0x10;
00102     write_data_byte();
00103     
00104     lcd_busy_wait();
00105     data[0]= 0x43;
00106     write_cmd_byte();
00107     
00108     
00109     lcd_busy_wait();
00110     data[0]= 0x98;
00111     write_cmd_byte();
00112     
00113     lcd_busy_wait();
00114     data[0]= 0x00;
00115     write_data_byte();
00116    
00117     lcd_busy_wait();
00118     data[0]= 0x00;
00119     write_data_byte();
00120     
00121     lcd_busy_wait();
00122     data[0]= 0x24;
00123     write_cmd_byte();
00124     
00125    /*
00126     data_write
00127     i2c.write(adress_PCF8574,cmd[4], 1);/0xF7
00128     i2c.writ(adress_PCF8574+2,data, 1);
00129     i2c.write(adress_PCF8574,cmd[4]& 0xF2, 1);
00130     i2c.write(adress_PCF8574,cmd[4]& 0xF7, 1);
00131     i2c.write(adress_PCF8574,cmd[0], 1);
00132    
00133     */
00134    
00135   
00136 
00137 }
00138