zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    网易严选的wkwebview测试之路
    【工程实践】服务器数据解析
    从加班论客户端开发中的建模
    UVaLive 6802 Turtle Graphics (水题,模拟)
    UVaLive 6694 Toy Boxes (二分+想法)
    UVaLive 6693 Flow Game (计算几何,线段相交)
    UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)
    UVaLive 6697 Homework Evaluation (DP)
    UVALive 6692 Lucky Number (思路 + 枚举)
    CodeForces 710E Generate a String (DP)
  • 原文地址:https://www.cnblogs.com/zitech/p/3712864.html
Copyright © 2011-2022 走看看