STM32F407添加LCD12864后没有显示? 10C

用的是LCD12864带字库的液晶,加载完整程序后,编译正常,下载后无显示,怎么修改,求大神帮忙指点,谢谢

3个回答

源码:
int main(void)
{

uint8_t i=0;
bsp_InitUart(); /* ³õʼ»¯´®¿Ú 256000pbs */
bsp_InitLed();

while (1)
{

LCD_GPIO_Init();
LCD12864_Init();

LCD_ShowString(0,1,"12ÈËÃñ±ÒµÄ»ÃÏëab");
bsp_DelayMS(500);

for(i=0;i<128;i++)
{
LCD_DrawPoint(i,0,1);
LCD_DrawPoint(i,63,1);
// delay_ms(100);
}
for(i=0;i<64;i++)
{
LCD_DrawPoint(0,i,1);
// delay_ms(100);
LCD_DrawPoint(127,i,1);
}

LCD_Refresh_GRAM();
for(i=1;i<127;i++)
{
LCD_DrawPoint(i,1,1);
LCD_DrawPoint(i,62,1);
// delay_ms(100);
}

LCD_Refresh_GRAM();
bsp_DelayMS(500);
for(i=1;i<127;i++)
{
LCD_DrawPoint(i,1,0);
LCD_DrawPoint(i,62,0);
// delay_ms(100);
}
LCD_Refresh_GRAM();

}

}


/*************************************************************************************
LCD12864
LCD_RS PA7
LCD_RW PC1
LCD_EN PC4
LCD_PSB PC6

LCD_RST ½Óµ½°å×ÓRSTÉÏ
LCD_D0 PB9
LCD_D1 PB8
LCD_D2 PB5
LCD_D3 PB6
LCD_D4 PB10
LCD_D5 PB11
LCD_D6 PB12
LCD_D7 PB13

************************************************************************************/

#include "bsp.h"

uint8_t LCD_GRAM[32][32];

void LCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|
RCC_AHB1Periph_GPIOC,ENABLE);
//PA7
GPIO_InitStructure.GPIO_Pin=LCD_RS_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//ÆÕͨÊä³ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//ÉÏÀ­
GPIO_Init(LCD_RS_PORT,&GPIO_InitStructure);
GPIO_SetBits(LCD_RS_PORT,LCD_RS_Pin);
//GPIO_ResetBits(LCD_BL_PORT,LCD_BL_Pin);//µãÁÁ±³¹â

//PC1,PC4,PC6
GPIO_InitStructure.GPIO_Pin=LCD_RW_Pin|LCD_EN_Pin|LCD_PSB_Pin ;
GPIO_Init(LCD_EN_PORT,&GPIO_InitStructure); 

GPIO_SetBits(LCD_EN_PORT,LCD_RW_Pin|LCD_EN_Pin|LCD_PSB_Pin);

GPIO_InitStructure.GPIO_Pin=LCD_D0_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//ÆÕͨÊä³ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_OD;//¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//ÉÏÀ­    
GPIO_Init(LCD_D0_PORT,&GPIO_InitStructure); 
GPIO_SetBits(LCD_D0_PORT,LCD_D0_Pin);
GPIO_InitStructure.GPIO_Pin=LCD_D1_Pin|LCD_D2_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//ÆÕͨÊä³ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_OD;//¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//ÉÏÀ­    
GPIO_Init(LCD_D1_PORT,&GPIO_InitStructure);
GPIO_SetBits(LCD_D1_PORT,LCD_D1_Pin|LCD_D2_Pin);
GPIO_InitStructure.GPIO_Pin=LCD_D3_Pin|LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;//ÆÕͨÊä³ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_OD;//¿ªÂ©Êä³ö
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//ÉÏÀ­
GPIO_Init(LCD_D3_PORT,&GPIO_InitStructure); 

GPIO_SetBits(LCD_D3_PORT,LCD_D3_Pin|LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin);

}
//Êý¾Ý¸ñʽ
//D7 D6 D5 D4 D3 D2 D1 D0
uint8_t ReadByteFromLCD(void)
{
uint8_t res=0;
res=(LCD_D0_IN<<0)|(LCD_D1_IN<<1)
|(LCD_D2_IN<<2)|(LCD_D3_IN<<3)
|(LCD_D4_IN<<4)|(LCD_D5_IN<<5)
|(LCD_D6_IN<<6)|(LCD_D7_IN<<7);
return res;

}

