2.2寸(14PIN)TFT液晶屏STM32 SPI 控制


屏幕如圖所示,共14個IO口(也可能只有13個),控制屏幕的有9個IO口

詳細版介紹見:http://www.ciast.net/post/20151112.html

 

反面IO口圖:

 

連接通過SPI方式連接:

//默認程序接線說明:
#define LCD_CTRL             GPIOB                //定義TFT數據端口為PB組
#define LCD_LED            GPIO_Pin_9  //MCU_PB9           對應接液晶屏(或者模塊)TFT --PIN_LED背光正極(背光可以由IO口提供電流,或者外接3.3V電壓)
#define LCD_CS            GPIO_Pin_11 //MCU_PB11            對應接液晶屏(或者模塊)TFT --CS
#define LCD_SCL            GPIO_Pin_13    //MCU_PB13            對應接液晶屏(或者模塊)TFT --SCL
#define LCD_SDA            GPIO_Pin_15    //MCU_PB15 MOSI    對應接液晶屏(或者模塊)TFT --SDA 
#define LCD_SDO            GPIO_Pin_14    //MCU_PB14 MISO    對應接液晶屏(或者模塊)TFT --SDO 
#define LCD_RS             GPIO_Pin_10    //MCU_PB10            對應接液晶屏(或者模塊)TFT --RS/DC
#define LCD_RST           GPIO_Pin_12    //MCU_PB12            對應接液晶屏(或者模塊)TFT --RST

  實現功能:

//本測試程序演示功能包括:
//1.純色填充測試
//2.英文顯示測試示例
//3.中文顯示測試示例
//4.2D按鈕顯示測試示例
//5.數碼管字體數字顯示測試示例
//6.圖片顯示測試示例
//7.橫豎屏切換測試示例

main.c文件:

//////////////////////////////////////////////////////////////////////////////////     

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "Lcd_Driver.h"
#include "GUI.h"
#include "delay.h"
#include "Picture.h"

GPIO_InitTypeDef GPIO_InitStructure;

void RCC_Configuration(void);

void Delayms(__IO uint32_t nCount);

unsigned char Num[10]={0,1,2,3,4,5,6,7,8,9};



void Redraw_Mainmenu(void)
{

    Lcd_Clear(GRAY0);
    
    Gui_DrawFont_GBK16(16,0,BLUE,GRAY0,"全動電子技術");
    Gui_DrawFont_GBK16(16,20,RED,GRAY0,"液晶測試程序");

    DisplayButtonUp(15,38,113,58); //x1,y1,x2,y2
    Gui_DrawFont_GBK16(16,40,YELLOW,GRAY0,"顏色填充測試");

    DisplayButtonUp(15,68,113,88); //x1,y1,x2,y2
    Gui_DrawFont_GBK16(16,70,BLUE,GRAY0,"文字顯示測試");

    DisplayButtonUp(15,98,113,118); //x1,y1,x2,y2
    Gui_DrawFont_GBK16(16,100,RED,GRAY0,"圖片顯示測試");


    Gui_DrawFont_GBK16(16,120,BLUE,GRAY0,"S1:Move.    ");
    Gui_DrawFont_GBK16(16,140,RED,GRAY0, "S2:Sellect  ");
    delay_ms(1000);
    delay_ms(1000);
    /*
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[5]);
    delay_ms(1000);
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[4]);
    delay_ms(1000);
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[3]);
    delay_ms(1000);
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[2]);
    delay_ms(1000);
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[1]);
    delay_ms(1000);
    Gui_DrawFont_Num32(100,125,RED,GRAY0,Num[0]);    */
}

