|
MM32F031开发板评测8:模拟SPI驱动2.2寸SPI屏
[复制链接]
有的人看到模拟SPI会不屑一顾,有些甚至看都不看,我确高兴的很,原因何在???
我是个看结果的人,也就是说一但我哪一天开发SPI的东东开发不出来了。也不会象《春天里》那首歌唱的,死在春天里。我应百折不挠地用模拟串口实现。
费话不说了,上图:
以下的是清红色的屏,那叫一个红。
那么怎么搞定的呢?很简单只要有这个屏的资料。下面是这个SPI屏的资料一并传上:
2.2寸天马SPI串口模块资料9341_240X320_Rev2.0.zip
(15.33 MB, 下载次数: 35)
把里边的STMF103例程里边的驱动及H文件考到点灯那个程序目录里。然后添加,然后编译。
至于,线怎么连其实H文件里边有,其顺序如下;
B12-----CS
A4----RES
B1----DC
B13----CLK
B15-----DIN
以下是主函数:
- int main(void)
- {
- delay_init();
- LED_Init();
- LCD_GPIO_Init();
- Lcd_Init();
- Lcd_Clear(RED);
- while(1) //ÎTÏTÑ-»·
- {
- LED1_TOGGLE();
- LED2_TOGGLE();
- LED3_TOGGLE();
- LED4_TOGGLE();
- delay_ms(1000);
- }
- }
复制代码
以下是H文件
- #ifndef _LCD_DRIVER_H_
- #define _LCD_DRIVER_H_
- #include "HAL_conf.h"
- /////////////////////////////////////óû§ÅäÖÃÇø///////////////////////////////////
- //Ö§3ÖoáêúÆá¿ìËù¶¨òåÇD»»
- #define USE_HORIZONTAL 0 //¶¨òåêÇ·ñê1óÃoáÆá 0,2»ê1óÃ.1,ê1óÃ.
- //-----------------------------SPI ×üÏßÅäÖÃ--------------------------------------//
- #define USE_HARDWARE_SPI 1 //1:Enable Hardware SPI;0:USE Soft SPI
- //-------------------------ÆáÄ»ÎïàíÏñËØéèÖÃ--------------------------------------//
- #define LCD_X_SIZE 240
- #define LCD_Y_SIZE 320
- #if USE_HORIZONTAL//èç1û¶¨òåáËoáÆá
- #define X_MAX_PIXEL LCD_Y_SIZE
- #define Y_MAX_PIXEL LCD_X_SIZE
- #else
- #define X_MAX_PIXEL LCD_X_SIZE
- #define Y_MAX_PIXEL LCD_Y_SIZE
- #endif
- //////////////////////////////////////////////////////////////////////////////////
-
- #define RED 0xf800
- #define GREEN 0x07e0
- #define BLUE 0x001f
- #define WHITE 0xffff
- #define BLACK 0x0000
- #define YELLOW 0xFFE0
- #define GRAY0 0xEF7D //»òé«0 3165 00110 001011 00101
- #define GRAY1 0x8410 //»òé«1 00000 000000 00000
- #define GRAY2 0x4208 //»òé«2 1111111111011111
- //±¾2aêÔ3ìDòê1óÃμÄêÇÄ£ÄaSPI½ó¿úÇy¶ˉ
- //¿é×Ôóé¸ü¸Ä½ó¿úIOÅäÖã¬ê1óÃèÎòa×îéù4 IO¼′¿éíê3é±¾¿îòo¾§Çy¶ˉÏÔê¾
- /******************************************************************************
- ½ó¿ú¶¨òåÔúLcd_Driver.hÄú¶¨ò壬Çë¸ù¾Y½óÏßDT¸Ä2¢DT¸ÄÏàó|IO3õê¼»ˉLCD_GPIO_Init()
- #define LCD_CTRL GPIOB //¶¨òåTFTêy¾Y¶Ë¿ú
- #define LCD_LED GPIO_Pin_9 //PB9 ᬽóÖáTFT -LED
- #define LCD_RS GPIO_Pin_10 //PB10ᬽóÖáTFT --RS
- #define LCD_CS GPIO_Pin_11 //PB11 ᬽóÖáTFT --CS
- #define LCD_RST GPIO_Pin_12 //PB12ᬽóÖáTFT --RST
- #define LCD_SCL GPIO_Pin_13 //PB13ᬽóÖáTFT -- CLK
- #define LCD_SDA GPIO_Pin_15 //PB15ᬽóÖáTFT - SDI
- *******************************************************************************/
- #define LCD_CTRL GPIOB //¶¨òåTFTêy¾Y¶Ë¿ú
- #define LCD_LED GPIO_Pin_9 //MCU_PB9--->>TFT --BL
- #define LCD_RS GPIO_Pin_10 //PB11--->>TFT --RS/DC
- #define LCD_CS GPIO_Pin_11 //MCU_PB11--->>TFT --CS/CE
- #define LCD_RST GPIO_Pin_12 //PB10--->>TFT --RST
- #define LCD_SCL GPIO_Pin_13 //PB13--->>TFT --SCL/SCK
- #define LCD_SDA GPIO_Pin_15 //PB15 MOSI--->>TFT --SDA/DIN
- //#define LCD_CS_SET(x) LCD_CTRL->ODR=(LCD_CTRL->ODR&~LCD_CS)|(x ? LCD_CS:0)
- //òo¾§¿ØÖÆ¿úÖÃ12ù×÷óï¾äo궨òå
- #define LCD_CS_SET LCD_CTRL->BSRR=LCD_CS
- #define LCD_RS_SET LCD_CTRL->BSRR=LCD_RS
- #define LCD_SDA_SET LCD_CTRL->BSRR=LCD_SDA
- #define LCD_SCL_SET LCD_CTRL->BSRR=LCD_SCL
- #define LCD_RST_SET LCD_CTRL->BSRR=LCD_RST
- #define LCD_LED_SET LCD_CTRL->BSRR=LCD_LED
- //òo¾§¿ØÖÆ¿úÖÃ02ù×÷óï¾äo궨òå
- #define LCD_CS_CLR LCD_CTRL->BRR=LCD_CS
- #define LCD_RS_CLR LCD_CTRL->BRR=LCD_RS
- #define LCD_SDA_CLR LCD_CTRL->BRR=LCD_SDA
- #define LCD_SCL_CLR LCD_CTRL->BRR=LCD_SCL
- #define LCD_RST_CLR LCD_CTRL->BRR=LCD_RST
- #define LCD_LED_CLR LCD_CTRL->BRR=LCD_LED
- #define LCD_DATAOUT(x) LCD_DATA->ODR=x; //êy¾Yêä3ö
- #define LCD_DATAIN LCD_DATA->IDR; //êy¾Yêäèë
- #define LCD_WR_DATA(data){\
- LCD_RS_SET;\
- LCD_CS_CLR;\
- LCD_DATAOUT(data);\
- LCD_WR_CLR;\
- LCD_WR_SET;\
- LCD_CS_SET;\
- }
- void LCD_GPIO_Init(void);
- void Lcd_WriteIndex(u8 Index);
- void Lcd_WriteData(u8 Data);
- void Lcd_WriteReg(u8 Index,u8 Data);
- u16 Lcd_ReadReg(u8 LCD_Reg);
- void Lcd_Reset(void);
- void Lcd_Init(void);
- void Lcd_Clear(u16 Color);
- void Lcd_SetXY(u16 x,u16 y);
- void Gui_DrawPoint(u16 x,u16 y,u16 Data);
- unsigned int Lcd_ReadPoint(u16 x,u16 y);
- void Lcd_SetRegion(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd);
- void Lcd_WriteData_16Bit(u16 Data);
- #endif
复制代码
以下是C文件:
- /***************************************************************************************
- STM322aêÔƽ쨽ééü:
- ¿a·¢°å£oÕyμãÔ-×óMiniSTM32¿a·¢°å
- MCU £oSTM32_F103_RBT6
- ¾§Õñ £o12MHZ
- Ö÷Æμ £o72MHZ
- ½óÏßËμÃ÷:
- //-------------------------------------------------------------------------------------
- #define LCD_CTRL GPIOB //¶¨òåTFTêy¾Y¶Ë¿ú
- #define LCD_LED GPIO_Pin_9 //PB9 ᬽóÖáTFT -LED
- #define LCD_RS GPIO_Pin_10 //PB10ᬽóÖáTFT --RS
- #define LCD_CS GPIO_Pin_11 //PB11 ᬽóÖáTFT --CS
- #define LCD_RST GPIO_Pin_12 //PB12ᬽóÖáTFT --RST
- #define LCD_SCL GPIO_Pin_13 //PB13ᬽóÖáTFT -- CLK
- #define LCD_SDA GPIO_Pin_15 //PB15ᬽóÖáTFT - SDI
- //VCC:¿éòÔ½ó5Vò2¿éòÔ½ó3.3V
- //LED:¿éòÔ½ó5Vò2¿éòÔ½ó3.3V»òÕßê1óÃèÎòa¿ÕÏDIO¿ØÖÆ(¸ßμçƽê1Äü)
- //GND£o½óμçÔ′μØ
- //ËμÃ÷£oèçDèòa¾¡¿éÄüéùÕ¼óÃIO£¬¿éòÔ½«LCD_CS½óμØ£¬LCD_LED½ó3.3V£¬LCD_RST½óÖáμ¥Ƭ»ú¸′λ¶Ë£¬
- //½«¿éòÔêí·Å3¸ö¿éóÃIO
- //½ó¿ú¶¨òåÔúLcd_Driver.hÄú¶¨ò壬
- //èçDè±ä¸üIO½ó·¨£¬Çë¸ù¾YÄúμÄêμ¼ê½óÏßDT¸ÄÏàó|IO3õê¼»ˉLCD_GPIO_Init()
- //-----------------------------------------------------------------------------------------
- ày3ì1|ÄüËμÃ÷£o
- 1. ¼òμ¥Ë¢Æá2aêÔ
- 2. ó¢ÎÄÏÔê¾2aêÔê¾ày
- 3. ÖDÎÄÏÔê¾2aêÔê¾ày
- 4. êyÂë1ü×ÖìåÏÔê¾ê¾ày
- 5. í¼Æ¬ÏÔê¾ê¾ày
- 6. 2D°′¼ü2Ëμ¥ê¾ày
- 7. ±¾ày3ìÖ§3ÖoáÆá/êúÆáÇD»»(¿aÆôoêUSE_HORIZONTAL,Ïê¼ûLcd_Driver.h)
- 8. ±¾ày3ìÖ§3Öèí¼tÄ£ÄaSPI/ó2¼tSPIÇD»»(¿aÆôoêUSE_HARDWARE_SPI,Ïê¼ûLcd_Driver.h)
- **********************************************************************************************/
- //---------------------------------function----------------------------------------------------//
- /****************************************************************************
- * Ãû 3Æ£ovoid LCD_GPIO_Init(void)
- * 1| Äü£oSTM32_Ä£ÄaSPIËùóÃμ½μÄGPIO3õê¼»ˉ
- * èë¿ú2Îêy£oÎT
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£o3õê¼»ˉÄ£ÄaSPIËùóÃμÄGPIO
- ****************************************************************************/
- void LCD_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd( RCC_AHBPeriph_GPIOB ,ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14| GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- }
- /****************************************************************************
- * Ãû 3Æ£ovoid SPIv_WriteData(u8 Data)
- * 1| Äü£oSTM32_Ä£ÄaSPID′ò»¸ö×Ö½úêy¾Yμ×2ãoˉêy
- * èë¿ú2Îêy£oData
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oSTM32_Ä£ÄaSPI¶áD′ò»¸ö×Ö½úêy¾Yμ×2ãoˉêy
- ****************************************************************************/
- void SPIv_WriteData(u8 Data)
- {
- unsigned char i=0;
- for(i=8;i>0;i--)
- {
- if(Data&0x80)
- LCD_SDA_SET; //êä3öêy¾Y
- else LCD_SDA_CLR;
-
- LCD_SCL_CLR;
- LCD_SCL_SET;
- Data<<=1;
- }
- }
- ///****************************************************************************
- //* Ãû 3Æ£ou8 SPI_WriteByte(SPI_TypeDef* SPIx,u8 Byte)
- //* 1| Äü£oSTM32_ó2¼tSPI¶áD′ò»¸ö×Ö½úêy¾Yμ×2ãoˉêy
- //* èë¿ú2Îêy£oSPIx,Byte
- //* 3ö¿ú2Îêy£o·μ»Ø×üÏßêÕμ½μÄêy¾Y
- //* Ëμ Ã÷£oSTM32_ó2¼tSPI¶áD′ò»¸ö×Ö½úêy¾Yμ×2ãoˉêy
- //****************************************************************************/
- //u8 SPI_WriteByte(SPI_TypeDef* SPIx,u8 Byte)
- //{
- // while((SPIx->SR&SPI_I2S_FLAG_TXE)==RESET); //μè′y·¢ËíÇø¿Õ
- // SPIx->DR=Byte; //·¢Ëíò»¸öbyte
- // while((SPIx->SR&SPI_I2S_FLAG_RXNE)==RESET);//μè′y½óêÕíêò»¸öbyte
- // return SPIx->DR; //·μ»ØêÕμ½μÄêy¾Y
- //}
- ///****************************************************************************
- //* Ãû 3Æ£ovoid SPI_SetSpeed(SPI_TypeDef* SPIx,u8 SpeedSet)
- //* 1| Äü£oéèÖÃSPIμÄËù¶è
- //* èë¿ú2Îêy£oSPIx,SpeedSet
- //* 3ö¿ú2Îêy£oÎT
- //* Ëμ Ã÷£oSpeedSet:1,¸ßËù;0,μíËù;
- //****************************************************************************/
- //void SPI_SetSpeed(SPI_TypeDef* SPIx,u8 SpeedSet)
- //{
- // SPIx->CR1&=0XFFC7;
- // if(SpeedSet==1)//¸ßËù
- // {
- // SPIx->CR1|=SPI_BaudRatePrescaler_2;//Fsck=Fpclk/2
- // }
- // else//μíËù
- // {
- // SPIx->CR1|=SPI_BaudRatePrescaler_32; //Fsck=Fpclk/32
- // }
- // SPIx->CR1|=1<<6; //SPIé豸ê1Äü
- //}
- ///****************************************************************************
- //* Ãû 3Æ£oSPI2_Init(void)
- //* 1| Äü£oSTM32_SPI2ó2¼tÅäÖÃ3õê¼»ˉ
- //* èë¿ú2Îêy£oÎT
- //* 3ö¿ú2Îêy£oÎT
- //* Ëμ Ã÷£oSTM32_SPI2ó2¼tÅäÖÃ3õê¼»ˉ
- //****************************************************************************/
- //void SPI2_Init(void)
- //{
- // SPI_InitTypeDef SPI_InitStructure;
- // GPIO_InitTypeDef GPIO_InitStructure;
- //
- // //ÅäÖÃSPI21ü½Å
- // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB, ENABLE);
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15;
- // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
- // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12;
- // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- // GPIO_Init(GPIOB, &GPIO_InitStructure);
- //
- // //SPI2ÅäÖÃÑ¡Ïî
- // RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE);
- //
- // SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- // SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- // SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- // SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
- // SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
- // SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
- // SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
- // SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
- // SPI_InitStructure.SPI_CRCPolynomial = 7;
- // SPI_Init(SPI2, &SPI_InitStructure);
- // //ê1ÄüSPI2
- // SPI_Cmd(SPI2, ENABLE);
- //}
- /****************************************************************************
- * Ãû 3Æ£oLcd_WriteIndex(u8 Index)
- * 1| Äü£oÏòòo¾§ÆáD′ò»¸ö8λָáî
- * èë¿ú2Îêy£oIndex ¼Ä′æÆ÷μØÖ·
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oμ÷óÃÇ°DèÏèÑ¡ÖD¿ØÖÆÆ÷£¬Äú2¿oˉêy
- ****************************************************************************/
- void Lcd_WriteIndex(u8 Index)
- {
- LCD_CS_CLR;
- LCD_RS_CLR;
- SPIv_WriteData(Index);
- LCD_CS_SET;
- }
- /****************************************************************************
- * Ãû 3Æ£oLcd_WriteData(u8 Data)
- * 1| Äü£oÏòòo¾§ÆáD′ò»¸ö8λêy¾Y
- * èë¿ú2Îêy£odat ¼Ä′æÆ÷êy¾Y
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oÏò¿ØÖÆÆ÷Ö¸¶¨μØÖ·D′èëêy¾Y£¬Äú2¿oˉêy
- ****************************************************************************/
- void Lcd_WriteData(u8 Data)
- {
- LCD_CS_CLR;
- LCD_RS_SET;
- SPIv_WriteData(Data);
- LCD_CS_SET;
- }
- /****************************************************************************
- * Ãû 3Æ£ovoid LCD_WriteReg(u8 Index,u16 Data)
- * 1| Äü£oD′¼Ä′æÆ÷êy¾Y
- * èë¿ú2Îêy£oIndex,Data
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£o±¾oˉêyÎa×éoÏoˉêy£¬ÏòIndexμØÖ·μļÄ′æÆ÷D′èëDataÖμ
- ****************************************************************************/
- void LCD_WriteReg(u8 Index,u16 Data)
- {
- Lcd_WriteIndex(Index);
- Lcd_WriteData_16Bit(Data);
- }
- /****************************************************************************
- * Ãû 3Æ£ovoid Lcd_WriteData_16Bit(u16 Data)
- * 1| Äü£oÏòòo¾§ÆáD′ò»¸ö16λêy¾Y
- * èë¿ú2Îêy£oData
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oÏò¿ØÖÆÆ÷Ö¸¶¨μØÖ·D′èëò»¸ö16λêy¾Y
- ****************************************************************************/
- void Lcd_WriteData_16Bit(u16 Data)
- {
- Lcd_WriteData(Data>>8);
- Lcd_WriteData(Data);
- }
- /****************************************************************************
- * Ãû 3Æ£ovoid Lcd_Reset(void)
- * 1| Äü£oòo¾§ó2¸′λoˉêy
- * èë¿ú2Îêy£oÎT
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oòo¾§3õê¼»ˉÇ°DèÖ′DDò»′θ′λ2ù×÷
- ****************************************************************************/
- void Lcd_Reset(void)
- {
- LCD_RST_CLR;
- delay_ms(100);
- LCD_RST_SET;
- delay_ms(50);
- }
- /****************************************************************************
- * Ãû 3Æ£ovoid Lcd_Init(void)
- * 1| Äü£oòo¾§3õê¼»ˉoˉêy
- * èë¿ú2Îêy£oÎT
- * 3ö¿ú2Îêy£oÎT
- * Ëμ Ã÷£oòo¾§3õê¼»ˉ_ILI9225_176X220
- ****************************************************************************/
- void Lcd_Init(void)
- {
- LCD_GPIO_Init();//ê1óÃÄ£ÄaSPI
- Lcd_Reset(); //Reset before LCD Init.
- //2.2inch TM2.2-G2.2 Init 20171020
- Lcd_WriteIndex(0x11);
- Lcd_WriteData(0x00);
- Lcd_WriteIndex(0xCF);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0XC1);
- Lcd_WriteData(0X30);
- Lcd_WriteIndex(0xED);
- Lcd_WriteData(0X64);
- Lcd_WriteData(0X03);
- Lcd_WriteData(0X12);
- Lcd_WriteData(0X81);
- Lcd_WriteIndex(0xE8);
- Lcd_WriteData(0X85);
- Lcd_WriteData(0X11);
- Lcd_WriteData(0X78);
- Lcd_WriteIndex(0xF6);
- Lcd_WriteData(0X01);
- Lcd_WriteData(0X30);
- Lcd_WriteData(0X00);
- Lcd_WriteIndex(0xCB);
- Lcd_WriteData(0X39);
- Lcd_WriteData(0X2C);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0X34);
- Lcd_WriteData(0X05);
- Lcd_WriteIndex(0xF7);
- Lcd_WriteData(0X20);
- Lcd_WriteIndex(0xEA);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0X00);
- Lcd_WriteIndex(0xC0);
- Lcd_WriteData(0X20);
- Lcd_WriteIndex(0xC1);
- Lcd_WriteData(0X11);
- Lcd_WriteIndex(0xC5);
- Lcd_WriteData(0X31);
- Lcd_WriteData(0X3C);
- Lcd_WriteIndex(0xC7);
- Lcd_WriteData(0XA9);
- Lcd_WriteIndex(0x3A);
- Lcd_WriteData(0X55);
-
- Lcd_WriteIndex(0x36);
- #if USE_HORIZONTAL
- Lcd_WriteData(0xE8);//oáÆá2Îêy
- #else
- Lcd_WriteData(0x48);//êúÆá2Îêy
- #endif
- Lcd_WriteIndex(0xB1);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0X18);
- Lcd_WriteIndex(0xB4);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0X00);
- Lcd_WriteIndex(0xF2);
- Lcd_WriteData(0X00);
- Lcd_WriteIndex(0x26);
- Lcd_WriteData(0X01);
- Lcd_WriteIndex(0xE0);
- Lcd_WriteData(0X0F);
- Lcd_WriteData(0X17);
- Lcd_WriteData(0X14);
- Lcd_WriteData(0X09);
- Lcd_WriteData(0X0C);
- Lcd_WriteData(0X06);
- Lcd_WriteData(0X43);
- Lcd_WriteData(0X75);
- Lcd_WriteData(0X36);
- Lcd_WriteData(0X08);
- Lcd_WriteData(0X13);
- Lcd_WriteData(0X05);
- Lcd_WriteData(0X10);
- Lcd_WriteData(0X0B);
- Lcd_WriteData(0X08);
- Lcd_WriteIndex(0xE1);
- Lcd_WriteData(0X00);
- Lcd_WriteData(0X1F);
- Lcd_WriteData(0X23);
- Lcd_WriteData(0X03);
- Lcd_WriteData(0X0E);
- Lcd_WriteData(0X04);
- Lcd_WriteData(0X39);
- Lcd_WriteData(0X25);
- Lcd_WriteData(0X4D);
- Lcd_WriteData(0X06);
- Lcd_WriteData(0X0D);
- Lcd_WriteData(0X0B);
- Lcd_WriteData(0X33);
- Lcd_WriteData(0X37);
- Lcd_WriteData(0X0F);
- Lcd_WriteIndex(0x29);
- }
- /*************************************************
- oˉêyÃû£oLCD_Set_XY
- 1|Äü£oéèÖÃlcdÏÔê¾Æeê¼μã
- èë¿ú2Îêy£oxy×ø±ê
- ·μ»ØÖμ£oÎT
- *************************************************/
- void Lcd_SetXY(u16 Xpos, u16 Ypos)
- {
- Lcd_WriteIndex(0x2A);
- Lcd_WriteData_16Bit(Xpos);
- Lcd_WriteIndex(0x2B);
- Lcd_WriteData_16Bit(Ypos);
- Lcd_WriteIndex(0x2c);
- }
- /*************************************************
- oˉêyÃû£oLCD_Set_Region
- 1|Äü£oéèÖÃlcdÏÔê¾Çøóò£¬Ôú′ËÇøóòD′μãêy¾Y×Ô¶ˉ»»DD
- èë¿ú2Îêy£oxyÆeμãoíÖÕμã
- ·μ»ØÖμ£oÎT
- *************************************************/
- //éèÖÃÏÔê¾′°¿ú
- void Lcd_SetRegion(u16 xStar, u16 yStar,u16 xEnd,u16 yEnd)
- {
- Lcd_WriteIndex(0x2A);
- Lcd_WriteData_16Bit(xStar);
- Lcd_WriteData_16Bit(xEnd);
- Lcd_WriteIndex(0x2B);
- Lcd_WriteData_16Bit(yStar);
- Lcd_WriteData_16Bit(yEnd);
- Lcd_WriteIndex(0x2c);
- }
-
- /*************************************************
- oˉêyÃû£oLCD_DrawPoint
- 1|Äü£o»-ò»¸öμã
- èë¿ú2Îêy£oxy×ø±êoíÑÕé«êy¾Y
- ·μ»ØÖμ£oÎT
- *************************************************/
- void Gui_DrawPoint(u16 x,u16 y,u16 Data)
- {
- Lcd_SetXY(x,y);
- Lcd_WriteData_16Bit(Data);
- }
- /*************************************************
- oˉêyÃû£oLcd_Clear
- 1|Äü£oè«ÆáÇåÆáoˉêy
- èë¿ú2Îêy£oìî3äÑÕé«COLOR
- ·μ»ØÖμ£oÎT
- *************************************************/
- void Lcd_Clear(u16 Color)
- {
- unsigned int i;
- Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1);
- LCD_CS_CLR;
- LCD_RS_SET;
- for(i=0;i<X_MAX_PIXEL*Y_MAX_PIXEL;i++)
- {
- //Lcd_WriteData_16Bit(Color);
- SPIv_WriteData(Color>>8);
- SPIv_WriteData(Color);
- }
- LCD_CS_SET;
- }
复制代码
下一下是挑战硬件的SPI,欲知后事如何且看下次分享
|
|