液晶屏不显示,不知道问题出在哪里了,求助!
stm32F103的板子,液晶屏用的是240*128点阵;控制IC:T6963C;液晶屏供电用的是开发板上的5V供电
引脚设置
RD-> PD4;WR-> PD5;CE-> PD7;FS->
D12;RST-> PC4;C/D-> PD11
DB0-DB2
8-D10;DB3-DB7:E11-E15
下面是我的代码,有相应的注释,不知道都对不对
#define LCDT_WR_ABLE GPIO_WriteBit(GPIOD, GPIO_Pin_5, (BitAction)(0)) //LCD??? 0????
#define LCDT_WR_UNABLE GPIO_WriteBit(GPIOD, GPIO_Pin_5, (BitAction)(1))
#define LCDT_RD_ABLE GPIO_WriteBit(GPIOD, GPIO_Pin_4, (BitAction)(0)) //LCD??? 0????
#define LCDT_RD_UNABLE GPIO_WriteBit(GPIOD, GPIO_Pin_4, (BitAction)(1))
#define LCDT_CE_ABLE GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(0)) //LCD???? 0????
#define LCDT_CE_UNABLE GPIO_WriteBit(GPIOD, GPIO_Pin_7, (BitAction)(1)) //1????
#define LCDT_CD_DATA GPIO_WriteBit(GPIOD, GPIO_Pin_11, (BitAction)(0)) //LCD??????
#define LCDT_CD_CMD GPIO_WriteBit(GPIOD, GPIO_Pin_11, (BitAction)(1)) //LCD??????
#define LCDT_RST_ABLE GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(0)) //LCD???? 0????
#define LCDT_RST_UNABLE GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1))
#define LCDT_FONT_0 GPIO_WriteBit(GPIOD, GPIO_Pin_12, (BitAction)(0))
#define LCDT_FONT_1 GPIO_WriteBit(GPIOD, GPIO_Pin_12, (BitAction)(1))
u8 Row[] = { 0,1,19,37,55,73,91,109 };
unsigned char code tab12[]={
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
/*-- 文字: 肇 --*/
0x10,0x40,0x08,0x40,0x3E,0xFE,0x23,0x48,0x3E,0x30,0x40,0xC8,0x41,0x06,0x9F,0xF0,
0x01,0x10,0x7F,0xFC,0x01,0x10,0x3F,0xF0,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,
/*-- 文字: 庆 --*/
0x01,0x00,0x00,0x80,0x3F,0xFE,0x20,0x80,0x20,0x80,0x20,0x80,0x3F,0xFE,0x21,0x40,
0x21,0x40,0x21,0x20,0x22,0x20,0x22,0x10,0x44,0x18,0x48,0x0E,0x90,0x04,0x00,0x00,
/*-- 文字: 金 --*/
0x01,0x00,0x01,0x00,0x02,0x80,0x04,0x40,0x08,0x30,0x30,0x0E,0xCF,0xF4,0x01,0x00,
0x01,0x00,0x3F,0xF8,0x01,0x00,0x09,0x20,0x05,0x20,0x05,0x40,0xFF,0xFE,0x00,0x00,
/*-- 文字: 鹏 --*/
0x00,0x10,0x77,0x20,0x55,0x7C,0x55,0x64,0x77,0x54,0x55,0x54,0x55,0x4C,0x55,0x40,
0x77,0x7E,0x55,0x02,0x55,0x02,0x55,0xFA,0x55,0x02,0xB9,0x14,0x13,0x08,0x00,0x00,
/*-- 文字: 科 --*/
0x06,0x08,0x78,0x88,0x08,0x48,0x08,0x48,0xFE,0x08,0x18,0x88,0x1C,0x48,0x2A,0x48,
0x28,0x0E,0x48,0x78,0x8B,0x88,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,
/*-- 文字: 技 --*/
0x10,0x20,0x10,0x20,0x10,0x20,0xFD,0xFE,0x10,0x20,0x14,0x20,0x19,0xFC,0x31,0x08,
0xD0,0x88,0x10,0x90,0x10,0x60,0x10,0x60,0x10,0x90,0x11,0x0E,0x56,0x04,0x20,0x00,
/*-- 文字: 有 --*/
0x01,0x00,0x01,0x00,0x7F,0xFE,0x02,0x00,0x04,0x00,0x0F,0xF0,0x18,0x10,0x28,0x10,
0x4F,0xF0,0x88,0x10,0x08,0x10,0x0F,0xF0,0x08,0x10,0x08,0x90,0x08,0x70,0x08,0x20,
/*-- 文字: 限 --*/
0x00,0x00,0xFB,0xF8,0x92,0x08,0x93,0xF8,0xA2,0x08,0xA2,0x08,0x93,0xF8,0x8A,0x80,
0x8A,0x48,0xAA,0x50,0x92,0x20,0x82,0x20,0x82,0x10,0x82,0x8E,0x83,0x04,0x82,0x00,
/*-- 文字: 公 --*/
0x00,0x00,0x04,0x40,0x06,0x40,0x04,0x40,0x08,0x20,0x08,0x10,0x10,0x18,0x22,0x0E,
0x43,0x04,0x02,0x00,0x04,0x20,0x08,0x10,0x11,0xF8,0x3F,0x18,0x10,0x10,0x00,0x00,
/*-- 文字: 司 --*/
0x00,0x00,0x3F,0xFC,0x00,0x04,0x00,0x04,0x7F,0xE4,0x00,0x04,0x00,0x04,0x3F,0xC4,
0x20,0x44,0x20,0x44,0x3F,0xC4,0x20,0x44,0x20,0x04,0x00,0x14,0x00,0x08,0x00,0x00,
/*-- 文字: 肇 --*/
0x10,0x40,0x08,0x40,0x3E,0xFE,0x23,0x48,0x3E,0x30,0x40,0xC8,0x41,0x06,0x9F,0xF0,
0x01,0x10,0x7F,0xFC,0x01,0x10,0x3F,0xF0,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,
/*-- 文字: 庆 --*/
0x01,0x00,0x00,0x80,0x3F,0xFE,0x20,0x80,0x20,0x80,0x20,0x80,0x3F,0xFE,0x21,0x40,
0x21,0x40,0x21,0x20,0x22,0x20,0x22,0x10,0x44,0x18,0x48,0x0E,0x90,0x04,0x00,0x00,
/*-- 文字: 市 --*/
0x02,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,0x1F,0xF8,0x11,0x08,0x11,0x08,
0x11,0x08,0x11,0x08,0x11,0x08,0x11,0x08,0x11,0x28,0x11,0x10,0x01,0x00,0x01,0x00,
/*-- 文字: 建 --*/
0x00,0x40,0x78,0x40,0x0B,0xF8,0x10,0x48,0x17,0xFE,0x20,0x48,0x7B,0xF8,0x08,0x40,
0x4B,0xFC,0x48,0x40,0x28,0x40,0x17,0xFC,0x28,0x40,0x46,0x40,0x81,0xFE,0x00,0x00,
/*-- 文字: 设 --*/
0x40,0x00,0x21,0xF0,0x31,0x10,0x21,0x10,0x01,0x10,0x01,0x10,0xE2,0x0E,0x25,0xF8,
0x21,0x08,0x21,0x08,0x20,0x90,0x20,0x90,0x28,0x60,0x30,0x90,0x23,0x0E,0x0C,0x04,
/*-- 文字: 三 --*/
0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,
/*-- 文字: 路 --*/
0x00,0x80,0x78,0x80,0x48,0xFC,0x49,0x88,0x4A,0x48,0x7C,0x50,0x50,0x20,0x10,0x58,
0x5D,0x86,0x53,0xFC,0x51,0x08,0x51,0x08,0x5D,0x08,0xE1,0xF8,0x01,0x08,0x00,0x00,
/*-- 文字: 三 --*/
0x00,0x00,0x00,0x00,0x7F,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFE,0x00,0x00,0x00,0x00,
/*-- 文字: 一 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x7F,0xFE,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*-- 文字: 号 --*/
0x1F,0xF0,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x00,0x00,0xFF,0xFE,0x08,0x00,
0x08,0x00,0x1F,0xF0,0x08,0x10,0x00,0x10,0x00,0x10,0x01,0x10,0x00,0xA0,0x00,0x40};
void LCD_Init()
{
LCD_PORT_Init(); //定义变量
LCD_RST(); //复位LCD
double_parameter(0x00,0x00,0x40); //写入文本首地址0x0000
double_parameter(20,0x00,0x41); //写入文本区长度(一行几个字节) 160/8 =20
double_parameter(0x00,0x40,0x42); //写入图形区首地址 0x4000
double_parameter(20,0x00,0x43); //写入图形区长度(一行几个字节)
no_parameter(0x80); //设置显示方式:CGROM方式;文本 或 图形//地址80~FF代表用户自定义的字符,在汉字显示用到
no_parameter(0xa7); //设置光标形状,8x8
double_parameter(20,0x00,0x21); //设置光标的位置;参数1:x(0~80列),Y(0-32)
no_parameter(0x98); //图形开文本关,禁止光标显示和闪烁
//all_display(1,0x00); //图形屏幕全清 把这两个删除了,没有用,具体还没有弄明白
//all_display(0,0x00); //文本屏幕全清
delay_ms(10); //延时
}
//引脚设置
//RD-> PD4; WR-> PD5; CE-> PD7;FS->
D12
//RST-> PC4; C/D-> PD11
//DB0-DB2
8-D10 ; DB3-DB7:E11-E15
void LCD_PORT_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE,ENABLE);//使能PORTC,D,E以及AFIO复用功能时钟
//将控制和数据脚全部配置为AF PP模式
//RST为PP
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //PD10 推挽输出 背光
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//PORTD复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11; // //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORTE复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; // //PORTE复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void LCD_RST(void)
{
LCDT_RST_ABLE ; // 拉低液晶屏复位脚
delay_ms(2);
LCDT_RST_UNABLE;
delay_ms(2);
}
void Data_Mode_Out(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//PORTD复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10; //PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORTE复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;//PORTE复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
//set port in
void Data_Mode_In(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//PORTD复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;//PORTD复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
//PORTE复用推挽输出 //Data
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;//PORTE复用推挽输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
/************************写双字节参数命令*********************************/
void double_parameter(uint data1,uint data2,uchar com)
{
check_sta01(); //测忙
wrdate(data1); //写第一字节参数
check_sta01(); //测忙
wrdate(data2); //写第二节节参数
check_sta01(); //测忙
wrcomm(com); //写命令
}
/************************写无参数命令************************************/
void no_parameter(uchar comm)
{
check_sta01(); //测忙
wrcomm(comm); //写命令
}
/*******************测读写命令忙***********************************/
void check_sta01()
{
u8 a;
Data_Mode_In();
delay_ms(1);
LCDT_CD_CMD; //命令有效
LCDT_CE_ABLE; //使能片选
LCDT_WR_UNABLE; //禁写
while(1)
{
LCDT_RD_UNABLE; //LCDT_RD_ABLE; //使能读 问题是用LCDT_RD_ABEL后下面的IF语句不能通过,我改为LCDT_RD_UNABLE下面的IF就可通过了,不知道是为什么
delay_us(1); //延时
a=Read_data();
// LCDT_RD_UNABLE;
if((a&0x03)==0x03)
{
Data_Mode_Out();
delay_us(1);
return;
} /
}
}
//读数据
//IDR读出数据寄存器IO口状态,GE11-15,GD8-10 LCD的数据接口
u8 Read_data(void)
{
u8 Data04,Data57;//D5-7:PD8-10
Data04 = (GPIOE->IDR>>11)&0x1F; //读出的IO口是PE11-15状态
Data57 = (GPIOD->IDR>>3)&0xE0; //读出的IO口是PD8,9,10状态
return (Data04|Data57);
}
//写命令
void wrcomm(u8 comm)
{
LCDT_CD_CMD; //操作命令
LCDT_CE_ABLE; //选中芯 片
LCDT_RD_UNABLE; //读高电平无效
LCDT_WR_ABLE; //写使能
Write_data(comm); //把命令送给总线
delay_us(1); //延时
LCDT_WR_UNABLE; //拉高写
}
//写数据
void Write_data(u8 data)
{
u32 Data04,Data57;//D0-4:PE11-15;
Data04 = data&0x1F;
Data57 = data&0xE0;
GPIOD->BSRR = (Data57<<3)|(((~Data57)&0xE0)<<19);
GPIOE->BSRR = (Data04<<11)|(((~Data04)&0x1F)<<27);//将对应的引脚
}
//写数据
void wrdate(u8 date)
{
LCDT_CD_DATA; //操作命令
LCDT_CE_ABLE; //使能片选
LCDT_RD_UNABLE; //读无效
LCDT_WR_ABLE; //使能写
Write_data(date); //把命令送给总线
delay_us(1); //延时
LCDT_WR_UNABLE; //拉高写
}
/******************************汉字写入函数*******************************************/
//x_hz:0~19; y_hz:0~127
//注意:横坐标是以8个点为单位的
//一行20字节,一共128行
//显示16*16的任何都可以
/*
取模方式位是行列式,高位在前
*/
void writehz(u8 x_hz,u8 y_hz,u8 code_hz)
{
u8 i_hz;
u16 address,addr_hz;
address=y_hz*20+x_hz+0x4000; //计算显示存储器地址,
addr_hz=code_hz*32; //计算汉字字模地址(cgtab的下标)
for(i_hz=0;i_hz<16;i_hz++) //计数值16,字高16
{
double_parameter((u8)(address),(u8)(address>>8),0x24); //设置显示存储器地址
One_parameter(tab12[addr_hz],0xc0); //写入汉字字模左部,地址+1
One_parameter(tab12[addr_hz+16],0xc2); //写入汉字字模右部,地址+1
addr_hz++;
address+=20; //修改显示存储器地址,显示下一行,一行20
}
}
int main(void)
{
delay_init();
LCDT_Init();
}
一周热门 更多>