library
Revision 0:bf9618815a4a, committed 2017-12-08
- Comitter:
- toiy01344
- Date:
- Fri Dec 08 10:15:02 2017 +0000
- Commit message:
- LCD4884
Changed in this revision
diff -r 000000000000 -r bf9618815a4a LCD4884.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD4884.cpp Fri Dec 08 10:15:02 2017 +0000 @@ -0,0 +1,275 @@ +/* +Modified by COX +version 0.1 + +Editor : COX +Date : 06.03.2013 + +* +* Update DFRobot source to work on FRDM KL25Z +* +*/ + +#include "LCD4884.h" +#include "font_6x8.h" +#include "font_big.h" + +DigitalOut SpiClk(D2); //2- Serial Clock(Master Output) +DigitalOut SpiMosi(D3); //3- Master Output,Slave Input +DigitalOut LcdDC(D4); //4- Data/Command(command active low) +DigitalOut SpiCS(D5); //5- Chip Select,Slave Transmit Enable(active low,Master Output) +DigitalOut LcdRst(D6); //6- One Reset button +PwmOut LcdBl(D7); //7- LCD backlight + +LCD4884::LCD4884() +{}; + +/******************************************************************/ +void LCD4884::backlight(float dat) +{ + LcdBl = dat; +} + +/******************************************************************/ +void LCD4884::LCD_init(void) +{ + /* pin intializer */ + SpiClk = LOW; + SpiMosi = LOW; + SpiCS = LOW; + LcdDC = LOW; + LcdBl = LOW; + + LcdRst = LOW; + wait(ONE_US); + LcdRst = HIGH; + + SpiCS = LOW; //Chip Select, Slave Transmit Enable(active low, Master Output) + wait(ONE_US); + SpiCS = HIGH; + wait(ONE_US); + LcdBl = LCD_INITIAL_BRIGHTNESS; + + //data_type=0, all are command bytes + LCD_write_byte(0x21, 0); //Function Set:0 0 1 0 0 PD V H=0010 0001;PD=0,V=0,H=1; + LCD_write_byte(0xc0, 0); //Set Vop:1 Vop6 Vop5 Vop4 Vop3 Vop2 Vop1 Vop0=1100 0000 + 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) + 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 + + LCD_write_byte(0x20, 0);//Function Set:0 0 1 0 0 PD V H=0010 0000;PD=0,V=0,H=0; + LCD_clear(); + LCD_write_byte(0x0c, 0);//Display Control: 0 0 0 0 1 D 0 E=0000 1100 ;D=1,E=0:normal mode + + SpiCS = LOW; +} + +/******************************************************************/ +void LCD4884::LCD_write_byte(unsigned char dat, unsigned char dat_type) +{ + unsigned int i; + SpiCS = LOW; //Chip Enable:Active LOW + + if (dat_type == 0) + LcdDC = LOW; // D/C=0:the current data byte is interpreted as command byte + else + LcdDC = HIGH; // D/C=1:write data to display RAM + + for(i=0;i<8;i++) + { + if(dat&0x80) //1000 0000 + { + SpiMosi = HIGH; + } + else + { + SpiMosi = LOW; + } + SpiClk = LOW; + dat = dat << 1; + SpiClk = HIGH; + } + SpiCS = HIGH; +} + +/******************************************************************/ +void LCD4884::LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map, + unsigned char Pix_x,unsigned char Pix_y) +{ + unsigned int i,n; + unsigned char row; + + if (Pix_y%8==0) + row=Pix_y/8; //row from 1 to 6;Pix_y from R0 to R47 + else + row=Pix_y/8+1; //Quotient+1 + + for (n=0;n<row;n++) + { + LCD_set_XY(X,Y); + for(i=0; i<Pix_x; i++) + { + LCD_write_byte(map[i+n*Pix_x], 1); // D/C=1:write data to display RAM + } + Y++; + } +} + +/**************************************************************************************/ +void LCD4884::LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode) +{ + LCD_set_XY(X,Y); + while (*s) + { + LCD_write_char(*s, mode); + s++; + } +} + +/**************************************************************************************/ +void LCD4884::LCD_prop_write_string(unsigned char X,unsigned char Y,char *s, char mode) +{ + LCD_set_XY(X,Y); + while (*s) + { + LCD_prop_write_char(*s, mode); + s++; + } +} + +/*************************************************************************************/ +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) +{ + unsigned char i,n; + LCD_set_XY(X,Y); + for (i=0;i<num;) + { + for (n=0; n<ch_with*2; n++) + { + if (n==ch_with) + { + if (i==0) + LCD_set_XY(X,Y+1); + else + LCD_set_XY((X+(ch_with+row)*i),Y+1); + } + LCD_write_byte(c[(i*ch_with*2)+n],1); + } + i++; + LCD_set_XY((X+(ch_with+row)*i),Y); + } +} + + +/******************************************************************/ +void LCD4884::LCD_write_string_big ( unsigned char X,unsigned char Y, char *string, char mode ) +{ + while ( *string ) + { + LCD_write_char_big( X, Y, *string , mode ); + + if(*string++ == '.') + X += 5; + else + X += 12; + } +} + +/******************************************************************/ +/* write char in big font */ +void LCD4884::LCD_write_char_big (unsigned char X,unsigned char Y, unsigned char ch, char mode) +{ + unsigned char i, j; + unsigned char *pFont; + unsigned char ch_dat; + + pFont = (unsigned char *) big_number; + + if(ch == '.') + ch = 10; + else if (ch == '+') + ch = 11; + else if (ch == '-') + ch = 12; + else + ch = ch & 0x0f; + + for(i=0;i<3;i++) + { + LCD_set_XY ( X, Y+i); + + for(j=0; j<16; j++) + { + ch_dat = *(pFont+ch*48 + i*16 +j); + LCD_write_byte( (mode == MENU_NORMAL)? ch_dat : (ch_dat^0xff), 1); + } + } +} + +/******************************************************************/ +void LCD4884::LCD_write_char(unsigned char c, char mode) +{ + unsigned char line; + unsigned char *pFont; + unsigned char ch; + + pFont = (unsigned char *)font6_8; //pointer *pFont points at font6_8[][6] + c -= 32; // the ASCII of "SP" is 32 + + for (line=0; line<6; line++) + { + ch = *(pFont+c*6+line); //read c from the font6_8[][6] (the detail information is in the "font6x8.h") + LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); //MENU_NORMAL=0,True:return ch;False:return ch + } +} + +/*******************************************************************/ +unsigned char LCD4884::LCD_prop_write_char(unsigned char c, char mode) +{ + int line, line_s=0, line_e=2; + unsigned char *pFont; + unsigned char ch; + + pFont = (unsigned char *)font6_8; + if (c -= 32) + { + for (line_s=0; line_s<6; line_s++) + { + if(*(pFont+c*6+line_s)) + break; + } + for (line_e=5; line_e<0; line_e--) + { + if(*(pFont+c*6+line_e)) + break; + } + } + for (line=line_s; line<line_e+1; line++) + { + ch = *(pFont+c*6+line); + LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); + } + LCD_write_byte( (mode==MENU_NORMAL)? 0:0xff, 1); + return ((unsigned char)(line_e+2 - line_s)); +} + +/******************************************************************/ +void LCD4884::LCD_set_XY(unsigned char X, unsigned char Y) +{ + LCD_write_byte(0x40 | Y, 0); // column + LCD_write_byte(0x80 | X, 0); // row +} + +/******************************************************************/ +void LCD4884::LCD_clear(void) +{ + unsigned int i; + + LCD_write_byte(0x0c, 0); + LCD_write_byte(0x80, 0); + + for (i=0; i<504; i++) //6*84 + { + LCD_write_byte(0, 1); + } +} +
diff -r 000000000000 -r bf9618815a4a LCD4884.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD4884.h Fri Dec 08 10:15:02 2017 +0000 @@ -0,0 +1,61 @@ +/* +Modified by COX +version 0.1 + +Editor : COX +Date : 06.03.2013 + +* +* Update DFRobot source to work on FRDM KL25Z +* +*/ + +#ifndef LCD4884_h +#define LCD4884_h + +#include "mbed.h" + +// SPI Interface --- (on arduino Arduino Digital Pin 2,3,4,5,6) +#define SPI_SCK D2 //Serial Clock(Master Output) +#define SPI_MOSI D3 //Master Output,Slave Input +#define LCD_DC D4 //Data/Command(command active low) +#define SPI_CS D5 //Chip Select,Slave Transmit Enable(active low,Master Output) +#define LCD_RST D6 //One Reset button +#define LCD_BL D7 //PWM Backlit control (Arduino DIO Pin 7) + + +//display mode -- normal / highlight +#define MENU_NORMAL 0 +#define MENU_HIGHLIGHT 1 +#define OFF 0 +#define ON 1 +#define LOW 0 +#define HIGH 1 +#define ONE_US 0.000001 +#define LCD_INITIAL_BRIGHTNESS 1 + +namespace mbed { + +class LCD4884 +{ + public: + LCD4884(); + void LCD_init(void); + void backlight(float dat); + void LCD_write_byte(unsigned char dat, unsigned char dat_type); + void LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map,unsigned char Pix_x,unsigned char Pix_y); + void LCD_write_string(unsigned char X,unsigned char Y,char *s, char mode); + void LCD_prop_write_string(unsigned char X,unsigned char Y,char *s, char mode); + void 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); + void LCD_write_string_big ( unsigned char X,unsigned char Y, char *string, char mode ); + void LCD_write_char_big (unsigned char X,unsigned char Y, unsigned char ch, char mode); + void LCD_write_char(unsigned char c, char mode); + unsigned char LCD_prop_write_char(unsigned char c, char mode); + void LCD_set_XY(unsigned char X, unsigned char Y); + void LCD_clear(void); + }; +} +extern LCD4884 lcd; + +#endif +
diff -r 000000000000 -r bf9618815a4a font_6x8.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font_6x8.h Fri Dec 08 10:15:02 2017 +0000 @@ -0,0 +1,99 @@ +// 6 x 8 font +// 1 pixel space at left and bottom +// index = ASCII - 32 + +unsigned char font6_8[][6]= +{ + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp + { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! + { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " + { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # + { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ + { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % + { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & + { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' + { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( + { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) + { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * + { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + + { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , + { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - + { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . + { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / + { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 + { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 + { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 + { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 + { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 + { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 + { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 + { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 + { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 + { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 + { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // : + { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; + { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // < + { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // = + { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // > + { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? + { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ + { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A + { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B + { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C + { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D + { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E + { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F + { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G + { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H + { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I + { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J + { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K + { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L + { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M + { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N + { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O + { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P + { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q + { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R + { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S + { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T + { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U + { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V + { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W + { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X + { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y + { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z + { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ + { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55 + { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] + { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ + { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ + { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' + { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a + { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b + { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c + { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d + { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e + { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f + { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g + { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h + { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i + { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j + { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k + { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l + { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m + { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n + { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o + { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p + { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q + { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r + { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s + { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t + { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u + { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v + { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w + { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x + { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y + { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z + { 0x00,0x00, 0x06, 0x09, 0x09, 0x06 } // horiz lines +};
diff -r 000000000000 -r bf9618815a4a font_big.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/font_big.h Fri Dec 08 10:15:02 2017 +0000 @@ -0,0 +1,140 @@ +// big font + + +//******* VERY LARGE FONTS ********** +//used here for displaying temperature + +unsigned char big_number[13][3][16] = { + +0,128,192,224,224,96,224,224, //'0' +192,128,0,0,0,0,0,0 +, +112,255,255,1,0,0,0,0, +255,255,254,0,0,0,0,0 +, +0,15,31,60,56,48,56,56, +31,15,3,0,0,0,0,0 +, + +0,0,0,0,128,224,224,0, //'1' +0,0,0,0,0,0,0,0 +, +0,0,3,3,3,255,255,0, +0,0,0,0,0,0,0,0 +, +0,0,56,56,56,63,63,56, +56,56,0,0,0,0,0,0 +, + +0,192,192,224,96,96,224,224, //'2' +192,128,0,0,0,0,0,0 +, +0,1,0,0,128,192,224,249, +63,31,0,0,0,0,0,0 +, +0,60,62,63,63,59,57,56, +56,56,56,0,0,0,0,0 +, + +0,192,224,224,96,96,224,224, //'3' +192,192,0,0,0,0,0,0 +, +0,1,0,0,48,48,56,125, +239,207,0,0,0,0,0,0 +, +0,28,56,56,48,48,56,60, +31,15,1,0,0,0,0,0 +, + +0,0,0,0,0,128,192,224, //'4' +224,0,0,0,0,0,0,0 +, +224,240,248,222,207,199,193,255, +255,192,192,0,0,0,0,0 +, +0,0,0,0,0,0,0,63, +63,0,0,0,0,0,0,0 +, + +0,224,224,224,224,224,224,224, //'5' +224,224,224,0,0,0,0,0 +, +0,63,63,63,56,56,48,112, +240,224,0,0,0,0,0,0 +, +0,28,56,56,48,48,56,60, +31,15,1,0,0,0,0,0 +, + +0,0,128,192,192,224,96,96, //'6' +224,224,0,0,0,0,0,0 +, +224,254,255,55,57,24,24,56, +240,240,192,0,0,0,0,0 +, +0,15,31,28,56,48,48,56, +31,15,7,0,0,0,0,0 +, + +0,224,224,224,224,224,224,224, //'7' +224,224,224,0,0,0,0,0 +, +0,0,0,0,128,224,248,126, +31,7,1,0,0,0,0,0 +, +0,0,56,62,31,7,1,0, +0,0,0,0,0,0,0,0 +, + +0,128,192,224,224,96,96,224, //'8' +192,192,0,0,0,0,0,0 +, +0,207,255,127,56,48,112,112, +255,239,199,0,0,0,0,0 +, +3,15,31,60,56,48,48,56, +31,31,15,0,0,0,0,0 +, + +0,128,192,224,224,96,224,224, //'9' +192,128,0,0,0,0,0,0 +, +12,63,127,241,224,192,192,225, +255,255,254,0,0,0,0,0 +, +0,0,56,48,48,56,56,30, +15,7,0,0,0,0,0,0 +, + + +0,0,0,0,0,0,0,0, //'.' +0,0,0,0,0,0,0,0 +, +0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0 +, +60,60,60,0,0,0,0,0, +0,0,0,0,0,0,0,0 +, + +0,0,0,0,0,0,0,0, //'+' +0,0,0,0,0,0,0,0 +, +0,0,64,64,64,64,64,254, +254,64,64,64,64,64,0,0 +, +0,0,0,0,0,0,0,15, +15,0,0,0,0,0,0,0 +, + +0,0,0,0,0,0,0,0, //'-' +0,0,0,0,0,0,0,0 +, +0,64,64,64,64,64,64,0, +0,0,0,0,0,0,0,0 +, +0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0 +}; + +