lcd

Dependencies:   LCD mbed

Committer:
DrMirko
Date:
Mon Oct 24 12:39:46 2016 +0000
Revision:
0:339986724a03
lcd

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DrMirko 0:339986724a03 1 #include "LCD.h"
DrMirko 0:339986724a03 2
DrMirko 0:339986724a03 3 DigitalOut RS(D12);
DrMirko 0:339986724a03 4 DigitalOut E(D11);
DrMirko 0:339986724a03 5
DrMirko 0:339986724a03 6 BusOut data(D5, D4, D3, D2);
DrMirko 0:339986724a03 7
DrMirko 0:339986724a03 8 void toggle_enable(void)
DrMirko 0:339986724a03 9 {
DrMirko 0:339986724a03 10 E=1;
DrMirko 0:339986724a03 11 wait(0.001);
DrMirko 0:339986724a03 12 E=0;
DrMirko 0:339986724a03 13 wait(0.001);
DrMirko 0:339986724a03 14 }
DrMirko 0:339986724a03 15 //initialize LCD function
DrMirko 0:339986724a03 16 void LCD_init(void)
DrMirko 0:339986724a03 17 {
DrMirko 0:339986724a03 18 wait(0.02); // pause for 20 ms
DrMirko 0:339986724a03 19 RS=0; // set low to write control data
DrMirko 0:339986724a03 20 E=0; // set low
DrMirko 0:339986724a03 21 //function mode
DrMirko 0:339986724a03 22 data=0x2; // 4 bit mode (data packet 1, DB4-DB7)
DrMirko 0:339986724a03 23 toggle_enable();
DrMirko 0:339986724a03 24 data=0x8; // 2-line, 7 dot char (data packet 2, DB0-DB3)
DrMirko 0:339986724a03 25 toggle_enable();
DrMirko 0:339986724a03 26 //display mode
DrMirko 0:339986724a03 27 data=0x0; // 4 bit mode (data packet 1, DB4-DB7)
DrMirko 0:339986724a03 28 toggle_enable();
DrMirko 0:339986724a03 29 data=0xF; // display on, cursor on, blink on
DrMirko 0:339986724a03 30 toggle_enable();
DrMirko 0:339986724a03 31 //clear display
DrMirko 0:339986724a03 32 data=0x0; //
DrMirko 0:339986724a03 33 toggle_enable();
DrMirko 0:339986724a03 34 data=0x1; // clear
DrMirko 0:339986724a03 35 toggle_enable();
DrMirko 0:339986724a03 36 }
DrMirko 0:339986724a03 37 //display function
DrMirko 0:339986724a03 38 void display_to_LCD(char value)
DrMirko 0:339986724a03 39 {
DrMirko 0:339986724a03 40 RS=1; // set high to write character data
DrMirko 0:339986724a03 41 data=value>>4; // value shifted right 4 = upper nibble
DrMirko 0:339986724a03 42 toggle_enable();
DrMirko 0:339986724a03 43 data=value; // value bitmask with 0x0F = lower nibble
DrMirko 0:339986724a03 44 toggle_enable();
DrMirko 0:339986724a03 45 }
DrMirko 0:339986724a03 46 //locate function
DrMirko 0:339986724a03 47 void set_location(char location)
DrMirko 0:339986724a03 48 {
DrMirko 0:339986724a03 49 RS=0;
DrMirko 0:339986724a03 50 data=(location|0x80)>>4; // upper nibble
DrMirko 0:339986724a03 51 toggle_enable();
DrMirko 0:339986724a03 52 data=location&0x0F; // lower nibble
DrMirko 0:339986724a03 53 toggle_enable();
DrMirko 0:339986724a03 54 }