void Num_Test(void)
{
    u8 i=0;
    Lcd_Clear(GRAY0);
    Gui_DrawFont_GBK16(16,20,RED,GRAY0,"Num Test");
    delay_ms(1000);
    Lcd_Clear(GRAY0);

    for(i=0;i<10;i++)
    {
    Gui_DrawFont_Num32((i%3)*40,32*(i/3)+30,RED,GRAY0,Num[i+1]);
    delay_ms(100);
    }
    delay_ms(1000);
    
}
//文字顯示測試全動電子技術商城因為專注所以專業程
void Font_Test(void)
{
    u8 x_offset;
#ifdef H_VIEW  //如果定義了橫屏顯示
    x_offset=40;
#else
    x_offset=0;
#endif
    Lcd_Clear(GRAY0);
    Gui_DrawFont_GBK16(16,10,BLUE,GRAY0,  "   文字顯示測試   ");

    delay_ms(1000);
    Lcd_Clear(WHITE);
    Gui_DrawFont_GBK16(x_offset,10,RED,WHITE,  "     全動電子技術有限公司      ");
    Gui_DrawFont_GBK16(x_offset,30,RED,WHITE,  "         QDtech .,LTD         ");
    Gui_DrawFont_GBK24(x_offset,50,BLUE,WHITE, "           歡迎您            ");
    Gui_DrawFont_GBK16(x_offset,100,GREEN,WHITE,   "     全程技術支持     ");    
    Gui_DrawFont_GBK16(x_offset,120,RED,YELLOW,   "http://qdtech.taobao.com");
    Gui_DrawFont_GBK16(x_offset,140,RED,YELLOW,   "E-Mail:QDtech2008@gmail.com");
    Gui_DrawFont_GBK16(x_offset,160,RED,YELLOW,   "技術交流群:324828016");    
    Gui_DrawFont_GBK16(x_offset,180,BLUE,WHITE,   "Tel:15989313508 ");
    delay_ms(3000);    
}

void Color_Test(void)
{
    u8 i=2;
    Lcd_Clear(GRAY0);
    
    Gui_DrawFont_GBK16(20,10,BLUE,GRAY0,"Color Test");
    delay_ms(1000);

    while(i--)
    {
    Lcd_Clear(WHITE);
    Lcd_Clear(BLACK);
    Lcd_Clear(RED);
      Lcd_Clear(GREEN);
      Lcd_Clear(BLUE);
    }        
}
//16位 垂直掃描  右到左  高位在前
void show_pic(const unsigned char *p)
{
    int i,j;
    unsigned char picH,picL;
    //Lcd_SetRegion(0,0,240-1,240-1);
    for(i=0;i<240;i++)
    for(j=0;j<320;j++)
    {
        picH=*p++;
        picL=*p++;
        Lcd_WriteData(picH);
        Lcd_WriteData(picL);
    }        
} 

u16 ID=0;
int main(void)
{
  //uint16_t a;
  /* System Clocks Configuration **********************************************/
  SystemInit();
  delay_init(72);//延時初始化 
  while(1) 
  {
        Lcd_Init();            
        Lcd_Clear(WHITE);
        LCD_LED_SET;
        //delay_ms(500);
        // LCD_LED_CLR;
        //delay_ms(500);
        //LCD_LED_SET;
        Redraw_Mainmenu();//簡單菜單測試
        Color_Test();//簡單刷屏測試
        Num_Test();//數碼管字體顯示
        Font_Test();//中英文測試  
            
        Lcd_Clear(WHITE);  
        show_pic(gImage_123);//圖片顯示測試
        delay_ms(1000);
        delay_ms(1000);
        Lcd_Clear(WHITE);  
        Gui_DrawFont_GBK16(10,50,BLUE,GRAY0,"測試成功.");
        delay_ms(1000);
  }
 
}


void RCC_Configuration(void)
{   
  /* Setup the microcontroller system. Initialize the Embedded Flash Interface,  
     initialize the PLL and update the SystemFrequency variable. */
  SystemInit();
}


void Delayms(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param file: pointer to the source file name
  * @param line: assert_param error line source number
  * @retval : None
  */



void assert_failed(uint8_t* file, uint32_t line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

最終效果圖:

----------------------------------------------------------------------------------------------------------

其他文件:

整個 STM程序下載:http://download.csdn.net/detail/zgc261/7306853


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM