- #include "st7789.h"
- #include "delay.h"
- unsigned int POINT_COLOR = 0X0000;
- unsigned int BACK_COLOR = 0XFFFF;
- void LCD_WR_DATA(unsigned int val)
- {
- LCD_RS=1; //RS=1;
- LCD_CS=0; //CS=0;
- P2=val;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- void LCD_WR_REG(unsigned int reg)
- {
- LCD_RS=0; //RS=0;
- LCD_CS=0; //CS=0;
- P2=reg;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- void LCD_Init()
- {
- delay_ms(120);
- LCD_WR_REG(0x11); // Sleep Out
- delay_ms(120);
- LCD_WR_REG(0x36);
- LCD_WR_DATA(0x60);
- LCD_WR_REG(0x3A);
- LCD_WR_DATA(0x05);
- LCD_WR_REG(0xB2);
- LCD_WR_DATA(0x0C);
- LCD_WR_DATA(0x0C);
- LCD_WR_DATA(0x00);
- LCD_WR_DATA(0x33);
- LCD_WR_DATA(0x33);
- LCD_WR_REG(0xB7);
- LCD_WR_DATA(0x35);
- LCD_WR_REG(0xBB);
- LCD_WR_DATA(0x29); //32 Vcom=1.35V
-
- LCD_WR_REG(0xC2);
- LCD_WR_DATA(0x01);
- LCD_WR_REG(0xC3);
- LCD_WR_DATA(0x19); //GVDD=4.8V
-
- LCD_WR_REG(0xC4);
- LCD_WR_DATA(0x20); //VDV, 0x20:0v
- LCD_WR_REG(0xC5);
- LCD_WR_DATA(0x1A);//VCOM Offset Set
- LCD_WR_REG(0xC6);
- LCD_WR_DATA(0x1F); //0x0F:60Hz
- LCD_WR_REG(0xD0);
- LCD_WR_DATA(0xA4);
- LCD_WR_DATA(0xA1);
-
-
- LCD_WR_REG( 0xE0);
- LCD_WR_DATA( 0xD0);
- LCD_WR_DATA( 0x08);
- LCD_WR_DATA( 0x0E);
- LCD_WR_DATA( 0x09);
- LCD_WR_DATA( 0x09);
- LCD_WR_DATA( 0x05);
- LCD_WR_DATA( 0x31);
- LCD_WR_DATA( 0x33);
- LCD_WR_DATA( 0x48);
- LCD_WR_DATA( 0x17);
- LCD_WR_DATA( 0x14);
- LCD_WR_DATA( 0x15);
- LCD_WR_DATA( 0x31);
- LCD_WR_DATA( 0x34);
- LCD_WR_REG( 0xE1);
- LCD_WR_DATA( 0xD0);
- LCD_WR_DATA( 0x08);
- LCD_WR_DATA( 0x0E);
- LCD_WR_DATA( 0x09);
- LCD_WR_DATA( 0x09);
- LCD_WR_DATA( 0x15);
- LCD_WR_DATA( 0x31);
- LCD_WR_DATA( 0x33);
- LCD_WR_DATA( 0x48);
- LCD_WR_DATA( 0x17);
- LCD_WR_DATA( 0x14);
- LCD_WR_DATA( 0x15);
- LCD_WR_DATA( 0x31);
- LCD_WR_DATA( 0x34);
-
- LCD_WR_REG(0x21);
- LCD_WR_REG(0x29);
- }
- void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy)
- {
- LCD_WR_REG(0x2A);
- LCD_WR_DATA(stx>>8);
- LCD_WR_DATA(stx&0xff);
- LCD_WR_DATA(endx>>8);
- LCD_WR_DATA(endx&0xff);
- LCD_WR_REG(0x2B);
- LCD_WR_DATA(sty>>8);
- LCD_WR_DATA(sty&0xff);
- LCD_WR_DATA(endy>>8);
- LCD_WR_DATA(endy&0xff);
- }
- /* »-μãoˉêy 2ÎêyêÇÑÕé« */
- void LcdWirteColorData(unsigned int color)
- {
- LCD_RS=1; //RS=1;
- LCD_CS=0; //CS=0;
- P2=color>>8;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- P2=color;
- LCD_WR=0; //WR=0;
- LCD_WR=1; //WR=1;
- LCD_CS=1; //CS=1;
- }
- void LCD_Clear(unsigned int color)
- {
- unsigned int i,j;
- LCD_SetArea(0,0,319,239);
- LCD_WR_REG(0x2C);
- for(i=0;i<240;i++)
- {
- for(j=0;j<320;j++)
- {
- LcdWirteColorData(color);
- }
- }
- }
- void LCD_Show16(unsigned int x, unsigned int y, unsigned char* zifu)
- {
- unsigned int i,j;
- unsigned char temp;
-
- LCD_SetArea(x,y,x+15,y+15);
- LCD_WR_REG(0x2C);
-
- for(i=0;i<32;i++)
- {
- temp = *(zifu + i);
- for(j=0;j<8;j++)
- {
- if(temp&0x80)
- LcdWirteColorData(POINT_COLOR);
- else
- LcdWirteColorData(BACK_COLOR);
- temp=temp<<1;
- }
- }
- }
- void LCD_Show24(unsigned int x, unsigned int y, unsigned char* zifu)
- {
- unsigned int i,j;
- unsigned char temp;
-
- LCD_SetArea(x,y,x+23,y+23);
- LCD_WR_REG(0x2C);
-
- for(i=0;i<72;i++)
- {
- temp = *(zifu + i);
- for(j=0;j<8;j++)
- {
- if(temp&0x80)
- LcdWirteColorData(POINT_COLOR);
- else
- LcdWirteColorData(BACK_COLOR);
- temp=temp<<1;
- }
- }
- }
- void LCD_Show32(unsigned int x, unsigned int y, unsigned char* zifu)
- {
- unsigned int i,j;
- unsigned char temp;
-
- LCD_SetArea(x,y,x+31,y+31);
- LCD_WR_REG(0x2C);
-
- for(i=0;i<128;i++)
- {
- temp = *(zifu + i);
- for(j=0;j<8;j++)
- {
- if(temp&0x80)
- LcdWirteColorData(POINT_COLOR);
- else
- LcdWirteColorData(BACK_COLOR);
- temp=temp<<1;
- }
- }
- }
復制代碼 |