liamgrazier lcd library 16x02

Dependents:   Final351CW_FINAL

Fork of LGLCDv2 by Liam Grazier

Committer:
liam_grazier
Date:
Tue Jan 09 11:32:39 2018 +0000
Revision:
2:d812a2a643bc
Parent:
1:9020af47a312
V9.9

Who changed what in which revision?

UserRevisionLine numberNew contents of line
liam_grazier 2:d812a2a643bc 1 /* ELEC351 COURSEWORK 2018
liam_grazier 2:d812a2a643bc 2 DESIGNED USING MBED ONLINE COMPILER IMPORTED TO KEIL
liam_grazier 2:d812a2a643bc 3 LIAM GRAZIER // DOUG TILLEY // ALEX BARON
liam_grazier 2:d812a2a643bc 4 */
liam_grazier 0:ef052de2d7d0 5 #include "mbed.h"
liam_grazier 0:ef052de2d7d0 6 #include "lglcd.h"
liam_grazier 2:d812a2a643bc 7 lglcd::lglcd(PinName RS, PinName E, PinName D4, PinName D5,PinName D6, PinName D7) : _lcdrs(RS),_lcde(E), _lcdinfo(D4, D5, D6, D7)
liam_grazier 0:ef052de2d7d0 8 {
liam_grazier 2:d812a2a643bc 9 _lcde=1; //clear enable
liam_grazier 0:ef052de2d7d0 10 _lcdrs=0; // command
liam_grazier 0:ef052de2d7d0 11 writedata(_lcde,CMD);
liam_grazier 2:d812a2a643bc 12 wait(0.000004);
liam_grazier 2:d812a2a643bc 13 writedata(0x28,CMD);
liam_grazier 0:ef052de2d7d0 14 wait(0.000004);
liam_grazier 2:d812a2a643bc 15 writedata(0x0C,CMD); //turnoncursor and blink
liam_grazier 0:ef052de2d7d0 16 wait(0.000004);
liam_grazier 0:ef052de2d7d0 17 writedata(0x10,CMD);
liam_grazier 0:ef052de2d7d0 18 wait(0.000004);
liam_grazier 2:d812a2a643bc 19 LCD_CLR; //clearlcd
liam_grazier 0:ef052de2d7d0 20 wait(0.000004);
liam_grazier 2:d812a2a643bc 21 writedata(0x06,CMD); //movecursor right
liam_grazier 0:ef052de2d7d0 22 wait(0.000004);
liam_grazier 2:d812a2a643bc 23 LCD_HOME; //Return to the 0,0
liam_grazier 0:ef052de2d7d0 24 }
liam_grazier 2:d812a2a643bc 25 void lglcd::clear(void)//lcd clear command with a tiny wait to ensure commadn finishes
liam_grazier 0:ef052de2d7d0 26 {
liam_grazier 2:d812a2a643bc 27 LCD_CLR; //clearcommandwitha small wait
liam_grazier 2:d812a2a643bc 28 wait(0.002);
liam_grazier 0:ef052de2d7d0 29 }
liam_grazier 2:d812a2a643bc 30 void lglcd::setline(int row,int column) //set lu=ine and column function
liam_grazier 1:9020af47a312 31 {
liam_grazier 2:d812a2a643bc 32 if(row == 1)
liam_grazier 2:d812a2a643bc 33 {
liam_grazier 2:d812a2a643bc 34 writedata(LINE1|column,CMD); //line1 included
liam_grazier 2:d812a2a643bc 35 wait(0.005);
liam_grazier 1:9020af47a312 36 }
liam_grazier 2:d812a2a643bc 37 if(row == 2)
liam_grazier 2:d812a2a643bc 38 {
liam_grazier 2:d812a2a643bc 39 writedata(LINE2|column,CMD);
liam_grazier 2:d812a2a643bc 40 wait(0.005);
liam_grazier 1:9020af47a312 41 }
liam_grazier 2:d812a2a643bc 42 }
liam_grazier 2:d812a2a643bc 43 void lglcd::writedata(unsigned char data, unsigned char type) //manual write data wherever the pointer is , requires the line to be set first .
liam_grazier 0:ef052de2d7d0 44 {
liam_grazier 1:9020af47a312 45 if(type == CMD)
liam_grazier 1:9020af47a312 46 {
liam_grazier 2:d812a2a643bc 47 _lcdrs=0; //COMMAND MODE
liam_grazier 0:ef052de2d7d0 48 }
liam_grazier 2:d812a2a643bc 49 else
liam_grazier 2:d812a2a643bc 50 {
liam_grazier 2:d812a2a643bc 51 _lcdrs=1; //CHARACTER/DATA MODE
liam_grazier 2:d812a2a643bc 52 }
liam_grazier 2:d812a2a643bc 53 _lcdinfo = data >> 4;
liam_grazier 2:d812a2a643bc 54 wait(0.000050f);
liam_grazier 0:ef052de2d7d0 55 _lcde = 0;
liam_grazier 2:d812a2a643bc 56 wait(0.000050f);
liam_grazier 0:ef052de2d7d0 57 _lcde = 1;
liam_grazier 2:d812a2a643bc 58 _lcdinfo = data >> 0;
liam_grazier 2:d812a2a643bc 59 wait(0.000050f);
liam_grazier 0:ef052de2d7d0 60 _lcde = 0;
liam_grazier 2:d812a2a643bc 61 wait(0.000050f);
liam_grazier 0:ef052de2d7d0 62 _lcde = 1;
liam_grazier 0:ef052de2d7d0 63 }
liam_grazier 2:d812a2a643bc 64 void lglcd::write(char charq[]) //write character, not used, used writedata mainly, this works well if need to write along string to 2 lines (FOR LOOP FOR CHANING LINE AUTO)
liam_grazier 0:ef052de2d7d0 65 {
liam_grazier 2:d812a2a643bc 66 for (int n = 0; n < strlen(charq); n++)
liam_grazier 2:d812a2a643bc 67 {
liam_grazier 2:d812a2a643bc 68 int count = 0;
liam_grazier 2:d812a2a643bc 69 count++;
liam_grazier 2:d812a2a643bc 70 writedata(charq[n], TXT);
liam_grazier 2:d812a2a643bc 71 if (n == 15)
liam_grazier 2:d812a2a643bc 72 {
liam_grazier 2:d812a2a643bc 73 writedata(LINE2 | 0, CMD);
liam_grazier 2:d812a2a643bc 74 }
liam_grazier 2:d812a2a643bc 75 if (n == 32)
liam_grazier 2:d812a2a643bc 76 {
liam_grazier 2:d812a2a643bc 77 clear();
liam_grazier 2:d812a2a643bc 78 writedata(LINE1, CMD);
liam_grazier 2:d812a2a643bc 79 }
liam_grazier 2:d812a2a643bc 80 }
liam_grazier 0:ef052de2d7d0 81 }