Test mbed1.

Dependencies:   mbed-src

Committer:
mja054
Date:
Thu Mar 13 16:23:16 2014 +0000
Revision:
1:1019095e41c4
capability to add input.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mja054 1:1019095e41c4 1 #include "SLCD.h"
mja054 1:1019095e41c4 2 #include "LCDconfig.h"
mja054 1:1019095e41c4 3
mja054 1:1019095e41c4 4
mja054 1:1019095e41c4 5 const uint8_t WF_ORDERING_TABLE[ ] =
mja054 1:1019095e41c4 6 {
mja054 1:1019095e41c4 7 CHAR1a, // LCD81 --- Pin:5 LCDnAddress=51
mja054 1:1019095e41c4 8 CHAR1b, // LCD82 --- Pin:6 LCDnAddress=52
mja054 1:1019095e41c4 9 CHAR2a, // LCD83 --- Pin:7 LCDnAddress=53
mja054 1:1019095e41c4 10 CHAR2b, // LCD84 --- Pin:8 LCDnAddress=54
mja054 1:1019095e41c4 11 CHAR3a, // LCD85 --- Pin:9 LCDnAddress=55
mja054 1:1019095e41c4 12 CHAR3b, // LCD86 --- Pin:10 LCDnAddress=56
mja054 1:1019095e41c4 13 CHAR4a, // LCD87 --- Pin:11 LCDnAddress=57
mja054 1:1019095e41c4 14 CHAR4b, // LCD88 --- Pin:12 LCDnAddress=58
mja054 1:1019095e41c4 15 CHARCOM0, // LCD77 --- Pin:1 LCDnAddress=4D
mja054 1:1019095e41c4 16 CHARCOM1, // LCD78 --- Pin:2 LCDnAddress=4E
mja054 1:1019095e41c4 17 CHARCOM2, // LCD79 --- Pin:3 LCDnAddress=4F
mja054 1:1019095e41c4 18 CHARCOM3, // LCD80 --- Pin:4 LCDnAddress=50
mja054 1:1019095e41c4 19 };
mja054 1:1019095e41c4 20
mja054 1:1019095e41c4 21 const char ASCII_TO_WF_CODIFICATION_TABLE [ ] =
mja054 1:1019095e41c4 22 {
mja054 1:1019095e41c4 23
mja054 1:1019095e41c4 24 /*
mja054 1:1019095e41c4 25 segA
mja054 1:1019095e41c4 26 ________
mja054 1:1019095e41c4 27 | |
mja054 1:1019095e41c4 28 segF | | segB
mja054 1:1019095e41c4 29 | |
mja054 1:1019095e41c4 30 -segG--
mja054 1:1019095e41c4 31 | |
mja054 1:1019095e41c4 32 segE | | segC
mja054 1:1019095e41c4 33 |________|
mja054 1:1019095e41c4 34 segD
mja054 1:1019095e41c4 35 */
mja054 1:1019095e41c4 36
mja054 1:1019095e41c4 37 ( SEGD+ SEGE+ SEGF+!SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = 0, offset=0
mja054 1:1019095e41c4 38 (!SEGD+!SEGE+!SEGF+!SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = 1, offset=4
mja054 1:1019095e41c4 39 ( SEGD+ SEGE+!SEGF+ SEGG) , (!SEGC+ SEGB+ SEGA) ,//Char = 2, offset=8
mja054 1:1019095e41c4 40 ( SEGD+!SEGE+!SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = 3, offset=12
mja054 1:1019095e41c4 41 (!SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = 4, offset=16
mja054 1:1019095e41c4 42 ( SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+ SEGA) ,//Char = 5, offset=20
mja054 1:1019095e41c4 43 ( SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+ SEGA) ,//Char = 6, offset=24
mja054 1:1019095e41c4 44 (!SEGD+!SEGE+!SEGF+!SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = 7, offset=28
mja054 1:1019095e41c4 45 ( SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = 8, offset=32
mja054 1:1019095e41c4 46 ( SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = 9, offset=36
mja054 1:1019095e41c4 47 (!SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = :, offset=40
mja054 1:1019095e41c4 48 (!SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = ;, offset=44
mja054 1:1019095e41c4 49 (!SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = <, offset=48
mja054 1:1019095e41c4 50 ( SEGD+!SEGE+!SEGF+ SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = =, offset=52
mja054 1:1019095e41c4 51 (!SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = >, offset=56
mja054 1:1019095e41c4 52 (!SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = ?, offset=60
mja054 1:1019095e41c4 53 ( SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = @, offset=64
mja054 1:1019095e41c4 54 (!SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = A, offset=68
mja054 1:1019095e41c4 55 ( SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+!SEGA) ,//Char = B, offset=72
mja054 1:1019095e41c4 56 ( SEGD+ SEGE+ SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = C, offset=76
mja054 1:1019095e41c4 57 ( SEGD+ SEGE+!SEGF+ SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = D, offset=80
mja054 1:1019095e41c4 58 ( SEGD+ SEGE+ SEGF+ SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = E, offset=84
mja054 1:1019095e41c4 59 (!SEGD+ SEGE+ SEGF+ SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = F, offset=88
mja054 1:1019095e41c4 60 ( SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+ SEGA) ,//Char = G, offset=92
mja054 1:1019095e41c4 61 (!SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = H, offset=96
mja054 1:1019095e41c4 62 (!SEGD+!SEGE+!SEGF+!SEGG) , ( SEGC+!SEGB+!SEGA) ,//Char = I, offset=100
mja054 1:1019095e41c4 63 ( SEGD+ SEGE+!SEGF+!SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = J, offset=104
mja054 1:1019095e41c4 64 (!SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+ SEGA) ,//Char = K, offset=108
mja054 1:1019095e41c4 65 ( SEGD+ SEGE+ SEGF+!SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = L, offset=112
mja054 1:1019095e41c4 66 (!SEGD+ SEGE+ SEGF+!SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = M, offset=116
mja054 1:1019095e41c4 67 (!SEGD+ SEGE+!SEGF+ SEGG) , ( SEGC+!SEGB+!SEGA) ,//Char = N, offset=120
mja054 1:1019095e41c4 68 ( SEGD+ SEGE+!SEGF+ SEGG) , ( SEGC+!SEGB+!SEGA) ,//Char = O, offset=124
mja054 1:1019095e41c4 69 (!SEGD+ SEGE+ SEGF+ SEGG) , (!SEGC+ SEGB+ SEGA) ,//Char = P, offset=128
mja054 1:1019095e41c4 70 ( SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+ SEGA) ,//Char = Q, offset=132
mja054 1:1019095e41c4 71 (!SEGD+ SEGE+!SEGF+ SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = R, offset=136
mja054 1:1019095e41c4 72 ( SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+!SEGB+ SEGA) ,//Char = S, offset=140
mja054 1:1019095e41c4 73 ( SEGD+ SEGE+ SEGF+ SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = T, offset=144
mja054 1:1019095e41c4 74 ( SEGD+ SEGE+ SEGF+!SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = U, offset=148
mja054 1:1019095e41c4 75 ( SEGD+ SEGE+!SEGF+!SEGG) , ( SEGC+!SEGB+!SEGA) ,//Char = V, offset=152
mja054 1:1019095e41c4 76 ( SEGD+ SEGE+ SEGF+!SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = W, offset=156
mja054 1:1019095e41c4 77 (!SEGD+ SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = X, offset=160
mja054 1:1019095e41c4 78 ( SEGD+!SEGE+ SEGF+ SEGG) , ( SEGC+ SEGB+!SEGA) ,//Char = Y, offset=164
mja054 1:1019095e41c4 79 ( SEGD+!SEGE+!SEGF+ SEGG) , (!SEGC+!SEGB+!SEGA) ,//Char = Z, offset=168
mja054 1:1019095e41c4 80 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = [, offset=172
mja054 1:1019095e41c4 81 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = \, offset=176
mja054 1:1019095e41c4 82 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = ], offset=180
mja054 1:1019095e41c4 83 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = ^, offset=184
mja054 1:1019095e41c4 84 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = _, offset=188
mja054 1:1019095e41c4 85 ( SEGD+!SEGE+!SEGF+!SEGG) , (!SEGC+!SEGB+ SEGA) ,//Char = `, offset=192
mja054 1:1019095e41c4 86 };
mja054 1:1019095e41c4 87
mja054 1:1019095e41c4 88 SLCD::SLCD() {
mja054 1:1019095e41c4 89 init();
mja054 1:1019095e41c4 90 CharPosition = 0;
mja054 1:1019095e41c4 91 }
mja054 1:1019095e41c4 92
mja054 1:1019095e41c4 93 void SLCD::init(){
mja054 1:1019095e41c4 94 SIM->SCGC5 |= SIM_SCGC5_SLCD_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
mja054 1:1019095e41c4 95
mja054 1:1019095e41c4 96 // configure pins for LCD operation
mja054 1:1019095e41c4 97 PORTC->PCR[20] = 0x00000000; //VLL2
mja054 1:1019095e41c4 98 PORTC->PCR[21] = 0x00000000; //VLL1
mja054 1:1019095e41c4 99 PORTC->PCR[22] = 0x00000000; //VCAP2
mja054 1:1019095e41c4 100 PORTC->PCR[23] = 0x00000000; //VCAP1
mja054 1:1019095e41c4 101 // Enable IRCLK
mja054 1:1019095e41c4 102 MCG->C1 = MCG_C1_IRCLKEN_MASK | MCG_C1_IREFSTEN_MASK;
mja054 1:1019095e41c4 103 MCG->C2 &= ~MCG_C2_IRCS_MASK ; //0 32KHZ internal reference clock; 1= 4MHz irc
mja054 1:1019095e41c4 104 LCD->GCR = 0x0;
mja054 1:1019095e41c4 105 LCD->AR = 0x0;
mja054 1:1019095e41c4 106 // LCD configurartion
mja054 1:1019095e41c4 107 LCD->GCR = ( LCD_GCR_RVEN_MASK*_LCDRVEN
mja054 1:1019095e41c4 108 | LCD_GCR_RVTRIM(_LCDRVTRIM) //0-15
mja054 1:1019095e41c4 109 | LCD_GCR_CPSEL_MASK*_LCDCPSEL
mja054 1:1019095e41c4 110 | LCD_GCR_LADJ(_LCDLOADADJUST) //0-3
mja054 1:1019095e41c4 111 | LCD_GCR_VSUPPLY_MASK*_LCDSUPPLY //0-1
mja054 1:1019095e41c4 112 |!LCD_GCR_FDCIEN_MASK
mja054 1:1019095e41c4 113 | LCD_GCR_ALTDIV(_LCDALTDIV) //0-3
mja054 1:1019095e41c4 114 |!LCD_GCR_LCDDOZE_MASK
mja054 1:1019095e41c4 115 |!LCD_GCR_LCDSTP_MASK
mja054 1:1019095e41c4 116 |!LCD_GCR_LCDEN_MASK //WILL BE ENABLE ON SUBSEQUENT STEP
mja054 1:1019095e41c4 117 | LCD_GCR_SOURCE_MASK*_LCDCLKSOURCE
mja054 1:1019095e41c4 118 | LCD_GCR_ALTSOURCE_MASK*_LCDALRCLKSOURCE
mja054 1:1019095e41c4 119 | LCD_GCR_LCLK(_LCDLCK) //0-7
mja054 1:1019095e41c4 120 | LCD_GCR_DUTY(_LCDDUTY) //0-7
mja054 1:1019095e41c4 121 );
mja054 1:1019095e41c4 122 uint8_t i;
mja054 1:1019095e41c4 123 uint32_t *p_pen;
mja054 1:1019095e41c4 124 uint8_t pen_offset; // 0 or 1
mja054 1:1019095e41c4 125 uint8_t pen_bit; // 0 to 31
mja054 1:1019095e41c4 126 LCD->PEN[0] = 0x0;
mja054 1:1019095e41c4 127 LCD->PEN[1] = 0x0;
mja054 1:1019095e41c4 128 LCD->BPEN[0] = 0x0;
mja054 1:1019095e41c4 129 LCD->BPEN[1] = 0x0;
mja054 1:1019095e41c4 130 p_pen = (uint32_t *)&LCD->PEN[0];
mja054 1:1019095e41c4 131 for (i=0;i<_LCDUSEDPINS;i++)
mja054 1:1019095e41c4 132 {
mja054 1:1019095e41c4 133 pen_offset = WF_ORDERING_TABLE[i]/32;
mja054 1:1019095e41c4 134 pen_bit = WF_ORDERING_TABLE[i]%32;
mja054 1:1019095e41c4 135 p_pen[pen_offset] |= 1 << pen_bit;
mja054 1:1019095e41c4 136 if (i>= _LCDFRONTPLANES) // Pin is a backplane
mja054 1:1019095e41c4 137 {
mja054 1:1019095e41c4 138 p_pen[pen_offset+2] |= 1 << pen_bit; // Enable BPEN
mja054 1:1019095e41c4 139 LCD->WF8B[(uint8_t)WF_ORDERING_TABLE[i]] = 1 << (i - _LCDFRONTPLANES); // fill with 0x01, 0x02, etc
mja054 1:1019095e41c4 140 }
mja054 1:1019095e41c4 141 }
mja054 1:1019095e41c4 142 LCD->GCR |= LCD_GCR_LCDEN_MASK;
mja054 1:1019095e41c4 143 }
mja054 1:1019095e41c4 144
mja054 1:1019095e41c4 145 int SLCD::_putc(int c) {
mja054 1:1019095e41c4 146 Write_Char(c);
mja054 1:1019095e41c4 147 return 0;
mja054 1:1019095e41c4 148 }
mja054 1:1019095e41c4 149
mja054 1:1019095e41c4 150 void SLCD::Write_Char (char lbValue) {
mja054 1:1019095e41c4 151 uint8_t char_val;
mja054 1:1019095e41c4 152 uint8_t temp;
mja054 1:1019095e41c4 153 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 154 uint8_t lbCounter;
mja054 1:1019095e41c4 155 uint16_t arrayOffset;
mja054 1:1019095e41c4 156 uint8_t position;
mja054 1:1019095e41c4 157
mja054 1:1019095e41c4 158 if (CharPosition >= _CHARNUM)
mja054 1:1019095e41c4 159 CharPosition = 0;
mja054 1:1019095e41c4 160 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 161 /* only ascii character if value not writeable write as @ */
mja054 1:1019095e41c4 162 if (lbValue>='a' && lbValue<='z') {
mja054 1:1019095e41c4 163 lbValue -= 32; // UpperCase
mja054 1:1019095e41c4 164 }
mja054 1:1019095e41c4 165 if (lbValue<ASCCI_TABLE_START || lbValue >ASCCI_TABLE_END) {
mja054 1:1019095e41c4 166 lbValue = BLANK_CHARACTER; // default value as space
mja054 1:1019095e41c4 167 }
mja054 1:1019095e41c4 168 lbValue -=ASCCI_TABLE_START; // Remove the offset to search in the ascci table
mja054 1:1019095e41c4 169 arrayOffset = (lbValue * _CHAR_SIZE); // Compensate matrix offset
mja054 1:1019095e41c4 170 // ensure bLCD position is in valid limit
mja054 1:1019095e41c4 171 lbCounter = 0; //number of writings to complete one char
mja054 1:1019095e41c4 172 while (lbCounter<_CHAR_SIZE) {
mja054 1:1019095e41c4 173 position = (CharPosition) *_LCDTYPE + lbCounter;
mja054 1:1019095e41c4 174 temp=0;
mja054 1:1019095e41c4 175 if (lbCounter==1) {
mja054 1:1019095e41c4 176 temp = lbpLCDWF[WF_ORDERING_TABLE[position]] & 0x01;//bit 0 has the special symbol information
mja054 1:1019095e41c4 177 }
mja054 1:1019095e41c4 178 char_val = ASCII_TO_WF_CODIFICATION_TABLE[arrayOffset + lbCounter];
mja054 1:1019095e41c4 179 lbpLCDWF[WF_ORDERING_TABLE[position]] = char_val | temp;
mja054 1:1019095e41c4 180 // if (char_val==0) lbCounter = _CHAR_SIZE; //end of this character
mja054 1:1019095e41c4 181 lbCounter++;
mja054 1:1019095e41c4 182 }
mja054 1:1019095e41c4 183 CharPosition++;
mja054 1:1019095e41c4 184 }
mja054 1:1019095e41c4 185
mja054 1:1019095e41c4 186 void SLCD::Home (void)
mja054 1:1019095e41c4 187 {
mja054 1:1019095e41c4 188 CharPosition = 0;
mja054 1:1019095e41c4 189 }
mja054 1:1019095e41c4 190
mja054 1:1019095e41c4 191 void SLCD::Contrast (uint8_t lbContrast)
mja054 1:1019095e41c4 192 {
mja054 1:1019095e41c4 193 lbContrast &= 0x0F; //Forced to the only values accepted
mja054 1:1019095e41c4 194 LCD->GCR |= LCD_GCR_RVTRIM(lbContrast);
mja054 1:1019095e41c4 195 }
mja054 1:1019095e41c4 196
mja054 1:1019095e41c4 197 void SLCD::All_Segments (int mode)
mja054 1:1019095e41c4 198 {
mja054 1:1019095e41c4 199 uint8_t lbTotalBytes = _CHARNUM * _LCDTYPE;
mja054 1:1019095e41c4 200 uint8_t lbCounter=0;
mja054 1:1019095e41c4 201 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 202
mja054 1:1019095e41c4 203 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 204 while (lbCounter < lbTotalBytes)
mja054 1:1019095e41c4 205 {
mja054 1:1019095e41c4 206 if (mode==1){lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[lbCounter++]]=_ALLON;}
mja054 1:1019095e41c4 207 else {lbpLCDWF[WF_ORDERING_TABLE[lbCounter++]]=0;}
mja054 1:1019095e41c4 208 }
mja054 1:1019095e41c4 209 }
mja054 1:1019095e41c4 210
mja054 1:1019095e41c4 211 void SLCD::DP1 (int mode)
mja054 1:1019095e41c4 212 {
mja054 1:1019095e41c4 213 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 214 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 215 if (mode==1){lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[1]]|=1;}
mja054 1:1019095e41c4 216 else {lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[1]]&=~1;}
mja054 1:1019095e41c4 217 }
mja054 1:1019095e41c4 218
mja054 1:1019095e41c4 219 void SLCD::DP2 (int mode)
mja054 1:1019095e41c4 220 {
mja054 1:1019095e41c4 221 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 222 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 223 if (mode==1){lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[3]]|=1;}
mja054 1:1019095e41c4 224 else {lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[3]]&=~1;}
mja054 1:1019095e41c4 225 }
mja054 1:1019095e41c4 226
mja054 1:1019095e41c4 227 void SLCD::DP3 (int mode)
mja054 1:1019095e41c4 228 {
mja054 1:1019095e41c4 229 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 230 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 231 if (mode==1){lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[5]]|=1;}
mja054 1:1019095e41c4 232 else {lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[5]]&=~1;}
mja054 1:1019095e41c4 233 }
mja054 1:1019095e41c4 234
mja054 1:1019095e41c4 235 void SLCD::Colon (int mode)
mja054 1:1019095e41c4 236 {
mja054 1:1019095e41c4 237 uint8_t *lbpLCDWF;
mja054 1:1019095e41c4 238 lbpLCDWF = (uint8_t *)&LCD->WF8B[0];
mja054 1:1019095e41c4 239 if (mode==1){lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[7]]|=1;}
mja054 1:1019095e41c4 240 else {lbpLCDWF[(uint8_t)WF_ORDERING_TABLE[7]]&=~1;}
mja054 1:1019095e41c4 241 }
mja054 1:1019095e41c4 242
mja054 1:1019095e41c4 243