liamgrazier lcd library 16x02
lglcd.cpp@0:ef052de2d7d0, 2018-01-05 (annotated)
- Committer:
- liam_grazier
- Date:
- Fri Jan 05 14:13:07 2018 +0000
- Revision:
- 0:ef052de2d7d0
mylcd driver for nucleof429ZI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
liam_grazier | 0:ef052de2d7d0 | 1 | #include "mbed.h" |
liam_grazier | 0:ef052de2d7d0 | 2 | #include "lglcd.h" |
liam_grazier | 0:ef052de2d7d0 | 3 | |
liam_grazier | 0:ef052de2d7d0 | 4 | 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 | 5 | { |
liam_grazier | 0:ef052de2d7d0 | 6 | cline=1; //set the current line to the top line |
liam_grazier | 0:ef052de2d7d0 | 7 | cpos=0; //sets the current position to the left most CHARACTER |
liam_grazier | 0:ef052de2d7d0 | 8 | _lcde=1; //clear enable |
liam_grazier | 0:ef052de2d7d0 | 9 | _lcdrs=0; // command |
liam_grazier | 0:ef052de2d7d0 | 10 | l = 0; |
liam_grazier | 0:ef052de2d7d0 | 11 | writedata(_lcde,CMD); |
liam_grazier | 0:ef052de2d7d0 | 12 | wait(0.000004); //delay for LCD to initialise. |
liam_grazier | 0:ef052de2d7d0 | 13 | writedata(0x28,CMD); //set to 4 bit interface, 2 line and 5*8 font |
liam_grazier | 0:ef052de2d7d0 | 14 | wait(0.000004); |
liam_grazier | 0:ef052de2d7d0 | 15 | writedata(0x0C,CMD); //cursor on, cursor position 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 | 0:ef052de2d7d0 | 19 | LCD_CLR; //clear display |
liam_grazier | 0:ef052de2d7d0 | 20 | wait(0.000004); |
liam_grazier | 0:ef052de2d7d0 | 21 | writedata(0x06,CMD); //move cursor right after write |
liam_grazier | 0:ef052de2d7d0 | 22 | wait(0.000004); |
liam_grazier | 0:ef052de2d7d0 | 23 | LCD_HOME; //return home |
liam_grazier | 0:ef052de2d7d0 | 24 | |
liam_grazier | 0:ef052de2d7d0 | 25 | } |
liam_grazier | 0:ef052de2d7d0 | 26 | /*---------------------------------------------------------------------*/ |
liam_grazier | 0:ef052de2d7d0 | 27 | void lglcd::clear(void)//set a function to clear the lcd since just calling LCD_CLR can throw error if called to quickly |
liam_grazier | 0:ef052de2d7d0 | 28 | { |
liam_grazier | 0:ef052de2d7d0 | 29 | LCD_CLR; |
liam_grazier | 0:ef052de2d7d0 | 30 | wait(0.002); //2ms delay to stop timing error |
liam_grazier | 0:ef052de2d7d0 | 31 | } |
liam_grazier | 0:ef052de2d7d0 | 32 | |
liam_grazier | 0:ef052de2d7d0 | 33 | /*---------------------------------------------------------------------*/ |
liam_grazier | 0:ef052de2d7d0 | 34 | void lglcd::writedata(unsigned char info, unsigned char type) |
liam_grazier | 0:ef052de2d7d0 | 35 | { |
liam_grazier | 0:ef052de2d7d0 | 36 | if(type == CMD) { |
liam_grazier | 0:ef052de2d7d0 | 37 | _lcdrs=0; //COMMAND MODE |
liam_grazier | 0:ef052de2d7d0 | 38 | } else { |
liam_grazier | 0:ef052de2d7d0 | 39 | _lcdrs=1; //CHARACTER/DATA MODE |
liam_grazier | 0:ef052de2d7d0 | 40 | } |
liam_grazier | 0:ef052de2d7d0 | 41 | |
liam_grazier | 0:ef052de2d7d0 | 42 | _lcdinfo = info >> 4; |
liam_grazier | 0:ef052de2d7d0 | 43 | wait(0.000040f); // most instructions take 40us |
liam_grazier | 0:ef052de2d7d0 | 44 | _lcde = 0; |
liam_grazier | 0:ef052de2d7d0 | 45 | wait(0.000040f); |
liam_grazier | 0:ef052de2d7d0 | 46 | _lcde = 1; |
liam_grazier | 0:ef052de2d7d0 | 47 | _lcdinfo = info >> 0; |
liam_grazier | 0:ef052de2d7d0 | 48 | wait(0.000040f); |
liam_grazier | 0:ef052de2d7d0 | 49 | _lcde = 0; |
liam_grazier | 0:ef052de2d7d0 | 50 | wait(0.000040f); // most instructions take 40us |
liam_grazier | 0:ef052de2d7d0 | 51 | _lcde = 1; |
liam_grazier | 0:ef052de2d7d0 | 52 | } |
liam_grazier | 0:ef052de2d7d0 | 53 | |
liam_grazier | 0:ef052de2d7d0 | 54 | void lglcd::write(char charq[]) |
liam_grazier | 0:ef052de2d7d0 | 55 | { |
liam_grazier | 0:ef052de2d7d0 | 56 | for (int i = 0; i < strlen(charq); i++) |
liam_grazier | 0:ef052de2d7d0 | 57 | { |
liam_grazier | 0:ef052de2d7d0 | 58 | wait(0.003); |
liam_grazier | 0:ef052de2d7d0 | 59 | int count = 0; |
liam_grazier | 0:ef052de2d7d0 | 60 | count++; |
liam_grazier | 0:ef052de2d7d0 | 61 | writedata(charq[i], TXT); |
liam_grazier | 0:ef052de2d7d0 | 62 | if (i == 15) { |
liam_grazier | 0:ef052de2d7d0 | 63 | writedata(LINE2 | 0, CMD); |
liam_grazier | 0:ef052de2d7d0 | 64 | } |
liam_grazier | 0:ef052de2d7d0 | 65 | if (i == 32) { |
liam_grazier | 0:ef052de2d7d0 | 66 | clear(); |
liam_grazier | 0:ef052de2d7d0 | 67 | writedata(LINE1, CMD); |
liam_grazier | 0:ef052de2d7d0 | 68 | } |
liam_grazier | 0:ef052de2d7d0 | 69 | } |
liam_grazier | 0:ef052de2d7d0 | 70 | } |