以下是我的程序,大神看看是不是我的引脚模式配置不对,还是我的写数据命令函数,或者显示字符或字符串的函数不对,由于字节数限制,我只发了部分程序源码
#include "bsp_nokia5110_lcd.h"
#include "ascii.h"
#define WIDTH 6
#define HEIGHT 8
#define DEBUG_DELAY()
void LCD_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11
;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_12);//
}
void LCD_write_byte(unsigned char dat ,unsigned char command)
{
unsigned char i;
LCD_ce_0;
if(command==0)
LCD_dc_0;
else LCD_dc_1;
for(i=0;i<8;i++)
{
if(dat&0x80)
LCD_sdin_1;
else
LCD_sdin_0;
dat=dat<<1;
LCD_sclk_0;
LCD_sclk_1;
}
LCD_dc_1;
LCD_ce_1;
LCD_sdin_1;
}
void delay_ms(unsigned int t)
{
unsigned i,j;
for(i=t;i>0;i--)
for(j=110;j>0;j--);
}
void LCD5110_init(void)
{
LCD_GPIO_Config();
LCD_ce_1;
LCD_rst_0;
delay_ms(10);
LCD_rst_1;
delay_ms(100);
LCD_write_byte(0x21,0);
LCD_write_byte(0x13,0);
LCD_write_byte(0xbb,0);
LCD_write_byte(0x20,0);
LCD_write_byte(0x0c,0);
LCD_clear();
}
void LCD_clear(void)
{
unsigned int i;
LCD_set_XY(0,0);
for(i=0;i<504;i++)
LCD_write_byte(0x00,1);
}
void LCD_write_string(unsigned char X,unsigned char Y,char *s)
{
unsigned char i=0,j=0;
while (*s)
{
LCD_set_XY(X,Y);
LCD_write_char(*s++);
X+=WIDTH;
i++;
if(i>=(84/WIDTH))
{
X=0;
Y+=HEIGHT;
i=0;
j++;
}
if(j>=(48/HEIGHT))
{
return ;
}
}
}
#define LCD_rst_0 GPIOA->BRR=1<<7
#define LCD_rst_1 GPIOA->BSRR=1<<7
#define LCD_ce_0 GPIOA->BRR=1<<8
#define LCD_ce_1 GPIOA->BSRR=1<<8
#define LCD_dc_0 GPIOA->BRR=1<<9
#define LCD_dc_1 GPIOA->BSRR=1<<9
#define LCD_sdin_0 GPIOA->BRR=1<<10
#define LCD_sdin_1 GPIOA->BSRR=1<<10
#define LCD_sclk_0 GPIOA->BRR=1<<11
#define LCD_sclk_1 GPIOA->BSRR=1<<11
#define LCD_bl_0 GPIOA->BRR=1<<12
#define LCD_bl_1 GPIOA->BSRR=1<<12
int main(void)
{
LCD5110_init();
LCD_clear();
while(1)
{
LCD_write_string(0,0,"nakia5110");
}
}
|