123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- #include "includes.h"
- static u16 susLcdBackColor; //背景颜色
- static u16 susLcdForeColor; //画笔颜色
- extern const unsigned char g_apucLetter16[];
- extern const unsigned char g_apucCLetter16[];
- extern const unsigned char g_apucLetter24[];
- extern const unsigned char g_apucCLetter24[];
- extern const unsigned char g_apucFonts16[];
- extern const unsigned char g_apucCFonts16[];
- extern const unsigned char g_apucFonts24[];
- extern const unsigned char g_apucCFonts24[];
- unsigned char showApn=1;
- unsigned char LastKeyLight=0;//熄屏首次电量屏幕
- unsigned char KeyLightFlag=-1;
- /***************************************************************************
- *LcdSetColor 设置画笔颜色和背景颜色
- ****************************************************************************/
- static void LcdPortInit(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- #if(LCD_BUS_TYPE==LCD_BUS_IO)
- /* Enable GPIOD and GPIOE clocks */
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, 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_DCX_HIGH;
- LCD_SDA_HIGH;
- LCD_RESET_HIGH;
- LCD_BL_HIGH;
- GPIO_InitStructure.GPIO_Pin = (LCD_RESET_PIN|LCD_BL_PIN);
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- LCD_RESET_HIGH;
- LCD_BL_HIGH;
- #elif(LCD_BUS_TYPE==LCD_BUS_SPI)
- SPI_InitTypeDef SPI_InitStructure;
- RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA, ENABLE);
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
-
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
- GPIO_InitStructure.GPIO_Pin = LCD_DCX_PIN;
- GPIO_Init(LCD_DCX_PORT, &GPIO_InitStructure);
- LCD_DCX_HIGH;
- /* NS */
- GPIO_InitStructure.GPIO_Pin = LCD_SPI_NSS_PIN;
- GPIO_Init(LCD_SPI_PORT, &GPIO_InitStructure);
- /*SCK */
- GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(LCD_SPI_PORT, &GPIO_InitStructure);
- /*MOSI */
- GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
- GPIO_Init(LCD_SPI_PORT, &GPIO_InitStructure);
-
- LCD_SPI_NSS_HIGH;
- SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;//半双工,只发不读
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; //2分频
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
- SPI_InitStructure.SPI_CRCPolynomial = 7;
- SPI_Init(LCD_SPI_HANDLE, &SPI_InitStructure);
- SPI_Cmd(LCD_SPI_HANDLE, ENABLE);
-
-
-
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Pin = (LCD_RESET_PIN|LCD_BL_PIN);
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- LCD_RESET_HIGH;
- LCD_BL_HIGH;
- #endif
- }
- #if(LCD_BUS_TYPE==LCD_BUS_IO)
- void LcdSendCommand(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;
- }
- void LcdSendData(unsigned char Data)
- {
- unsigned char i,j;
- unsigned char ret;
- 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;
- }
- #elif(LCD_BUS_TYPE==LCD_BUS_SPI)
- void LCD_SPIx_ReadWriteByte(unsigned char byte)
- {
- SPI_I2S_SendData(LCD_SPI_HANDLE, byte);
- while (SPI_I2S_GetFlagStatus(LCD_SPI_HANDLE, SPI_I2S_FLAG_BSY) == SET);
- }
- void LcdSendCommand(unsigned char Cmd)
- {
- LCD_DCX_LOW;
- LCD_SPI_NSS_LOW;
- LCD_SPIx_ReadWriteByte(Cmd);
- LCD_SPI_NSS_HIGH;
- }
- void LcdSendData(unsigned char Data)
- {
- LCD_DCX_HIGH;
- LCD_SPI_NSS_LOW;
- LCD_SPIx_ReadWriteByte(Data);
- LCD_SPI_NSS_HIGH;
- }
- #endif
- /***************************************************************************
- *LcdSetColor 设置画笔颜色和背景颜色
- ****************************************************************************/
- void LcdSetColor(u16 BrushColor,u16 BackColor)
- {
- susLcdForeColor=BrushColor; //画笔颜色
- susLcdBackColor=BackColor; //背景颜色
- }
- void LcdInit(void)
- {
- LcdPortInit();
- LCD_BL_LOW;//用户体验
-
- //reset
- LCD_RESET_HIGH;
- DelayMs(1);
- LCD_RESET_LOW;
- DelayMs(1);
- LCD_RESET_HIGH;
- DelayMs(120);
-
- LcdSendCommand(0xfe);
- LcdSendCommand(0xef);
- LcdSendCommand(0x36);
- LcdSendData(0x68);
-
- LcdSendCommand(0x3a);
- LcdSendData(0x05);//
- LcdSendCommand(0xb6);
- LcdSendData(0x11);
- LcdSendCommand(0xac);
- LcdSendData(0x0b);
- LcdSendCommand(0xb4);
- LcdSendData(0x21);
- LcdSendCommand(0xb1);
- LcdSendData(0xc0);
- LcdSendCommand(0xb2);
- LcdSendData(0x08);
- LcdSendCommand(0xb3);
- LcdSendData(0x23);
- LcdSendCommand(0xeb);
- LcdSendData(0x11);
- LcdSendData(0x66);
- LcdSendCommand(0x2a);
- LcdSendData(0x00);
- LcdSendData(0x00);
- LcdSendData(0x00);
- LcdSendData(0x7f);
- LcdSendCommand(0x2b);
- LcdSendData(0x00);
- LcdSendData(0x10);
- LcdSendData(0x00);
- LcdSendData(0xa0);
- LcdSendCommand(0xf5);
- LcdSendData(0x09);
- LcdSendData(0x84);
- LcdSendCommand(0xe6);
- LcdSendData(0x28);
- LcdSendData(0x00);
- LcdSendCommand(0xe7);
- LcdSendData(0x70);
- LcdSendData(0x00);
- //////////////////////////////////////////
- LcdSendCommand(0xF0);
- LcdSendData(0X4);
- LcdSendData(0X32);
- LcdSendData(0X25);
- LcdSendData(0X41);
- LcdSendData(0XBA);
- LcdSendData(0XE);
- LcdSendData(0XF);
- LcdSendData(0X0);
- LcdSendData(0X1);
- LcdSendData(0XB);
- LcdSendData(0XE);
- LcdSendData(0X19);
- LcdSendData(0X18);
- LcdSendData(0XF);
- LcdSendCommand(0xF1);
- LcdSendData(0X7);
- LcdSendData(0X3C);
- LcdSendData(0X2D);
- LcdSendData(0X50);
- LcdSendData(0XAC);
- LcdSendData(0X25);
- LcdSendData(0X25);
- LcdSendData(0X0);
- LcdSendData(0X1);
- LcdSendData(0XC);
- LcdSendData(0XE);
- LcdSendData(0X15);
- LcdSendData(0X14);
- LcdSendData(0XF);
- LcdSendCommand(0xfe);
- LcdSendCommand(0xff);
- LcdSendCommand(0x21);
- LcdSendCommand(0x11);
- DelayMs(120);
- LcdSendCommand(0x29);
- //设置前景色和背景色
- LcdSetColor(0x0000,0xffff);
- //清屏
- LcdClrAll();
- LCD_BL_HIGH;
- }
- void LCDBackLight(char Ct)
- {
- LastKeyLight=KeyLightFlag;
- if(Ct==0){
- KeyLightFlag=Ct;
- LCD_BL_LOW;
- LcdSendCommand(0x28);
- if(GPS_TimeTable[newPara.gpsTimeIndex]>=30||GPS_TimeTable[newPara.gpsTimeIndex]==0)QueryTime=60;
- else QueryTime=GPS_TimeTable[newPara.gpsTimeIndex]*2;
- }else{
- QueryTime=10;
- KeyLightFlag=Ct;
- LCD_BL_HIGH;
- LcdSendCommand(0x29);
- }
- }
- /**********************************************************************************************
- 设置一个写地址区域
- ************************************************************************************************/
- void LcdBlockWrite(u16 x1,u16 y1,u16 x2,u16 y2)
- {
- u16 Xstart,Xend,Ystart,Yend;
- #if(LCD_TYPE==0)
- //旧屏
- Xstart=x1+1;
- Xend=x2+1;
- Ystart=y1+2;
- Yend=y2+2;
- #else
- //新屏
- Xstart=x1;
- Xend=x2;
- Ystart=y1;
- Yend=y2;
- #endif
-
- LcdSendCommand(0x2a);
- LcdSendData(Xstart>>8);
- LcdSendData(Xstart&0xff);
- LcdSendData(Xend>>8);
- LcdSendData(Xend&0xff);
- LcdSendCommand(0x2b);
- LcdSendData(Ystart>>8);
- LcdSendData(Ystart&0xff);
- LcdSendData(Yend>>8);
- LcdSendData(Yend&0xff);
-
- LcdSendCommand(0x2c);
- }
- void LcdClrAll(void)
- {
- int i,j;
- unsigned char colorH,colorL;
- colorH=susLcdBackColor>>8;
- colorL=susLcdBackColor&0xff;
- LcdBlockWrite(0,0,127,127);
-
- for(i=0;i<LCD_HEIGHT;i++)
- {
- for(j=0;j<LCD_WIDTH;j++)
- {
- LcdSendData(colorH);
- LcdSendData(colorL);
- }
- }
- }
- void LcdClrAll2(void)
- {
- int i,j;
- unsigned char colorH,colorL;
- colorH=susLcdForeColor>>8;
- colorL=susLcdForeColor&0xff;
- LcdBlockWrite(0,0,127,127);
-
- for(i=0;i<LCD_HEIGHT;i++)
- {
- for(j=0;j<LCD_WIDTH;j++)
- {
- LcdSendData(colorH);
- LcdSendData(colorL);
- }
- }
- }
|