Gerrit Pathuis
/
LCD_serial_16x2
LCD 16x2, www.Sparkfun.com part LCD-09067, serial enabled
main.cpp@1:c5d938ddc153, 2017-09-22 (annotated)
- Committer:
- GerritPathuis
- Date:
- Fri Sep 22 20:51:09 2017 +0000
- Revision:
- 1:c5d938ddc153
- Parent:
- 0:e7b0972dec10
- Child:
- 2:062905d74f97
update mbed lib version 151
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:c5d938ddc153 | 10 | void clear_lcd(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 | 1:c5d938ddc153 | 17 | clear_lcd(); |
GerritPathuis | 0:e7b0972dec10 | 18 | lcd.printf("Hello World"); |
GerritPathuis | 0:e7b0972dec10 | 19 | wait(1); |
GerritPathuis | 1:c5d938ddc153 | 20 | clear_lcd(); |
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 | 1:c5d938ddc153 | 31 | //------clear the LCD display-------- |
GerritPathuis | 1:c5d938ddc153 | 32 | void clear_lcd(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 | } |