zoukankan      html  css  js  c++  java
  • LCD_FSMC

    /**************************************************************************
    * 文件名:LCD_FSMC.h                                                      *
    * 编写人:离逝的风                                                        *
    * 更新时间:2018.12.15                                                    *
    * 说明:此文件属于开源,所有权对任何人开放                                             *
    * 如有问题请联系邮箱:1477153217@qq.com                                   *
    * 使用步骤:                                                              *
    * 1.在主函数中调用LcdInit()函数对LCD初始化即可使用其他函数                *
    * 说明:程序中采用的是ILI9325液晶控制器,若不是该控制器,则需要在初始化中 *
    * 修改替换成相对应得控制器初始化程序                                      *
    ***************************************************************************/
    
    #ifndef   __LCD_FSMC_H_
    #define   __LCD_FSMC_H_
    
    #include "stm32f10x.h"
    /*################################FSMC引脚说明###############################################
    FSMC_NOE-----PD4     FSMC_NE1/FSMC_NCE2-----PD7     FSMC_NE2/FSMC_NCE3----PG9
    FSMC_NWE-----PD5     FSMC_NCE4_1/FSMC_NE3---PG10    FSMC_NCE4_2------PG11
    FSMC_NE4-----PG12
    
    FSMC_A0----PF0    FSMC_A1----PF1   FSMC_A2----PF2   FSMC_A3----PF3
    FSMC_A4----PF4    FSMC_A5----PF5   FSMC_A6----PF12  FSMC_A7----PF13
    FSMC_A8----PF14   FSMC_A9----PF15  FSMC_A10---PG0   FSMC_A11---PG1
    FSMC_A12---PG2    FSMC_A13---PG3   FSMC_A14---PG4   FSMC_A15---PG5
    FSMC_A16---PD11   FSMC_A17---PD12  FSMC_A18---PD13  FSMC_A19---PE3
    FSMC_A20---PE4    FSMC_A21---PE5   FSMC_A22---PE6   FSMC_A23---PE2
    FSMC_A24---PG13   FSMC_A25---PG14 
    
    FSMC_D0----PD14   FSMC_D1----PD15  FSMC_D2----PD0   FSMC_D3----PD1
    FSMC_D4----PE7    FSMC_D5----PE8   FSMC_D6----PE9   FSMC_D7----PE10
    FSMC_D8----PE11   FSMC_D9----PE12  FSMC_D10---PE13  FSMC_D11---PE14
    FSMC_D12---PE15   FSMC_D13---PD8   FSMC_D14---PD9   FSMC_D15---PD10
    
    FSMC_INT2--PG6    FSMC_INT3--PG77  FSMC_NIORD-PF6   FSMC_NREG--PF7
    FSMC_NIOWR-PF8    FSMC_CD----PF9   FSMC_INTR--PF10  FSMC_NIOS16-PF11
    FSMC_CLK---PD3    FSMC_NWAIT-PD6   FSMC_NBL0--PE0   FSMC_NBL1---PE1
    *********************************************************************************************/
    
    /*################################寄存器说明##################################################
    BTCR[0]---FSMC_BCR1     BTCR[1]---FSMC_BTR1      
    BTCR[2]---FSMC_BCR2     BTCR[3]---FSMC_BTR2 
    BTCR[4]---FSMC_BCR3     BTCR[5]---FSMC_BTR3 
    BTCR[6]---FSMC_BCR4     BTCR[7]---FSMC_BTR4
    
    BWTR[0]---FSMC_BWTR1    BWTR[2]---FSMC_BWTR2
    BWTR[4]---FSMC_BWTR3    BWTR[6]---FSMC_BWTR4 
    
    BWTR[1] BWTR[3] BWTR[5]保留
    *********************************************************************************************/
    /*###################################下面是LCD的引脚连线#####################################*/
    //片选线 1:连接在块1   2:连接在块2    3:连接在块3     4:连接在块4
    #define     LCD_CS         4
    //数据和命令选择线  0-25:分别连接在A0-A25上
    #define     LCD_RS         10
    //背光线
    #define     LCD_BLK        RCC->APB2ENR|=(1<<3);GPIOB->CRL&=0xffffffF0;GPIOB->CRL|=0X00000003;
    //背光控制
    #define     LCD_BLK_ON     GPIOB->BRR|=(1<<0);
    #define     LCD_BLK_OFF    GPIOB->BSRR|=(1<<0);
    
    
    /*###################################下面函数供用户调用#####################################*/
    //液晶初始化函数
    void LcdInit(void);
    //液晶填充函数
    void LcdFill(unsigned long color);
    
    #endif
    
    
    //FILE END
    /**************************************************************************
    * 文件名:LCD_FSMC.c                                                      *
    * 编写人:离逝的风                                                        *
    * 更新时间:2018.12.15                                                    *
    * 说明:此文件属于开源,所有权对任何人开放                                             *
    * 如有问题请联系邮箱:1477153217@qq.com                                   *
    * 使用步骤:                                                              *
    * 1.在主函数中调用LcdInit()函数对LCD初始化即可使用其他函数                *
    * 说明:程序中采用的是ILI9325液晶控制器,若不是该控制器,则需要在初始化中 *
    * 修改替换成相对应得控制器初始化程序                                      *
    ***************************************************************************/
    
    #include "LCD_FSMC.h"
    
    /************************************************************************************
    函数:LcdDelay
    参数:time时间长短
    返回值:无
    说明:初始化使用的延时函数
    *************************************************************************************/
    void LcdDelay(unsigned int time)
    {
        unsigned int x,y;
        for(x=0;x<time;x++)
           for(y=0;y<11000;y++);
    }
    
    /************************************************************************************
    函数:LcdWriteData
    参数:Data:写入的数据
    返回值:无
    说明:液晶屏写数据函数
    *************************************************************************************/
    void LcdWriteData(unsigned int Data)
    {
        *(volatile unsigned long *)(0x6c000000+0X000007FE+(1<<(LCD_RS+1)))=Data;
    }
    /************************************************************************************
    函数:LcdWriteCom
    参数:Com:写入的指令
    返回值:无
    说明:液晶屏写指令函数
    *************************************************************************************/
    void LcdWriteCom(unsigned int Com)
    {
        *(volatile unsigned long *)(0x6c000000+0X000007FE)=Com;
    }
    
    
    /************************************************************************************
    函数:LcdWriteDatCom
    参数:Com:写入的指令   Data:写入的数据
    返回值:无
    说明:液晶屏写指令和数据函数
    *************************************************************************************/
    void LcdWriteDatCom(unsigned int Com,unsigned int Data)
    {
        LcdWriteCom(Com);
        LcdWriteData(Data);
    }
    
    
    /************************************************************************************
    函数:LcdInit
    参数:无
    返回值:无
    说明:初始化液晶屏
    *************************************************************************************/
    void LcdInit(void)
    {
        RCC->AHBENR |= 1 << 8;            //开启FSMC是时钟
      RCC->APB2ENR |=1 << 3 | 1 << 5 | 1 << 6 | 1 << 8; //  开启GPIO B,D,E,G引脚时钟
      RCC->APB2ENR |= 1 << 0;           //开启引脚复用时钟
      //GPIOB配置为复用推完输出
      GPIOB->CRL &= 0xfffffff0;          
      GPIOB->CRL |= 0x00000003; 
      //GPIOD配置为复用推完输出
      GPIOD->CRL &= 0xff00ff00;
      GPIOD->CRL |= 0x00bb00bb; 
      GPIOD->CRH &= 0x00fff000;
      GPIOD->CRH |= 0xbb000bbb; 
      //GPIOE配置为复用推完输出
      GPIOE->CRL &= 0x0fffffff;
      GPIOE->CRL |= 0xb0000000; 
      GPIOE->CRH &= 0x00000000; 
      GPIOE->CRH |= 0xbbbbbbbb; 
      //GPIOG配置为复用推完输出
      GPIOG->CRL &= 0xfffffff0;
      GPIOG->CRL |= 0x0000000b;
      GPIOG->CRH &= 0xfff0ffff;
      GPIOG->CRH |= 0x000b0000;
        
        FSMC_Bank1->BTCR[(LCD_CS-1)*2] &= 0x00000000;
      FSMC_Bank1->BTCR[(LCD_CS-1)*2] |= 1 << 14| 1 << 12 | 0x01 << 4 | 0x00 << 2 | 1 << 0; 
        
      FSMC_Bank1->BTCR[(LCD_CS-1)*2+1] &= 0x00000000; 
      FSMC_Bank1->BTCR[(LCD_CS-1)*2+1] |= 0x00 << 28 | 0x0000 << 20 | 0x0f << 8 | 0x01; 
    
      FSMC_Bank1E->BWTR[(LCD_CS-1)*2] &= 0x00000000;                         
      FSMC_Bank1E->BWTR[(LCD_CS-1)*2] |= 0x00 << 28 | 0x0000 << 20 | 0x03 << 8 | 0x00;
        
        /*******下面为LCD初始化**************/
      LcdWriteDatCom(0xE5, 0x78f0); // set SRAM internal timing
        LcdWriteDatCom(0x01, 0x0100); // set Driver Output Control  
        LcdWriteDatCom(0x02, 0x0700); // set 1 line inversion  
        LcdWriteDatCom(0x03, 0xe030); // set GRAM write direction and BGR=1.  
        LcdWriteDatCom(0x04, 0x0000); // Resize register  
        LcdWriteDatCom(0x08, 0x0207); // set the back porch and front porch  
        LcdWriteDatCom(0x09, 0x0000); // set non-display area refresh cycle ISC[3:0]  
        LcdWriteDatCom(0x0A, 0x0000); // FMARK function  
        LcdWriteDatCom(0x0C, 0x0001); // RGB interface setting  
        LcdWriteDatCom(0x0D, 0x0000); // Frame marker Position  
        LcdWriteDatCom(0x0F, 0x0000); // RGB interface polarity  
        //*************Power On sequence ****************//  
        LcdWriteDatCom(0x10, 0x0000); // SAP, BT[3:0], AP, DSTB, SLP, STB  
        LcdWriteDatCom(0x11, 0x0007); // DC1[2:0], DC0[2:0], VC[2:0]  
        LcdWriteDatCom(0x12, 0x0000); // VREG1OUT voltage  
        LcdWriteDatCom(0x13, 0x0000); // VDV[4:0] for VCOM amplitude  
        LcdWriteDatCom(0x07, 0x0001);  
        LcdDelay(20); // Dis-charge capacitor power voltage  
        LcdWriteDatCom(0x10, 0x1090); // SAP, BT[3:0], AP, DSTB, SLP, STB  
        LcdWriteDatCom(0x11, 0x0227); // Set DC1[2:0], DC0[2:0], VC[2:0]  
        LcdDelay(5); // Delay 50ms  
        LcdWriteDatCom(0x12, 0x001F); // 0012  
        LcdDelay(5); // Delay 50ms  
        LcdWriteDatCom(0x13, 0x1500); // VDV[4:0] for VCOM amplitude  
        LcdWriteDatCom(0x29, 0x0027); // 04  VCM[5:0] for VCOMH  
        LcdWriteDatCom(0x2B, 0x000D); // Set Frame Rate  
        LcdDelay(5); // Delay 50ms  
        LcdWriteDatCom(0x20, 0x0000); // GRAM horizontal Address  
        LcdWriteDatCom(0x21, 0x0000); // GRAM Vertical Address  
        // ----------- Adjust the Gamma Curve ----------//  
        LcdWriteDatCom(0x30, 0x0000);  
        LcdWriteDatCom(0x31, 0x0707);  
        LcdWriteDatCom(0x32, 0x0307);  
        LcdWriteDatCom(0x35, 0x0200);  
        LcdWriteDatCom(0x36, 0x0008);  
        LcdWriteDatCom(0x37, 0x0004);  
        LcdWriteDatCom(0x38, 0x0000);  
        LcdWriteDatCom(0x39, 0x0707);  
        LcdWriteDatCom(0x3C, 0x0002);  
        LcdWriteDatCom(0x3D, 0x1D04);  
        //------------------ Set GRAM area ---------------//  
        LcdWriteDatCom(0x50, 0x0000); // Horizontal GRAM Start Address  
        LcdWriteDatCom(0x51, 0x00EF); // Horizontal GRAM End Address  
        LcdWriteDatCom(0x52, 0x0000); // Vertical GRAM Start Address  
        LcdWriteDatCom(0x53, 0x013F); // Vertical GRAM Start Address  
        LcdWriteDatCom(0x60, 0xA700); // Gate Scan Line  
        LcdWriteDatCom(0x61, 0x0001); // NDL,VLE, REV   
        LcdWriteDatCom(0x6A, 0x0000); // set scrolling line  
        //-------------- Partial Display Control ---------//  
        LcdWriteDatCom(0x80, 0x0000);  
        LcdWriteDatCom(0x81, 0x0000);  
        LcdWriteDatCom(0x82, 0x0000);  
        LcdWriteDatCom(0x83, 0x0000);  
        LcdWriteDatCom(0x84, 0x0000);  
        LcdWriteDatCom(0x85, 0x0000);  
        //-------------- Panel Control -------------------//  
        LcdWriteDatCom(0x90, 0x0010);  
        LcdWriteDatCom(0x92, 0x0600);  
        LcdWriteDatCom(0x07, 0x0133); // 262K color and display ON   
      LcdWriteDatCom(0x00,0x0022);//
        LcdDelay(50);
         
    }
    
    /************************************************************************************
    函数:LcdFill
    参数:color:颜色值,16bit
    返回值:无
    说明:整屏填充颜色
    *************************************************************************************/
    void LcdFill(unsigned long color)
    {
        unsigned int x,y;
        LcdWriteDatCom(0x50, 0); // Horizontal GRAM Start Address  
        LcdWriteDatCom(0x51, 240); // Horizontal GRAM End Address  
        LcdWriteDatCom(0x52, 0); // Vertical GRAM Start Address 
        LcdWriteDatCom(0x53, 320); // Vertical GRAM Start Address   
        for(x=0;x<240;x++)
           for(y=0;y<320;y++)
           {
                    LcdWriteDatCom(0x22,color);
             }
        
    }
    
    
    
    //FILE END
  • 相关阅读:
    Power of Cryptography
    Radar Installation
    Emag eht htiw Em Pleh
    Help Me with the Game
    89. Gray Code
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    82. Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/listenscience/p/10176511.html
Copyright © 2011-2022 走看看