void WriteByteToLCD(uint8_t byte)
{

LCD_D0_OUT=(byte&0x01)>>0;
LCD_D1_OUT=(byte&0x02)>>1;
LCD_D2_OUT=(byte&0x04)>>2;
LCD_D3_OUT=(byte&0x08)>>3;
LCD_D4_OUT=(byte&0x10)>>4;
LCD_D5_OUT=(byte&0x20)>>5;
LCD_D6_OUT=(byte&0x40)>>6;
LCD_D7_OUT=(byte&0x80)>>7;
}
/*************************************************************************************

************************************************************************************/
/*************************************************************************************
LCDÅÐ溯Êý
1:æ
0:²»Ã¦
************************************************************************************/
uint8_t LCD_Busy(void)
{
uint8_t res=0;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
//Êý¾ÝÏßIO·½ÏòÉ趨
//GPIO_Set(GPIOB,PIN9,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
//GPIO_Set(GPIOB,PIN8|PIN11,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
GPIO_Set(GPIOB,PIN9|PIN8|PIN5|PIN6|PIN10|PIN11|PIN12|PIN13,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
bsp_DelayUS(5);
//¶ÁÊý¾Ý
res=(ReadByteFromLCD()&0x80);
LCD_EN = 0;

return res;
}
//дָÁî/Êý¾Ýµ½LCD
void WriteToLCD(uint8_t mode,uint8_t byte)
{

if(mode==LCD_CMD)//дָÁî
{
  while(LCD_Busy());
  LCD_RS = 0;//Ö¸Áî
  LCD_RW = 0;//д
  LCD_EN = 0;
  bsp_DelayUS(5);
  //GPIO_Set(GPIOE,PIN6,GPIO_MODE_OUT,GPIO_OTYPE_OD,GPIO_SPEED_100M,GPIO_PUPD_PU);
 // GPIO_Set(GPIOF,PIN6|PIN11,GPIO_MODE_OUT,GPIO_OTYPE_OD,GPIO_SPEED_100M,GPIO_PUPD_PU); 
  GPIO_Set(GPIOB,PIN9|PIN8|PIN5|PIN6|PIN10|PIN11|PIN12|PIN13,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
  WriteByteToLCD(byte);//д
  bsp_DelayUS(5);

  LCD_EN = 1;
  bsp_DelayUS(5);
  LCD_EN = 0;

}else            //дÊý¾Ý
{
   while(LCD_Busy());
   LCD_RS = 1;//Êý¾Ý
   LCD_RW = 0;
   LCD_EN = 0;
   bsp_DelayUS(5);
   //GPIO_Set(GPIOE,PIN6,GPIO_MODE_OUT,GPIO_OTYPE_OD,GPIO_SPEED_100M,GPIO_PUPD_PU);
   //GPIO_Set(GPIOF,PIN6|PIN11,GPIO_MODE_OUT,GPIO_OTYPE_OD,GPIO_SPEED_100M,GPIO_PUPD_PU); 
   GPIO_Set(GPIOB,PIN9|PIN8|PIN5|PIN6|PIN10|PIN11|PIN12|PIN13,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
   WriteByteToLCD(byte);//д
   bsp_DelayUS(5);

   LCD_EN = 1;
   bsp_DelayUS(5);
   LCD_EN = 0;     
}

}
void LCD12864_Init(void)
{
LCD_PSB =1;
WriteToLCD(LCD_CMD,0x34);//À©³äÖ¸Áî²Ù×÷
bsp_DelayMS(100);
WriteToLCD(LCD_CMD,0x30);//»ù±¾Ö¸Áî²Ù×÷
bsp_DelayMS(100);
WriteToLCD(LCD_CMD,0x0C);//ÏÔʾ¿ª£¬¹Ø¹â±ê
bsp_DelayMS(100);
WriteToLCD(LCD_CMD,0x01);//ÇåLCD
bsp_DelayMS(5);

}
void LCD_Clear(void)
{
WriteToLCD(LCD_CMD,0x01);//ÇåLCD
bsp_DelayMS(5);

}
//É趨ÏÔʾλÖÃ
//x=0-3,y=0-7
//128*64=16*8*16*4
void LCD_SetCursor(uint8_t x,uint8_t y)
{

if (y==0)
{y=0x80;}
else if (y==1)
{y=0x90;}
else if (y==2)
{y=0x88;}
else if (y==3)
{y=0x98;}

WriteToLCD(LCD_CMD,x+y); //ÏÔʾµØÖ·
}
void LCD_ShowString(uint8_t x,uint8_t y, uint8_t s)
{
LCD_SetCursor(x,y);
while(*s!='\0')
{
WriteToLCD(LCD_DATA,*s++);
}
*s=0;
}
//»­µãº¯Êý
/

GDRAM·Ö²¼
256(16*16) X
|-----------------------------|-----------------------------------|
|0 | |
| ÉÏ°ëÆÁ128*32 | Ï°ëÆÁ128*32 |
Y|32 | |
|-----------------------------|-----------------------------------|
ˮƽx×ø±êÿ¸ô16¸öµã²ÅÓÐÒ»¸öλַ£¬Òò´Ë¸Ä±äij¸öµãÐèÒªÖªµÀ¸ÃµãλÓÚÕâ16¸öµãµÄÄĸöλÖÃ
´¹Ö±y×ø±êÔÚ´óÓÚ31ʱ´¦ÓÚÏ°ëÆÁ£¬Ð¡ÓÚ31´¦ÓÚÉÏ°ëÆÁ
*/
void LCD_SetPoint(uint8_t x,uint8_t y)
{
uint16_t volatile readdata=0;
//Åжϴ¦ÓÚÄÄÐÐÄÄÁÐ
uint8_t x_pos,x_bit;//x_posÓÃÀ´Åжϴ¦ÓÚλַ£¬x_bitÓÃÀ´Åжϴ¦ÓÚλַÖеÄλÖÃ
uint8_t y_pos,y_bit;//y_posÓÃÀ´Åжϴ¦ÓÚÉÏ°ëÆÁ»¹ÊÇÏ°ëÆÁ y_bitÓÃÀ´ÅжÏλÓÚÄÄÐÐ

y_pos=y/32; //0:ÉÏ°ëÆÁ£»1:Ï°ëÆÁ
y_bit=y%32; //µÃµ½¾ßÌåÐÐλÖÃ
x_pos=x/16;
x_bit=x%16;
WriteToLCD(LCD_CMD,LCD_EXTERN_SET);//À©Õ¹Ö¸Á
WriteToLCD(LCD_CMD,LCD_DRAW_OFF);//¹Øµô»æͼÏÔʾ
WriteToLCD(LCD_CMD,0x80+y_bit);
WriteToLCD(LCD_CMD,0x80+8*y_pos+x_pos);
//Êý¾ÝÏßIO·½ÏòÉ趨
// GPIO_Set(GPIOE,PIN6,GPIO_MODE_IN,0,0,GPIO_PUPD_PD);
//GPIO_Set(GPIOF,PIN6|PIN11,GPIO_MODE_IN,0,0,GPIO_PUPD_PD);
GPIO_Set(GPIOB,PIN9|PIN8|PIN5|PIN6|PIN10|PIN11|PIN12|PIN13,GPIO_MODE_IN,0,0,GPIO_PUPD_PU);
bsp_DelayMS(1);
ReadByteFromLCD();//¿Õ¶ÁÒ»´Î
readdata=ReadByteFromLCD();
readdata<<=8;
readdata|=ReadByteFromLCD();
WriteToLCD(LCD_CMD,0x80+y_bit);
WriteToLCD(LCD_CMD,0x80+8*y_pos+x_pos);
if(x_bit {
WriteToLCD(LCD_DATA,((uint8_t)(readdata>>8))|(0x01<<(7-x_bit)));
WriteToLCD(LCD_DATA,(uint8_t)readdata);
}else
{
WriteToLCD(LCD_DATA,(uint8_t)(readdata>>8));
WriteToLCD(LCD_DATA,(uint8_t)readdata|(0x01<<(15-x_bit)));
}

WriteToLCD(LCD_CMD,LCD_DRAW_ON);//¿ª»æͼÏÔʾ
WriteToLCD(LCD_CMD,LCD_BASIC_SET);//»Øµ½»ù±¾Ö¸Á

}

void LCD_Refresh_GRAM(void)
{
uint8_t i;uint16_t j;
WriteToLCD(LCD_CMD,LCD_EXTERN_SET);//À©Õ¹Ö¸Á
WriteToLCD(LCD_CMD,LCD_DRAW_OFF);//¹Øµô»æͼÏÔʾ
for(i=0;i<32;i++)//±éÀú0-31ÐÐ
{
WriteToLCD(LCD_CMD,0x80+i);//дÈëÐеØÖ·
WriteToLCD(LCD_CMD,0x80); //дÈëÁеØÖ·
for(j=0;j<32;j++)
{
WriteToLCD(LCD_DATA,LCD_GRAM[i][j]);

}

}

WriteToLCD(LCD_CMD,LCD_DRAW_ON);//¿ªÆô»æͼÏÔʾ
WriteToLCD(LCD_CMD,LCD_BASIC_SET);//»Øµ½»ù±¾Ö¸Á

}
void LCD_Clear_DGRAM(void)
{
uint8_t i,j;
for(i=0;i<32;i++)//ÇåÆÁ
{
for(j=0;j<32;j++)//ÿÐÐÕ¼ÓÃλÖà 16*16/8=32¸ö×Ö½Ú
{
LCD_GRAM[i][j]=0x00;

}
}

}
//x:0-127
//y:0-63
//mode:1,»­µã
//mode:0,Çå¿Õ
void LCD_DrawPoint(uint8_t x,uint8_t y,uint8_t mode)
{
//Åжϴ¦ÓÚÄÄÐÐÄÄÁÐ
uint8_t x_pos,x_bit;//x_posÓÃÀ´Åжϴ¦ÓÚλַ£¬x_bitÓÃÀ´Åжϴ¦ÓÚλַÖеÄλÖÃ
uint8_t y_pos,y_bit;//y_posÓÃÀ´Åжϴ¦ÓÚÉÏ°ëÆÁ»¹ÊÇÏ°ëÆÁ y_bitÓÃÀ´ÅжÏλÓÚÄÄÐÐ
// uint8_t x_pos_temp;
if((x>127)||(y>63)||(x y_pos=y/32; //0:ÉÏ°ëÆÁ£»1:Ï°ëÆÁ
y_bit=y%32; //µÃµ½¾ßÌåÐÐλÖÃ
x_pos=x/16;
x_bit=x%16;
if(y_pos>0)//Ï°ëÆÁ
{
if(mode)
{
if(x_bit<8)
{
LCD_GRAM[y_bit][x_pos*2+16]|=(1<<(7-x_bit));
LCD_GRAM[y_bit][x_pos*2+1+16]|=0x00;
}else
{
LCD_GRAM[y_bit][x_pos*2+16]|=0x00;
LCD_GRAM[y_bit][x_pos*2+1+16]|=(1<<(15-x_bit));
}
}
else
{

if(x_bit<8)
{
LCD_GRAM[y_bit][x_pos*2+16]&=~(1<<(7-x_bit));
LCD_GRAM[y_bit][x_pos*2+1+16]&=~0x00;
}else
{
LCD_GRAM[y_bit][x_pos*2+16]&=~0x00;
LCD_GRAM[y_bit][x_pos*2+1+16]&=~(1<<(15-x_bit));
}
}
}else//ÉÏ°ëÆÁ
{
if(mode)
{
if(x_bit<8)
{
LCD_GRAM[y_bit][x_pos*2]|=(1<<(7-x_bit));
LCD_GRAM[y_bit][x_pos*2+1]|=0x00;
}else
{
LCD_GRAM[y_bit][x_pos*2]|=0x00;
LCD_GRAM[y_bit][x_pos*2+1]|=(1<<(15-x_bit));
}
}
else
{

if(x_bit<8)
{
LCD_GRAM[y_bit][x_pos*2]&=~(1<<(7-x_bit));
LCD_GRAM[y_bit][x_pos*2+1]&=~0x00;
}else
{
LCD_GRAM[y_bit][x_pos*2]&=~0x00;
LCD_GRAM[y_bit][x_pos*2+1]&=~(1<<(15-x_bit));
}
}
}

// LCD_Refresh_GRAM();
}


LCD_GPIO_Init();
LCD12864_Init();
初始化一次就可以了,不用放在while里面

如果确定代码没问题,可以调一下LCD的背光,背光也会影响字符显示。

MOLLY0511
MOLLY0511 背光都调是了,依旧没有显示
大约 3 年之前 回复
MOLLY0511
MOLLY0511 显示放到main()函数中,这样LCD12864_Init(); DisPlayString(0,1,"26.453"); while (1) { }
大约 3 年之前 回复

可能是你的引脚使用不对,比如F4里面的PB8,PB9不适合做独立I/O口

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问