OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 6281|回复: 1

STM32驱动LCD,只有背光亮,显示不了字符

[复制链接]

3

主题

7

帖子

0

精华

新手上路

积分
39
金钱
39
注册时间
2015-5-4
在线时间
0 小时
发表于 2015-5-14 09:44:29 | 显示全部楼层 |阅读模式
5金钱
用的是STM32F103ZET6驱动KS0108的19264液晶显示屏,只有背光亮,程序不知道哪里有错,恳请大神帮忙啊

#include "stm32f10x_lib.h"
#include "lcd_fsmc.h"
#include "HzLib.h"

#define LCD_Data    ((u32)0x60020000)    //disp Data ADDR
#define LCD_Reg    ((u32)0x60000000) //disp Reg ADDR

////////////////////////////////////////////////////////////////////////////////////////
/*******************************************************************************
* Function Name : LCD_CtrlLinesConfig 引脚IO配置
* Description   : Configures LCD Control lines (FSMC Pins) in alternate function
                   ush-Pull mode.
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_CtrlLinesConfig(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

  /* Enable FSMC, GPIOD, GPIOE, GPIOG and AFIO clocks */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
                         RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO, ENABLE);

  /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.14(D0), PD.15(D1) 
  as alternate function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
                                GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Set PE.00(RST),PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7) 
  as alternate function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_7 |GPIO_Pin_8 | 
GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /* Set PD.07(NE1) as alternate function push pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  
  /* Set PG.12(NE4) as alternate function push pull */
  //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  //GPIO_Init(GPIOG, &GPIO_InitStructure);
}

/*******************************************************************************
* Function Name : 背光控制脚PE1_LCD_BackLightCtrl
* Description   : 
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_LightPin(void)  
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
  GPIO_SetBits(GPIOE, GPIO_Pin_1);
}
/*******************************************************************************
* Function Name : LCD_FSMCConfig  FSMC配置
* Description   : Configures the Parallel interface (FSMC) for LCD(Parallel mode)
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_FSMCConfig(void)
{
  FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  FSMC_NORSRAMTimingInitTypeDef  p;

/*-- FSMC Configuration ------------------------------------------------------*/
/*----------------------- SRAM Bank 1 ----------------------------------------*/
  /* FSMC_Bank1_NORSRAM1 configuration */
  p.FSMC_AddressSetupTime = 2;
  p.FSMC_AddressHoldTime = 0;
  p.FSMC_DataSetupTime = 5;
  p.FSMC_BusTurnAroundDuration = 0;
  p.FSMC_CLKDivision = 0;
  p.FSMC_DataLatency = 0;
  p.FSMC_AccessMode = FSMC_AccessMode_B;

  /* Color LCD configuration ------------------------------------
     LCD configured as follow:
        - Data/Address MUX = Disable
        - Memory Type = SRAM
        - Data Width = 8bit
        - Write Operation = Enable
        - Extended Mode = Enable
        - Asynchronous Wait = Disable 
  */
  FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
  FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
  FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  FSMC_NORSRAMInitStructure.FSMC_AsyncWait = FSMC_AsyncWait_Disable;
  FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;

  FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);  

  /* BANK 1 (of NOR/SRAM Bank 1~4) is enabled */
  FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
}

/*******************************************************************************
* Function Name : LCD_RST
* Description   : Reset
* Input         : None
* Output         : None
* Return         : None
*******************************************************************************/
void LCD_RST(void)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_0);
  LCD_Delay(0xAF0000);     
GPIO_SetBits(GPIOE, GPIO_Pin_0 );    
LCD_Delay(0xAF0000);
}

void LCD_X_Init(void)
{
  /*背光引脚初始化*/
  LCD_LightPin();

 /* Configure the LCD Control pins --------------------------------------------*/
  LCD_CtrlLinesConfig();

/* Configure the FSMC Parallel interface -------------------------------------*/
  LCD_FSMCConfig();
}


/*******************************************************************************
* Function Name : LCD_Write
* Description   : Writes to the selected LCD register.
* Input         : - DH,DL.
* Output         : None
* Return         : None
*******************************************************************************/

void LCD_Write(u8 index)
{
*(u8 *) (LCD_Reg)= index;

}

/*******************************************************************************
* Function Name : LCD_Read
* Description   : Reads the selected LCD Register.
* Input         : None
* Output         : None
* Return         : LCD Register Value.
*******************************************************************************/

