//以下是lcd5110.c
#include "lcd5110.h"
#include "english_6x8_pixel.h"
//中文字库自己添加,如果没有请注释起来#include "write_chinese_string_pixel.h"
//lcdgpio初始化函数
//GPIOC.0.9.10.11.12推挽输出,GPIO口可自己设置
void LCD_GPIO_init(void)
{
GPIO_InitTypeDef GPIO_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);
}
//初始化函数
void LCD_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;
}
//清屏函数
void LCD_clear(void)
{
unsigned int i;
LCD_write_byte(0x0c, 0);
LCD_write_byte(0x80, 0);
for (i=0; i<504; i++)
LCD_write_byte(0, 1);
}
//设置lcd坐标函数
void LCD_set_XY(unsigned char X, unsigned char Y)
{
LCD_write_byte(0x40 | Y, 0); // column
LCD_write_byte(0x80 | X, 0); // row
}
//显示英文字符
//输入参数c为显示的字符
void LCD_write_char(unsigned char c)
{
unsigned char line;
c -= 32;
for (line=0; line<6; line++)
LCD_write_byte(font6x8[c][line], 1);
}
//数字显示函数
void LCD_write_number(unsigned char X,unsigned char Y,u16 num)
{
//如果数字大于32000则显示输入错误
if(num>32000)
LCD_write_english_string(X,Y,"ERROR!");
//如果输入在32000内正常显示
else
{
unsigned char a,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;