A test of the lcd library

Dependencies:   lcd mbed

Committer:
mattegan
Date:
Fri Nov 08 07:52:40 2013 +0000
Revision:
1:2b8901be97f9
Parent:
0:b768eecbd7c0
[FIX] added mbed library;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mattegan 0:b768eecbd7c0 1 #include "mbed.h"
mattegan 0:b768eecbd7c0 2 #include "lcd.h"
mattegan 0:b768eecbd7c0 3
mattegan 0:b768eecbd7c0 4 //register select, read/write, enable, (db4,db5,db6,db7)
mattegan 0:b768eecbd7c0 5 lcd display(p21, p22, p23, p24, p25, p26, p27);
mattegan 0:b768eecbd7c0 6
mattegan 0:b768eecbd7c0 7 int main() {
mattegan 0:b768eecbd7c0 8 display.printf("Hello World\n");
mattegan 0:b768eecbd7c0 9 display.printf("Number: %d", 15);
mattegan 0:b768eecbd7c0 10
mattegan 0:b768eecbd7c0 11 wait(3);
mattegan 0:b768eecbd7c0 12
mattegan 0:b768eecbd7c0 13 display.clear();
mattegan 0:b768eecbd7c0 14
mattegan 0:b768eecbd7c0 15 //these graphics were generated using http://www.quinapalus.com/hd44780udg.html
mattegan 0:b768eecbd7c0 16 int graphics[8][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f},
mattegan 0:b768eecbd7c0 17 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 18 {0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 19 {0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 20 {0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 21 {0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 22 {0x00, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f},
mattegan 0:b768eecbd7c0 23 {0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}};
mattegan 0:b768eecbd7c0 24
mattegan 0:b768eecbd7c0 25 //define each character, user defined characters are of the values 0 through 7
mattegan 0:b768eecbd7c0 26 for(int i = 0; i < 8; i++) {
mattegan 0:b768eecbd7c0 27 display.defineCharacter(i, graphics[i]);
mattegan 0:b768eecbd7c0 28 }
mattegan 0:b768eecbd7c0 29
mattegan 0:b768eecbd7c0 30 int glyphs[9] = {0x20, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
mattegan 0:b768eecbd7c0 31
mattegan 0:b768eecbd7c0 32 int start = 0;
mattegan 0:b768eecbd7c0 33 while(1) {
mattegan 0:b768eecbd7c0 34 for(int i = 0; i < 16; i++) {
mattegan 0:b768eecbd7c0 35 int magnitude = (i + start);
mattegan 0:b768eecbd7c0 36 if(magnitude > 16) {
mattegan 0:b768eecbd7c0 37 magnitude = 32 - magnitude;
mattegan 0:b768eecbd7c0 38 }
mattegan 0:b768eecbd7c0 39 if(magnitude < 0) {
mattegan 0:b768eecbd7c0 40 magnitude = magnitude * -1;
mattegan 0:b768eecbd7c0 41 }
mattegan 0:b768eecbd7c0 42 display.locateCharacter(0, i, magnitude < 9 ? glyphs[0] : glyphs[magnitude - 8]);
mattegan 0:b768eecbd7c0 43 display.locateCharacter(1, i, magnitude > 8 ? glyphs[8] : glyphs[magnitude]);
mattegan 0:b768eecbd7c0 44 }
mattegan 0:b768eecbd7c0 45 start = (start + 1) % 33;
mattegan 1:2b8901be97f9 46 wait(.03);
mattegan 0:b768eecbd7c0 47 }
mattegan 0:b768eecbd7c0 48 }