123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- /****************************************Copyright (c)**************************************************
- * File Name: ST7735S.c
- * Function Describe: LCD Driver of ST7735S
- * Explain:
- * Writer: ShiLiangWen
- * Date: 2016-1-8
- ********************************************************************************************************/
- //-------------------------------------------------------
- #include "includes.h"
- //-------------------------------------------------------
- #define LCD_CS_PIN GPIO_Pin_12
- #define LCD_CS_PORT GPIOB
- #define LCD_CS_HIGH LCD_CS_PORT->BSRR = LCD_CS_PIN
- #define LCD_CS_LOW LCD_CS_PORT->BRR = LCD_CS_PIN
- #define LCD_SCK_PIN GPIO_Pin_13
- #define LCD_SCK_PORT GPIOB
- #define LCD_SCK_HIGH LCD_SCK_PORT->BSRR = LCD_SCK_PIN
- #define LCD_SCK_LOW LCD_SCK_PORT->BRR = LCD_SCK_PIN
- #define LCD_DCX_PIN GPIO_Pin_14
- #define LCD_DCX_PORT GPIOB
- #define LCD_DCX_HIGH LCD_DCX_PORT->BSRR = LCD_DCX_PIN
- #define LCD_DCX_LOW LCD_DCX_PORT->BRR = LCD_DCX_PIN
- #define LCD_SDA_PIN GPIO_Pin_15
- #define LCD_SDA_PORT GPIOB
- #define LCD_SDA_HIGH LCD_SDA_PORT->BSRR = LCD_SDA_PIN
- #define LCD_SDA_LOW LCD_SDA_PORT->BRR = LCD_SDA_PIN
- #define LCD_RESET_PIN GPIO_Pin_6
- #define LCD_RESET_PORT GPIOC
- #define LCD_RESET_HIGH LCD_RESET_PORT->BSRR = LCD_RESET_PIN
- #define LCD_RESET_LOW LCD_RESET_PORT->BRR = LCD_RESET_PIN
- #define LCD_BL_PIN GPIO_Pin_7
- #define LCD_BL_PORT GPIOC
- #define LCD_BL_HIGH LCD_BL_PORT->BSRR = LCD_BL_PIN
- #define LCD_BL_LOW LCD_BL_PORT->BRR = LCD_BL_PIN
- /*******************************************************************************
- ST7735PortInit
- *******************************************************************************/
- static void ST7735PortInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable GPIOD and GPIOE clocks */
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
-
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- LCD_CS_HIGH;
- LCD_BL_HIGH;
- GPIO_InitStructure.GPIO_Pin = (LCD_CS_PIN|LCD_SCK_PIN|LCD_DCX_PIN|LCD_SDA_PIN);
- GPIO_Init(GPIOB, &GPIO_InitStructure);
- LCD_CS_HIGH;
- LCD_SCK_HIGH;
- LCD_SDA_HIGH;
- LCD_DCX_HIGH;
- LCD_RESET_HIGH;
- LCD_BL_HIGH;
- GPIO_InitStructure.GPIO_Pin = (LCD_RESET_PIN|LCD_BL_PIN);
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- LCD_RESET_HIGH;
- LCD_BL_HIGH;
- }
- /*******************************************************************************
- ST7735SendCmd
- *******************************************************************************/
- void ST7735SendCmd(unsigned char Cmd)
- {
- unsigned char i,j;
- LCD_CS_LOW;
- LCD_DCX_LOW;
- for(i=0;i<8;i++){
- j=0x80>>i;
- LCD_SCK_LOW;
- if(Cmd&j)LCD_SDA_HIGH;
- else LCD_SDA_LOW;
- LCD_SCK_HIGH;
- }
- LCD_CS_HIGH;
- }
- /*******************************************************************************
- ST7735SendData
- *******************************************************************************/
- void ST7735SendData(unsigned char Data)
- {
- unsigned char i,j;
- LCD_CS_LOW;
- LCD_DCX_HIGH;
- for(i=0;i<8;i++){
- j=0x80>>i;
- LCD_SCK_LOW;
- if(Data & j)LCD_SDA_HIGH;
- else LCD_SDA_LOW;
- LCD_SCK_HIGH;
- }
- LCD_CS_HIGH;
- }
- void ST7735Init(void)
- {
- LcdPortInit();
- //reset
- LCD_RESET_HIGH;
- DelayMs(1);
- LCD_RESET_LOW;
- DelayMs(1);
- LCD_RESET_HIGH;
- DelayMs(120);
- //-----------------------------------ST7735S Set REG---------------------------------------------//
- ST7735SendCmd(0x11); //Sleep out
- DelayMs(120); //Delay 120ms
- //------------------------------------ST7735S Frame Rate-----------------------------------------//
- ST7735SendCmd(0xB1);
- ST7735SendData(0x05);
- ST7735SendData(0x3C);
- ST7735SendData(0x3C);
- ST7735SendCmd(0xB2);
- ST7735SendData(0x05);
- ST7735SendData(0x3C);
- ST7735SendData(0x3C);
- ST7735SendCmd(0xB3);
- ST7735SendData(0x05);
- ST7735SendData(0x3C);
- ST7735SendData(0x3C);
- ST7735SendData(0x05);
- ST7735SendData(0x3C);
- ST7735SendData(0x3C);
- //------------------------------------End ST7735S Frame Rate-----------------------------------------//
- ST7735SendCmd(0xB4); //Dot inversion
- ST7735SendData(0x03);
- //------------------------------------ST7735S Power Sequence-----------------------------------------//
- ST7735SendCmd(0xC0);
- ST7735SendData(0x28);
- ST7735SendData(0x08);
- ST7735SendData(0x04);
- ST7735SendCmd(0xC1);
- ST7735SendData(0XC0);
- ST7735SendCmd(0xC2);
- ST7735SendData(0x0D);
- ST7735SendData(0x00);
- ST7735SendCmd(0xC3);
- ST7735SendData(0x8D);
- ST7735SendData(0x2A);
- ST7735SendCmd(0xC4);
- ST7735SendData(0x8D);
- ST7735SendData(0xEE);
- //---------------------------------End ST7735S Power Sequence-------------------------------------//
- ST7735SendCmd(0xC5); //VCOM
- ST7735SendData(0x1A);
- ST7735SendCmd(0x36); //MX, MY, RGB mode
- ST7735SendData(0x60);//-----------这个值非常重要,决定了内部显存和显示区域的关系,以及RGB颜色顺序
- //------------------------------------ST7735S Gamma Sequence-----------------------------------------//
- ST7735SendCmd(0xE0);
- ST7735SendData(0x04);
- ST7735SendData(0x22);
- ST7735SendData(0x07);
- ST7735SendData(0x0A);
- ST7735SendData(0x2E);
- ST7735SendData(0x30);
- ST7735SendData(0x25);
- ST7735SendData(0x2A);
- ST7735SendData(0x28);
- ST7735SendData(0x26);
- ST7735SendData(0x2E);
- ST7735SendData(0x3A);
- ST7735SendData(0x00);
- ST7735SendData(0x01);
- ST7735SendData(0x03);
- ST7735SendData(0x13);
- ST7735SendCmd(0xE1);
- ST7735SendData(0x04);
- ST7735SendData(0x16);
- ST7735SendData(0x06);
- ST7735SendData(0x0D);
- ST7735SendData(0x2D);
- ST7735SendData(0x26);
- ST7735SendData(0x23);
- ST7735SendData(0x27);
- ST7735SendData(0x27);
- ST7735SendData(0x25);
- ST7735SendData(0x2D);
- ST7735SendData(0x3B);
- ST7735SendData(0x00);
- ST7735SendData(0x01);
- ST7735SendData(0x04);
- ST7735SendData(0x13);
- //------------------------------------End ST7735S Gamma Sequence-----------------------------------------//
- ST7735SendCmd(0x3A); //65k mode
- ST7735SendData(0x05);
- ST7735SendCmd(0x29); //Display on
- }
- /**********************************************************************************************
- 设置一个写地址区域
- ************************************************************************************************/
- void SetBlockWrite(u16 x1,u16 y1,u16 x2,u16 y2)
- {
- u16 Xstart,Xend,Ystart,Yend;
- Xstart=x1+1;
- Xend=x2+1;
- Ystart=y1+2;
- Yend=y2+2;
-
- ST7735SendCmd(0x2a);
- ST7735SendData(Xstart>>8);
- ST7735SendData(Xstart&0xff);
- ST7735SendData(Xend>>8);
- ST7735SendData(Xend&0xff);
- ST7735SendCmd(0x2b);
- ST7735SendData(Ystart>>8);
- ST7735SendData(Ystart&0xff);
- ST7735SendData(Yend>>8);
- ST7735SendData(Yend&0xff);
- ST7735SendCmd(0x2c);
- }
- /****************************************************************************
- * 名 称:void SetPoint(u16 x,u16 y,u16 color)
- * 功 能:指定坐标点
- * 入口参数:x轴y轴
- * 出口参数:无
- * 说 明:2012.4.27 hxm v1.0
- * 调用方法:无
- ****************************************************************************/
- void SetPoint(u16 x,u16 y,u16 color)
- {
- ST7735SendCmd(0x2a);
- ST7735SendData(x>>8);
- ST7735SendData(x&0x00ff);
-
- st7735_CMD(0x2b);
- ST7735SendData(y>>8);
- ST7735SendData(y&0x00ff);
-
- st7735_CMD(0X2C);
- st7735_DATA(color>>8);
- st7735_DATA(color&0x00ff);
- }
- /*********************************************************************************************************
- END FILE
- *********************************************************************************************************/
|