6 x 7 segment display library for PCA9637 driven breakout board

Dependents:   FTSE100 InternetDispBoB digitalThermometer Counter ... more

Committer:
d_worrall
Date:
Fri Jul 01 08:28:28 2011 +0000
Revision:
11:5e97be74f4d1
Parent:
10:1fda6b0ee3bc
Child:
12:2235c72db927
version7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d_worrall 0:843654413849 1 //NXP PCA9635 library
d_worrall 0:843654413849 2 //mbed Team - 28th June 2011
d_worrall 0:843654413849 3 //Daniel Worrall
d_worrall 0:843654413849 4
d_worrall 0:843654413849 5 #include "mbed.h"
d_worrall 0:843654413849 6 #include "PCA9635.h"
d_worrall 0:843654413849 7 #include "dispBoB.h"
d_worrall 0:843654413849 8
d_worrall 9:44de04d410df 9 static const char loc[] = {0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0x12, 0x12};
d_worrall 9:44de04d410df 10 static const short dispL[] = {
d_worrall 6:1721cdf1024e 11 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 12 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 9:44de04d410df 13 0x0000, 0x1008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0xC006, 0x600C, 0x0000, 0x0000, 0x0000, 0x0000, 0x1000, 0x0000,
d_worrall 0:843654413849 14 0xE00E, 0x2008, 0xC00D, 0x600D, 0x200B, 0x6007, 0xE007, 0x200E, 0xE00F, 0x600F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 15
d_worrall 0:843654413849 16 0x0000, 0xF001, 0xE003, 0xC001, 0xE009, 0xC007, 0x8007, 0x600F, 0xA003, 0x8000, 0x6008, 0xA007, 0x3008, 0xA005, 0xA001, 0xE001,
d_worrall 6:1721cdf1024e 17 0x800F, 0x300F, 0x8001, 0x6007, 0xC003, 0xE000, 0xE000, 0xE004, 0xA00B, 0x600B, 0xC00D, 0xC006, 0x0000, 0x600C, 0x0000, 0x4000,
d_worrall 0:843654413849 18 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 19 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xC006, 0x0000, 0x600C, 0x0000, 0x0000
d_worrall 6:1721cdf1024e 20 };
d_worrall 9:44de04d410df 21 static const short dispR[] = {
d_worrall 6:1721cdf1024e 22 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 23 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 9:44de04d410df 24 0x0000, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0C60, 0x06C0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0100, 0x0000,
d_worrall 6:1721cdf1024e 25 0x0EE0, 0x0280, 0x0CD0, 0x06D0, 0x02B0, 0x0670, 0x0E70, 0x02E0, 0x0EF0, 0x06F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 0:843654413849 26
d_worrall 0:843654413849 27 0x0000, 0x0F10, 0x0E30, 0x0C10, 0x0E90, 0x0C70, 0x0870, 0x06F0, 0x0A30, 0x0800, 0x0680, 0x0A70, 0x0380, 0x0A50, 0x0A10, 0x0E10,
d_worrall 6:1721cdf1024e 28 0x08F0, 0x03F0, 0x0810, 0x0670, 0x0C30, 0x0E00, 0x0E00, 0x0E40, 0x0AB0, 0x06B0, 0x0CD0, 0x0C60, 0x0000, 0x06C0, 0x0000, 0x0400,
d_worrall 0:843654413849 29 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 30 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C60, 0x0000, 0x06C0, 0x0000, 0x0000
d_worrall 0:843654413849 31 };
d_worrall 9:44de04d410df 32 short element[8];
d_worrall 9:44de04d410df 33 short ppair[4];
d_worrall 0:843654413849 34 string nullArray = " ";
d_worrall 0:843654413849 35
d_worrall 0:843654413849 36 dispBoB::dispBoB(PinName sda, PinName scl, PinName en): _pca(sda, scl), _en(en) {
d_worrall 0:843654413849 37 _en = 0;
d_worrall 9:44de04d410df 38 _pca.init(loc[0]);
d_worrall 0:843654413849 39 }
d_worrall 0:843654413849 40
d_worrall 0:843654413849 41 void dispBoB::cls(void){
d_worrall 0:843654413849 42 for(int j = 0; j < 8; j++){
d_worrall 0:843654413849 43 locate(j);
d_worrall 0:843654413849 44 _pca.bus(0x0000);
d_worrall 0:843654413849 45 }
d_worrall 9:44de04d410df 46 locate(0);
d_worrall 0:843654413849 47 }
d_worrall 0:843654413849 48
d_worrall 0:843654413849 49 void dispBoB::locate(char pos){
d_worrall 9:44de04d410df 50 _pca.setAddress(loc[pos]);
d_worrall 0:843654413849 51 _cursor = pos;
d_worrall 9:44de04d410df 52 _pos = pos;
d_worrall 0:843654413849 53 }
d_worrall 0:843654413849 54
d_worrall 9:44de04d410df 55 int dispBoB::_putc(int c){
d_worrall 11:5e97be74f4d1 56 if(_pos>5) return -1;
d_worrall 11:5e97be74f4d1 57
d_worrall 0:843654413849 58 if(_cursor & 1){
d_worrall 9:44de04d410df 59 element[_cursor] = dispR[toupper(c)];
d_worrall 0:843654413849 60 } else {
d_worrall 9:44de04d410df 61 element[_cursor] = dispL[toupper(c)];
d_worrall 0:843654413849 62 }
d_worrall 0:843654413849 63
d_worrall 0:843654413849 64 int i = _cursor/2;
d_worrall 9:44de04d410df 65 ppair[i] = element[(2*i)] + element[(2*i)+1];
d_worrall 9:44de04d410df 66 _pca.bus(ppair[i]);
d_worrall 9:44de04d410df 67
d_worrall 9:44de04d410df 68 locate(_pos+1);
d_worrall 9:44de04d410df 69
d_worrall 9:44de04d410df 70 return c;
d_worrall 0:843654413849 71 }
d_worrall 0:843654413849 72
d_worrall 9:44de04d410df 73 int dispBoB::_getc(){
d_worrall 9:44de04d410df 74 return -1;
d_worrall 0:843654413849 75 }
d_worrall 0:843654413849 76
d_worrall 0:843654413849 77 void dispBoB::scroll(string str, float speed){
d_worrall 0:843654413849 78 char buffer[6];
d_worrall 9:44de04d410df 79 str.insert(0, nullArray);
d_worrall 0:843654413849 80 str.insert(str.length(), nullArray);
d_worrall 0:843654413849 81
d_worrall 0:843654413849 82 for(int k = 0; k < str.length(); k++){
d_worrall 9:44de04d410df 83 str.copy(buffer, 6, k);
d_worrall 9:44de04d410df 84 locate(0);
d_worrall 9:44de04d410df 85 printf("%s", buffer);
d_worrall 9:44de04d410df 86 wait(speed);
d_worrall 0:843654413849 87 }
d_worrall 0:843654413849 88 }
d_worrall 0:843654413849 89
d_worrall 9:44de04d410df 90 //supply PCA9635 functionality to dispBoB class
d_worrall 8:a875c4229c57 91 void dispBoB::bus(short leds){
d_worrall 8:a875c4229c57 92 _pca.bus(leds);
d_worrall 8:a875c4229c57 93 }
d_worrall 0:843654413849 94
d_worrall 0:843654413849 95
d_worrall 0:843654413849 96
d_worrall 0:843654413849 97
d_worrall 0:843654413849 98
d_worrall 0:843654413849 99
d_worrall 0:843654413849 100
d_worrall 0:843654413849 101