6 x 7 segment display library for PCA9637 driven breakout board

Dependents:   FTSE100 InternetDispBoB digitalThermometer Counter ... more

Committer:
d_worrall
Date:
Wed Jun 29 13:24:44 2011 +0000
Revision:
6:1721cdf1024e
Parent:
0:843654413849
Child:
7:adcfb0f5e4de
version2

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 0:843654413849 9 Serial pc(USBTX, USBRX);
d_worrall 0:843654413849 10
d_worrall 0:843654413849 11 static const char _loc[] = {0x02, 0x02, 0x04, 0x04, 0x10, 0x10, 0x12, 0x12};
d_worrall 6:1721cdf1024e 12 static const short _dispL[] = {
d_worrall 6:1721cdf1024e 13 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 14 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 15 0x0000, 0x1008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0xC006, 0x600C, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000,
d_worrall 0:843654413849 16 0xE00E, 0x2008, 0xC00D, 0x600D, 0x200B, 0x6007, 0xE007, 0x200E, 0xE00F, 0x600F, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 17
d_worrall 0:843654413849 18 0x0000, 0xF001, 0xE003, 0xC001, 0xE009, 0xC007, 0x8007, 0x600F, 0xA003, 0x8000, 0x6008, 0xA007, 0x3008, 0xA005, 0xA001, 0xE001,
d_worrall 6:1721cdf1024e 19 0x800F, 0x300F, 0x8001, 0x6007, 0xC003, 0xE000, 0xE000, 0xE004, 0xA00B, 0x600B, 0xC00D, 0xC006, 0x0000, 0x600C, 0x0000, 0x4000,
d_worrall 0:843654413849 20 0x1000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 21 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xC006, 0x0000, 0x600C, 0x0000, 0x0000
d_worrall 6:1721cdf1024e 22 };
d_worrall 6:1721cdf1024e 23 static const short _dispR[] = {
d_worrall 6:1721cdf1024e 24 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 25 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 26 0x0000, 0x0180, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0C60, 0x06C0, 0x0000, 0x0000, 0x0000, 0x0010, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 27 0x0EE0, 0x0280, 0x0CD0, 0x06D0, 0x02B0, 0x0670, 0x0E70, 0x02E0, 0x0EF0, 0x06F0, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 0:843654413849 28
d_worrall 0:843654413849 29 0x0000, 0x0F10, 0x0E30, 0x0C10, 0x0E90, 0x0C70, 0x0870, 0x06F0, 0x0A30, 0x0800, 0x0680, 0x0A70, 0x0380, 0x0A50, 0x0A10, 0x0E10,
d_worrall 6:1721cdf1024e 30 0x08F0, 0x03F0, 0x0810, 0x0670, 0x0C30, 0x0E00, 0x0E00, 0x0E40, 0x0AB0, 0x06B0, 0x0CD0, 0x0C60, 0x0000, 0x06C0, 0x0000, 0x0400,
d_worrall 0:843654413849 31 0x0100, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
d_worrall 6:1721cdf1024e 32 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0C60, 0x0000, 0x06C0, 0x0000, 0x0000
d_worrall 0:843654413849 33 };
d_worrall 0:843654413849 34 short _element[8];
d_worrall 0:843654413849 35 short _pair[4];
d_worrall 0:843654413849 36 string nullArray = " ";
d_worrall 0:843654413849 37
d_worrall 0:843654413849 38 dispBoB::dispBoB(PinName sda, PinName scl, PinName en): _pca(sda, scl), _en(en) {
d_worrall 0:843654413849 39 _en = 0;
d_worrall 0:843654413849 40 _pca.init(_loc[5]);
d_worrall 0:843654413849 41 }
d_worrall 0:843654413849 42
d_worrall 0:843654413849 43 void dispBoB::cls(void){
d_worrall 0:843654413849 44 for(int j = 0; j < 8; j++){
d_worrall 0:843654413849 45 locate(j);
d_worrall 0:843654413849 46 _pca.bus(0x0000);
d_worrall 0:843654413849 47 }
d_worrall 0:843654413849 48 _cursor = 0x10;
d_worrall 0:843654413849 49 }
d_worrall 0:843654413849 50
d_worrall 0:843654413849 51 void dispBoB::locate(char pos){
d_worrall 0:843654413849 52 _pca.setAddress(_loc[pos]);
d_worrall 0:843654413849 53 _cursor = pos;
d_worrall 0:843654413849 54 }
d_worrall 0:843654413849 55
d_worrall 0:843654413849 56 void dispBoB::putc(char c){
d_worrall 0:843654413849 57
d_worrall 0:843654413849 58 if(_cursor & 1){
d_worrall 6:1721cdf1024e 59 _element[_cursor] = _dispR[c];
d_worrall 0:843654413849 60 } else {
d_worrall 6:1721cdf1024e 61 _element[_cursor] = _dispL[c];
d_worrall 0:843654413849 62 }
d_worrall 0:843654413849 63
d_worrall 0:843654413849 64 int i = _cursor/2;
d_worrall 0:843654413849 65 _pair[i] = _element[(2*i)] + _element[(2*i)+1];
d_worrall 0:843654413849 66 _pca.bus(_pair[i]);
d_worrall 0:843654413849 67 }
d_worrall 0:843654413849 68
d_worrall 0:843654413849 69 void dispBoB::putc(char c, char pos){
d_worrall 0:843654413849 70
d_worrall 0:843654413849 71 locate(pos);
d_worrall 6:1721cdf1024e 72
d_worrall 0:843654413849 73 if(_cursor & 1){
d_worrall 6:1721cdf1024e 74 _element[_cursor] = _dispR[c];
d_worrall 0:843654413849 75 } else {
d_worrall 6:1721cdf1024e 76 _element[_cursor] = _dispL[c];
d_worrall 0:843654413849 77 }
d_worrall 0:843654413849 78
d_worrall 0:843654413849 79 int i = _cursor/2;
d_worrall 0:843654413849 80 _pair[i] = _element[(2*i)] + _element[(2*i)+1];
d_worrall 0:843654413849 81 _pca.bus(_pair[i]);
d_worrall 0:843654413849 82 }
d_worrall 0:843654413849 83
d_worrall 0:843654413849 84 void dispBoB::write(string str){
d_worrall 0:843654413849 85 for(int j = 5; j >= 0; j--){
d_worrall 0:843654413849 86 putc(toupper(str[j]), j);
d_worrall 0:843654413849 87 }
d_worrall 0:843654413849 88 }
d_worrall 0:843654413849 89
d_worrall 0:843654413849 90 void dispBoB::scroll(string str, float speed){
d_worrall 0:843654413849 91 char buffer[6];
d_worrall 0:843654413849 92
d_worrall 0:843654413849 93 str.insert(0, nullArray);
d_worrall 0:843654413849 94 str.insert(str.length(), nullArray);
d_worrall 0:843654413849 95
d_worrall 0:843654413849 96 for(int k = 0; k < str.length(); k++){
d_worrall 0:843654413849 97 str.copy(buffer, 6, k);
d_worrall 0:843654413849 98 write(buffer);
d_worrall 0:843654413849 99 wait(speed);
d_worrall 0:843654413849 100 }
d_worrall 0:843654413849 101 }
d_worrall 0:843654413849 102
d_worrall 0:843654413849 103
d_worrall 0:843654413849 104
d_worrall 0:843654413849 105
d_worrall 0:843654413849 106
d_worrall 0:843654413849 107
d_worrall 0:843654413849 108
d_worrall 0:843654413849 109
d_worrall 0:843654413849 110