10.国民技术N32G45X例程之- XFMC驱动液晶屏软件篇

10.国民技术N32G45X例程之- XFMC驱动液晶屏软件篇


前言

10.国民技术N32G45X例程之- XFMC驱动液晶屏软件篇,例程利用硬件XFMC驱动16位数据总线LCD,最快速度有8M左右。


提示:以下是本篇文章正文内容,下面案例可供参考

一、XFMC是什么?

示例:XFMC是指静态控制器,用于控制SRAM、ROM等外部器件,用XFMC驱动LCD相当于控制SRAM。详细说明这里不再敷衍,本文主要介绍如何使用XFMC驱动LCD。

二、XFMC驱动LCD

1.初始化LCD复位引脚

代码如下(示例):

void LCD_REST_GPIO_Init(void)
{
    GPIO_InitType GPIO_InitStructure;

	//PE0  RESET 
    RCC_EnableAPB2PeriphClk(  RCC_APB2_PERIPH_GPIOE, ENABLE);	
	GPIO_InitStruct(&GPIO_InitStructure);
    GPIO_InitStructure.Pin        = GPIO_PIN_0;        
	GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;        
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;        
    GPIO_InitPeripheral(GPIOE, &GPIO_InitStructure);
	
}

2.初始化XFMC引脚

代码如下(示例):

