STM32驅(qū)動Nokia5110
//以下是lcd5110.c
#include"lcd5110.h"
#include"english_6x8_pixel.h"
//中文字庫自己添加,如果沒有請注釋起來#include"write_chinese_string_pixel.h"
//lcdgpio初始化函數(shù)
//GPIOC.0.9.10.11.12推挽輸出,GPIO口可自己設(shè)置
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);
}
//初始化函數(shù)
voidLCD_init(void)
{
//產(chǎn)生一個讓lcd復位的低電平脈沖
LCD_RST=0;
delay_us(1);
LCD_RST=1;
//關(guān)閉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);
//關(guān)閉lcd
LCD_CE=0;
}
//清屏函數(shù)
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);
}
//設(shè)置lcd坐標函數(shù)
voidLCD_set_XY(unsignedcharX,unsignedcharY)
{
LCD_write_byte(0x40|Y,0);//column
LCD_write_byte(0x80|X,0);//row
}
//顯示英文字符
//輸入?yún)?shù)c為顯示的字符
voidLCD_write_char(unsignedcharc)
{
unsignedcharline;
c-=32;
for(line=0;line<6;line++)
LCD_write_byte(font6x8[c][line],1);
}
//數(shù)字顯示函數(shù)
voidLCD_write_number(unsignedcharX,unsignedcharY,u16num)
{
//如果數(shù)字大于32000則顯示輸入錯誤
if(num>32000)
LCD_write_english_string(X,Y,"ERROR!");
//如果輸入在32000內(nèi)正常顯示
else
{
unsignedchara,b,c,d,e;//a,b,c,d,e分別代表數(shù)字的萬千百十個位
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);
}
}
//英文字符串顯示函數(shù)
//輸入?yún)?shù)*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++;
}
}
/*
//顯示漢字,此部分自行添加字庫,如果沒有請注釋起來
//輸入?yún)?shù)xy為漢字起始坐標
//ch_with為漢字點陣的寬度
//num為顯示漢字的個數(shù)
//line漢字點陣數(shù)組中的起始行數(shù)
//row為漢字顯示的行間距
voidLCD_write_chinese_string(unsignedcharX,unsignedcharY,
unsignedcharch_with,unsignedcharnum,
unsignedcharline,unsignedcharrow)
{
unsignedchari,n;