LCD4884
Dependents: 15A-ClassProjectFinal_masterfull-pae-za-leng
Fork of LCD4884 by
LCD4884.cpp@0:28f3c9274ea7, 2013-03-09 (annotated)
- Committer:
- COX
- Date:
- Sat Mar 09 21:07:35 2013 +0000
- Revision:
- 0:28f3c9274ea7
- Child:
- 1:480f22b7e9ae
draft...; first working version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
COX | 0:28f3c9274ea7 | 1 | /* |
COX | 0:28f3c9274ea7 | 2 | Modified by COX |
COX | 0:28f3c9274ea7 | 3 | version 0.1 |
COX | 0:28f3c9274ea7 | 4 | |
COX | 0:28f3c9274ea7 | 5 | Editor : COX |
COX | 0:28f3c9274ea7 | 6 | Date : 06.03.2013 |
COX | 0:28f3c9274ea7 | 7 | |
COX | 0:28f3c9274ea7 | 8 | * |
COX | 0:28f3c9274ea7 | 9 | * Update DFRobot source to work on FRDM KL25Z |
COX | 0:28f3c9274ea7 | 10 | * |
COX | 0:28f3c9274ea7 | 11 | */ |
COX | 0:28f3c9274ea7 | 12 | |
COX | 0:28f3c9274ea7 | 13 | #include "LCD4884.h" |
COX | 0:28f3c9274ea7 | 14 | #include "font_6x8.h" |
COX | 0:28f3c9274ea7 | 15 | #include "font_big.h" |
COX | 0:28f3c9274ea7 | 16 | |
COX | 0:28f3c9274ea7 | 17 | DigitalOut SpiClk(SPI_SCK); //2- Serial Clock(Master Output) |
COX | 0:28f3c9274ea7 | 18 | DigitalOut SpiMosi(SPI_MOSI); //3- Master Output,Slave Input |
COX | 0:28f3c9274ea7 | 19 | DigitalOut LcdDC(LCD_DC); //4- Data/Command(command active low) |
COX | 0:28f3c9274ea7 | 20 | DigitalOut SpiCS(SPI_CS); //5- Chip Select,Slave Transmit Enable(active low,Master Output) |
COX | 0:28f3c9274ea7 | 21 | DigitalOut LcdRst(LCD_RST); //6- One Reset button |
COX | 0:28f3c9274ea7 | 22 | PwmOut LcdBl(LCD_BL); //7- LCD backlight |
COX | 0:28f3c9274ea7 | 23 | |
COX | 0:28f3c9274ea7 | 24 | LCD4884::LCD4884() |
COX | 0:28f3c9274ea7 | 25 | {}; |
COX | 0:28f3c9274ea7 | 26 | |
COX | 0:28f3c9274ea7 | 27 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 28 | void LCD4884::backlight(float dat) |
COX | 0:28f3c9274ea7 | 29 | { |
COX | 0:28f3c9274ea7 | 30 | LcdBl = dat; |
COX | 0:28f3c9274ea7 | 31 | } |
COX | 0:28f3c9274ea7 | 32 | |
COX | 0:28f3c9274ea7 | 33 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 34 | void LCD4884::LCD_init(void) |
COX | 0:28f3c9274ea7 | 35 | { |
COX | 0:28f3c9274ea7 | 36 | /* pin intializer */ |
COX | 0:28f3c9274ea7 | 37 | SpiClk = LOW; |
COX | 0:28f3c9274ea7 | 38 | SpiMosi = LOW; |
COX | 0:28f3c9274ea7 | 39 | SpiCS = LOW; |
COX | 0:28f3c9274ea7 | 40 | LcdDC = LOW; |
COX | 0:28f3c9274ea7 | 41 | LcdBl = LOW; |
COX | 0:28f3c9274ea7 | 42 | |
COX | 0:28f3c9274ea7 | 43 | LcdRst = LOW; |
COX | 0:28f3c9274ea7 | 44 | wait(ONE_US); |
COX | 0:28f3c9274ea7 | 45 | LcdRst = HIGH; |
COX | 0:28f3c9274ea7 | 46 | |
COX | 0:28f3c9274ea7 | 47 | SpiCS = LOW; //Chip Select, Slave Transmit Enable(active low, Master Output) |
COX | 0:28f3c9274ea7 | 48 | wait(ONE_US); |
COX | 0:28f3c9274ea7 | 49 | SpiCS = HIGH; |
COX | 0:28f3c9274ea7 | 50 | wait(ONE_US); |
COX | 0:28f3c9274ea7 | 51 | LcdBl = LCD_INITIAL_BRIGHTNESS; |
COX | 0:28f3c9274ea7 | 52 | |
COX | 0:28f3c9274ea7 | 53 | //data_type=0, all are command bytes |
COX | 0:28f3c9274ea7 | 54 | LCD_write_byte(0x21, 0); //Function Set:0 0 1 0 0 PD V H=0010 0001;PD=0,V=0,H=1; |
COX | 0:28f3c9274ea7 | 55 | LCD_write_byte(0xc0, 0); //Set Vop:1 Vop6 Vop5 Vop4 Vop3 Vop2 Vop1 Vop0=1100 0000 |
COX | 0:28f3c9274ea7 | 56 | LCD_write_byte(0x06, 0); //Set Temperature Coefficient:0 0 0 0 0 1 Tc1 Tc0=0000 0110;Tc1=1,Tc0=0(Vlcd temperature coefficient 2) |
COX | 0:28f3c9274ea7 | 57 | LCD_write_byte(0x13, 0); //Set Bias System (BSx):0 0 0 1 0 BS2 BS1 BS0=0001 0011;BS2=0, BS1=1, BS0=1==>N=4,MUX RATE=1:48 |
COX | 0:28f3c9274ea7 | 58 | |
COX | 0:28f3c9274ea7 | 59 | LCD_write_byte(0x20, 0);//Function Set:0 0 1 0 0 PD V H=0010 0000;PD=0,V=0,H=0; |
COX | 0:28f3c9274ea7 | 60 | LCD_clear(); |
COX | 0:28f3c9274ea7 | 61 | LCD_write_byte(0x0c, 0);//Display Control: 0 0 0 0 1 D 0 E=0000 1100 ;D=1,E=0:normal mode |
COX | 0:28f3c9274ea7 | 62 | |
COX | 0:28f3c9274ea7 | 63 | SpiCS = LOW; |
COX | 0:28f3c9274ea7 | 64 | } |
COX | 0:28f3c9274ea7 | 65 | |
COX | 0:28f3c9274ea7 | 66 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 67 | void LCD4884::LCD_write_byte(unsigned char dat, unsigned char dat_type) |
COX | 0:28f3c9274ea7 | 68 | { |
COX | 0:28f3c9274ea7 | 69 | unsigned int i; |
COX | 0:28f3c9274ea7 | 70 | SpiCS = LOW; //Chip Enable:Active LOW |
COX | 0:28f3c9274ea7 | 71 | |
COX | 0:28f3c9274ea7 | 72 | if (dat_type == 0) |
COX | 0:28f3c9274ea7 | 73 | LcdDC = LOW; // D/C=0:the current data byte is interpreted as command byte |
COX | 0:28f3c9274ea7 | 74 | else |
COX | 0:28f3c9274ea7 | 75 | LcdDC = HIGH; // D/C=1:write data to display RAM |
COX | 0:28f3c9274ea7 | 76 | |
COX | 0:28f3c9274ea7 | 77 | for(i=0;i<8;i++) |
COX | 0:28f3c9274ea7 | 78 | { |
COX | 0:28f3c9274ea7 | 79 | if(dat&0x80) //1000 0000 |
COX | 0:28f3c9274ea7 | 80 | { |
COX | 0:28f3c9274ea7 | 81 | SpiMosi = HIGH; |
COX | 0:28f3c9274ea7 | 82 | } |
COX | 0:28f3c9274ea7 | 83 | else |
COX | 0:28f3c9274ea7 | 84 | { |
COX | 0:28f3c9274ea7 | 85 | SpiMosi = LOW; |
COX | 0:28f3c9274ea7 | 86 | } |
COX | 0:28f3c9274ea7 | 87 | SpiClk = LOW; |
COX | 0:28f3c9274ea7 | 88 | dat = dat << 1; |
COX | 0:28f3c9274ea7 | 89 | SpiClk = HIGH; |
COX | 0:28f3c9274ea7 | 90 | } |
COX | 0:28f3c9274ea7 | 91 | SpiCS = HIGH; |
COX | 0:28f3c9274ea7 | 92 | } |
COX | 0:28f3c9274ea7 | 93 | |
COX | 0:28f3c9274ea7 | 94 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 95 | void LCD4884::LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map, |
COX | 0:28f3c9274ea7 | 96 | unsigned char Pix_x,unsigned char Pix_y) |
COX | 0:28f3c9274ea7 | 97 | { |
COX | 0:28f3c9274ea7 | 98 | unsigned int i,n; |
COX | 0:28f3c9274ea7 | 99 | unsigned char row; |
COX | 0:28f3c9274ea7 | 100 | |
COX | 0:28f3c9274ea7 | 101 | if (Pix_y%8==0) |
COX | 0:28f3c9274ea7 | 102 | row=Pix_y/8; //row from 1 to 6;Pix_y from R0 to R47 |
COX | 0:28f3c9274ea7 | 103 | else |
COX | 0:28f3c9274ea7 | 104 | row=Pix_y/8+1; //Quotient+1 |
COX | 0:28f3c9274ea7 | 105 | |
COX | 0:28f3c9274ea7 | 106 | for (n=0;n<row;n++) |
COX | 0:28f3c9274ea7 | 107 | { |
COX | 0:28f3c9274ea7 | 108 | LCD_set_XY(X,Y); |
COX | 0:28f3c9274ea7 | 109 | for(i=0; i<Pix_x; i++) |
COX | 0:28f3c9274ea7 | 110 | { |
COX | 0:28f3c9274ea7 | 111 | LCD_write_byte(map[i+n*Pix_x], 1); // D/C=1:write data to display RAM |
COX | 0:28f3c9274ea7 | 112 | } |
COX | 0:28f3c9274ea7 | 113 | Y++; |
COX | 0:28f3c9274ea7 | 114 | } |
COX | 0:28f3c9274ea7 | 115 | } |
COX | 0:28f3c9274ea7 | 116 | |
COX | 0:28f3c9274ea7 | 117 | /**************************************************************************************/ |
COX | 0:28f3c9274ea7 | 118 | void LCD4884::LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode) |
COX | 0:28f3c9274ea7 | 119 | { |
COX | 0:28f3c9274ea7 | 120 | LCD_set_XY(X,Y); |
COX | 0:28f3c9274ea7 | 121 | while (*s) |
COX | 0:28f3c9274ea7 | 122 | { |
COX | 0:28f3c9274ea7 | 123 | LCD_write_char(*s, mode); |
COX | 0:28f3c9274ea7 | 124 | s++; |
COX | 0:28f3c9274ea7 | 125 | } |
COX | 0:28f3c9274ea7 | 126 | } |
COX | 0:28f3c9274ea7 | 127 | |
COX | 0:28f3c9274ea7 | 128 | /**************************************************************************************/ |
COX | 0:28f3c9274ea7 | 129 | void LCD4884::LCD_prop_write_string(unsigned char X,unsigned char Y,char *s, char mode) |
COX | 0:28f3c9274ea7 | 130 | { |
COX | 0:28f3c9274ea7 | 131 | LCD_set_XY(X,Y); |
COX | 0:28f3c9274ea7 | 132 | while (*s) |
COX | 0:28f3c9274ea7 | 133 | { |
COX | 0:28f3c9274ea7 | 134 | LCD_prop_write_char(*s, mode); |
COX | 0:28f3c9274ea7 | 135 | s++; |
COX | 0:28f3c9274ea7 | 136 | } |
COX | 0:28f3c9274ea7 | 137 | } |
COX | 0:28f3c9274ea7 | 138 | |
COX | 0:28f3c9274ea7 | 139 | /*************************************************************************************/ |
COX | 0:28f3c9274ea7 | 140 | void LCD4884::LCD_write_chinese(unsigned char X, unsigned char Y,unsigned char *c,unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row) |
COX | 0:28f3c9274ea7 | 141 | { |
COX | 0:28f3c9274ea7 | 142 | unsigned char i,n; |
COX | 0:28f3c9274ea7 | 143 | LCD_set_XY(X,Y); |
COX | 0:28f3c9274ea7 | 144 | for (i=0;i<num;) |
COX | 0:28f3c9274ea7 | 145 | { |
COX | 0:28f3c9274ea7 | 146 | for (n=0; n<ch_with*2; n++) |
COX | 0:28f3c9274ea7 | 147 | { |
COX | 0:28f3c9274ea7 | 148 | if (n==ch_with) |
COX | 0:28f3c9274ea7 | 149 | { |
COX | 0:28f3c9274ea7 | 150 | if (i==0) |
COX | 0:28f3c9274ea7 | 151 | LCD_set_XY(X,Y+1); |
COX | 0:28f3c9274ea7 | 152 | else |
COX | 0:28f3c9274ea7 | 153 | LCD_set_XY((X+(ch_with+row)*i),Y+1); |
COX | 0:28f3c9274ea7 | 154 | } |
COX | 0:28f3c9274ea7 | 155 | LCD_write_byte(c[(i*ch_with*2)+n],1); |
COX | 0:28f3c9274ea7 | 156 | } |
COX | 0:28f3c9274ea7 | 157 | i++; |
COX | 0:28f3c9274ea7 | 158 | LCD_set_XY((X+(ch_with+row)*i),Y); |
COX | 0:28f3c9274ea7 | 159 | } |
COX | 0:28f3c9274ea7 | 160 | } |
COX | 0:28f3c9274ea7 | 161 | |
COX | 0:28f3c9274ea7 | 162 | |
COX | 0:28f3c9274ea7 | 163 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 164 | void LCD4884::LCD_write_string_big ( unsigned char X,unsigned char Y, char *string, char mode ) |
COX | 0:28f3c9274ea7 | 165 | { |
COX | 0:28f3c9274ea7 | 166 | while ( *string ) |
COX | 0:28f3c9274ea7 | 167 | { |
COX | 0:28f3c9274ea7 | 168 | LCD_write_char_big( X, Y, *string , mode ); |
COX | 0:28f3c9274ea7 | 169 | |
COX | 0:28f3c9274ea7 | 170 | if(*string++ == '.') |
COX | 0:28f3c9274ea7 | 171 | X += 5; |
COX | 0:28f3c9274ea7 | 172 | else |
COX | 0:28f3c9274ea7 | 173 | X += 12; |
COX | 0:28f3c9274ea7 | 174 | } |
COX | 0:28f3c9274ea7 | 175 | } |
COX | 0:28f3c9274ea7 | 176 | |
COX | 0:28f3c9274ea7 | 177 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 178 | /* write char in big font */ |
COX | 0:28f3c9274ea7 | 179 | void LCD4884::LCD_write_char_big (unsigned char X,unsigned char Y, unsigned char ch, char mode) |
COX | 0:28f3c9274ea7 | 180 | { |
COX | 0:28f3c9274ea7 | 181 | unsigned char i, j; |
COX | 0:28f3c9274ea7 | 182 | unsigned char *pFont; |
COX | 0:28f3c9274ea7 | 183 | unsigned char ch_dat; |
COX | 0:28f3c9274ea7 | 184 | |
COX | 0:28f3c9274ea7 | 185 | pFont = (unsigned char *) big_number; |
COX | 0:28f3c9274ea7 | 186 | |
COX | 0:28f3c9274ea7 | 187 | if(ch == '.') |
COX | 0:28f3c9274ea7 | 188 | ch = 10; |
COX | 0:28f3c9274ea7 | 189 | else if (ch == '+') |
COX | 0:28f3c9274ea7 | 190 | ch = 11; |
COX | 0:28f3c9274ea7 | 191 | else if (ch == '-') |
COX | 0:28f3c9274ea7 | 192 | ch = 12; |
COX | 0:28f3c9274ea7 | 193 | else |
COX | 0:28f3c9274ea7 | 194 | ch = ch & 0x0f; |
COX | 0:28f3c9274ea7 | 195 | |
COX | 0:28f3c9274ea7 | 196 | for(i=0;i<3;i++) |
COX | 0:28f3c9274ea7 | 197 | { |
COX | 0:28f3c9274ea7 | 198 | LCD_set_XY ( X, Y+i); |
COX | 0:28f3c9274ea7 | 199 | |
COX | 0:28f3c9274ea7 | 200 | for(j=0; j<16; j++) |
COX | 0:28f3c9274ea7 | 201 | { |
COX | 0:28f3c9274ea7 | 202 | ch_dat = *(pFont+ch*48 + i*16 +j); |
COX | 0:28f3c9274ea7 | 203 | LCD_write_byte( (mode == MENU_NORMAL)? ch_dat : (ch_dat^0xff), 1); |
COX | 0:28f3c9274ea7 | 204 | } |
COX | 0:28f3c9274ea7 | 205 | } |
COX | 0:28f3c9274ea7 | 206 | } |
COX | 0:28f3c9274ea7 | 207 | |
COX | 0:28f3c9274ea7 | 208 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 209 | void LCD4884::LCD_write_char(unsigned char c, char mode) |
COX | 0:28f3c9274ea7 | 210 | { |
COX | 0:28f3c9274ea7 | 211 | unsigned char line; |
COX | 0:28f3c9274ea7 | 212 | unsigned char *pFont; |
COX | 0:28f3c9274ea7 | 213 | unsigned char ch; |
COX | 0:28f3c9274ea7 | 214 | |
COX | 0:28f3c9274ea7 | 215 | pFont = (unsigned char *)font6_8; //pointer *pFont points at font6_8[][6] |
COX | 0:28f3c9274ea7 | 216 | c -= 32; // the ASCII of "SP" is 32 |
COX | 0:28f3c9274ea7 | 217 | |
COX | 0:28f3c9274ea7 | 218 | for (line=0; line<6; line++) |
COX | 0:28f3c9274ea7 | 219 | { |
COX | 0:28f3c9274ea7 | 220 | ch = *(pFont+c*6+line); //read c from the font6_8[][6] (the detail information is in the "font6x8.h") |
COX | 0:28f3c9274ea7 | 221 | LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); //MENU_NORMAL=0,True:return ch;False:return ch |
COX | 0:28f3c9274ea7 | 222 | } |
COX | 0:28f3c9274ea7 | 223 | } |
COX | 0:28f3c9274ea7 | 224 | |
COX | 0:28f3c9274ea7 | 225 | /*******************************************************************/ |
COX | 0:28f3c9274ea7 | 226 | unsigned char LCD4884::LCD_prop_write_char(unsigned char c, char mode) |
COX | 0:28f3c9274ea7 | 227 | { |
COX | 0:28f3c9274ea7 | 228 | int line, line_s=0, line_e=2; |
COX | 0:28f3c9274ea7 | 229 | unsigned char *pFont; |
COX | 0:28f3c9274ea7 | 230 | unsigned char ch; |
COX | 0:28f3c9274ea7 | 231 | |
COX | 0:28f3c9274ea7 | 232 | pFont = (unsigned char *)font6_8; |
COX | 0:28f3c9274ea7 | 233 | if (c -= 32) |
COX | 0:28f3c9274ea7 | 234 | { |
COX | 0:28f3c9274ea7 | 235 | for (line_s=0; line_s<6; line_s++) |
COX | 0:28f3c9274ea7 | 236 | { |
COX | 0:28f3c9274ea7 | 237 | if(*(pFont+c*6+line_s)) |
COX | 0:28f3c9274ea7 | 238 | break; |
COX | 0:28f3c9274ea7 | 239 | } |
COX | 0:28f3c9274ea7 | 240 | for (line_e=5; line_e<0; line_e--) |
COX | 0:28f3c9274ea7 | 241 | { |
COX | 0:28f3c9274ea7 | 242 | if(*(pFont+c*6+line_e)) |
COX | 0:28f3c9274ea7 | 243 | break; |
COX | 0:28f3c9274ea7 | 244 | } |
COX | 0:28f3c9274ea7 | 245 | } |
COX | 0:28f3c9274ea7 | 246 | for (line=line_s; line<line_e+1; line++) |
COX | 0:28f3c9274ea7 | 247 | { |
COX | 0:28f3c9274ea7 | 248 | ch = *(pFont+c*6+line); |
COX | 0:28f3c9274ea7 | 249 | LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); |
COX | 0:28f3c9274ea7 | 250 | } |
COX | 0:28f3c9274ea7 | 251 | LCD_write_byte( (mode==MENU_NORMAL)? 0:0xff, 1); |
COX | 0:28f3c9274ea7 | 252 | return ((unsigned char)(line_e+2 - line_s)); |
COX | 0:28f3c9274ea7 | 253 | } |
COX | 0:28f3c9274ea7 | 254 | |
COX | 0:28f3c9274ea7 | 255 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 256 | void LCD4884::LCD_set_XY(unsigned char X, unsigned char Y) |
COX | 0:28f3c9274ea7 | 257 | { |
COX | 0:28f3c9274ea7 | 258 | LCD_write_byte(0x40 | Y, 0); // column |
COX | 0:28f3c9274ea7 | 259 | LCD_write_byte(0x80 | X, 0); // row |
COX | 0:28f3c9274ea7 | 260 | } |
COX | 0:28f3c9274ea7 | 261 | |
COX | 0:28f3c9274ea7 | 262 | /******************************************************************/ |
COX | 0:28f3c9274ea7 | 263 | void LCD4884::LCD_clear(void) |
COX | 0:28f3c9274ea7 | 264 | { |
COX | 0:28f3c9274ea7 | 265 | unsigned int i; |
COX | 0:28f3c9274ea7 | 266 | |
COX | 0:28f3c9274ea7 | 267 | LCD_write_byte(0x0c, 0); |
COX | 0:28f3c9274ea7 | 268 | LCD_write_byte(0x80, 0); |
COX | 0:28f3c9274ea7 | 269 | |
COX | 0:28f3c9274ea7 | 270 | for (i=0; i<504; i++) //6*84 |
COX | 0:28f3c9274ea7 | 271 | { |
COX | 0:28f3c9274ea7 | 272 | LCD_write_byte(0, 1); |
COX | 0:28f3c9274ea7 | 273 | } |
COX | 0:28f3c9274ea7 | 274 | } |
COX | 0:28f3c9274ea7 | 275 |