使用STM32控制T6963C液晶没有显示

2019-03-23 19:33发布

小弟这几天使用STM32F103的片子控制T6963C  24064 液晶,但是调试了好几天都没有任何显示,液晶屏在别人的程序上试过,没有问题,程序编译也很正常,控制端口输出电平读取电平也正常,估计是在对T6963C的控制上出现问题,小弟对液晶屏控制认识不多,请各位兄台指教一二,程序如下: /////////////////主函数////////////////////////////////////////////////////////////////// #include "Includes.h"
int main(void)
{
 InitSystem();
 GPIO_WriteBit(GPIOE, GPIO_Pin_5, (BitAction)(1));   LCD_RST_ABLE;
  delay_ms(1);
  LCD_RST_UNABLE;
  LCD_FONT_0;      LCDInit();
 ClearRAM();    while(1)
    {
      WriteRAM(1,1);  
 }
} /////////////////STM32系统初始化设置文件///////////////////////////////////////////////////
#include "Includes.h" void InitSystem(void)
{
 RCC_Configuration();
 GPIO_Configuration(); 
} void RCC_Configuration(void)
{
 RCC_DeInit();     //RCC系统复位
   RCC_HSICmd(ENABLE);     //使用内部高速晶振8M
 
 RCC_HCLKConfig(RCC_SYSCLK_Div1);   //设置高速总线时钟 HCLK = SYSCLK
   RCC_PCLK2Config(RCC_HCLK_Div1);   //配置低速总线时钟2 PCLK2 = HCLK
 RCC_PCLK1Config(RCC_HCLK_Div2);   //配置低速总线时钟1 PCLK1 = HCLK/2
 
   /* Flash 2 wait state */
   FLASH_SetLatency(FLASH_Latency_2);  //令FLASH处于等待状态
   /* Enable Prefetch Buffer */
   FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
 
   RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_9);  //使用锁相环将外部晶振9倍频到72MHz
 RCC_PLLCmd(ENABLE);     //使能锁相环       while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //等待锁相环输出稳定
   {
   }
 
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);  //选择锁相环输出作为系统时钟    while(RCC_GetSYSCLKSource() != 0x08)   //等待锁相环时钟作为系统时钟正常运行
   {
   }
  
 /* Enable peripheral clocks --------------------------------------------------*/
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOE, ENABLE);
} void GPIO_Configuration(void)
{
 GPIO_InitTypeDef GPIO_InitStructure;  /*配置PE*/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3 | GPIO_Pin_2 | GPIO_Pin_1 |      GPIO_Pin_0 ;
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOE, &GPIO_InitStructure);  /*配置PD*/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6 | GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3 |       GPIO_Pin_2 | GPIO_Pin_1 | GPIO_Pin_0 ;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_OD;
   GPIO_Init(GPIOD, &GPIO_InitStructure);
} /////////////////LCD控制函数//////////////////////////////////////////////////////////////////
#include "Includes.h" unsigned char hz[] = {0x08,0x02,0x08,0x82,0x08,0x92,0x08,0x92,0x7e,0x92,0x08,0x92, 0x08,0x92,0x08,0x92,0x08,0x92,0x08,0x92,0x0e,0x92,0x78,0x92,0x21,0x12,0x01,0x02,0x02,0x02,0x00,0x02}; //检查状态字的状态为0或1
void CheckBusy(unsigned char status)
{
   unsigned char data=0;
 
 GPIO_Write(GPIOD,0x00ff);
   LCD_CE_ABLE;  
 LCD_CD_CMD;  
 LCD_WR_UNABLE;
 LCD_RD_ABLE;
  
   while((data&status) != status)  
 {
  data = (unsigned char)(GPIO_ReadInputData(GPIOD));
 } 
 
  LCD_RD_UNABLE;
 LCD_WR_UNABLE;
 LCD_CE_UNABLE;  
} void WriteData(unsigned char data) 

 CheckBusy(0x03);
 GPIO_Write(GPIOD,(unsigned int)data);  LCD_CD_DATA;  
 LCD_RD_UNABLE;
 LCD_CE_ABLE;
 LCD_WR_ABLE;
 delay_us(1);
  
 LCD_WR_UNABLE;
 LCD_RD_UNABLE;
 LCD_CE_UNABLE;
} //无参数写指令函数
void WriteCmd0(unsigned char cmd)
{
 CheckBusy(0x03);
 WriteData(cmd);
    
 LCD_CD_CMD; 
 LCD_RD_UNABLE; 
 LCD_WR_ABLE;
 LCD_CE_ABLE;
   delay_us(1);
   
 LCD_WR_UNABLE;
 LCD_RD_UNABLE;
 LCD_CE_UNABLE;
} //单参数写指令函数
void WriteCmd1(unsigned char data,unsigned char cmd)
{
 WriteData(data); delay_us(1);
 WriteCmd0(cmd);  delay_us(1);
}
//双参数写指令函数
void WriteCmd2(unsigned char data0,unsigned char data1,unsigned char cmd)
{
 WriteData(data0);
 WriteData(data1);
 WriteCmd0(cmd);
} //液晶初始化
void LCDInit()
{
  WriteCmd2(0x00,0x00,0x42); /*图形首址*/
 WriteCmd2(0x1E,0x00,0x43); /*图形区域*/
 
  WriteCmd0(0xa7); //设置光标形状
 WriteCmd0(0x80); //设置显示方式
 WriteCmd0(0x98); //设置显示开关  ClearRAM();
} void WriteRAM(unsigned char lin,unsigned char column)
{
 unsigned char i;
 unsigned int StartAddr;  StartAddr=lin*30 + column; //定位起始行  for(i=0;i<16;i++)
 {
 WriteCmd2( (unsigned char)(StartAddr), (unsigned char)(StartAddr>>8), 0x24);
 WriteCmd1( hz[i*2], 0xc0); //左半部 地址加一
 WriteCmd1( hz[i*2+1], 0xc4); //右半部 字模地址加一  StartAddr=StartAddr + 0x1E;
 }
} void ClearRAM(void)
{
  unsigned int i;   // 清显示 RAM 区 0000h--2000h (8k)
  WriteCmd2(0x00,0x00,0x24); //设置指针地址0000H
  WriteCmd0(0xb0); //设置自动写状态
  for(i=0x00;i<0x2000;i++) WriteData(0x00); // data=0;
  WriteCmd0(0xb2); // 自动写结束 } void delay_us(unsigned long n)
{
  unsigned long j;
 
  while(n--)
  {
    j=8;
    while(j--);
  }
} void delay_ms(unsigned long n)
{
  while(n--)
   delay_us(1100);   //1ms 
}
/////////////////include.h文件///////////////////////////////////////////////////////////////
#define LCD_WR_ABLE    GPIO_WriteBit(GPIOE, GPIO_Pin_0, (BitAction)(0)) //LCD写操作 0电平有效
#define LCD_WR_UNABLE  GPIO_WriteBit(GPIOE, GPIO_Pin_0, (BitAction)(1)) #define LCD_RD_ABLE    GPIO_WriteBit(GPIOE, GPIO_Pin_1, (BitAction)(0)) //LCD读操作 0电平有效
#define LCD_RD_UNABLE  GPIO_WriteBit(GPIOE, GPIO_Pin_1, (BitAction)(1))
    
#define LCD_CE_ABLE    GPIO_WriteBit(GPIOE, GPIO_Pin_2, (BitAction)(0)) //LCD片选信号 0电平有效
#define LCD_CE_UNABLE  GPIO_WriteBit(GPIOE, GPIO_Pin_2, (BitAction)(1)) //1电平无效 #define LCD_CD_DATA    GPIO_WriteBit(GPIOE, GPIO_Pin_3, (BitAction)(0)) //LCD数据通道选择
#define LCD_CD_CMD GPIO_WriteBit(GPIOE, GPIO_Pin_3, (BitAction)(1)) //LCD指令通道选择 #define LCD_RST_ABLE   GPIO_WriteBit(GPIOE, GPIO_Pin_4, (BitAction)(0)) //LCD复位操作 0电平有效
#define LCD_RST_UNABLE GPIO_WriteBit(GPIOE, GPIO_Pin_4, (BitAction)(1)) #define LCD_FONT_0 GPIO_WriteBit(GPIOE, GPIO_Pin_5, (BitAction)(0))
#define LCD_FONT_1 GPIO_WriteBit(GPIOE, GPIO_Pin_5, (BitAction)(1)) 
/*----------------------------------------------------------------------------------*/
void WriteData(unsigned char data);
unsigned char ReadDataPort(void);
void CheckBusy(unsigned char status);
void WriteCmd0(unsigned char cmd);
void WriteCmd1(unsigned char data,unsigned char cmd);
void WriteCmd2(unsigned char data0,unsigned char data1,unsigned char cmd);
void RCC_Configuration(void);
void GPIO_Configuration(void);
void InitSystem(void);
void delay_us(unsigned long);
void delay_ms(unsigned long);
void LCDWriteRAM(void);
void LCDInit(void);
void WriteRAM(unsigned char x,unsigned char y);
void ClearRAM(void);
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。