u16 LCD_ReadData(u16 val)
{
u16  a;
LCD_Write (0x2e);
a=*(u8 *) (LCD_Data);
a<<=8;
a|=*(u8 *) (LCD_Data);
return a;
}


/*******************************************************************************
* Function Name : LCD_WriteRAM
* Description   : Writes to the LCD RAM.
* Input         : - DH,DL.
* Output         : None
* Return         : None
*******************************************************************************/

void LCD_WriteData(u8 val)
{
*(u8 *) (LCD_Data)= val;

}


/****************************************************************************
* 名    称:void LCD_Initializtion()
* 功    能:初始化 LCD 控制器
* 入口参数:无
* 出口参数:无
* 说    明:
* 调用方法:LCD_Initializtion();
****************************************************************************/
void LCD_Initializtion()
{
    LCD_RST();
LCD_X_Init();
LCD_Write(0x3f); //设置开显示命令
LCD_Write(0xc0); //设置起始位置
}

/****************************************************************************
* 名    称:void LCD_BackLight(u8 status)
* 功    能:开、关液晶背光
* 入口参数:status     1:背光开  0:背光关
* 出口参数:无
* 说    明:
* 调用方法:LCD_BackLight(1);
****************************************************************************/
void LCD_BackLight(u8 status)
{
  if ( status >= 1 )
  {
    GPIO_SetBits(GPIOE, GPIO_Pin_1);
  }
  else
  {
    GPIO_ResetBits(GPIOE, GPIO_Pin_1);
  }
}

/****************************************************************************
* 名    称:void LCD_Delay(vu32 nCount)
* 功    能:延时
* 入口参数:nCount   延时值
* 出口参数:无
* 说    明:
* 调用方法:LCD_Delay(10000);
****************************************************************************/
void LCD_Delay(vu32 nCount)
{
  for(; nCount != 0; nCount--);
}

/****************************************************************************
* 名    称:void SelectScreen(u8 Screen)
* 功    能:选择屏幕
* 入口参数:Screen
* 出口参数:无
* 说    明:
* 调用方法:SelectScreen(0);
****************************************************************************/
void SelectScreen(u8 Screen)
{
switch(Screen)
{
case 0:
GPIO_ResetBits(GPIOE, GPIO_Pin_2); //CS1=0
GPIO_SetBits(GPIOE, GPIO_Pin_6 | GPIO_Pin_5); //CS2=1,CS3=1
break;
case 1:
GPIO_ResetBits(GPIOE, GPIO_Pin_6); //CS2=0
GPIO_SetBits(GPIOE, GPIO_Pin_2 | GPIO_Pin_5); //CS1=1,CS3=1
break;
case 2:
GPIO_ResetBits(GPIOE, GPIO_Pin_5); //CS3=0
GPIO_SetBits(GPIOE, GPIO_Pin_2 | GPIO_Pin_6); //CS1=1,CS2=1
break;
}
}

/****************************************************************************
* 名    称:void SetAddress(u8 Address)
* 功    能:设置页地址,列地址
* 入口参数:
* 出口参数:无
* 说    明:
****************************************************************************/
void SetAddress(u8 Address)
{
LCD_Write(Address);
}

