Convenience routines for an I"C connected LCD display. Handy things like taking cursor to home, positioning cursor, clearing display, writing strings etc
jtlcd.cpp@0:8f724a47a820, 2012-11-07 (annotated)
- Committer:
- jont
- Date:
- Wed Nov 07 21:58:22 2012 +0000
- Revision:
- 0:8f724a47a820
- Child:
- 1:2ded47079af1
separated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jont | 0:8f724a47a820 | 1 | #include "mbed.h" |
jont | 0:8f724a47a820 | 2 | #include "jtlcd.h" |
jont | 0:8f724a47a820 | 3 | |
jont | 0:8f724a47a820 | 4 | I2C i2c(p28, p27); // sda, scl |
jont | 0:8f724a47a820 | 5 | void lcdinit() |
jont | 0:8f724a47a820 | 6 | { |
jont | 0:8f724a47a820 | 7 | |
jont | 0:8f724a47a820 | 8 | i2c.start(); |
jont | 0:8f724a47a820 | 9 | i2c.write(Slave); |
jont | 0:8f724a47a820 | 10 | i2c.write(0x00); |
jont | 0:8f724a47a820 | 11 | i2c.write(0x38); |
jont | 0:8f724a47a820 | 12 | wait(0.01); |
jont | 0:8f724a47a820 | 13 | i2c.write(0x39); //i assume now we juyst need data? |
jont | 0:8f724a47a820 | 14 | wait(0.01); |
jont | 0:8f724a47a820 | 15 | i2c.write(0x14); |
jont | 0:8f724a47a820 | 16 | i2c.write(0x74); |
jont | 0:8f724a47a820 | 17 | i2c.write(0x54); |
jont | 0:8f724a47a820 | 18 | i2c.write(0x6f); |
jont | 0:8f724a47a820 | 19 | i2c.write(0x0c); |
jont | 0:8f724a47a820 | 20 | i2c.write(0x01); |
jont | 0:8f724a47a820 | 21 | i2c.write(0x06); |
jont | 0:8f724a47a820 | 22 | wait(0.01); |
jont | 0:8f724a47a820 | 23 | i2c.stop(); |
jont | 0:8f724a47a820 | 24 | |
jont | 0:8f724a47a820 | 25 | |
jont | 0:8f724a47a820 | 26 | } |
jont | 0:8f724a47a820 | 27 | |
jont | 0:8f724a47a820 | 28 | void lcdclear() |
jont | 0:8f724a47a820 | 29 | { |
jont | 0:8f724a47a820 | 30 | i2c.start(); |
jont | 0:8f724a47a820 | 31 | i2c.write(Slave); |
jont | 0:8f724a47a820 | 32 | i2c.write(0x00); |
jont | 0:8f724a47a820 | 33 | i2c.write(0x01); |
jont | 0:8f724a47a820 | 34 | i2c.stop(); |
jont | 0:8f724a47a820 | 35 | wait(0.2); |
jont | 0:8f724a47a820 | 36 | } |
jont | 0:8f724a47a820 | 37 | |
jont | 0:8f724a47a820 | 38 | void test() |
jont | 0:8f724a47a820 | 39 | { |
jont | 0:8f724a47a820 | 40 | |
jont | 0:8f724a47a820 | 41 | i2c.start(); |
jont | 0:8f724a47a820 | 42 | i2c.write(Slave); |
jont | 0:8f724a47a820 | 43 | i2c.stop(); |
jont | 0:8f724a47a820 | 44 | wait(0.2); |
jont | 0:8f724a47a820 | 45 | } |
jont | 0:8f724a47a820 | 46 | |
jont | 0:8f724a47a820 | 47 | |
jont | 0:8f724a47a820 | 48 | void Show(char *text) |
jont | 0:8f724a47a820 | 49 | { |
jont | 0:8f724a47a820 | 50 | int n,d; |
jont | 0:8f724a47a820 | 51 | d=0x00; |
jont | 0:8f724a47a820 | 52 | int length = strlen(text); |
jont | 0:8f724a47a820 | 53 | i2c.start(); |
jont | 0:8f724a47a820 | 54 | i2c.write(Slave); //Slave=0x78 |
jont | 0:8f724a47a820 | 55 | i2c.write(Datasend);//Datasend=0x40 |
jont | 0:8f724a47a820 | 56 | for(n=0;n<length;n++){ |
jont | 0:8f724a47a820 | 57 | i2c.write(*text); |
jont | 0:8f724a47a820 | 58 | ++text; |
jont | 0:8f724a47a820 | 59 | } |
jont | 0:8f724a47a820 | 60 | i2c.stop(); |
jont | 0:8f724a47a820 | 61 | } |