share
Dependencies: mbed
lcd.cpp@0:5dbeda619328, 2015-11-13 (annotated)
- Committer:
- shaizeen
- Date:
- Fri Nov 13 02:03:19 2015 +0000
- Revision:
- 0:5dbeda619328
lcd custom
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shaizeen | 0:5dbeda619328 | 1 | // LCD.cpp File |
shaizeen | 0:5dbeda619328 | 2 | #include "lcd.h"// Define mbed objects |
shaizeen | 0:5dbeda619328 | 3 | |
shaizeen | 0:5dbeda619328 | 4 | |
shaizeen | 0:5dbeda619328 | 5 | DigitalOut RS(p26) ; |
shaizeen | 0:5dbeda619328 | 6 | DigitalOut E(p25) ; |
shaizeen | 0:5dbeda619328 | 7 | BusOut data(p24, p23, p22, p21) ; |
shaizeen | 0:5dbeda619328 | 8 | |
shaizeen | 0:5dbeda619328 | 9 | // Toggle enable function |
shaizeen | 0:5dbeda619328 | 10 | void toggle_enable(void) |
shaizeen | 0:5dbeda619328 | 11 | { E = 1 ; |
shaizeen | 0:5dbeda619328 | 12 | wait(0.001) ; |
shaizeen | 0:5dbeda619328 | 13 | E = 0 ; |
shaizeen | 0:5dbeda619328 | 14 | wait(0.001) ; |
shaizeen | 0:5dbeda619328 | 15 | }// Initialise LCD function |
shaizeen | 0:5dbeda619328 | 16 | void LCD_init(void) |
shaizeen | 0:5dbeda619328 | 17 | { wait(0.02) ; |
shaizeen | 0:5dbeda619328 | 18 | RS = 0 ; E = 0 ; |
shaizeen | 0:5dbeda619328 | 19 | |
shaizeen | 0:5dbeda619328 | 20 | // Function mode |
shaizeen | 0:5dbeda619328 | 21 | data = 0x2 ; |
shaizeen | 0:5dbeda619328 | 22 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 23 | data = 0x8 ; |
shaizeen | 0:5dbeda619328 | 24 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 25 | |
shaizeen | 0:5dbeda619328 | 26 | // Display mode |
shaizeen | 0:5dbeda619328 | 27 | data = 0x0 ; |
shaizeen | 0:5dbeda619328 | 28 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 29 | data = 0xF ; |
shaizeen | 0:5dbeda619328 | 30 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 31 | |
shaizeen | 0:5dbeda619328 | 32 | // Clear display |
shaizeen | 0:5dbeda619328 | 33 | data = 0x0 ; |
shaizeen | 0:5dbeda619328 | 34 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 35 | data = 0x1 ; |
shaizeen | 0:5dbeda619328 | 36 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 37 | |
shaizeen | 0:5dbeda619328 | 38 | } |
shaizeen | 0:5dbeda619328 | 39 | |
shaizeen | 0:5dbeda619328 | 40 | // Display function |
shaizeen | 0:5dbeda619328 | 41 | void display_to_LCD(char value ) |
shaizeen | 0:5dbeda619328 | 42 | { |
shaizeen | 0:5dbeda619328 | 43 | RS = 1;// display character |
shaizeen | 0:5dbeda619328 | 44 | data = value >> 4 ; // Upper 4 |
shaizeen | 0:5dbeda619328 | 45 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 46 | data = value & 0x0F ; // Lower 4 |
shaizeen | 0:5dbeda619328 | 47 | toggle_enable( ) ; |
shaizeen | 0:5dbeda619328 | 48 | |
shaizeen | 0:5dbeda619328 | 49 | } |