Solutions for the Character LCD experiments for LPC812 MAX

Dependencies:   TextLCD mbed

Committer:
embeddedartists
Date:
Mon Nov 25 10:49:58 2013 +0000
Revision:
1:31a672976229
Parent:
0:d2ddc9a2a84a
Small fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:d2ddc9a2a84a 1 #include "mbed.h"
embeddedartists 0:d2ddc9a2a84a 2 #include "TextLCD.h"
embeddedartists 0:d2ddc9a2a84a 3
embeddedartists 0:d2ddc9a2a84a 4 Serial pc(USBTX, USBRX); // tx, rx
embeddedartists 0:d2ddc9a2a84a 5
embeddedartists 0:d2ddc9a2a84a 6 TextLCD lcd(D0, D3, D10, D11, D12, D13, TextLCD::LCD16x2); // rs, e, d4-d7
embeddedartists 0:d2ddc9a2a84a 7
embeddedartists 0:d2ddc9a2a84a 8 static void experiment1_alt1()
embeddedartists 0:d2ddc9a2a84a 9 {
embeddedartists 0:d2ddc9a2a84a 10 // Example code from https://mbed.org/cookbook/Text-LCD-Enhanced
embeddedartists 0:d2ddc9a2a84a 11 pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
embeddedartists 0:d2ddc9a2a84a 12
embeddedartists 0:d2ddc9a2a84a 13 for (int row=0; row<lcd.rows(); row++) {
embeddedartists 0:d2ddc9a2a84a 14 int col=0;
embeddedartists 0:d2ddc9a2a84a 15
embeddedartists 0:d2ddc9a2a84a 16 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
embeddedartists 0:d2ddc9a2a84a 17 // lcd.putc('-');
embeddedartists 0:d2ddc9a2a84a 18 lcd.putc('0' + row);
embeddedartists 0:d2ddc9a2a84a 19
embeddedartists 0:d2ddc9a2a84a 20 for (col=1; col<lcd.columns()-1; col++) {
embeddedartists 0:d2ddc9a2a84a 21 lcd.putc('*');
embeddedartists 0:d2ddc9a2a84a 22 }
embeddedartists 0:d2ddc9a2a84a 23
embeddedartists 0:d2ddc9a2a84a 24 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
embeddedartists 0:d2ddc9a2a84a 25 lcd.putc('+');
embeddedartists 0:d2ddc9a2a84a 26
embeddedartists 0:d2ddc9a2a84a 27 }
embeddedartists 0:d2ddc9a2a84a 28
embeddedartists 0:d2ddc9a2a84a 29 // Show cursor as blinking character
embeddedartists 0:d2ddc9a2a84a 30 lcd.setCursor(TextLCD::CurOff_BlkOn);
embeddedartists 0:d2ddc9a2a84a 31
embeddedartists 0:d2ddc9a2a84a 32 // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
embeddedartists 0:d2ddc9a2a84a 33 // They are defined by a 5x7 bitpattern.
embeddedartists 0:d2ddc9a2a84a 34 lcd.setUDC(0, (char *) udc_0); // Show |>
embeddedartists 0:d2ddc9a2a84a 35 lcd.putc(0);
embeddedartists 0:d2ddc9a2a84a 36 lcd.setUDC(1, (char *) udc_1); // Show <|
embeddedartists 0:d2ddc9a2a84a 37 lcd.putc(1);
embeddedartists 0:d2ddc9a2a84a 38 lcd.setUDC(2, (char *) udc_2);
embeddedartists 0:d2ddc9a2a84a 39 lcd.putc(2);
embeddedartists 0:d2ddc9a2a84a 40 lcd.setUDC(3, (char *) udc_3);
embeddedartists 0:d2ddc9a2a84a 41 lcd.putc(3);
embeddedartists 0:d2ddc9a2a84a 42 lcd.setUDC(4, (char *) udc_4);
embeddedartists 0:d2ddc9a2a84a 43 lcd.putc(4);
embeddedartists 0:d2ddc9a2a84a 44 lcd.setUDC(5, (char *) udc_5);
embeddedartists 0:d2ddc9a2a84a 45 lcd.putc(5);
embeddedartists 0:d2ddc9a2a84a 46 lcd.setUDC(6, (char *) udc_6);
embeddedartists 0:d2ddc9a2a84a 47 lcd.putc(6);
embeddedartists 0:d2ddc9a2a84a 48 lcd.setUDC(7, (char *) udc_7);
embeddedartists 0:d2ddc9a2a84a 49 lcd.putc(7);
embeddedartists 0:d2ddc9a2a84a 50
embeddedartists 0:d2ddc9a2a84a 51 while(1)
embeddedartists 0:d2ddc9a2a84a 52 ;
embeddedartists 0:d2ddc9a2a84a 53 }
embeddedartists 0:d2ddc9a2a84a 54
embeddedartists 0:d2ddc9a2a84a 55 static void experiment1_alt2()
embeddedartists 0:d2ddc9a2a84a 56 {
embeddedartists 0:d2ddc9a2a84a 57 pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
embeddedartists 0:d2ddc9a2a84a 58
embeddedartists 0:d2ddc9a2a84a 59 // Clear screen
embeddedartists 0:d2ddc9a2a84a 60 lcd.cls();
embeddedartists 0:d2ddc9a2a84a 61
embeddedartists 0:d2ddc9a2a84a 62 lcd.printf("Hello\nWorld!");
embeddedartists 0:d2ddc9a2a84a 63 wait(3);
embeddedartists 0:d2ddc9a2a84a 64
embeddedartists 0:d2ddc9a2a84a 65 // Example using putc() which automatically moves the cursor
embeddedartists 0:d2ddc9a2a84a 66 lcd.cls();
embeddedartists 0:d2ddc9a2a84a 67 for (char c = '0'; c <= 'Z' ; c++)
embeddedartists 0:d2ddc9a2a84a 68 {
embeddedartists 0:d2ddc9a2a84a 69 lcd.putc(c);
embeddedartists 0:d2ddc9a2a84a 70 wait(0.3);
embeddedartists 0:d2ddc9a2a84a 71 }
embeddedartists 0:d2ddc9a2a84a 72
embeddedartists 0:d2ddc9a2a84a 73 while(1)
embeddedartists 0:d2ddc9a2a84a 74 ;
embeddedartists 0:d2ddc9a2a84a 75 }
embeddedartists 0:d2ddc9a2a84a 76
embeddedartists 0:d2ddc9a2a84a 77
embeddedartists 0:d2ddc9a2a84a 78 int main()
embeddedartists 0:d2ddc9a2a84a 79 {
embeddedartists 0:d2ddc9a2a84a 80 //experiment1_alt1(); // The sample application that comes with the library
embeddedartists 0:d2ddc9a2a84a 81 experiment1_alt2(); // Hello World!
embeddedartists 0:d2ddc9a2a84a 82 }