void  LCD_XFMC_GPIO_Init(void)
{
    GPIO_InitType GPIO_InitStructure;

    RCC_EnableAPB2PeriphClk(  RCC_APB2_PERIPH_AFIO 
                              |LCD_CS_CLK  | LCD_RS_CLK  | LCD_WR_CLK  | LCD_RD_CLK 
                              | LCD_D0_CLK  | LCD_D1_CLK | LCD_D2_CLK  | LCD_D3_CLK  
                              | LCD_D4_CLK  | LCD_D5_CLK | LCD_D6_CLK  | LCD_D7_CLK  
                              | LCD_D8_CLK  | LCD_D9_CLK | LCD_D10_CLK | LCD_D11_CLK 
                              | LCD_D12_CLK | LCD_D13_CLK| LCD_D14_CLK | LCD_D15_CLK,
                                ENABLE);

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;

    GPIO_InitStructure.Pin = LCD_D0_PIN;
    GPIO_InitPeripheral(LCD_D0_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D1_PIN;
    GPIO_InitPeripheral(LCD_D1_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D2_PIN;
    GPIO_InitPeripheral(LCD_D2_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D3_PIN;
    GPIO_InitPeripheral(LCD_D3_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D4_PIN;
    GPIO_InitPeripheral(LCD_D4_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D5_PIN;
    GPIO_InitPeripheral(LCD_D5_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D6_PIN;
    GPIO_InitPeripheral(LCD_D6_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D7_PIN;
    GPIO_InitPeripheral(LCD_D7_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D8_PIN;
    GPIO_InitPeripheral(LCD_D8_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D9_PIN;
    GPIO_InitPeripheral(LCD_D9_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D10_PIN;
    GPIO_InitPeripheral(LCD_D10_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D11_PIN;
    GPIO_InitPeripheral(LCD_D11_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D12_PIN;
    GPIO_InitPeripheral(LCD_D12_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D13_PIN;
    GPIO_InitPeripheral(LCD_D13_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D14_PIN;
    GPIO_InitPeripheral(LCD_D14_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_D15_PIN;
    GPIO_InitPeripheral(LCD_D15_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_RD_PIN;
    GPIO_InitPeripheral(LCD_RD_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_WR_PIN;
    GPIO_InitPeripheral(LCD_WR_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_CS_PIN;
    GPIO_InitPeripheral(LCD_CS_PORT, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = LCD_RS_PIN;
    GPIO_InitPeripheral(LCD_RS_PORT, &GPIO_InitStructure);

}

3.初始化XFMC

代码如下(示例):

void  LCD_XFMC_CONF_Init(void)
{
    XFMC_NorSramInitTpye XFMC_NORSRAMInitStructure;
    XFMC_NorSramTimingInitType readWriteTiming;

    RCC_EnableAHBPeriphClk(RCC_AHB_PERIPH_XFMC, ENABLE);
    
    readWriteTiming.AddrSetTime = XFMC_NOR_SRAM_ADDR_SETUP_TIME_1HCLK;
    readWriteTiming.AddrHoldTime     = XFMC_NOR_SRAM_ADDR_HOLD_TIME_1HCLK;
    readWriteTiming.DataSetTime = 0x03;  //0x01~0xFF  
    readWriteTiming.BusRecoveryCycle = XFMC_NOR_SRAM_BUSRECOVERY_TIME_1HCLK;
    readWriteTiming.ClkDiv           = XFMC_NOR_SRAM_CLK_DIV_2;
    readWriteTiming.DataLatency      = XFMC_NOR_SRAM_DATA_LATENCY_2CLK;
    readWriteTiming.AccMode     = XFMC_NOR_SRAM_ACC_MODE_A;
    
    XFMC_NORSRAMInitStructure.Block            = XFMC_BANK1_BLOCK1;
    XFMC_NORSRAMInitStructure.DataAddrMux      = XFMC_NOR_SRAM_MUX_DISABLE;//不复用地址
    XFMC_NORSRAMInitStructure.MemType          = XFMC_MEM_TYPE_SRAM;//SRAM
    XFMC_NORSRAMInitStructure.MemDataWidth     = XFMC_NOR_SRAM_DATA_WIDTH_16B;//数据宽16BIT
    XFMC_NORSRAMInitStructure.BurstAccMode     = XFMC_NOR_SRAM_BURST_MODE_DISABLE;
    XFMC_NORSRAMInitStructure.WaitSigPolarity  = XFMC_NOR_SRAM_WAIT_SIGNAL_LOW;
    XFMC_NORSRAMInitStructure.AsynchroWait     = XFMC_NOR_SRAM_ASYNC_NWAIT_DISABLE;
    XFMC_NORSRAMInitStructure.WrapMode         = XFMC_NOR_SRAM_WRAP_DISABLE;
    XFMC_NORSRAMInitStructure.WaitSigConfig    = XFMC_NOR_SRAM_NWAIT_BEFORE_STATE;
    XFMC_NORSRAMInitStructure.WriteEnable      = XFMC_NOR_SRAM_WRITE_ENABLE;
    XFMC_NORSRAMInitStructure.WaitSigEnable    = XFMC_NOR_SRAM_NWAIT_DISABLE;
    XFMC_NORSRAMInitStructure.ExtModeEnable    = XFMC_NOR_SRAM_EXTENDED_ENABLE;
    XFMC_NORSRAMInitStructure.WriteBurstEnable = XFMC_NOR_SRAM_BURST_WRITE_DISABLE;
    XFMC_NORSRAMInitStructure.RWTimingStruct   = &readWriteTiming;
    XFMC_NORSRAMInitStructure.WTimingStruct    = &readWriteTiming;

    XFMC_InitNorSram(&XFMC_NORSRAMInitStructure);

    XFMC_EnableNorSram(XFMC_BANK1_BLOCK1, ENABLE);
}

4.初始化LCD

代码如下(示例):

//初始化lcd  
void LCD_Init(void)
{ 
	LCD_REST_GPIO_Init();
    LCD_XFMC_GPIO_Init();
	LCD_XFMC_CONF_Init();
		 
	LCD_REST_H;
	delay_ms(1); 
	LCD_REST_L;
	delay_ms(10); 
	LCD_REST_H;
	delay_ms(120); 
	
    //+++++++++++++++++++++++++
    LCD_WR_REG(0x11);     
    delay_ms(120); //ms

    LCD_WR_REG(0x36);
    LCD_WR_DATA(0x60);

    LCD_WR_REG(0x3a);
    LCD_WR_DATA(0x05);

    LCD_WR_REG(0xB2);     
    LCD_WR_DATA(0x0C);   
    LCD_WR_DATA(0x0C);   
    LCD_WR_DATA(0x00);   
    LCD_WR_DATA(0x33);   
    LCD_WR_DATA(0x33);   

    LCD_WR_REG(0xB7);     
    LCD_WR_DATA(0x75);   //VGH=14.97V, VGL=-10.43V  

    LCD_WR_REG(0xBB);   //VCOM  
    LCD_WR_DATA(0x19);   

    LCD_WR_REG(0xC0);     
    LCD_WR_DATA(0x2C);   

    LCD_WR_REG(0xC2);     
    LCD_WR_DATA(0x01);   

    LCD_WR_REG(0xC3);   //GVDD    VRH
    LCD_WR_DATA(0x1D);   //GVDD=5V   

    LCD_WR_REG(0xC4);     
    LCD_WR_DATA(0x20);   

    LCD_WR_REG(0xC6);  //频率   
    LCD_WR_DATA(0x0F);   

    LCD_WR_REG(0xD0);     
    LCD_WR_DATA(0xA4);   
    LCD_WR_DATA(0xA1);   

    LCD_WR_REG(0xE0);     
    LCD_WR_DATA(0xD0);   
    LCD_WR_DATA(0x03);   
    LCD_WR_DATA(0x0B);   
    LCD_WR_DATA(0x14);   
    LCD_WR_DATA(0x17);   
    LCD_WR_DATA(0x1D);   
    LCD_WR_DATA(0x3F);   
    LCD_WR_DATA(0x44);   
    LCD_WR_DATA(0x4E);   
    LCD_WR_DATA(0x0A);   
    LCD_WR_DATA(0x13);   
    LCD_WR_DATA(0x13);   
    LCD_WR_DATA(0x1E);   
    LCD_WR_DATA(0x20);   

    LCD_WR_REG(0xE1);     
    LCD_WR_DATA(0xD0);   
    LCD_WR_DATA(0x03);   
    LCD_WR_DATA(0x0B);   
    LCD_WR_DATA(0x12);   
    LCD_WR_DATA(0x14);   
    LCD_WR_DATA(0x1C);   
    LCD_WR_DATA(0x3F);   
    LCD_WR_DATA(0x44);   
    LCD_WR_DATA(0x4E);   
    LCD_WR_DATA(0x0B);   
    LCD_WR_DATA(0x17);   
    LCD_WR_DATA(0x15);   
    LCD_WR_DATA(0x1E);   
    LCD_WR_DATA(0x21);   

    LCD_WR_REG(0x29);
    delay_ms(120); 

    LCD_WR_REG(0x2C); 
    delay_ms(120); 
    
	
}


二,软件下载

10.国民技术N32G45X例程之- XFMC驱动液晶屏软件篇

https://download.csdn.net/download/suqingxiao/72546758

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

suqingxiao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值