LCD4884

Dependents:   15A-ClassProjectFinal_masterfull-pae-za-leng

Fork of LCD4884 by Dan Ghiciulescu

Revision:
0:28f3c9274ea7
Child:
1:480f22b7e9ae
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD4884.cpp	Sat Mar 09 21:07:35 2013 +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(SPI_SCK);    //2- Serial Clock(Master Output)
+DigitalOut SpiMosi(SPI_MOSI);  //3- Master Output,Slave Input
+DigitalOut LcdDC(LCD_DC);      //4- Data/Command(command active low)
+DigitalOut SpiCS(SPI_CS);      //5- Chip Select,Slave Transmit Enable(active low,Master Output)
+DigitalOut LcdRst(LCD_RST);    //6- One Reset button
+PwmOut     LcdBl(LCD_BL);      //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);
+    }
+}
+