小弟找了一个程序,程序下进去之后测各个脚都有波形,但是就是没有任何显示,还烦请高手帮小弟看看是那里的问题。程序如下:
#include<stm32f4xx.h>
#define uint unsigned int
#define uchar unsigned char
void Delay(uint z);
//我用的是 D.8 D.9 D.10 D.11
#define DI GPIO_Pin_11
#define RW GPIO_Pin_12
#define EN GPIO_Pin_13
#define CS1 GPIO_Pin_14
#define CS2 GPIO_Pin_15
/*-- 文字: 欢 --*/
/*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/
uchar huan[] = {0x00,0x80,0x00,0x80,0xFC,0x80,0x04,0xFC,0x05,0x04,0x49,0x08,0x2A,0x40,0x14,0x40,
0x10,0x40,0x28,0xA0,0x24,0xA0,0x45,0x10,0x81,0x10,0x02,0x08,0x04,0x04,0x08,0x02,};
void RCC_Configuration(void) //推挽输出模式 ,管脚配置,不多解释,库函数有
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = DI|RW|EN|CS1|CS2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, 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_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
/*写指令函数*/
void LCD_write_cmmand(uchar cmd)
{
GPIO_ResetBits(GPIOB,DI);
GPIO_ResetBits(GPIOB,RW);
GPIO_ResetBits(GPIOB,EN);
GPIO_Write(GPIOD, cmd);
Delay(50000);
GPIO_SetBits(GPIOB,EN);
Delay(50000);
GPIO_ResetBits(GPIOB,EN);
}
/*写数据函数*/
void LCD_write_data(uchar dat)
{
GPIO_SetBits(GPIOB,DI);
GPIO_ResetBits(GPIOB,RW);
GPIO_ResetBits(GPIOB,EN);
GPIO_Write(GPIOD, dat);
Delay(50000);
GPIO_SetBits(GPIOB,EN);
Delay(50000);
GPIO_ResetBits(GPIOB,EN);
}
void selectscreen(uchar screen) //选屏
{
switch(screen)
{
case 0: //全屏
GPIO_ResetBits(GPIOB,CS1);
GPIO_ResetBits(GPIOB,CS2);
break;
case 1: //选左半屏
GPIO_ResetBits(GPIOB,CS1);
GPIO_SetBits(GPIOB,CS2);
break;
case 2: //选右半屏
GPIO_SetBits(GPIOB,CS1);
GPIO_ResetBits(GPIOB,CS2);
break;
default:
break;
}
}
void clearscreen(uchar screen) //清屏
{
uchar i,j;
selectscreen(screen);
for(i=0xb8;i<0xc0;i++) //控制页数0--7,共8页
{
LCD_write_cmmand(i);
LCD_write_cmmand(0x40);
for(j=0;j<64;j++) //控制列数0-63,共64列
{
LCD_write_data(0x00); //写入0,地址指针自加1
}
}
}
/*LCD显示汉字字库函数*/
void lcd_display_hanzi(uchar screen,uchar page,uchar lie,uint mun)
{
//screen:选择屏幕参数,page:选择页参数0-3,lie列参数0-3,mun:显示第几个汉字的参数
int i; //page页其实就是行,是行计数器页指针 共九位计数器,高三位为X,低六位为Y
mun=mun*32;
selectscreen(screen) ; //片选看哪个段
LCD_write_cmmand(0x40+(lie*16)); //一个汉字占用两个字节
LCD_write_cmmand(0xb8+(page*2)); //一个字节显示
for (i=0;i<16;i++)
{
LCD_write_data(huan[mun++]);
}
LCD_write_cmmand(0x40+(lie*16));
LCD_write_cmmand(0xb8+(page*2)+1);
for (i=0;i<16;i++)
{
LCD_write_data(huan[mun++]);
}
}
/*LCD初始化函数*/
void LCD_init()
{
LCD_write_cmmand(0x3f); // 显示开启
Delay(50);
LCD_write_cmmand(0xc0); //显示起始行,从第一位开始,从0到63
Delay(50);
LCD_write_cmmand(0xb8); // 设置页得地址从0到7
Delay(50);
LCD_write_cmmand(0x40); //设置列的地址,从第一位开始,从0到63
Delay(50);
/* LCD_write_cmmand(0x30); // 显示开启
Delay(50);
LCD_write_cmmand(0x0c); //显示起始行,从第一位开始,从0到63
Delay(50);
LCD_write_cmmand(0x01); // 设置页得地址从0到7
Delay(50);*/
}
/*主函数*/
void main()
{
RCC_Configuration();
LCD_init(); //lcd初始化
clearscreen(0);
while(1)
{
lcd_display_hanzi(0,0,0,0); //欢
}
}
/*延时函数*/
void Delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
} |