STM32驱动Nokia5110
扫描二维码
随时随地手机看文章
//以下是lcd5110.c
#include"lcd5110.h"
#include"english_6x8_pixel.h"
//中文字库自己添加,如果没有请注释起来#include"write_chinese_string_pixel.h"
//lcdgpio初始化函数
//GPIOC.0.9.10.11.12推挽输出,GPIO口可自己设置
voidLCD_GPIO_init(void)
{
GPIO_InitTypeDefGPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
}
//初始化函数
voidLCD_init(void)
{
//产生一个让lcd复位的低电平脉冲
LCD_RST=0;
delay_us(1);
LCD_RST=1;
//关闭lcd
LCD_CE=0;
delay_us(1);
//使能lcd
LCD_CE=1;
delay_us(1);
LCD_write_byte(0x21,0);
LCD_write_byte(0xc8,0);
LCD_write_byte(0x06,0);
LCD_write_byte(0x13,0);
LCD_write_byte(0x20,0);
LCD_clear();
LCD_write_byte(0x0c,0);
//关闭lcd
LCD_CE=0;
}
//清屏函数
voidLCD_clear(void)
{
unsignedinti;
LCD_write_byte(0x0c,0);
LCD_write_byte(0x80,0);
for(i=0;i<504;i++)
LCD_write_byte(0,1);
}
//设置lcd坐标函数
voidLCD_set_XY(unsignedcharX,unsignedcharY)
{
LCD_write_byte(0x40|Y,0);//column
LCD_write_byte(0x80|X,0);//row
}
//显示英文字符
//输入参数c为显示的字符
voidLCD_write_char(unsignedcharc)
{
unsignedcharline;
c-=32;
for(line=0;line<6;line++)
LCD_write_byte(font6x8[c][line],1);
}
//数字显示函数
voidLCD_write_number(unsignedcharX,unsignedcharY,u16num)
{
//如果数字大于32000则显示输入错误
if(num>32000)
LCD_write_english_string(X,Y,"ERROR!");
//如果输入在32000内正常显示
else
{
unsignedchara,b,c,d,e;//a,b,c,d,e分别代表数字的万千百十个位
a=num/10000;
b=(num-a*10000)/1000;
c=(num-a*10000-b*1000)/100;
d=(num-a*10000-b*1000-c*100)/10;
e=num-a*10000-b*1000-c*100-d*10;
a+=48;
b+=48;
c+=48;
d+=48;
e+=48;
LCD_set_XY(X,Y);
LCD_write_char(a);
X++;
LCD_write_char(b);
X++;
LCD_write_char(c);
X++;
LCD_write_char(d);
X++;
LCD_write_char(e);
}
}
//英文字符串显示函数
//输入参数*s为英文字符串指针
//xy为显示字符串的位置x0-83,y0-5
voidLCD_write_english_string(unsignedcharX,unsignedcharY,charchar*s)
{
LCD_set_XY(X,Y);
while(*s)
{
LCD_write_char(*s);
s++;
}
}
/*
//显示汉字,此部分自行添加字库,如果没有请注释起来
//输入参数xy为汉字起始坐标
//ch_with为汉字点阵的宽度
//num为显示汉字的个数
//line汉字点阵数组中的起始行数
//row为汉字显示的行间距
voidLCD_write_chinese_string(unsignedcharX,unsignedcharY,
unsignedcharch_with,unsignedcharnum,
unsignedcharline,unsignedcharrow)
{
unsignedchari,n;