Gerrit Pathuis / Mbed 2 deprecated LCD_serial_16x2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //--- Sparkfun part LCD-09067
00003 //-------- LCD 16x2 ----------
00004 // MBED p28-------------------RX
00005 // MBED Vout------------------5V (text on LCD is wrong must be 3,3 Volt)
00006 // MBED GND-------------------GND
00007 // ---------------------------
00008 // or
00009 // KL25Z PTE0 (TX)-------------RX
00010 // KL25Z Vout------------------3.3V (text on LCD is wrong must be 3,3 Volt)
00011 // KL25Z GND-------------------GND
00012 // ---------------------------
00013 
00014 
00015 Serial lcd(PTE0, PTE1);       // tx, rx (mbed)
00016 Serial pc(USBTX, USBRX);      // to PC
00017 
00018 void clear_lcd(void);
00019 void move_cursor(int, int);
00020 
00021 int main() {
00022     int c=0;
00023     lcd.baud(9600);
00024     
00025     clear_lcd();
00026     lcd.printf("LCD-09067");
00027     wait(1);
00028     clear_lcd();
00029 
00030     while (1) {
00031         move_cursor(0,0);
00032         lcd.printf("pos %02d", c);
00033         wait_ms(200);
00034         move_cursor(1,0);
00035         lcd.printf("speed %02d", c);
00036         wait_ms(200);
00037         c += 1;
00038     }
00039 }
00040 
00041 //------clear the LCD display--------
00042 void clear_lcd(void) {
00043     lcd.putc(0xFE);
00044     lcd.putc(0x01);
00045 }
00046 
00047 //----------- line 0 or 1----------
00048 //----------- position 0/15--------
00049 // (0,0) is top left position
00050 // (1,15) is bottom right position
00051 void move_cursor(int line, int pos) {
00052     int cp;
00053     cp = pos + (line * 64) +128;
00054     lcd.putc(0xFE);
00055     lcd.putc(cp);
00056     pc.printf("%d\r\n",cp);
00057 }