/*******************************************************************************
* Function Name : Draw_Point
* Description   : 画点函数
* Input         : - Xpos: 水平坐标,0-63之间
*                  - Ypos: 竖直坐标,0-191之间 
*                  - Color: 颜色,color=0为变白,color=1为变黑,color=2为反转 
*******************************************************************************/
void Draw_Point(u8 Xpos, u8 Ypos, u8 Color)
{
    u8 x_num, y_num, num;
    u8 read_data;
    u8 write_data;
    u8 ypos_data;
    /*确定x位于哪一块,即页地址*/
    if ( Ypos > 63 )
    {
        return;//越界
    }
    else if ( Ypos < 8 )
    {
        x_num = 0xB8;
    }
    else if ( Ypos < 16 )
    {
        x_num = 0xB9;
    }
    else if ( Ypos < 24 )
    {
        x_num = 0xBA;
    }
    else if ( Ypos < 32 )
    {
        x_num = 0xBB;
    }
    else if ( Ypos < 40 )
    {
        x_num = 0xBC;
    }
    else if ( Ypos < 48 )
    {
        x_num = 0xBD;
    }
    else if ( Ypos < 56 )
    {
        x_num = 0xBE;
    }
    else
    {
        x_num = 0xBF;
    }  
    /*确定y的位置,即列地址*/
    if ( Xpos > 191 )
    {
        return;//越界
    }
    else if ( Xpos < 64 )
    {
        num = 0;
        y_num = Xpos + 0x40;//起始位置为0x40
    }
    else if ( Xpos < 128 )
    {
        num = 1;
        y_num = Xpos - 64 + 0x40;
    }
    else
    {
        num = 2;
        y_num = Xpos - 128 + 0x40;
    }
    SelectScreen(num);  //选择芯片
    SetAddress(x_num);//选择页地址
    SetAddress(y_num);//选择列地址
    //读一列数据点
    switch ( num )
    {
        case 0: 
            read_data = LCD_ReadData( 0 );//读数据需要读两次
            read_data = LCD_ReadData(0);
            break;
        case 1:
            read_data = LCD_ReadData( 1 );
            read_data = LCD_ReadData( 1 );
            break;
        case 2:
            read_data = LCD_ReadData(2 );
            read_data = LCD_ReadData(2 );
            break;
        default:break;
    }
    
    ypos_data = 1 << (Ypos % 8);        //得到点的位置
    
    switch ( Color )
    {
        case 0:
            write_data = read_data & (~ypos_data);//重新给这8个列点赋值,即将自己的点值覆盖进去
            break;
        case 1:
            write_data = read_data | ypos_data;
            break;
        case 2:
            write_data = read_data ^ ypos_data;
            break;
        default:break;
    }
    SelectScreen(num);  //选择芯片
    SetAddress(x_num);//选择页地址
    SetAddress(y_num);//选择列地址
    
    switch ( num )
    {
        case 0:
            LCD_Write(  write_data );                //显示出来
            break;
        case 1:
            LCD_Write(  write_data );
            break;
        case 2:
            LCD_Write(  write_data );
            break;
        default:break;
    }
}  

void LCD_SetPoint(u16 color,u16 x1,u16 y1)
// 起始列x1,起始行y1,宽w,高h
{
    u16 x2,y2;
    u8 color1,color2; 
    color1=(color>>8)&0x00ff;
    color2=color&0x00ff;  
x2=x1;
    y2=y1;

    LCD_Write(0x2a); 
    LCD_WriteData((x1>>8)&0x00ff); //列起始高8位
    LCD_WriteData(x1&0x00ff);      //列起始低8位
    LCD_WriteData((x2>>8)&0x00ff); //列结束高8位
    LCD_WriteData(x2&0x00ff);      //列结束低8位 
   
    LCD_Write(0x2b); 
    LCD_WriteData((y1>>8)&0x00ff); //行起始高8位
    LCD_WriteData(y1&0x00ff);      //行起始低8位
    LCD_WriteData((y2>>8)&0x00ff); //行结束高8位  
    LCD_WriteData(y2&0x00ff);      //行结束低8位  

   
LCD_Write(0x2c);//开始写数据
LCD_WriteData(color1); 
LCD_WriteData(color2);
}
/******************************************************************************
* Function Name : Draw_ChinseseChar
* Description   : 将Lcd屏上任意位置显示一个中文字
* Input         : - Xpos: 水平坐标 
*                  - Ypos: 垂直坐标  
*                  - str: 显示的中文字
*                  - Color: 字符颜色   
*                  - bkColor: 背景颜色 
* Attention : 显示扫描方式横向,大小12*12
*******************************************************************************/
void Draw_ChinseseChar(u8 Xpos,u8 Ypos,u8 *str,u8 Color,u8 bkColor)
{
        u8 i,j;
        u8 buffer[24];
        u16 tmp_char=0;
        GetGBKCode(buffer,str);  /* 取字模数据 */
        for ( i = 0; i < 12; i++ )
        {
                tmp_char = buffer[i*2];
                tmp_char = ( tmp_char << 8 );
                tmp_char |= buffer[2*i+1];
                for (j = 0; j < 12; j++ )
                {
                    if ( (tmp_char >> 15-j ) & 0x01 == 0x01 )
                {
                        Draw_Point(Xpos+j, Ypos+i, Color);  /* 字符颜色 */
                }
                else
                {
                    Draw_Point(Xpos+j, Ypos+i, bkColor);  /* 背景颜色 */
                }
            }
        }
}    

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

3

主题

2170

帖子

0

精华

资深版主

Rank: 8Rank: 8

积分
5781
金钱
5781
注册时间
2013-11-22
在线时间
1212 小时
发表于 2015-5-14 18:58:30 | 显示全部楼层
可能是驱动不对     你得去问屏幕卖家   去他那儿找这个屏的驱动
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-22 14:40

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表