LCD For I2C
LCDTaonoi.cpp@1:a8cb70204513, 2016-12-03 (annotated)
- Committer:
- sweilz
- Date:
- Sat Dec 03 10:50:46 2016 +0000
- Revision:
- 1:a8cb70204513
- Parent:
- 0:ef783944caa1
LCD FIBO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pruek | 0:ef783944caa1 | 1 | #include "LCDTaonoi.h" |
pruek | 0:ef783944caa1 | 2 | |
pruek | 0:ef783944caa1 | 3 | |
pruek | 0:ef783944caa1 | 4 | |
pruek | 0:ef783944caa1 | 5 | LCDTaonoi::LCDTaonoi(PinName _SDA, PinName _SCL , int _addr):lcd(_SDA,_SCL),addr(_addr) |
pruek | 0:ef783944caa1 | 6 | { |
sweilz | 1:a8cb70204513 | 7 | wait_ms(55); |
sweilz | 1:a8cb70204513 | 8 | |
sweilz | 1:a8cb70204513 | 9 | Command(0x01);//CLS |
sweilz | 1:a8cb70204513 | 10 | wait_ms(15); |
pruek | 0:ef783944caa1 | 11 | |
pruek | 0:ef783944caa1 | 12 | //Begin |
pruek | 0:ef783944caa1 | 13 | Command(0x3); |
pruek | 0:ef783944caa1 | 14 | wait(0.005); |
pruek | 0:ef783944caa1 | 15 | Command(0x3); |
pruek | 0:ef783944caa1 | 16 | wait_us(100); |
pruek | 0:ef783944caa1 | 17 | Command(0x3); |
pruek | 0:ef783944caa1 | 18 | Command(0x2); |
pruek | 0:ef783944caa1 | 19 | Command(0x28); //Funtionset DL(4bit,8bit) = 0 N(2line,4line) = 1 F(5x8,5x10) = 0 |
pruek | 0:ef783944caa1 | 20 | //Command(0x0); |
pruek | 0:ef783944caa1 | 21 | //Command(0xC); |
pruek | 0:ef783944caa1 | 22 | Command(0x0C); //Display on/off D(Display) = 1 C(Cursor) = 0 B(Blinking) = 0 |
pruek | 0:ef783944caa1 | 23 | //Command(0x0); |
pruek | 0:ef783944caa1 | 24 | //Command(0x6); |
pruek | 0:ef783944caa1 | 25 | Command(0x06); //Entry mode set I/D(Decrement,Increment) = 1 S(No shift) = 0 |
pruek | 0:ef783944caa1 | 26 | |
pruek | 0:ef783944caa1 | 27 | |
pruek | 0:ef783944caa1 | 28 | } |
sweilz | 1:a8cb70204513 | 29 | void LCDTaonoi::clear() |
sweilz | 1:a8cb70204513 | 30 | { |
sweilz | 1:a8cb70204513 | 31 | Command(0x01); |
sweilz | 1:a8cb70204513 | 32 | wait_ms(5); |
sweilz | 1:a8cb70204513 | 33 | setCursor(0,0); |
sweilz | 1:a8cb70204513 | 34 | } |
pruek | 0:ef783944caa1 | 35 | void LCDTaonoi::Command (char value, int Mode ) |
pruek | 0:ef783944caa1 | 36 | { |
pruek | 0:ef783944caa1 | 37 | char _command[2]; |
pruek | 0:ef783944caa1 | 38 | char Temp[2]; |
pruek | 0:ef783944caa1 | 39 | char _value[2]; |
pruek | 0:ef783944caa1 | 40 | |
pruek | 0:ef783944caa1 | 41 | |
pruek | 0:ef783944caa1 | 42 | Temp[0] = 0x0C; |
pruek | 0:ef783944caa1 | 43 | Temp[1] = 0x08; |
pruek | 0:ef783944caa1 | 44 | if(Mode == 0) { |
pruek | 0:ef783944caa1 | 45 | _command[0] = 0x0C; |
pruek | 0:ef783944caa1 | 46 | _command[1] = 0x08; |
pruek | 0:ef783944caa1 | 47 | } else { |
pruek | 0:ef783944caa1 | 48 | _command[0] = 0x0D; |
pruek | 0:ef783944caa1 | 49 | _command[1] = 0x09; |
pruek | 0:ef783944caa1 | 50 | } |
pruek | 0:ef783944caa1 | 51 | _value[0] = value & 0xF0; |
pruek | 0:ef783944caa1 | 52 | _value[0] = _value[0] | _command[0]; |
pruek | 0:ef783944caa1 | 53 | lcd.write(addr,&_value[0],1); |
pruek | 0:ef783944caa1 | 54 | wait_us(40); |
pruek | 0:ef783944caa1 | 55 | _value[0] = value & 0xF0; |
pruek | 0:ef783944caa1 | 56 | _value[0] = _value[0] | _command[1]; |
pruek | 0:ef783944caa1 | 57 | lcd.write(addr,&_value[0],1); |
pruek | 0:ef783944caa1 | 58 | wait_us(40); |
pruek | 0:ef783944caa1 | 59 | |
pruek | 0:ef783944caa1 | 60 | //lcd.write(addr,&Temp[0],1); |
pruek | 0:ef783944caa1 | 61 | //wait_us(40); |
pruek | 0:ef783944caa1 | 62 | |
pruek | 0:ef783944caa1 | 63 | |
pruek | 0:ef783944caa1 | 64 | _value[1] = value << 4; |
pruek | 0:ef783944caa1 | 65 | _value[1] = _value[1] | _command[0]; |
pruek | 0:ef783944caa1 | 66 | lcd.write(addr,&_value[1],1); |
pruek | 0:ef783944caa1 | 67 | wait_us(40); |
pruek | 0:ef783944caa1 | 68 | _value[1] = value << 4; |
pruek | 0:ef783944caa1 | 69 | _value[1] = _value[1] | _command[1]; |
pruek | 0:ef783944caa1 | 70 | lcd.write(addr,&_value[1],1); |
pruek | 0:ef783944caa1 | 71 | wait_us(40); |
pruek | 0:ef783944caa1 | 72 | lcd.write(addr,&Temp[0],1); |
pruek | 0:ef783944caa1 | 73 | } |
pruek | 0:ef783944caa1 | 74 | |
pruek | 0:ef783944caa1 | 75 | int LCDTaonoi::address(int column, int row) |
pruek | 0:ef783944caa1 | 76 | { |
pruek | 0:ef783944caa1 | 77 | |
pruek | 0:ef783944caa1 | 78 | switch (row) { |
pruek | 0:ef783944caa1 | 79 | case 0: |
pruek | 0:ef783944caa1 | 80 | return 0x80 + column; |
pruek | 0:ef783944caa1 | 81 | case 1: |
pruek | 0:ef783944caa1 | 82 | return 0xc0 + column; |
pruek | 0:ef783944caa1 | 83 | case 2: |
pruek | 0:ef783944caa1 | 84 | return 0x94 + column; |
pruek | 0:ef783944caa1 | 85 | case 3: |
pruek | 0:ef783944caa1 | 86 | return 0xd4 + column; |
pruek | 0:ef783944caa1 | 87 | } |
pruek | 0:ef783944caa1 | 88 | return 0; |
pruek | 0:ef783944caa1 | 89 | } |
pruek | 0:ef783944caa1 | 90 | |
pruek | 0:ef783944caa1 | 91 | void LCDTaonoi::setCursor (int column, int row) |
pruek | 0:ef783944caa1 | 92 | { |
pruek | 0:ef783944caa1 | 93 | int adr; |
pruek | 0:ef783944caa1 | 94 | adr = address(column,row); |
pruek | 0:ef783944caa1 | 95 | Command(adr); |
pruek | 0:ef783944caa1 | 96 | |
pruek | 0:ef783944caa1 | 97 | } |
pruek | 0:ef783944caa1 | 98 | |
sweilz | 1:a8cb70204513 | 99 | void LCDTaonoi::print (string Data) |
pruek | 0:ef783944caa1 | 100 | { |
sweilz | 1:a8cb70204513 | 101 | int8_t i=0; |
sweilz | 1:a8cb70204513 | 102 | while(Data[i]!='\0') |
sweilz | 1:a8cb70204513 | 103 | { |
sweilz | 1:a8cb70204513 | 104 | Command(Data[i++],1); |
pruek | 0:ef783944caa1 | 105 | } |
pruek | 0:ef783944caa1 | 106 | } |