我用的是stm32f407的开发板,lcm19264b的液晶屏
求问哪里出了问题,难道是我的硬件连接错了吗?求高手指正!!!
头文件:
#include "stm32f4xx_conf.h"
#include "stdint.h"
#include "stm32f4xx.h"
#include "stdint.h"
#ifndef __LCD_DRIVER_H
#define __LCD_DRIVER_H
#define LCD_RS GPIOB, GPIO_Pin_0// B.0
#define LCD_E GPIOB, GPIO_Pin_1// B.1
#define LCD_CS1 GPIOB, GPIO_Pin_2// B.2
#define LCD_RST GPIOB, GPIO_Pin_3// B.3
#define LCD_CS2 GPIOB, GPIO_Pin_4// B.4
#define LCD_CS3 GPIOB, GPIO_Pin_5// B.5
#define LCD_RW GPIOB, GPIO_Pin_6// B.6
#define LCD_DATA_IN(x) GPIOE->IDR=(GPIOE->IDR&0x807F)|((x & 0x00FF)<<7) //PE7~14,作为数据线
#define LCD_DATA_OUT(x) GPIOE->ODR=(GPIOE->ODR&0x807F)|((x & 0x00FF)<<7) //PE7~14,作为数据线
#define LCD_PAGE_ADDR 0xb8
#define LCD_COL_ADDR 0x40
void wtcom(void);
void Locatexy(void);
void SelectChip1(void);
void SelectChip2(void);
void SelectChip3(void);
void WriteCommandL( unsigned char CommandByte );
void WriteCommandM( unsigned char CommandByte );
void WriteCommandR( unsigned char CommandByte );
void LcmClear( void );
void LcmInit( void );
void LcmPutDots( unsigned char DotByte );
void LcmPutHeng( unsigned char DotByte );
void LcmPutBMP( unsigned char *puts );
void LcmPutHz(unsigned char Col_x,unsigned char age_y,unsigned char *puts );
#endif
驱动程序:
#include "Lcd_Driver.h"
#include "delay.h"
//function all 函数定义=========================
unsigned int age; //页 地址
unsigned int Col; //列 地址
void LCDPortSet(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 最高输入速率50MHz
GPIO_Init(GPIOE, &GPIO_InitStructure); // 选择E端口,连接数据线
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3|
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_0);
GPIO_SetBits(GPIOB, GPIO_Pin_1);
GPIO_SetBits(GPIOB, GPIO_Pin_2);
GPIO_SetBits(GPIOB, GPIO_Pin_3);
GPIO_SetBits(GPIOB, GPIO_Pin_4);
GPIO_SetBits(GPIOB, GPIO_Pin_5);
GPIO_SetBits(GPIOB, GPIO_Pin_6);
}
void SelectChip1(void) //选择第1屏
{
GPIO_ResetBits(LCD_CS1);
GPIO_SetBits(LCD_CS2);
GPIO_SetBits(LCD_CS3);
wtcom();
}
void SelectChip2(void) //选择第2屏
{
GPIO_SetBits(LCD_CS1);
GPIO_ResetBits(LCD_CS2);
GPIO_SetBits(LCD_CS3);
wtcom();
}
void SelectChip3(void) //选择第3屏
{
GPIO_SetBits(LCD_CS1);
GPIO_SetBits(LCD_CS2);
GPIO_ResetBits(LCD_CS3);
wtcom();
}
void wtcom(void)
{
//BUSY_CS=0; //坚鸿测试架增加指令,控制P0.7输入输出
GPIO_ResetBits(LCD_RS); //RS = 0; //指令
GPIO_SetBits(LCD_RW);//RW = 1;
//P0 = 0xFF; //输出0xff以便读取正确
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
//while(P0 & 0x80); //Status Read Bit7 = BUSY
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
//GPIO_SetBits(LCD_CS);//BUSY_CS=1;
}
/********************************************************/
/*根据设定的坐标数据,定位LCM上的下一个操作单元位置 */
/********************************************************/
void Locatexy(void)
{
unsigned char x,y;
switch (Col&0xc0) /* col.and.0xC0 */
{ /*条件分支执行 */
case 0: {SelectChip1();break;}/*左区 */
case 0x40: {SelectChip2();break;}/*中区 */
case 0x80: {SelectChip3();break;}/*右区 */
}
x = Col&0x3F|0x40; /* col.and.0x3f.or.Set Y Address*/
y = age&0x07|0xB8; /* row.and.0x07.or.set Page */
wtcom(); /* waitting for enable */
GPIO_ResetBits(LCD_RS);//RS = 0; //指令
GPIO_ResetBits(LCD_RW);//RW = 0; //写
LCD_DATA_OUT(y); //设置页面地址
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
wtcom(); /* waitting for enable */
GPIO_ResetBits(LCD_RS);//RS = 0;
GPIO_ResetBits(LCD_RW);//RW = 0;
LCD_DATA_OUT(x); //设置列地址
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
}
/***************************/
/*写指令 */
/***************************/
void WriteCommandL( unsigned char CommandByte )
{
SelectChip1();
//P1 = CommandByte;
GPIO_ResetBits(LCD_RS);//RS = 0; //指令
GPIO_ResetBits(LCD_RW);//RW = 0;
LCD_DATA_OUT(CommandByte);
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
}
void WriteCommandM( unsigned char CommandByte )
{
SelectChip2();
//P1 = CommandByte;
GPIO_ResetBits(LCD_RS);//RS = 0; //指令
GPIO_ResetBits(LCD_RW);//RW = 0;
LCD_DATA_OUT(CommandByte);
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
}
void WriteCommandR( unsigned char CommandByte )
{
SelectChip3();
//P1 = CommandByte;
GPIO_ResetBits(LCD_RS);//RS = 0; //指令
GPIO_ResetBits(LCD_RW);//RW = 0;
LCD_DATA_OUT(CommandByte);
GPIO_SetBits(LCD_E);//E = 1;
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
}
/***************************/
/*读数据 */
/***************************/
unsigned char ReadData( void )
{
unsigned char DataByte;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3|
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_PuPd = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
GPIO_SetBits(LCD_RS);//RS = 1; /*数据输出*/
GPIO_SetBits(LCD_RW);//RW = 1; /*读入 */
LCD_DATA_OUT(0xFF);//P1 = 0xFF; //输出0xff以便读取正确
GPIO_SetBits(LCD_E);//E = 1; /*读入到LCM*/
Delay(200);
DataByte=LCD_DATA_OUT(0xFF);//DataByte = P1; /*数据读出到数据口P1 */
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3|
GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
return DataByte;
}
/***************************/
/*写数据 */
/***************************/
void WriteData( unsigned char DataByte )
{
Locatexy(); /*坐标定位,返回时保留分区状态不变 */
GPIO_SetBits(LCD_RS);//RS = 1; /*数据输出*/
GPIO_ResetBits(LCD_RW);//RW = 0; /*写输出 */
Delay(200);
LCD_DATA_OUT(DataByte); /*数据输出到数据口 */
GPIO_SetBits(LCD_E);//E = 1; /*写入到LCM*/
Delay(200);
GPIO_ResetBits(LCD_E);//E = 0;
Delay(200);
}
void LcmClear( void )
{
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
for(Col=0;Col<192;Col++)
WriteData(0x00);
}
void LcmInit( void )
{
WriteCommandL(0x3f); //开显示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
WriteCommandL(0xc0); //设置起始地址=0
WriteCommandM(0xc0);
WriteCommandR(0xc0);
WriteCommandL(0x3f); //开显示
WriteCommandM(0x3f);
WriteCommandR(0x3f);
LcmClear();
Col = 0;
Page= 0;
Locatexy();
}
void LcmPutDots( unsigned char DotByte )
{
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<100;Col++)
{
WriteData( DotByte );
DotByte = ~DotByte;
}
}
}
void LcmPutHeng( unsigned char DotByte )
{
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<192;Col++)
{
WriteData( DotByte );
}
}
}
void LcmPutBMP( unsigned char *puts )
{
unsigned int X=0;
Page = 0;
Col = 0;
for(Page=0;Page<8;Page++)
{
for(Col=0;Col<192;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
void LcmPutHz(unsigned char Col_x,unsigned char Page_y,unsigned char *puts )
{
unsigned int X=0;
for(Page=Page_y;Page<2+Page_y;Page++)
{
for(Col=Col_x;Col<16+Col_x;Col++)
{
WriteData( puts[X] );
X++;
}
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
那些管脚你都接了吗?我一开始没有接滑动变阻器,所以显示不出来
---------------------------------
我这边是因为延时的问题 最后才发现 谢谢你的回复
---------------------------------
楼主,可以分享下19264的驱动代码么,现在需要用,谢谢了
一周热门 更多>