这里讲我写的STC12C5A60S2控制洛基亚LCD5110的程序共享一下,是希望前辈们指点。
(补充:以下代码只需要修改lcd5110.h文件中含有 “选择” 字样的部分和字库头文件wordCode.h,就可以达到复用的效果)
测试程序:
#include <reg52.h> #include "lcd5110.h" #include "wordCode.h" void main() { LCD5110Init(); //汉字 LCD5110AddressWriteWord(0,0,wordcode1[0],16,3,0); // 每 LCD5110AddressWriteWord(2*8,0,wordcode1[0],16,2,1); // 天 LCD5110AddressWriteWord(4*8,0,wordcode1[0],16,2,2); // 进 LCD5110AddressWriteWord(6*8,0,wordcode1[0],16,2,3); // 步 LCD5110AddressWriteWord(8*8,0,wordcode1[0],16,2,4); // 一 LCD5110AddressWriteWord(0,2,wordcode1[0],16,2,5); // 点 LCD5110AddressWriteWord(2*8,2,wordcode1[0],16,2,6); // 点 LCD5110AddressWriteWord(4*8,2,wordcode1[0],16,2,7); // 就 LCD5110AddressWriteWord(6*8,2,wordcode1[0],16,2,8); // 不 LCD5110AddressWriteWord(8*8,2,wordcode1[0],16,2,9); // 再 LCD5110AddressWriteWord(0,4,wordcode1[0],16,2,10); // 简 LCD5110AddressWriteWord(2*8,4,wordcode1[0],16,2,11); // 单 //图片 //LCD5110AddressWritePicture(0,0,Pic,42,12,0); while(1); }
/*################lcd5110.h start ################*/
#ifndef __LCD5110_H__ #define __LCD5110_H__ #include <reg52.h> #include "common.h" sbit LCD5110_RST_bit = P1^0; /*根据硬件连接选择*/ sbit LCD5110_CE_bit = P1^1; /*根据硬件连接选择*/ sbit LCD5110_DC_bit = P1^2; /*根据硬件连接选择*/ sbit LCD5110_SDIN_bit= P1^3; /*根据硬件连接选择*/ sbit LCD5110_SCLK_bit= P1^4; /*根据硬件连接选择*/ #define LCD5110_DC_DATA HIGH_LEVEL #define LCD5110_DC_COMMAND LOW_LEVEL #define LCD5110_X_AXIS_START_ADDRESS 0x80 #define LCD5110_Y_AXIS_START_ADDRESS 0x40 /*****************外部接口函数******************/ //清屏 extern void LCD5110ClearAll(void) ; //初始化 extern void LCD5110Init(void) ; //地址写文字 extern void LCD5110AddressWriteWord(UB8 x,UB8 y, UB8 const *WCP,UB8 uintLong,UB8 uintNumber,UW16 index); //地址画图 extern void LCD5110AddressWritePicture(UB8 x,UB8 y,UB8 *PCP,UB8 uintLong,UB8 uintNumber,UW16 index) ; /**********************************************/ #endif /*__LCD5110_H__*/
/*################lcd5110.h end################*/
/*################ lcd5110.c start################*/
/*************************************************************************** Module :lcd5110.c Purpose :Implementation of lcd5110 module. Version :0.01 2014/02/03 12:00(OK) Complier:Keil 8051 C complier V9.01 MCU :STC12C5A60S2 Author :yangrui QQ :279729201 Email :yangrui90s@163.com Modification: ================= 2014/04/11 11:53 Reason: 1.完成 ================= ***************************************************************************/ #include <intrins.h> #include "lcd5110.h" /*外部接口函数在lcd5110.h中声明*/ /*****************内部函数******************/ static void LCD5110FreeBus(void) ; static void LCD5111WriteByte(UB8 dataCode,bit dataOrCommand) ; /**********************************************/ /****************************************************** Function :LCD5110FreeBus Input :N/A Output :N/A Return :N/A Description :free bus (high) Note :N/A ******************************************************/ static void LCD5110FreeBus(void) { LCD5110_CE_bit = HIGH_LEVEL ; LCD5110_DC_bit = HIGH_LEVEL ; LCD5110_SCLK_bit = HIGH_LEVEL ; LCD5110_SDIN_bit = HIGH_LEVEL ; LCD5110_RST_bit = HIGH_LEVEL ; } /****************************************************** Function :LCD5111WriteByte Input :byte-data ,command or data flag Output :N/A Return :N/A Description :Write byte-data to LCD5110 Note :dataOrCommand为1:数据(将会写入RAM) 0:命令 ******************************************************/ static void LCD5111WriteByte(UB8 dataCode,bit dataOrCommand) { UB8 i; LCD5110_CE_bit = HIGH_LEVEL ; LCD5110_DC_bit = dataOrCommand ; LCD5110_SCLK_bit = HIGH_LEVEL ; LCD5110_CE_bit = LOW_LEVEL ; for(i=0 ; i<8 ; i++) { LCD5110_SCLK_bit = LOW_LEVEL ; LCD5110_SDIN_bit = dataCode & (0x80 >>i) ; LCD5110_SCLK_bit = HIGH_LEVEL ; } LCD5110_CE_bit = HIGH_LEVEL ; LCD5110FreeBus(); } /****************************************************** Function :LCD5110ClearAll Input :N/A Output :N/A Return :N/A Description :清屏 Note :N/A ******************************************************/ void LCD5110ClearAll(void) { UW16 i; LCD5111WriteByte(0x40,LCD5110_DC_COMMAND);//Y坐标回0 LCD5111WriteByte(0x80,LCD5110_DC_COMMAND);//X坐标回0 for(i=0;i<504;i++) { LCD5111WriteByte(0x00,LCD5110_DC_DATA); } } /****************************************************** Function :LCD5110Init Input :N/A Output :N/A Return :N/A Description :LCD5110 initialization Note :N/A ******************************************************/ void LCD5110Init(void) { //复位一下 LCD5110_RST_bit = HIGH_LEVEL ; _nop_() ; _nop_() ; LCD5110_RST_bit = LOW_LEVEL ; _nop_() ; _nop_() ; LCD5110_RST_bit = HIGH_LEVEL ; LCD5111WriteByte(0x21,LCD5110_DC_COMMAND);//选择H=1模式 LCD5111WriteByte(0xc8,LCD5110_DC_COMMAND);//设置Vlcd电压 LCD5111WriteByte(0x20,LCD5110_DC_COMMAND);//选择H=0模式 LCD5111WriteByte(0x0c,LCD5110_DC_COMMAND);//普通显示模式 D=1 E=0 //LCD5111WriteByte(0x0d,LCD5110_DC_COMMAND);//阳文转换成阴文 D=1 E=1 //LCD5111WriteByte(0x08,LCD5110_DC_COMMAND);//全白 啥都不显 D=0 E=0 //LCD5111WriteByte(0x09,LCD5110_DC_COMMAND);//全黑 D=0 E=1 LCD5110ClearAll(); } /****************************************************** Function :LCD5110AddressWriteWord Input : x :x_axis value y :y_axis value *WCP:Word Code Point存放字模数据的二维数组的数组的起始地址,如table[0] uintLong:二维数组中,一维数组的长度 uintNumber:二维数组中,构成一个完整字形的一维数组个数 index:字形在二维数组中的索引号0~n Output :N/A Return :N/A Description :N/A Note :使用PCtoLCD2002提取字模,字宽和字高必须为偶数。 【汉字】:软件中设置点阵值等于字宽值,即 【点阵=字宽】 【英文】:软件中设置点阵值等于字宽值除以2,即 【点阵=字宽/2】 将所得到的字模数据存放到"WordsCode.h"头文件中 ******************************************************/ void LCD5110AddressWriteWord(UB8 x,UB8 y,UB8 *WCP,UB8 uintLong,UB8 uintNumber,UW16 index) { UL32 start; UB8 i,j; start=uintLong * uintNumber * index;/*确定字模数据提取的起始位置*/ WCP=WCP+start;/*将数组指针定位到要取得数据的起始位置*/ for(i=0;i<uintNumber;i++) { LCD5111WriteByte(LCD5110_X_AXIS_START_ADDRESS|x,LCD5110_DC_COMMAND);/*X坐标 */ LCD5111WriteByte(LCD5110_Y_AXIS_START_ADDRESS|(y+i),LCD5110_DC_COMMAND);/*Y坐标 +iLine是为了保证拼汉字的数据能自动向下一行*/ for(j=0;j<uintLong;j++)//将一维数组中的数据顺序输出 { LCD5111WriteByte(*WCP++,LCD5110_DC_DATA); } } } /****************************************************** Function :LCD5110AddressWritePicture Input : x :x_axis value y :y_axis value *PCP:Picture Code Point存放字模数据的二维数组的起始地址,如table[0] uintLong:二维数组中,一维数组的长度 uintNumber:二维数组中,构成一个完整图形的一维数组个数 index:图形在二维数组中的索引号0~n Output :N/A Return :N/A Description :N/A Note :使用PCtoLCD2002提取字模。 【图像】:要做先期处理,最大宽度84,高度48。 软件中设置点阵值等于图片的宽度除以2,即 【点阵=图片宽度/2】 将所得到的字模数据存放到"WordsCode.h"头文件中 ******************************************************/ void LCD5110AddressWritePicture(UB8 x,UB8 y,UB8 *PCP,UB8 uintLong,UB8 uintNumber,UW16 index) { UL32 start; UB8 i,j; UB8 Count=0; start=uintLong * uintNumber * index;/*确定字模数据提取的起始位置*/ PCP=PCP+start;/*将数组指针定位到要取得数据的起始位置*/ LCD5111WriteByte(LCD5110_X_AXIS_START_ADDRESS|x,LCD5110_DC_COMMAND);/*X坐标*/ LCD5111WriteByte(LCD5110_Y_AXIS_START_ADDRESS|y,LCD5110_DC_COMMAND);/*Y坐标*/ for(j=0;j<uintLong;j++)/*将一维数组中的数据顺序输出*/ { LCD5111WriteByte(*(PCP++),LCD5110_DC_DATA); } //输出第一个一维数组的数据 Count++; for(i=1;i<uintNumber;i++) { if(Count==2) { LCD5111WriteByte(LCD5110_Y_AXIS_START_ADDRESS|++y,LCD5110_DC_COMMAND);//Y坐标 +1是为了能自动向下一行 LCD5111WriteByte(LCD5110_X_AXIS_START_ADDRESS|x,LCD5110_DC_COMMAND);//X坐标 Count=0; } else { LCD5111WriteByte(LCD5110_Y_AXIS_START_ADDRESS|y,LCD5110_DC_COMMAND);//Y坐标 LCD5111WriteByte(LCD5110_X_AXIS_START_ADDRESS|(x+uintLong),LCD5110_DC_COMMAND);//X坐标 } for(j=0;j<uintLong;j++)//将一维数组中的数据顺序输出 { LCD5111WriteByte(*(PCP++),LCD5110_DC_DATA); } Count++; } }
/*################ lcd5110.c end################*/
/*################
wordCode.h start################*/
#ifndef _WORDCODE_H_ #define _WORDCODE_H_ #include <reg52.h> #include "common.h" UB8 code wordcode1[][16]= { // 每(0) // 天(1) // 进(2) // 步(3) // 一(4) // 点(5) // 点(6) // 就(7) // 不(8) // 再(9) // 简(10) // 单(11) {0x20,0x10,0x0C,0xF3,0x12,0x12,0x52,0x92,0x12,0x12,0x12,0xF2,0x02,0x02,0x00,0x00}, {0x01,0x01,0x1F,0x11,0x11,0x11,0x15,0x19,0x51,0x91,0x51,0x3F,0x11,0x11,0x01,0x00},/*"每",0*/ {0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xFE,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00}, {0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00},/*"天",1*/ {0x40,0x40,0x42,0xCC,0x00,0x80,0x88,0x88,0xFF,0x88,0x88,0xFF,0x88,0x88,0x80,0x00}, {0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x4C,0x43,0x40,0x40,0x5F,0x40,0x40,0x40,0x00},/*"进",2*/ {0x40,0x40,0x40,0x7C,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00}, {0x80,0x90,0x88,0x46,0x40,0x40,0x20,0x2F,0x10,0x10,0x08,0x04,0x02,0x00,0x00,0x00},/*"步",3*/ {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"一",4*/ {0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x00,0x00}, {0x80,0x40,0x37,0x04,0x04,0x14,0x64,0x04,0x14,0x64,0x04,0x07,0x10,0xE0,0x00,0x00},/*"点",5*/ {0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,0x48,0x48,0x48,0xC8,0x08,0x08,0x00,0x00}, {0x80,0x40,0x37,0x04,0x04,0x14,0x64,0x04,0x14,0x64,0x04,0x07,0x10,0xE0,0x00,0x00},/*"点",6*/ {0x04,0xE4,0x25,0x26,0x24,0xE4,0x04,0x20,0x20,0xFF,0x20,0xE2,0x2C,0x20,0x20,0x00}, {0x10,0x4B,0x82,0x7E,0x02,0x0B,0x90,0x60,0x1C,0x03,0x00,0x3F,0x40,0x40,0x70,0x00},/*"就",7*/ {0x00,0x02,0x02,0x02,0x02,0x82,0x42,0xF2,0x0E,0x42,0x82,0x02,0x02,0x02,0x00,0x00}, {0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0x01,0x02,0x0C,0x00,0x00},/*"不",8*/ {0x02,0x02,0xF2,0x92,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0x92,0xF2,0x02,0x02,0x00}, {0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x44,0x84,0x7F,0x04,0x04,0x00},/*"再",9*/ {0x08,0x04,0xC3,0x12,0x26,0x8A,0xA2,0xAA,0xA4,0xA3,0x22,0x26,0xEA,0x02,0x02,0x00}, {0x00,0x00,0xFF,0x00,0x00,0x3F,0x24,0x24,0x24,0x3F,0x00,0x80,0xFF,0x00,0x00,0x00},/*"简",10*/ {0x00,0x00,0xF8,0x49,0x4A,0x4C,0x48,0xF8,0x48,0x4C,0x4A,0x49,0xF8,0x00,0x00,0x00}, {0x10,0x10,0x13,0x12,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x12,0x13,0x10,0x10,0x00},/*"单",11*/ }; UB8 code wordcode2[][8]= { {0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18}, {0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"f",0*/ {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00}, {0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20},/*"a",1*/ }; UB8 code Pic[12][42]= { {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xE0,0xE0,0xE0,0xF0,0xF0,0xF0,0xF0,0x78,0x78,0x38,0x38,0x38,0x3C,0x3C,0x1C,0xDC,0xCC,0xDA,0x52,0x42,0x4E,0x5E,0x5E}, {0x9C,0xCE,0x8E,0x4E,0x4E,0x4E,0x4E,0x5E,0xDC,0xDC,0xDE,0xFE,0xFC,0x3C,0x3C,0x3C,0x3C,0x38,0x78,0x70,0xF0,0xF0,0xF0,0xF0,0xE0,0xE0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xF8,0xF8,0xFC,0x7E,0x3E,0x1F,0xDF,0x4F,0x47,0xCF,0x4B,0x19,0xF9,0x10,0x17,0x17,0x11,0x09,0x0D,0x06,0x00,0x3F,0x1F,0x00,0x01,0xB5,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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0xEE,0xC9,0xF9,0xCD,0xEB,0xE2,0xBC,0x30,0x10,0xD0,0x50,0x50,0x20,0xE0,0x00,0x00,0x00,0x00,0xFF,0xF7,0x07,0xFF,0xFF,0x07,0xFF,0xF5,0x00}, {0x7F,0xFF,0x81,0xFF,0xFF,0xFF,0xFF,0xFF,0x83,0xFF,0x7E,0x00,0x0F,0x07,0x60,0xF0,0x90,0x90,0xF0,0xF0,0x50,0x1F,0x99,0xB3,0xE6,0xC4,0xE5,0xF3,0x70,0x78,0x3C,0x3E,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00}, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x03,0x07,0x07,0x0F,0x07,0x0F,0x1F,0x1F,0x1F,0x3D,0x3D,0x3D,0x38,0x3C,0x3C,0x38,0x7F,0x7F,0x70,0x7F,0x7F,0x70,0x7F,0x7F,0x70}, {0x77,0x7F,0x7F,0x7B,0x7F,0x7F,0x7F,0x7B,0x7F,0x7F,0x3F,0x3C,0x3F,0x1F,0x1C,0x1C,0x1D,0x0F,0x0F,0x0E,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"C:\Users\lenovo\Desktop\5110\Pic\C_129_conew1.bmp",0*/ }; #endif
/*################
wordCode.h end################*/
补充:common.h
#ifndef __COMMON_H__ #define __COMMON_H__ typedef unsigned char UB8 ; typedef unsigned short int UW16 ; typedef unsigned long UL32 ; typedef char SB8; typedef short int SW16 ; typedef long SL32 ; #define HIGH_LEVEL 1 #define LOW_LEVEL 0 #endif /*__COMMON_H__*/
单片机控制NOKIA5110液晶屏之模块化编程,布布扣,bubuko.com
原文:http://blog.csdn.net/yagnruinihao/article/details/23435391