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

Dependencies:   mbed

Committer:
GerritPathuis
Date:
Sun Nov 12 14:59:04 2017 +0000
Revision:
2:062905d74f97
Parent:
1:c5d938ddc153
Sparkfun LCD-09067 connected to KL25Z.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GerritPathuis 0:e7b0972dec10 1 #include "mbed.h"
GerritPathuis 2:062905d74f97 2 //--- Sparkfun part LCD-09067
GerritPathuis 2:062905d74f97 3 //-------- LCD 16x2 ----------
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 2:062905d74f97 8 // or
GerritPathuis 2:062905d74f97 9 // KL25Z PTE0 (TX)-------------RX
GerritPathuis 2:062905d74f97 10 // KL25Z Vout------------------3.3V (text on LCD is wrong must be 3,3 Volt)
GerritPathuis 2:062905d74f97 11 // KL25Z GND-------------------GND
GerritPathuis 2:062905d74f97 12 // ---------------------------
GerritPathuis 0:e7b0972dec10 13
GerritPathuis 2:062905d74f97 14
GerritPathuis 2:062905d74f97 15 Serial lcd(PTE0, PTE1); // tx, rx (mbed)
GerritPathuis 2:062905d74f97 16 Serial pc(USBTX, USBRX); // to PC
GerritPathuis 2:062905d74f97 17
GerritPathuis 1:c5d938ddc153 18 void clear_lcd(void);
GerritPathuis 0:e7b0972dec10 19 void move_cursor(int, int);
GerritPathuis 0:e7b0972dec10 20
GerritPathuis 0:e7b0972dec10 21 int main() {
GerritPathuis 0:e7b0972dec10 22 int c=0;
GerritPathuis 0:e7b0972dec10 23 lcd.baud(9600);
GerritPathuis 0:e7b0972dec10 24
GerritPathuis 1:c5d938ddc153 25 clear_lcd();
GerritPathuis 2:062905d74f97 26 lcd.printf("LCD-09067");
GerritPathuis 0:e7b0972dec10 27 wait(1);
GerritPathuis 1:c5d938ddc153 28 clear_lcd();
GerritPathuis 0:e7b0972dec10 29
GerritPathuis 0:e7b0972dec10 30 while (1) {
GerritPathuis 2:062905d74f97 31 move_cursor(0,0);
GerritPathuis 0:e7b0972dec10 32 lcd.printf("pos %02d", c);
GerritPathuis 2:062905d74f97 33 wait_ms(200);
GerritPathuis 2:062905d74f97 34 move_cursor(1,0);
GerritPathuis 0:e7b0972dec10 35 lcd.printf("speed %02d", c);
GerritPathuis 2:062905d74f97 36 wait_ms(200);
GerritPathuis 0:e7b0972dec10 37 c += 1;
GerritPathuis 0:e7b0972dec10 38 }
GerritPathuis 0:e7b0972dec10 39 }
GerritPathuis 0:e7b0972dec10 40
GerritPathuis 1:c5d938ddc153 41 //------clear the LCD display--------
GerritPathuis 1:c5d938ddc153 42 void clear_lcd(void) {
GerritPathuis 0:e7b0972dec10 43 lcd.putc(0xFE);
GerritPathuis 0:e7b0972dec10 44 lcd.putc(0x01);
GerritPathuis 0:e7b0972dec10 45 }
GerritPathuis 0:e7b0972dec10 46
GerritPathuis 0:e7b0972dec10 47 //----------- line 0 or 1----------
GerritPathuis 0:e7b0972dec10 48 //----------- position 0/15--------
GerritPathuis 0:e7b0972dec10 49 // (0,0) is top left position
GerritPathuis 0:e7b0972dec10 50 // (1,15) is bottom right position
GerritPathuis 0:e7b0972dec10 51 void move_cursor(int line, int pos) {
GerritPathuis 0:e7b0972dec10 52 int cp;
GerritPathuis 0:e7b0972dec10 53 cp = pos + (line * 64) +128;
GerritPathuis 0:e7b0972dec10 54 lcd.putc(0xFE);
GerritPathuis 0:e7b0972dec10 55 lcd.putc(cp);
GerritPathuis 2:062905d74f97 56 pc.printf("%d\r\n",cp);
GerritPathuis 0:e7b0972dec10 57 }