Liews Wuttipat / LCDTaonoi
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCDTaonoi.cpp Source File

LCDTaonoi.cpp

00001 #include "LCDTaonoi.h"
00002 
00003 
00004 
00005 LCDTaonoi::LCDTaonoi(PinName _SDA, PinName _SCL , int _addr):lcd(_SDA,_SCL),addr(_addr)
00006 {
00007     wait_ms(55);
00008 
00009     Command(0x01);//CLS
00010     wait_ms(15);
00011     
00012     //Begin
00013     Command(0x3);
00014     wait(0.005);
00015     Command(0x3);
00016     wait_us(100);
00017     Command(0x3);
00018     Command(0x2);
00019     Command(0x28); //Funtionset DL(4bit,8bit) = 0 N(2line,4line) = 1 F(5x8,5x10) = 0
00020     //Command(0x0);
00021     //Command(0xC);
00022     Command(0x0C); //Display on/off D(Display) = 1 C(Cursor) = 0 B(Blinking) = 0
00023     //Command(0x0);
00024     //Command(0x6);
00025     Command(0x06); //Entry mode set I/D(Decrement,Increment) = 1 S(No shift) = 0
00026     
00027     
00028 }
00029 void LCDTaonoi::clear()
00030 {
00031     Command(0x01);
00032     wait_ms(5);
00033     setCursor(0,0);
00034 }
00035 void LCDTaonoi::Command (char value, int Mode )
00036 {
00037     char _command[2];
00038     char Temp[2];
00039     char _value[2];
00040     
00041 
00042     Temp[0] = 0x0C;
00043     Temp[1] = 0x08;
00044     if(Mode == 0) {
00045         _command[0] = 0x0C;
00046         _command[1] = 0x08;
00047     } else {
00048         _command[0] = 0x0D;
00049         _command[1] = 0x09;
00050     }
00051     _value[0] = value & 0xF0;
00052     _value[0] = _value[0] | _command[0];
00053     lcd.write(addr,&_value[0],1);
00054     wait_us(40);
00055     _value[0] = value & 0xF0;
00056     _value[0] = _value[0] | _command[1];
00057     lcd.write(addr,&_value[0],1);
00058     wait_us(40);
00059 
00060     //lcd.write(addr,&Temp[0],1);
00061     //wait_us(40);
00062 
00063 
00064     _value[1] = value << 4;
00065     _value[1] = _value[1] | _command[0];
00066     lcd.write(addr,&_value[1],1);
00067     wait_us(40);
00068     _value[1] = value << 4;
00069     _value[1] = _value[1] | _command[1];
00070     lcd.write(addr,&_value[1],1);
00071     wait_us(40);
00072     lcd.write(addr,&Temp[0],1);
00073 }
00074 
00075 int LCDTaonoi::address(int column, int row)
00076 {
00077 
00078     switch (row) {
00079         case 0:
00080             return 0x80 + column;
00081         case 1:
00082             return 0xc0 + column;
00083         case 2:
00084             return 0x94 + column;
00085         case 3:
00086             return 0xd4 + column;
00087     }
00088     return 0;
00089 }
00090 
00091 void LCDTaonoi::setCursor (int column, int row)
00092 {
00093     int adr;
00094     adr = address(column,row);
00095     Command(adr);
00096     
00097 }
00098 
00099 void LCDTaonoi::print (string Data)
00100 {
00101     int8_t i=0;
00102     while(Data[i]!='\0')
00103     {
00104         Command(Data[i++],1);
00105     }
00106 }