LCD 16x2, www.Sparkfun.com part LCD-09067, serial enabled

Dependencies:   mbed

Committer:
GerritPathuis
Date:
Fri Dec 31 18:44:38 2010 +0000
Revision:
0:e7b0972dec10
Child:
1:c5d938ddc153
Dated 31-12-2010

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:e7b0972dec10 1 #include "mbed.h"
GerritPathuis 0:e7b0972dec10 2 //--- Spark fun part LCD-09067
GerritPathuis 0:e7b0972dec10 3 //-------- LCD 2x26 ----------
GerritPathuis 0:e7b0972dec10 4 // MBED p28-------------------RX
GerritPathuis 0:e7b0972dec10 5 // MBED Vout------------------5V (text on LCD is wrong must be 3,3 Volt)
GerritPathuis 0:e7b0972dec10 6 // MBED GND-------------------GND
GerritPathuis 0:e7b0972dec10 7 // ---------------------------
GerritPathuis 0:e7b0972dec10 8
GerritPathuis 0:e7b0972dec10 9 Serial lcd(p28, p27); // tx, rx
GerritPathuis 0:e7b0972dec10 10 void clear(void);
GerritPathuis 0:e7b0972dec10 11 void move_cursor(int, int);
GerritPathuis 0:e7b0972dec10 12
GerritPathuis 0:e7b0972dec10 13 int main() {
GerritPathuis 0:e7b0972dec10 14 int c=0;
GerritPathuis 0:e7b0972dec10 15 lcd.baud(9600);
GerritPathuis 0:e7b0972dec10 16
GerritPathuis 0:e7b0972dec10 17 clear();
GerritPathuis 0:e7b0972dec10 18 lcd.printf("Hello World");
GerritPathuis 0:e7b0972dec10 19 wait(1);
GerritPathuis 0:e7b0972dec10 20 clear();
GerritPathuis 0:e7b0972dec10 21
GerritPathuis 0:e7b0972dec10 22 while (1) {
GerritPathuis 0:e7b0972dec10 23 move_cursor(0,3);
GerritPathuis 0:e7b0972dec10 24 lcd.printf("pos %02d", c);
GerritPathuis 0:e7b0972dec10 25 move_cursor(1,3);
GerritPathuis 0:e7b0972dec10 26 lcd.printf("speed %02d", c);
GerritPathuis 0:e7b0972dec10 27 c += 1;
GerritPathuis 0:e7b0972dec10 28 }
GerritPathuis 0:e7b0972dec10 29 }
GerritPathuis 0:e7b0972dec10 30
GerritPathuis 0:e7b0972dec10 31 //------clears the dispaly--------
GerritPathuis 0:e7b0972dec10 32 void clear(void) {
GerritPathuis 0:e7b0972dec10 33 lcd.putc(0xFE);
GerritPathuis 0:e7b0972dec10 34 lcd.putc(0x01);
GerritPathuis 0:e7b0972dec10 35 }
GerritPathuis 0:e7b0972dec10 36
GerritPathuis 0:e7b0972dec10 37 //----------- line 0 or 1----------
GerritPathuis 0:e7b0972dec10 38 //----------- position 0/15--------
GerritPathuis 0:e7b0972dec10 39 // (0,0) is top left position
GerritPathuis 0:e7b0972dec10 40 // (1,15) is bottom right position
GerritPathuis 0:e7b0972dec10 41 void move_cursor(int line, int pos) {
GerritPathuis 0:e7b0972dec10 42 int cp;
GerritPathuis 0:e7b0972dec10 43 cp = pos + (line * 64) +128;
GerritPathuis 0:e7b0972dec10 44 lcd.putc(0xFE);
GerritPathuis 0:e7b0972dec10 45 lcd.putc(cp);
GerritPathuis 0:e7b0972dec10 46 }