基于LPC2366的LCD12864-5液晶驱动程序
LCD12864的驱动
LCD12864驱动LCD12864在市面上主要分为两种,一种是采用st7920控制器的,它一般带有中文字库字模,价格略高一点。
另一种是采用KS0108控制器,它只是点阵模式,不带字库。
很可惜,我的这块就是KS0108控制器不带汉字库的,不过不打算用它专门显示文本,也就无所谓了。
LCD12864模块的20个引脚定义如下:1。
Vss 逻辑电源地2。
VDD 逻辑电源正5v3。
V0 LCD驱动电压4。
RS 数据/指令选择:高电平为数据,低电平为指令5。
R/W 读/写选择:高电平为读数据,低电平为写数据6。
E 读写使能,高电平有效,下降沿锁定数据7。
DB0 数据输入输出引脚8。
DB1 数据输入输出引脚9。
DB2 数据输入输出引脚10。
DB3 数据输入输出引脚11。
DB4 数据输入输出引脚12。
DB5 数据输入输出引脚13。
DB6 数据输入输出引脚14。
DB7 数据输入输出引脚15。
CS1 片选择号,低电平时选择前64列16。
CS2 片选择号,低电平时选择后64列17。
RET 复位信号,低电平有效。
18。
VEE 输出-15v电源给V0提供驱动电源19。
A 背光电源LED正极20。
K 背光电源LED负极具体电路图如下:制做如下:接口说明:装上12864具体的电路还是两个电阻。
一个背光限流电阻。
一个液晶驱动电压调节电阻。
背光电阻还是任何时候在19、20脚与电源之间串上个100欧电位器接上电源。
调节电位器到合适亮度。
具体值最好是到调试完程序能够正常显示后再将阻值确定换成固定电阻。
液晶驱动电压的调整在数据线、电源线接好的前提下是在Vee(-15v)和地之间接一个电位器。
中间接V0,通过调节电位器来调节V0上的电压。
当V0上为-15V时为全暗(液晶显示为全黑)。
当V0为0V 时为全亮。
调节电位器使屏幕从全暗刚好变到亮时,便可进行程序的调试。
待屏幕显示正常后,进行对比度的细调,然后测量这两边的阻值在地和V0之间、V0和Vee之间换成两个固定电阻焊上就好了。
LCD12864驱动程序(带字库的)
{
while(buf--);
}*/
/***********忙检测********************/
void Busy()
{
DataPort=0xFF;
RS=0;
RW=1;
while (1)
{
E =1;
if (P0^7==0) break;
}
E=0;
}
void main(void)
{
TMOD=0x01; ///选择定时器模式
TR0=1; //开中断,并允许T0中断
ET0=1;
EA=1; //总开关
Init_LCቤተ መጻሕፍቲ ባይዱ();
Clear_LCD();
while(1);
}
void t0(void) interrupt 1 using 0
{
//delay(100);
/*void Line_Num(uchar k)
{
//uint l;
if(k>=128&&k<=135)l=1;
if(k>135&&k<=143) l=3;
if(k>143&&k<=151) l=2;
if(k>151&&k<=159) l=4;
}*/
/*******************逐行显示***************************************/
void Write_Data(uchar Data)
{
Busy();
RS=1;
RW=0;
12864(ST7565P)液晶驱动
12864(ST7565P)液晶驱动显示概念含有ST7565P 芯片的液晶,是没有文库支持的功能,但是没有就没有啦!液晶可以给我画画,那么它就是好东西了。
液晶的“显示”,液晶的“扫描次序”全部都与CGRAM分配有很大的关系。
我们先了解“扫描次序”吧。
宏观上一副液晶是“64高x 128宽”。
微观上由芯片ST7565P驱动的一副12864 液晶是由“8个8 高x 128宽的页”组成。
至于液晶的“扫描次序”就与4个命令有关系。
上图表示了,当命令为0xA0列扫描是“自左向右”,如果命令式0xA1列扫描是“自右向左”。
总归,这两个命令控制了“列扫描次序”除了控制列扫描的命令以外,当然还有控制“页扫描次序”的命令。
如上图,命令0xC0 控制页扫描是“从下至上”,然而命令0xc8 控制页扫描“又上至下”。
无论页扫描的次序是“从上至下”还是“从下至上”,然而每一页的列填充,都是“低位开始高位结束”关于列扫描就有列填充的问题。
我们知道每“一页”都是由“8 高x 128宽”组成。
换句话说,这里没有“行扫描”的概念,因为“一页”都是由“一个字节数据,列填充128次”成为一页。
如上图中所示。
假设“页扫描次序”是由上至下,填充的值是0x0f,那么经过128次的“列扫描”以后,一页的扫描结果会是如上图所示。
关于ST7565P 芯片,命令,和液晶扫描它们之间的关系而已,我们简单来总结一下:(一)CGRAM分布是由8页组成。
(二)每一页是由一个字节填充和128次列扫描组成。
(三)列扫描次序与命令0xA0 与0xA1有关。
(四)页扫描次序与命令0xC0 与0xC8 有关。
(五)列填充字节的高位低位关系与页扫描命令有关。
(六)不存在行扫描概念。
上图所示是“页扫描”由上至下,“列扫描”由左至右,列填充值是0x0f。
在CGRAM分布方面。
CGRAM 可以说是由8 bits x 1024 words,如果以“页”去分配,也就是说8 page x 8 bits x 128 words ,那么“页”的偏移量就是128。
PIC单片机驱动LCD12864液晶显示闪动字体程序
PIC单片机驱动LCD12864液晶显示闪动字体程序/************************************************ ************************* 功能:12864LCD显示显示闪动字体,各位同学可以自己修改。
*** 实验内容:0x81 0x90 0x88 0x98 分别是LCD四行的行首地址,我们操作LCD现实的字符就是分别放在这里面的*** 开发板连接方法:接上有字库LCD12864 注意调节对比度,LCD12864工作电流较大,请用外接电源供电。
************************************************* ************************************************* **/#include;__CONFIG(0xff32);//芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡#define rsRA5//定义LCD的数据/命令控制口#define rwRA4//定义LCD的读/写控制口#define eRA3//定义LCD的使能口#define psbRA2//定义通信方式控制口#define rstRA1//定义复位口#define nop() asm("nop")//定义空操作函数const unsigned char TAB1A[ ] = {"中科技电子网"};const unsigned char TAB1B[ ] ={***.*********.***"};const unsigned char TAB1C[ ] ={"0755-110"};const unsigned char TAB1D[ ] = {"HD-34 PIC 开发板"};unsigned int lcd_x;//定义LCD页地址寄存器unsigned int lcd_y;//定义LCD列地址寄存器bit busy;//定义LCD忙标志位void init();//申明I/O口设置函数void lcd_init();//申明LCD初始化函数void clear_p();//申明清屏函数void writelcd(const unsigned char *pt); //声明LCD写字符串函数void wr_zb();//申明有关显示设置函数void flash();//申明设置LCD显示闪烁函数void send_d(unsigned char x);//申明送一字节数据显示函数void send_i(unsigned char x);//申明送一字节控制命令函数void chk_busy();//申明检测LCD是否工作繁忙函数void delay();//申明延时函数1,供各命令之间的延时和决定显示快慢void delay1();//申明延时函数2,用以决定显示闪烁快慢/************************************************ ***************************** 名称:main()* 功能:主函数* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void main()init();//调用I/O口设置函数while (1){lcd_init();//调用LCD初始化函数clear_p();//调用清屏函数send_i(0x81);//第1行writelcd(TAB1A);send_i(0x90);//第2行writelcd(TAB1B);send_i(0x88); //第3行writelcd(TAB1C);send_i(0x98); //第4行writelcd(TAB1D);delay();//延长显示一段时间flash();//调用显示闪烁函数clear_p();//调用清屏函数}}/************************************************ ***************************** 名称:init()* 功能:I/O口初始化* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void init(){ADCON1 = 0X07;//设置A口为普通I/O口TRISA = 0X00;//设置A口为输出TRISD = 0X00;//设置D口为输出PORTA = 0X00000001;}/************************************************ ***************************** 名称:lcd_init()* 功能:LCD初始化* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void lcd_init(){rst = 0;//复位LCDdelay();//保证复位所需要的时间rst = 1;//恢复LCD正常工作nop();psb = 1;//设置LCD为8位并口通信send_i(0x30);//基本指令操作send_i(0x01);//清除显示send_i(0x06);//指定在写入或读取时,光标的移动方向send_i(0x0c);//开显示,关光标,不闪烁}/************************************************ ***************************** 名称:wr_zb()* 功能:显示设置* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void wr_zb(){send_i(lcd_y);send_i(lcd_x);}/************************************************ ***************************** 名称:flash()* 功能:显示闪烁* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void flash(){send_i(0x08);//关显示delay1();//延长一定时间send_i(0x0c);//开显示delay1();delay1(); //延长关显示两倍的时间send_i(0x08);//关显示delay1();send_i(0x0c);//开显示delay1();delay1();send_i(0x08);//关显示delay1();send_i(0x0c);//开显示delay1();delay1();}/************************************************ ***************************** 名称:clear_p()* 功能:清屏* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void clear_p(){send_i(0x1);//清除所有显示send_i(0x34);//扩展指令操作send_i(0x30);//基本指令操作}/************************************************ ***************************** 名称:send_d()* 功能:写一个字节数据到LCD* 入口参数:unsigned char x 字符* 出口参数:* 说明:****************************************************************************/ void send_d(unsigned char x) {chk_busy();//检测LCD是否工作繁忙rs = 1;//设置该字节数据是显示数据rw = 0;//设置该次操作为写PORTD = x;//送数据口PORTDe = 1;//使能nop();nop();nop();e = 0;//禁止}/************************************************ ***************************** 名称:send_i()* 功能:写一个字节命令到LCD* 入口参数:unsigned char x 字符* 出口参数:* 说明:************************************************* ***************************/void send_i(unsigned char x){chk_busy();//检测LCD是否工作繁忙rs = 0;//设置该字节数据为控制命令rw = 0;//设置此次操作为写PORTD = x;//送数据口PORTDe = 1;//使能nop();nop();nop();e = 0;//禁止}/************************************************ ***************************** 名称:chk_busy()* 功能:检测LCD是否工作繁忙* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void chk_busy(){busy = 1;//先置位繁忙标志位TRISD = 0XFF;//更改通信为输入rs = 0;//设置该字节数据为命令代码rw = 1;//设置此次操作为读while (busy){nop();nop();nop();e = 1;//使能nop();nop();nop();if (!RD7) busy = 0;//检测LCD是否工作繁忙nop();nop();nop();e = 0;//禁止}e = 0;//禁止TRISD = 0X00;//恢复通信为输出}/************************************************ ***************************** 名称:delay()* 功能:延时* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void delay(){int i;for (i = 0;i < 5000;i++);}/************************************************ ***************************** 名称:delayl()* 功能:延时* 入口参数:* 出口参数:* 说明:************************************************* ***************************/void delay1(){int i;for (i = 0;i < 10;i++){delay();//调用延时函数}}/************************************************ ***************************** 名称: writelcd()* 功能:在LCD上显示字符串* 入口参数:const unsigned char *pt 字符串的首地址* 出口参数:* 说明:************************************************* ***************************/void writelcd(const unsigned char *pt){while(*pt)//检测是否达到了字符串最后send_d(*pt++); //发送数据给lcd}。
12864液晶屏串口驱动程序
12864液晶屏串口驱动程序代码12864液晶屏驱动采用4_Wire-SPI串口驱动方式,可有效的减少IO口的占用,方便使用调试,本程序的代码驱动IC为ST7565R,是基于STC89C53RC的12864串行模式的程序,硬件电路连接只需要5根线:RS、 SDA、 SCLK、RES、CS 。
程序已经调试通过,很好用。
代码如下://----------------------------------------------------------------------/*hotdisplay CO,.LTD.*/// Module : HTG12864// Lanuage : C51 Code// Create :// Version : 1.0// Date : OCT-21-2016// LCM Drive IC : ST7565R// INTERFACE : 4_Wire-SPI// MCU : STC89C53RC// VDD : 3.3V//********************************************************* ******************#include<reg51.h>#define uchar unsigned char#define uint unsigned intuchar bdata transdata;sbit R_S= P3^5;sbit RES= P3^4;sbit SCK= P1^6;sbit SDA= P1^7;sbit CS1= P3^7;sbit transbit = transdata^7 ;#define Page 0xb0//##########################################//void Comwrite(unsigned char com); //D′??á?3ìDò//void Datawrite(unsigned char dat);void Delay(unsigned int time); //?óê±×ó3ìDò//char code Hanzi[]={0xFF,0x01,0x01,0x09,0xF9,0x09,0x01,0x01,0x09,0xF9,0x09,0xE1 ,0x11,0x09,0x09,0x09,0x11,0xE1,0x01,0x19,0x09,0x09,0xF9,0x09,0x09,0x19,0x01,0x01 ,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x09,0xF9,0x09,0x09,0x09,0x11,0xE1,0x01,0x01 ,0x09,0x09,0xF9,0x09,0x09,0x01,0x01,0x01,0x71,0x89,0x09,0x09,0x09,0x39,0x01,0x09 ,0xF9,0x09,0x09,0x09,0x09,0xF1,0x01,0x01,0x01,0xC1,0x39,0xE1,0x01,0x01,0x01,0x09 ,0xF9,0x09,0x01,0x01,0x01,0x01,0x01,0x09,0x39,0xC9,0x01,0xC9,0x39,0x09,0x01,0x01 ,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x09,0xF9,0x09,0x01,0x01,0x01,0x01,0x01,0xC1 ,0x31,0x09,0x09,0x09,0x09,0x39,0x01,0x09,0xF9,0x09,0x09,0x09,0x11,0xE1,0x01,0x01 ,0x01,0x01,0x01,0xFF,0xFF,0x00,0x00,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,0x0F ,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x00 ,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,0x20 ,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,0x20 ,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,0x07 ,0x18,0x20,0x20,0x20,0x10,0x08,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x00 ,0x00,0x08,0xF8,0x08,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x08,0xF8,0xF8,0x00 ,0xF8,0xF8,0x08,0x00,0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08 ,0x08,0x88,0x70,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x88 ,0x88,0x18,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x21,0x01 ,0x01,0x21,0x3F,0x20,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x20,0x3F,0x00,0x3F ,0x00,0x3F,0x20,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x00,0x30,0x28,0x24 ,0x22,0x21,0x30,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x0F,0x11,0x20 ,0x20,0x11,0x0E,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0xE0,0x10,0x08,0x08 ,0x08,0x10,0xE0,0x00,0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x70,0x88,0x08 ,0x08,0x08,0x38,0x00,0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x70,0x88,0x08 ,0x08,0x88,0x70,0x00,0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0xE0,0x10,0x88 ,0x88,0x18,0x00,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,0x0F,0x10,0x20,0x20 ,0x20,0x10,0x0F,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,0x00,0x38,0x20,0x21 ,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x20,0x20,0x3F ,0x20,0x20,0x00,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,0x00,0x1C,0x22,0x21 ,0x21,0x22,0x1C,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,0x00,0x0F,0x11,0x20 ,0x20,0x11,0x0E,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0xFF,0xFF,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x08,0x88 ,0x88,0x48,0x30,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0xF8,0x08,0x88 ,0x88,0x08,0x08,0x00,0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x38,0x08,0x08 ,0xC8,0x38,0x08,0x00,0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0xE0,0x10,0x08 ,0x08,0x10,0xE0,0x00,0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x10,0x10,0xF8 ,0x00,0x00,0x00,0x00,0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x08,0x88 ,0x88,0x48,0x30,0x00,0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0xF8,0x08,0x88 ,0x88,0x08,0x08,0xFF,0xFF,0x8F,0x90,0xA0,0xA0,0x90,0x8F,0x80,0x80,0xA0,0xA0,0xBF ,0xA0,0xA0,0x80,0x80,0x80,0xB0,0xA8,0xA4,0xA2,0xA1,0xB0,0x80,0x80,0x98,0xA0,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x87,0x84,0xA4,0xA4,0xBF,0xA4,0x80,0x80,0x99,0xA1,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x8F,0x91,0xA0,0xA0,0x91,0x8E,0x80,0x80,0x80,0x80,0xBF ,0x80,0x80,0x80,0x80,0x80,0x9C,0xA2,0xA1,0xA1,0xA2,0x9C,0x80,0x80,0x80,0xB1,0xA2 ,0xA2,0x91,0x8F,0x80,0x80,0x8F,0x90,0xA0,0xA0,0x90,0x8F,0x80,0x80,0xA0,0xA0,0xBF ,0xA0,0xA0,0x80,0x80,0x80,0xB0,0xA8,0xA4,0xA2,0xA1,0xB0,0x80,0x80,0x98,0xA0,0xA0 ,0xA0,0x91,0x8E,0x80,0x80,0x87,0x84,0xA4,0xA4,0xBF,0xA4,0x80,0x80,0x99,0xA1,0xA0 ,0xA0,0x91,0x8E,0xFF};//###############################################//char code Hanzi1[]={0x00,0x04,0xFC,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x00,0xA0 ,0xA0,0xA0,0xA0,0xC0,0x00,0x00,0x00,0xC0,0x40,0x20,0x20,0x44,0xFC,0x00,0x00,0x00 ,0x00,0x20,0x20,0xE4,0x00,0x00,0x00,0x00,0x00,0xC0,0x40,0x20,0x20,0x20,0x40,0xC0 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x84,0x84,0x84 ,0x44,0xF8,0x00,0x00,0x00,0x08,0x04,0x04,0x84,0x44,0x38,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0x88,0x44,0x44,0x44,0x80,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x30,0xC0,0x00,0xC0,0x30,0xFC,0x04 ,0x04,0xFC,0x44,0x40,0x40,0x40,0x44,0xFC,0x04,0x00,0x60,0x20,0x20,0x20,0xA0,0x60 ,0x20,0x00,0x00,0x00,0x40,0x48,0x4F,0x48,0x40,0x41,0x42,0x4C,0x48,0x40,0x47,0x48 ,0x48,0x48,0x48,0x47,0x48,0x40,0x40,0x47,0x44,0x48,0x48,0x44,0x4F,0x48,0x40,0x40 ,0x40,0x48,0x48,0x4F,0x48,0x48,0x40,0x40,0x40,0x47,0x44,0x48,0x48,0x48,0x44,0x47 ,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x48,0x48,0x48 ,0x44,0x43,0x40,0x40,0x40,0x4C,0x4A,0x49,0x48,0x48,0x48,0x40,0x40,0x40,0x40,0x40 ,0x4C,0x4C,0x40,0x40,0x40,0x40,0x40,0x47,0x48,0x48,0x48,0x48,0x47,0x40,0x40,0x40 ,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x48,0x4F,0x48,0x40,0x43,0x40,0x48,0x4F,0x48 ,0x48,0x4F,0x48,0x40,0x40,0x40,0x48,0x4F,0x48,0x40,0x48,0x4C,0x4A,0x49,0x48,0x48 ,0x4C,0x40,0x40,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xE0,0xE0,0xE0,0xFC,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C ,0x1C,0xFC,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0xE0,0xFC ,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0xFC,0xE0,0xE0,0xE0,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xE0,0xE0,0xFC,0x1C,0x1C,0x1C,0x1C ,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0xFC,0xE0,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00 ,0x00,0xF0,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x00,0x00,0x80,0x00,0x80,0x80 ,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0xC0,0x30,0x00,0xF0,0x00,0x80 ,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x1F,0x1F,0x1F,0xFF,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0 ,0xE0,0xFF,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0xFF ,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0x1F,0x1F,0x1F,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0xFF,0xE0,0xE0,0xE0,0xE0 ,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xFF,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00 ,0x00,0xFF,0x08,0x04,0x02,0x07,0x08,0x30,0x40,0x80,0x00,0x00,0xFF,0x01,0x00,0x00 ,0x00,0xFF,0x01,0x00,0x00,0x00,0xFF,0x00,0xC0,0x3C,0x03,0x00,0x00,0xFF,0x01,0x00 ,0x00,0x00,0xFF,0x00,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x84,0xC4,0x04,0x04,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x84 ,0xC4,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04 ,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0x84,0x44 ,0x44,0x44,0x84,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x84,0x84 ,0xC4,0x04,0x04,0x04,0x04,0x04,0xC4,0x44,0x44,0x44,0x44,0x04,0x04,0x04,0x04,0x04 ,0x04,0x04,0x04,0x04,0x04,0x84,0x44,0x44,0x44,0x84,0x04,0x04,0x04,0xC4,0x44,0x44 ,0x44,0x44,0x04,0x04,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x00,0x40,0x40,0x7F,0x40,0x40,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,0x40,0x40 ,0x7F,0x40,0x40,0x00,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x08,0x08,0x08 ,0x08,0x08,0x08,0x08,0x00,0x00,0x20,0x40,0x44,0x44,0x3B,0x00,0x00,0x00,0x3F,0x40 ,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x40 ,0x7F,0x40,0x40,0x00,0x00,0x00,0x27,0x44,0x44,0x44,0x38,0x00,0x00,0x00,0x00,0x00 ,0x21,0x00,0x00,0x00,0x00,0x60,0x50,0x48,0x44,0x43,0x00,0x00,0x00,0x27,0x44,0x44 ,0x44,0x38,0x00,0x00,};void Delay(unsigned int time){unsigned char j;while(time--){for(j=0;j<=50;j++){}}}/******************************************************/ void Display(unsigned char sda,unsigned char sda1){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<66;j++){Datawrite(sda);Datawrite(sda1);}k++;}}/*****************************************************/void Hanzi_Disp(void){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<128;j++){Datawrite(Hanzi[i*128+j]);}k++;}Delay(5000);}void Hanzi_Disp1(void){unsigned char i,j,k=0;Comwrite(0x40);for(i=0;i<8;i++){Comwrite(Page+k);Comwrite(0x10);Comwrite(0x00);for(j=0;j<128;j++){Datawrite(Hanzi1[i*128+j]);}k++;}Delay(5000);}//######################################################### void Intial(void){Delay(100);Comwrite(0xe3);Comwrite(0xA2);Comwrite(0xA0); //A0为正显示,A1为镜像显示Comwrite(0xc9);Comwrite(0x2c);Comwrite(0x2e);Comwrite(0x2F);Comwrite(0xf8);Comwrite(0x00);Comwrite(0x81);Comwrite(0x10);Comwrite(0x25);Comwrite(0xAF);Comwrite(0x40);Delay(20);}/********************************************************** /int main(){/*PINSEL0=0x00000000; IO0DIR=SPIIOCON;RES=0;Delay(20);RES=1;Delay(20);while(1){Intial();Delay(20);Display(0xFF,0xFF);Delay(1000);Display(0x00,0x00);Delay(1000);Display(0xFF,0x00);Delay(1000);Display(0x00,0xff);Delay(1000);Display(0x55,0xAA);Delay(1000);Display(0xAA,0x55);Delay(1000);Hanzi_Disp(); Delay(1000);Hanzi_Disp1();Delay(1000);}}//###############################################// void Comwrite(char com){unsigned char data i;transdata=com;CS1=0;R_S=0;SCK=1;for(i=0;i<8;i++){SDA=transbit;SCK=0;SCK=1;transdata=transdata<<1;}CS1=1;R_S=0;}//######################################################### ##//void Datawrite(char dat){unsigned char data i;transdata=dat;CS1=0;R_S=1;SCK=1;for(i=0;i<8;i++){SDA=transbit;SCK=0;SCK=1;transdata=transdata<<1;}CS1=1;R_S=0;}以上是鑫洪泰的小编为你带来的12864液晶屏驱动程序编写示例,如果你想有更进一步的了解,请您关注我们微信,或者点击我们官网了解我们,也可以在线咨询或者拨打我们的热线电话与我们联系!我们会有专业的工作人员为你实时解答。
LCD12864液晶驱动编程指南
二、显示图片
显示图片和显示汉字的原理是一样的, 只不过是大小的问题! 现在我们就以一张 128*64 分辨率的图片进行取模。 取模图片:
现在我们主要看一下显isplay_BMP(uchar a[][64])//显示图形的左边部分 { uchar i,j; for(j=0;j<8;j++) { SelectScreen(1); Set_page(j); Set_column(0); for(i=0;i<64;i++) //显示左屏 { write_LCD_data(a[2*j][i]);//每隔一行取一次数组中的数据 } SelectScreen(2); Set_page(j); Set_column(0); for(i=0;i<64;i++) //显示右屏 { write_LCD_data(a[2*j+1][i]);//每隔一行取一次数组中的数据 } } } 取出图片的数据是二维数组形式!注意,液晶是先显示左半屏,再显示右半屏, 但 是取数组中的元素是逐个往下取出的, 所以是对于一个半屏而言, 每隔一行取数组中的元素, 而隔去的那一行是另一个半屏要取的数据!这一点一定要注意。 还有一点要补充的就是,这个取模软件只能识别 BMP 和 ICO 格式的单色图片,如果我 们选择的图片不是 128*64 大小的话, 可以通过软件将其改成 128*64 大小的, 如果我们直接 用软件取模的话,显示的会是乱码,解决办法是我们可以通过 windows 自带的画图工具, 什么也不做修改,将大小设置好的图片另存为 BMP 单色文件就行了,然后再用取模软件取 模就 OK 了,=^_^ = !算了,给大家截个图
LCD_databusrite_LCD_command(column);//列位置 } void SetOnOff(uchar onoff) //显示开关 函数:0x3E 是关显示,0x3F 是开显示 { onoff=0x3e|onoff; //0011 111x,onoff 只能为 0 或者 1 write_LCD_command(onoff); } void SelectScreen(uchar screen) //选屏 { switch(screen) { case 0: CS1=0;CS2=0;break; //全屏 case 1: CS1=0;CS2=1;break;//左半屏 case 2: CS1=1;CS2=0;break;//右半屏 default:break; } } void ClearScreen(uchar screen) { uchar i,j; SelectScreen(screen); for(i=0;i<8;i++)//控制页数 0-7,共 8 页 { Set_page(i); Set_column(0); for(j=0;j<64;j++) //控制列数 0-63,共 64 列 { write_LCD_data(0x00); //写入 0,地址指针自加 1 } } } void InitLCD() { Read_busy(); SelectScreen(0); SetOnOff(0); //关显示 SelectScreen(0); SetOnOff(1); //开显示 SelectScreen(0); //LCD 的初始化 } void main() { InitLCD(); ClearScreen(0); Set_line(0); Display(1,0,2*16,huan);//欢 Display(1,0,3*16,ying);//迎 Display(2,0,0*16,fang);//访 Display(2,0,1*16,wen);//问 Display(1,2,0*16,da);//大 Display(1,2,1*16,hai);//海 Display(1,2,2*16,xiang);//橡 Display(1,2,3*16,shu);//树 Display(2,2,0*16,bai);//百 Display(2,2,1*16,du);//度 Display(2,2,2*16,kong);//空 Display(2,2,3*16,jian);//间 While(1); } //初始化 //清屏 //显示开始行 } //清屏 据输出 { write_LCD_data(p[i+16]); //汉字的下半部分 上半部分 } Set_page(page+1); //写下半页 Set_column(column); for(i=0;i<16;i++) //控制列 //控制 16 列的数 } void Display(uchar ss,uchar page,uchar column,uchar *p) { uchar i; SelectScreen(ss); Set_page(page); for(i=0;i<16;i++) 的数据输出 { write_LCD_data(p[i]); //汉字的 //写上半页 //控制 16 列 Set_column(column); //控制列 //显示汉字 ClearScreen(0);//清屏 Set_line(0); //开始行:0
LCD12864菜单程序
一起来学LCD12864菜单程序(包含完整程序)一起来学LCD12864菜单程序(包含完整程序)/*-------------------------------------------项目名:家电中央控制系统工程程序名:显示MCU总体程序编写人:杜洋初写时间:2005年9月5日晚20时程序功能:实现液晶、语音部分的人机对话和总线的通信实现方法:用中断实现总线接收CPU说明:89S5212MHZ晶振接口说明:(详见初定义)信息说明:修改日志:NO.1--------------------------------------------*/;----------------------------------------初定义LCDDAT EQU P2RS EQU P3.5RW EQU P3.6E EQU P3.7REDLED EQU P3.4BACKLED EQU P3.1PLAY EQU P1.7STOPIN EQU P3.0LIN EQU P3.2SPDAT EQU P1XX2 EQU P0.0LT_RAM EQU 30HLR_RAM EQU 40HSP_RAM EQU 20HDIS1_RAM EQU 50HDIS2_RAM EQU 70HDIS3_RAM EQU 60HDIS4_RAM EQU 80HRR1 EQU 26HRR3 EQU 21HRR4 EQU 22HT0_RAM EQU 23HQR3_RAM EQU 24HQR2_RAM EQU 25HLCDDISPLAY EQU 26H ;菜单显示移位寄存器MENU_RAM EQU 27H;菜单位置寄存器ONOFFLCD EQU 28H;-------------------------------------程序入口ORG 0000HJMP LCD_STARTORG 0003HJMP LIN_INT0ORG 000BHJMP LED_T0ORG 0030H;--------------------------------------主程序开始LCD_START br>SETB PLAYMOV T0_RAM,#250MOV TMOD,#01HSETB ET0MOV TL0,#0B0H ;50MS 定时初值(T0计时用)MOV TH0,#3CH ;50MS定时初值CLR IT0SETB EX0SETB TR0SETB EAMOV DPTR,#TAB_0CALL START_LCD;-----自检程序CALL DL1SMOV MENU_RAM,#00HMOV DPTR,#TAB_HCALL START_LCDCLR LCDDISPLAY;--------------------------------------主循环体程序LCD_LOOP br>JB ONOFFLCD,DISPLAY_PROLCD_LOOP_1br>JMP LCD_LOOP;---------------------------- 菜单显示处理DISPLAY_PRO br>MOV A,MENU_RAMMOV DPTR,#MENUTAB_HOSTRLC AJMP @A+DPTRMENUNEXT br>CALL START_LCDCLR LCDDISPLAYCLR ONOFFLCDJMP LCD_LOOP;-------------------------MENUTAB_HOST:JMP HOST_H ;主菜单JMP HOST_1 ; 1,控制JMP HOST_2 ; 2,设置JMP HOST_3 ; 3,智能JMP HOST_4 ; 4,帮助<。
LCD12864驱动程序(STM32F103RCT6)
CS_LOW; RS_DATA; for(i=0;i<8;i++) {
SCLK_LOW; if(data&0x80) {
SDA_HI; } else {
SDA_LOW; } SCLK_HI; data <<= 1; } } /************************************************************************ 函 数 名:void JLX12864_Init(void) 功 能:12864 初始化 入口参数:无 返 回 值:无 说 明: 作 者:Joe 日 期:2015/1/13 16:33:38 修 改:XX 修改说明:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
************************************************************************/ void JLX12864_Init(void) {
GPIO_Init(GPIOB, GPIO_Pin_1, GPIO_Mode_Out_PP_High_Fast); GPIO_Init(GPIOB, GPIO_Pin_2, GPIO_Mode_Out_PP_High_Fast); GPIO_Init(GPIOB, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast); GPIO_Init(GPIOB, GPIO_Pin_5, GPIO_Mode_Out_PP_High_Fast); GPIO_Init(GPIOB, GPIO_Pin_6, GPIO_Mode_Out_PP_High_Fast);
/************************************************************************ 函 数 名:JLX12864_ClearScreen(void) 功 能:清屏 入口参数:无 返 回 值:无 说 明: 作 者:Joe 日 期:2015/1/13 16:33:38 修 改:XX 修改说明:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ************************************************************************/ void JLX12864_ClearScreen(void) {
LCD12864 并口液晶驱动
#include "LCD12864.h"/*原程序参考于网络,原作者不明,liangjin2807修改适用于MSP430单片机,驱动MGLS12864液晶屏,HD61202芯片*/typedef unsigned char uchar;typedef unsigned int uint;uchardigital[21][16]={{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x0F,0x1F,0x30,0x20,0x30,0x1F, 0x0F},/*"0",0*/{0x00,0x10,0x10,0xF8,0xF8,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x00},/*"1",1*/ {0x00,0x70,0x78,0x08,0x08,0x88,0xF8,0x70,0x00,0x30,0x38,0x2C,0x26,0x23,0x31,0x30},/*"2",2* /{0x00,0x30,0x38,0x88,0x88,0xC8,0x78,0x30,0x00,0x18,0x38,0x20,0x20,0x31,0x1F,0x0E},/*"3",3* /{0x00,0x00,0xC0,0xE0,0x30,0xF8,0xF8,0x00,0x00,0x07,0x07,0x24,0x24,0x3F,0x3F,0x24},/*"4",4*/ {0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x08,0x00,0x19,0x39,0x21,0x20,0x31,0x1F,0x0E},/*"5",5*/ {0x00,0xE0,0xF0,0x98,0x88,0x98,0x18,0x00,0x00,0x0F,0x1F,0x31,0x20,0x31,0x1F,0x0E},/*"6",6*/ {0x00,0x38,0x38,0x08,0xC8,0xF8,0x38,0x08,0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00},/*"7",7*/ {0x00,0x70,0xF8,0x88,0x08,0x88,0xF8,0x70,0x00,0x1C,0x3E,0x23,0x21,0x23,0x3E,0x1C},/*"8",8* /{0x00,0xE0,0xF0,0x18,0x08,0x18,0xF0,0xE0,0x00,0x00,0x31,0x33,0x22,0x33,0x1F,0x0F},/*"9",9*/ {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",0* /{0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",1*/ {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",2* /{0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",3*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",4*/ {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",5*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",6*/ {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",7*/ {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",8* /{0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",9*/ {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01},/*"-",10 */};/*"*",12*//**************宏定义***************/#define DataDir P2DIR#define DataPort P2OUT#define Busy 0x80#define CtrlDir P6DIR#define CLR_RS P6OUT&=~BIT3; //RS = P6.3#define SET_RS P6OUT|=BIT3;#define CLR_RW P6OUT&=~BIT4; //RW = P6.4#define SET_RW P6OUT|=BIT4;#define CLR_EN P6OUT&=~BIT5; //EN = P6.5#define SET_EN P6OUT|=BIT5;#define CLR_CS1 P6OUT&=~BIT0; //RW = 6.0#define SET_CS1 P6OUT|=BIT0;#define CLR_CS2 P6OUT&=~BIT1; //EN = 6.1#define SET_CS2 P6OUT|=BIT1;/***********************************************函数名称:DispStr功能:让液晶从某个位置起连续显示一个字符串参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/void DispStr(uchar x,uchar y,uchar *ptr){uchar *temp;uchar i;temp = ptr;//计算字符串有效字符的个数LocateXY( x, y );for (i=0;i<64;i++) //连续显示4个16*16字符{LcdWriteData( temp[i] );}}/***********************************************函数名称:DispDigital功能:让液晶从某个位置显示一个数字,上列数组寻址方式,不建议使用参数:x--位置的列坐标y--位置的行坐标返回值:无***********************************************/void DispDigetal(uchar x,uchar y,uchar n){uchar i;uchar x_1;if(x<64){LcdChoiceL();LocateXY( x, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}else{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );for (i=0;i<8;i++)LcdWriteData( digital[n][i] );LocateXY( x_1, y+1 );for (i=8;i<16;i++)LcdWriteData( digital[n][i] );}}/*********************************************** 函数名称:DispHex功能:让液晶从某个位置显示四个十六进数字参数:x--位置的列坐标y--位置的行坐标ptr--指向字符串存放位置的指针返回值:无***********************************************/ void DispHex(uchar x,uchar y,uint temp){uchar n;n=temp/0x1000;DispDigetal(x,y,n);n=(temp/0x100)%0x10;DispDigetal(x+8,y,n);n=(temp/0x10)%0x10;DispDigetal(x+16,y,n);n=temp%0x10;DispDigetal(x+24,y,n);}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/ void LocateXY(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xb8;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/*******************************************函数名称:DispNChar功能:在某个位置显示一个字符12864参数:x--位置的列坐标y--位置的行坐标n--显示的字个数data--显示的字符数据返回值:无********************************************/void DispNChar(uchar x,uchar y,uchar n,uchar (*ptr)[64]) { uchar i;uchar x_1;for(i=0;i<(16*n);i++)//输入总共的字符数{if(x<64){LcdChoiceL();//指定左屏LocateXY( x, y );//定位地址LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {if(x<128)//如果64<X<128,则选择右屏{x_1=x-64;LcdChoiceR();LocateXY( x_1, y );LcdWriteData( *(*ptr+i) );LocateXY( x_1, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else {x=0;y+=2;if(y<8){LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}else{y=0;LcdChoiceL();LocateXY( x, y );LcdWriteData( *(*ptr+i) );LocateXY( x, y+1 );LcdWriteData( *(*(ptr+1)+i) );}}}x++;}}/******************************************* 函数名称:LcdChoiceL功能:对12864液晶模块左侧参数:无返回值:无********************************************/ void LcdChoiceL(void){SET_CS2;//片选命令,选择左侧CLR_CS1;}/*******************************************函数名称:LcdChoiceR功能:对12864液晶模块右侧参数:无返回值:无********************************************/void LcdChoiceR(void){SET_CS1;//片选命令,选择右侧CLR_CS2;}/*******************************************函数名称:LcdStop功能:对12864液晶模块禁止参数:无返回值:无********************************************/void LcdStop(void){SET_CS1;//片选命令,禁止SET_CS2;}/*******************************************函数名称:LcdReset功能:对12864液晶模块进行复位操作参数:无返回值:无********************************************/void LcdReset(void){CtrlDir |= 0x3B; //控制线端口设为输出状态DataDir = 0xFF; //数据端口设为输出状态LcdChoiceL();//选择右侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(0x3f, 1); //设置显示屏数据开LcdWriteCommand(0xc0, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列//显示模式设置}/*******************************************函数名称:LcdLine功能:改变lCD显示的第一行,从而实现滚屏效果参数:Line 取值0-63之间,增大向上滚,减小向下滚返回值:无********************************************/void LcdLine(uchar Line){if(Line<64){Line=Line+0xc0;LcdChoiceL();//选择右侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列/*_NOP();_NOP();_NOP();*/Delay5ms();LcdChoiceR();//选择左侧LcdWriteCommand(Line, 1);//设置显示屏0行为第一行//LcdWriteCommand(0x40, 1);//设置显示屏0列为第一列}//显示模式设置}/*******************************************函数名称:LcdClear功能:对12864液晶模块屏幕清屏参数:无返回值:无********************************************/void LcdClear(void){ uchar k;uchar n;for(k=0;k<8;k++){for(n=0;n<64;n++){ LcdChoiceL();//选择左侧LocateXY( n,k );LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( n,k );LcdWriteData(0x00);}}}/*******************************************函数名称:LcdWriteCommand功能:向液晶模块写入命令12864参数:cmd--命令,chk--是否判忙的标志,1:判忙,0:不判返回值:无********************************************/void LcdWriteCommand(uchar cmd,uchar chk){if (chk) WaitForEnable(); // 检测忙信号?CLR_RS;CLR_RW;_NOP();DataPort = cmd; //将命令字写入数据端口_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;}/*******************************************函数名称:LcdWriteData功能:向液晶显示的当前地址写入显示数据参数:data--显示字符数据返回值:无********************************************/void LcdWriteData( uchar data ){WaitForEnable(); //等待液晶不忙SET_RS;CLR_RW;_NOP();_NOP();_NOP();_NOP();DataPort = data; //将显示数据写入数据端口_NOP();_NOP();_NOP();_NOP();SET_EN; //产生使能脉冲信号_NOP();_NOP();CLR_EN;DataPort =0xff;}/*******************************************函数名称:WaitForEnable功能:等待12864液晶完成内部操作参数:无返回值:无********************************************/ void WaitForEnable(void){P2DIR &= 0x00; //将P2口切换为输入状态SET_RW;CLR_RS;_NOP();SET_EN;_NOP();_NOP();while((P2IN & Busy)!=0); //检测忙标志CLR_EN;P2DIR |= 0xFF; //将P2口切换为输出状态}/*******************************************函数名称:Delay5ms功能:延时约5ms参数:无返回值:无********************************************/void Delay5ms(void){uint i=40000;while (i != 0){i--;}}/************************************************************函数名:LCD_Write_16X16Font*功能:写一个16X16的汉字*参数:x , y , c[2] x:0-83 y:0-5*返回值:无*备注:***********************************************************/void LCD_Write_16X16Font(unsigned char x,unsigned char y,unsigned char c[2]) {unsigned char i,k;if(x<64){LcdChoiceL();LocateXY(x,y);}else{LcdChoiceL();x=x-64;LocateXY(x,y);}for(k=0; k<70; k++) //K的值表示汉字库最多存放的字的数量(可改大){if((font16X16[k].Index[0]==c[0])&&(font16X16[k].Index[1]==c[1])){for(i=0; i<32; i++){LcdWriteData(font16X16[k].Msk[i]);if(i==16){y++;LocateXY(x,y);}}}}}/************************************************************函数名:DisplarString*功能:写一行的中文字符*参数:*返回值:无*备注:***********************************************************/void DisplarString(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/*******************************************函数名称:LocateXY功能:向液晶输入显示字符位置的坐标信息,按照像素点定位行参数:x--位置的列坐标y--位置的行坐标返回值:无********************************************/void LocateXY_1(uchar x,uchar y){uchar tempx;uchar tempy;tempx=x|0x40;tempy=y|0xC0;LcdWriteCommand(tempx,1);LcdWriteCommand(tempy,1);}/************************************************************函数名:DisplarString2*功能:写指定个数的汉字,按照像素点定位行*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarString2(unsigned char x,unsigned char y,unsigned char n,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;for(a=0;a<n*2;a+=2) //计数列,每列7个字符{for(b=0;b<70;b++) //50个字符内搜索需要显示的字符{if((font16X16[b].Index[0]==MemuTemp[a])&&(font16X16[b].Index[1]==MemuTemp[a+1])) //找到需要显示的字符,显示{if((a*8+x)<64){LcdChoiceL();x_1=a*8+x;y_1=y;}else{ if((a*8+x)<128){LcdChoiceR();x_1=a*8+x-64;y_1=y;}else{LcdChoiceL();x_1=a*8+x-128;y_1=y+2;}}LocateXY_1(x_1,y_1);for(i=0; i<32; i++){if(i==16) //如果已经传送16个字节,换行传送字符下半部分{LocateXY_1(x_1,y_1+1);}LcdWriteData(font16X16[b].Msk[i]);}break;}}}}/************************************************************函数名:DisplarFont8x16_2*功能:写一行的指定个数的字母*参数:x列数,y行数,n显示汉字个数,MemuTemp汉字字符串*返回值:无*备注:***********************************************************/void DisplarFont8x16_2(unsigned char x,unsigned char y,unsigned char d,unsigned char *MemuTemp){uchar a,b,i,x_1,y_1;uchar n;n=d*8;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16*功能:写一行的字母*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16(unsigned char x,unsigned char y,unsigned char *MemuTemp) {uchar a,b,i,x_1,y_1;uchar n=0;while(MemuTemp[n]!='\0')n++;for(a=0;a<n;a++) //计数列,每列7个字符{if((a*8+x)<64) //判断是否在左侧屏幕{LcdChoiceL(); //选择左侧x_1=a*8+x; //定位坐标y_1=y;}else{ if((a*8+x)<128) //在右侧屏幕{LcdChoiceR();x_1=a*8+x-64;y_1=y;}else //超出右侧屏幕{if(a*8+x-128<64){LcdChoiceL(); //选择左侧屏幕x_1=a*8+x-128;y_1=y+2; //行下移一行}else{if(a*8+x-192<64){LcdChoiceR(); //选择右侧侧屏幕x_1=a*8+x-192;y_1=y+2; //行下移一行}}}}LocateXY(x_1,y_1);for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分{LocateXY(x_1,y_1+1);}LcdWriteData(font8x16[b][i]);}break;}}}}/************************************************************函数名:DisplarFont8x16Left*功能:写左侧一行的字母,y参数为1-4之间数字,字符组MemuTemp包含8个字符*参数:*返回值:无*备注:***********************************************************/void DisplarFont8x16Left(unsigned char y,unsigned char *MemuTemp){uchar a,b,i,x;y=2*y-2;uchar n=0;LcdChoiceL(); // 清除所选择行数据开始LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00); // 清除所选择行数据结束for(a=0;a<8;a++) //计数每行字节,每行7个字符{for(b=0;b<94;b++) //50个字符内搜索需要显示的字符{if(font8x16[b][0]==MemuTemp[a]) //找到需要显示的字符,显示{x=a*8; //计算LocateXY(x,y); //开始定位y 行0位上半部分for(i=1; i<17; i++){if(i==9) //如果已经传送16个字节,换行传送字符下半部分LocateXY(x,y+1); ////开始定位y 行0位下半部分LcdWriteData(font8x16[b][i]);}break;}}}}/*******************************************函数名称:LcdChoiceLine功能:对12864液晶指定行进行清除参数:无返回值:无********************************************/void LcdClearLine(uchar y){uchar n;LcdChoiceL();//选择左侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);LcdChoiceR();//选择右侧LocateXY( 0,y);for(n=0;n<64;n++)LcdWriteData(0x00);LocateXY( 0,y+1);for(n=0;n<64;n++)LcdWriteData(0x00);}typedef struct{unsigned char Index[2];unsigned char Msk[32];}TYPE_FONT16X16;const TYPE_FONT16X16 font16X16[]={"宁",0x20,0x18,0x88,0x88,0x88,0x88,0x89,0x8E,0x88,0x88,0x88,0x88,0x88,0x28,0x18,0x00, 0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,"波",0x10,0x60,0x02,0x0C,0xC0,0x00,0xF8,0x88,0x88,0x88,0xFF,0x88,0x88,0xA8,0x18,0x00, 0x04,0x04,0x7C,0x03,0x80,0x60,0x1F,0x80,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00,"钢",0x20,0x10,0x2C,0xE7,0x24,0x24,0x00,0xFE,0x12,0x62,0x82,0x72,0x02,0xFE,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x00,0xFF,0x08,0x06,0x01,0x4E,0x80,0x7F,0x00,0x00,"铁",0x20,0x10,0x2C,0xE7,0x24,0x24,0x40,0x3C,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00, 0x01,0x01,0x01,0x7F,0x21,0x11,0x80,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"有",0x04,0x04,0x04,0x84,0xE4,0x3C,0x27,0x24,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00, 0x04,0x02,0x01,0x00,0xFF,0x09,0x09,0x09,0x09,0x49,0x89,0x7F,0x00,0x00,0x00,0x00,"限",0x00,0xFE,0x22,0x5A,0x86,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00, 0x00,0xFF,0x04,0x08,0x07,0x00,0xFF,0x40,0x20,0x03,0x0C,0x14,0x22,0x41,0x40,0x00,"公",0x00,0x80,0x40,0x20,0x18,0x06,0x80,0x00,0x07,0x18,0x20,0x40,0x80,0x00,0x00,0x00, 0x01,0x00,0x20,0x70,0x28,0x26,0x21,0x20,0x20,0x24,0x38,0x60,0x00,0x01,0x01,0x00,"司",0x00,0x10,0x12,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x12,0x02,0xFE,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0x10,0x10,0x10,0x10,0x3F,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,"能",0x08,0xCC,0x4A,0x49,0x48,0x4A,0xCC,0x18,0x00,0x7F,0x88,0x88,0x84,0x82,0xE0,0x00, 0x00,0xFF,0x12,0x12,0x52,0x92,0x7F,0x00,0x00,0x7E,0x88,0x88,0x84,0x82,0xE0,0x00,"环",0x04,0x84,0x84,0xFC,0x84,0x84,0x00,0x04,0x04,0x84,0xE4,0x1C,0x84,0x04,0x04,0x00, 0x20,0x60,0x20,0x1F,0x10,0x10,0x04,0x02,0x01,0x00,0xFF,0x00,0x00,0x01,0x06,0x00,"部",0x40,0x44,0x54,0x65,0x46,0x44,0x64,0x54,0x44,0x40,0xFE,0x02,0x22,0xDA,0x06,0x00, 0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0xFF,0x08,0x10,0x08,0x07,0x00,"煤",0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0xFF,0x24,0x24,0x24,0xFF,0x04,0x04,0x00,0x80,0x60,0x18,0x07,0x08,0x30,0x44,0x24,0x15,0x0D,0xFF,0x0D,0x15,0x24,0x44,0x00,"气",0x20,0x10,0x4C,0x47,0x54,0x54,0x54,0x54,0x54,0x54,0x54,0xD4,0x04,0x04,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x30,0x40,0xF0,0x00,"排",0x10,0x10,0x10,0xFF,0x90,0x08,0x88,0x88,0xFF,0x00,0x00,0xFF,0x88,0x88,0x08,0x00,0x02,0x42,0x81,0x7F,0x00,0x08,0x08,0x08,0xFF,0x00,0x00,0xFF,0x08,0x08,0x08,0x00,"水",0x00,0x20,0x20,0x20,0xA0,0x60,0x00,0xFF,0x60,0x80,0x40,0x20,0x18,0x00,0x00,0x00, 0x20,0x10,0x08,0x06,0x01,0x40,0x80,0x7F,0x00,0x01,0x02,0x04,0x08,0x10,0x10,0x00,"器",0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00, 0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00,"报",0x10,0x10,0x10,0xFF,0x10,0x90,0x00,0xFE,0x82,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x04,0x44,0x82,0x7F,0x01,0x00,0x00,0xFF,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00,"警",0x12,0xEA,0xAF,0xAA,0xEA,0x0F,0xFA,0x02,0x88,0x8C,0x57,0x24,0x54,0x8C,0x84,0x00, 0x02,0x02,0xEA,0xAA,0xAA,0xAB,0xAA,0xAB,0xAA,0xAA,0xAA,0xAA,0xEA,0x02,0x02,0x00,"CO",0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00C, 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,"信",0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00, 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,"号",0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00,"正",0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00, 0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,"常",0x20,0x18,0x08,0xEA,0xAC,0xA8,0xA8,0xAF,0xA8,0xA8,0xAC,0xEA,0x08,0x28,0x18,0x00, 0x00,0x00,0x3E,0x02,0x02,0x02,0x02,0xFF,0x02,0x02,0x12,0x22,0x1E,0x00,0x00,0x00,"在",0x08,0x08,0x88,0xC8,0x38,0x0C,0x0B,0x08,0x08,0xE8,0x08,0x08,0x08,0x08,0x08,0x00,0x02,0x01,0x00,0xFF,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x00,"发",0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00, 0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00,"送",0x40,0x40,0x42,0xCC,0x00,0x88,0x89,0x8E,0x88,0xF8,0x88,0x8C,0x8B,0x88,0x80,0x00, 0x00,0x40,0x20,0x1F,0x20,0x40,0x50,0x48,0x46,0x41,0x42,0x44,0x58,0x40,0x40,0x00,"短",0x90,0x88,0x87,0xFC,0x84,0x84,0x80,0x02,0xF2,0x12,0x12,0x12,0x12,0xF2,0x02,0x00, 0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x40,0x45,0x59,0x41,0x41,0x51,0x4D,0x40,0x00,"成",0x00,0x00,0xF8,0x48,0x48,0x48,0xC8,0x08,0xFF,0x08,0x09,0x0A,0xC8,0x88,0x08,0x00, 0x40,0x30,0x0F,0x00,0x08,0x50,0x4F,0x20,0x10,0x0B,0x0C,0x12,0x21,0x40,0xF0,0x00,"功",0x00,0x04,0x04,0x04,0xFC,0x04,0x14,0x14,0x10,0x90,0x7F,0x10,0x10,0xF0,0x00,0x00, 0x04,0x0C,0x04,0x04,0x03,0x42,0x22,0x11,0x0C,0x23,0x20,0x60,0x20,0x1F,0x00,0x00," ",0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,"手",0x00,0x24,0x24,0x24,0x24,0x24,0x24,0xFE,0x22,0x22,0x22,0x22,0x22,0x20,0x00,0x00, 0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x00,"机",0x08,0x08,0xC8,0xFF,0x48,0x88,0x08,0x00,0xFE,0x02,0x02,0x02,0xFE,0x00,0x00,0x00, 0x04,0x03,0x00,0xFF,0x00,0x41,0x30,0x0C,0x03,0x00,0x00,0x00,0x3F,0x40,0x78,0x00,"卡",0x00,0x40,0x40,0x40,0x40,0x40,0x40,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x40,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x02,0x04,0x0C,0x38,0x10,0x00,0x00,"错",0x40,0x30,0x2C,0xE7,0x24,0x24,0x40,0x48,0x7F,0x48,0x48,0x7F,0x48,0x48,0x40,0x00, 0x01,0x01,0x01,0xFF,0x41,0x21,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,"误",0x40,0x41,0xCE,0x04,0x00,0x40,0x5F,0x51,0x51,0xD1,0x51,0x51,0x5F,0x40,0x00,0x00, 0x00,0x00,0x3F,0x10,0x88,0x42,0x22,0x12,0x0A,0x07,0x0A,0x12,0x22,0xE2,0x42,0x00,/*********************************************/"强",0x02,0xE2,0x22,0x22,0x3E,0x00,0x80,0x9E,0x92,0x92,0xF2,0x92,0x92,0x9E,0x80,0x00, 0x00,0x43,0x82,0x42,0x3E,0x40,0x47,0x44,0x44,0x44,0x7F,0x44,0x44,0x54,0xE7,0x00,"度",0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00, 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,"中",0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00,"国",0x00,0xFE,0x02,0x12,0x92,0x92,0x92,0xF2,0x92,0x92,0x92,0x12,0x02,0xFE,0x00,0x00, 0x00,0xFF,0x40,0x48,0x48,0x48,0x48,0x4F,0x48,0x4A,0x4C,0x48,0x40,0xFF,0x00,0x00,"移",0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x10,0x08,0x94,0x67,0x24,0x94,0x0C,0x00,0x00, 0x08,0x06,0x01,0xFF,0x01,0x06,0x00,0x89,0x89,0x44,0x4A,0x33,0x12,0x0A,0x06,0x00,"动",0x40,0x44,0xC4,0x44,0x44,0x44,0x40,0x10,0x10,0xFF,0x10,0x10,0x10,0xF0,0x00,0x00, 0x10,0x3C,0x13,0x10,0x14,0xB8,0x40,0x30,0x0E,0x01,0x40,0x80,0x40,0x3F,0x00,0x00,"联",0x02,0xFE,0x92,0x92,0xFE,0x02,0x00,0x10,0x11,0x16,0xF0,0x14,0x13,0x10,0x00,0x00, 0x10,0x1F,0x08,0x08,0xFF,0x04,0x81,0x41,0x31,0x0D,0x03,0x0D,0x31,0x41,0x81,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"服",0x00,0x00,0xFE,0x22,0x22,0x22,0xFE,0x00,0xFE,0x82,0x82,0x92,0xA2,0x9E,0x00,0x00, 0x80,0x60,0x1F,0x02,0x42,0x82,0x7F,0x00,0xFF,0x40,0x2F,0x10,0x2C,0x43,0x80,0x00,"务",0x00,0x00,0x90,0x88,0x4C,0x57,0xA4,0x24,0x54,0x54,0x8C,0x84,0x00,0x00,0x00,0x00, 0x01,0x01,0x80,0x42,0x22,0x1A,0x07,0x02,0x42,0x82,0x42,0x3E,0x01,0x01,0x01,0x00,"串",0x00,0x00,0x3C,0x24,0x24,0x24,0x24,0xFF,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,0x00, 0x00,0x1F,0x09,0x09,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x09,0x09,0x1F,0x00,0x00,"口",0x00,0x00,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x00,0x00,0x00, 0x00,0x00,0x7F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7F,0x00,0x00,0x00,"通",0x40,0x42,0xCC,0x00,0x00,0xE2,0x22,0x2A,0x2A,0xF2,0x2A,0x26,0x22,0xE0,0x00,0x00, 0x80,0x40,0x3F,0x40,0x80,0xFF,0x89,0x89,0x89,0xBF,0x89,0xA9,0xC9,0xBF,0x80,0x00,"讯",0x40,0x40,0x42,0xCC,0x00,0x82,0x82,0xFE,0x82,0x82,0x02,0xFE,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFF,0x00,0x00,0x00,0x0F,0x30,0x40,0xF8,0x00,"异",0x00,0x00,0x7E,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x9E,0x80,0xE0,0x00,0x00, 0x08,0x88,0x48,0x28,0x1E,0x08,0x08,0x08,0x08,0x08,0xFE,0x08,0x08,0x08,0x08,0x00,"修",0x40,0x20,0xF8,0x07,0xF0,0xA0,0x90,0x4C,0x57,0x24,0xA4,0x54,0x4C,0x80,0x80,0x00, 0x00,0x00,0xFF,0x00,0x1F,0x80,0x92,0x52,0x49,0x29,0x24,0x12,0x08,0x00,0x00,0x00,//修0,"改",0x04,0x84,0x84,0x84,0x84,0xFC,0x40,0x30,0xCC,0x0B,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x7F,0x20,0x10,0x10,0x08,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//改1,"码",0x04,0x84,0xE4,0x5C,0x44,0xC4,0x00,0x02,0xF2,0x82,0x82,0x82,0xFE,0x80,0x80,0x00,0x02,0x01,0x7F,0x10,0x10,0x3F,0x00,0x08,0x08,0x08,0x08,0x48,0x88,0x40,0x3F,0x00,//码2,"电",0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00,//电3,"话",0x40,0x40,0x42,0xCC,0x00,0x00,0x20,0x24,0x24,0x24,0xFE,0x22,0x23,0x22,0x20,0x00,0x00,0x00,0x00,0x7F,0x20,0x10,0x00,0xFE,0x42,0x42,0x43,0x42,0x42,0xFE,0x00,0x00,//话4,"接",0x10,0x10,0x10,0xFF,0x10,0x50,0x44,0x54,0x65,0xC6,0x44,0x64,0x54,0x44,0x40,0x00,0x04,0x44,0x82,0x7F,0x01,0x82,0x82,0x4A,0x56,0x23,0x22,0x52,0x4E,0x82,0x02,0x00,//接5,"收",0x00,0xFC,0x00,0x00,0xFF,0x00,0x40,0x20,0xD8,0x17,0x10,0x10,0xF0,0x10,0x10,0x00,0x00,0x0F,0x04,0x02,0xFF,0x00,0x80,0x40,0x21,0x16,0x08,0x16,0x21,0x40,0x80,0x00,//收6,"息",0x00,0x00,0x00,0xFC,0x54,0x54,0x56,0x55,0x54,0x54,0x54,0xFC,0x00,0x00,0x00,0x00,0x40,0x30,0x00,0x03,0x39,0x41,0x41,0x45,0x59,0x41,0x41,0x73,0x00,0x08,0x30,0x00,//息7,"数",0x90,0x52,0x34,0x10,0xFF,0x10,0x34,0x52,0x80,0x70,0x8F,0x08,0x08,0xF8,0x08,0x00,0x82,0x9A,0x56,0x63,0x22,0x52,0x8E,0x00,0x80,0x40,0x33,0x0C,0x33,0x40,0x80,0x00,//数8,"量",0x20,0x20,0x20,0xBE,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0xBE,0x20,0x20,0x20,0x00, 0x00,0x80,0x80,0xAF,0xAA,0xAA,0xAA,0xFF,0xAA,0xAA,0xAA,0xAF,0x80,0x80,0x00,0x00,//量9,"存",0x04,0x04,0x84,0xE4,0x1C,0x07,0x24,0x24,0x24,0x24,0xA4,0x64,0x24,0x04,0x04,0x00,0x02,0x01,0x00,0xFF,0x00,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x00,//存10,"储",0x80,0x60,0xF8,0x87,0x84,0x98,0x00,0x20,0x24,0xA4,0x7F,0x24,0x34,0x28,0x24,0x00,0x00,0x00,0xFF,0x00,0x00,0x7F,0x24,0x12,0x01,0xFF,0x49,0x49,0x49,0xFF,0x00,0x00,//储11,"无",0x00,0x40,0x42,0x42,0x42,0xC2,0x7E,0x42,0xC2,0x42,0x42,0x42,0x40,0x40,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,0x00,};/************************************************************说明:该font.h 文件中包含的是5110显示所用的ASCII、部分汉字、及图片字模。
LCD12864液晶驱动程序
/ void LCD_12864_Write_Data(uchar dat) { LCD_12864_BUSY_WAIT(); LCD_12864_RS_1(); LCD_12864_RW_0(); LCD_12864_DATA=dat; LCD_12864_E_1(); LCD_12864_E_0(); } /****************************************************************************** * Function:void LCD_12864_Init(void) Description:液晶初始化 Calls:LCD_12864_Write_Command(); CallS By:Sytem_Init.c 中的 System_Init() Input: None Output:None Others: ******************************************************************************* / void LCD_12864_Init(void) { /*光标的移动方向*/ LCD_12864_Write_Command(0x06); /*开显示,关游标*/ LCD_12864_Write_Command(0x0C); /*开显示,开游标*/ //LCD_12864_Write_Command(0x0F); /*基本指令动作*/ LCD_12864_Write_Command(0x30); } /****************************************************************************** * Function:void LCD_12864_Clean_GDRAM(void) Description:清屏,GDRAM 填满 0 Calls:LCD_12864_Init(); LCD_12864_Write_Command(0x36); LCD_12864_Write_Data(0x00);
基于STM32--LCD12864驱动程序.doc
基于 STM32--LCD12864驱动程序STM32 LCD12864 驱动程序(头文件)(2012-05-29 21:25:08) 转载▼标签:杂谈#ifndef LCD12864_H#define LCD12864_H#define LCD_CONTROL GPIOD//默认LCD12864的控制口在 PD口#define LCD_DATAPORTGPIOD//默认LCD12864的数据口在 PD口#define LCD_RESET_PinGPIO_Pin_12 // 默认LCD12864的复位引脚连接到 PD.12 也可不用#define LCD_RS_Pin GPIO_Pin_13 // 默认LCD12864 RS -- PD.13#define LCD_RW_PinGPIO_Pin_14 // 默认LCD12864 RW -- PD.14#define LCD_EN_Pin GPIO_Pin_15 // 默认LCD12864 E -- PD.15#define LCD_CONTROL_CLOCKRCC_APB2Periph_GPIOD //默认 LCD12864的控制口时钟#define LCD_DATAPORT_CLOCKRCC_APB2Periph_GPIOD //默认 LCD12864的数据口时钟#define LCD_RS_1LCD_CONTROL->BSRR&=~LCD_RS_Pin;LCD_CONTROL->BSRR |=LCD_RS_Pin //RS 置高电平#define LCD_RS_0LCD_CONTROL->BRR&=~LCD_RS_Pin;LCD_CONTROL->BRR |=LCD_RS_Pin //RS 置低电平#define LCD_RW_1 LCD_CONTROL->BSRR &=~LCD_RW_Pin;LCD_CONTROL->BSRR|=LCD_RW_Pin //RW 置高电平#define LCD_RW_0 LCD_CONTROL->BRR &=~LCD_RW_Pin;LCD_CONTROL->BRR|=LCD_RW_Pin //RW 置低电平#define LCD_EN_1LCD_CONTROL->BSRR &=~LCD_EN_Pin;LCD_CONTROL->BSRR|=LCD_EN_Pin //EN 置高电平#define LCD_EN_0LCD_CONTROL->BRR&=~LCD_EN_Pin;LCD_CONTROL->BRR |=LCD_EN_Pin //EN 置低电平#define LCD_RESET_0 LCD_CONTROL->BRR= LCD_RESET_Pin // 复位#define LCD_RESET_1 LCD_CONTROL->BSRR= LCD_RESET_Pin // 复位脚拉高#define DATAOUT LCD_DATAPORT->ODR&=0xff00;LCD_DATAPORT->ODR // 数据输出寄存器#define DATAIN LCD_DATAPORT->IDR //数据输入寄存器#define LCD_BF((DATAIN)&0x0080)//忙状态void LCD_delayus(unsigned long n); //n(us)void LCD_delayms(unsigned long n); //n(ms)void LCD_WriteInitcmd(uint8_t initcmd); 延时延时//写初始化命令void LCD_WaitLaisure(void); //一直等待到 LCD内部操作完成,变为空闲状态void LCD_Writecmd(uint8_t cmd); //写命令到 LCD12864void LCD_WriteByte(uint8_t byte); //写一字节数据到 LCD12864void LCD_pos(uint16_t pos); //LCD显示位置设置col);// void 设定 LCD12864的显示地址,根据习惯LCD_DispChar(char ch); //显示一个字符voidrow,uint16_tLCD_Setpos_DispChar(uint16_t col,char ch);//在指定位置显示一个字符void LCD_DispString(char str[]); // 显示一个字符串,显示位置需提前设定//在指定位置显示一个字符串void LCD_Setpos_DispString(uint16_t row,uint16_t col,char str[]);void LCD_Dispnum(uint32_t num); //显示一个不超过 8 位的整数,显示位置需提前设置//在指定位置显示一个不超过 8 位的整数void LCD_Setpos_Dispnum(uint16_t row,uint16_t col,uint32_t num);void LCD_DispDecimal(uint32_t num,uint16_tdot);// 显示一个有效位不超过 8 位的浮点数 , 显示位置需要提前设定//在指定位置显示一个有效位不超过 8 位的浮点数void LCD_Setpos_DispDecimal(uint16_t row,uint16_t col,uint32_t num,uint16_t dot);//显示日历,显示日期与时间void LCD_DispDateTime(uint32_t year,uint16_t month,uint16_t day,uint16_t hour,uint16_tmin,uint16_t sec);void LCD_DispPicture(const unsigned char picture[]); //显示一幅图像128*64//屏幕整体左移一格,用于滚动显示void LCD_ShiftLeft(void);//屏幕整体右移一格,用于滚动显示void LCD_ShiftRight(void);//清屏,清除显示void LCD_Clear(void);//使光标还回原点位置void LCD_Return(void);//关显示void LCD_Close(void);//开显示void LCD_Open(void);void LCD_FlickerChar(uint16_t row,uint16_t col);//关闭字符闪烁void LCD_CloseFlicker(void);//屏幕秒闪烁一次void LCD_FlickerScreen(void);void LCD_PORT_Init(void);//LCD连接端口初始化void LCD_Init(void);//LCD配置初始化#endif#include "stm32f10x.h"#include "stm32f10x_gpio.h"#include "LCD12864.h"#include "picture.h"// 延时 n(us)void LCD_delayus(unsigned long n) {unsigned long j;while(n--){ j=8;while(j--);}}// 延时 n(ms)void LCD_delayms(unsigned long n) {while(n--)LCD_delayus(1100);}//写初始化命令void LCD_WriteInitcmd(uint8_t initcmd){LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= initcmd;LCD_delayus(600);LCD_EN_0;LCD_RW_1;}//一直等待到 LCD内部操作完成,变为空闲状态void LCD_WaitLaisure(void){uint16_t flag=0x00;LCD_RS_0;LCD_RW_1;do{LCD_EN_0;LCD_delayus(5);LCD_EN_1;LCD_delayus(5);flag=(uint16_t)LCD_BF;}while(flag);}// 写命令到 LCD12864void LCD_Writecmd(uint8_t cmd){LCD_WaitLaisure();LCD_RS_0;LCD_RW_0;LCD_EN_1;DATAOUT |= cmd;LCD_delayus(600); //经过测试,取600。
液晶显示屏LCD12864驱动解析
液晶显示器LCD12864驱动程序#include<msp430g2553.h>#include "lcd12864.h"#include "typedef.h"#define cyCS BIT0 //P2.0,片选信号#define cySID BIT1 //P2.1,串行数据#define cyCLK BIT2 //P2.2,同步时钟#define cyPORT P2OUT#define cyDDR P2DIRvoid Write_8bits(u8 W_bits){u8 i;cyDDR |= cyCLK + cySID; //设置输出方向for(i = 0; i < 8; i++){if(( W_bits << i )&0x80){cyPORT |= cySID;}else{cyPORT &= ~cySID;}delay_ms(1);cyPORT |= cyCLK;delay_ms(1);delay_ms(1);cyPORT &= ~cyCLK;}}void w_1byte(u8 RS, u8 w_data){u8 H_Data,L_Data;u8 tmp_Data = 0xf8;cyDDR |= cyCS; //设置CS口为输出if(RS == 0) tmp_Data &= ~0x02;else tmp_Data |= 0x02;H_Data = w_data; //高位数据H_Data &= 0xf0;L_Data = w_data; //低位数据L_Data &= 0x0f;L_Data <<= 4;cyPORT |= cyCS;Write_8bits(tmp_Data);Write_8bits(H_Data);Write_8bits(L_Data);cyPORT &= ~cyCS;}void init_Lcd(void){cyDDR |= cyCLK + cySID + cyCS; //相应的位端口设置为输出delay_ms(10); //延时等待液晶完成复位w_1byte(0,0x30);delay_ms(1);w_1byte(0,0x02);delay_ms(5);w_1byte(0,0x0c);delay_ms(1);w_1byte(0,0x01);delay_ms(5);w_1byte(0,0x06);delay_ms(1);}//清屏void clear_lcd(void){delay_ms(1);w_1byte(0,0x01);delay_ms(5);}void lcd_pos(u8 x,u8 y)//定位{u8 pos;switch(x){case 1:pos=0x80;break;case 2:pos=0x90;break;case 3:pos=0x88;break;case 4:pos=0x98;break;default:pos=0x80;}pos += y;w_1byte(0,pos);}//显示汉字void Disp_HZ(const u8 * pt,u8 num){u8 i;for(i = 0;i < num*2;i++){w_1byte(1,*(pt++));}}//显示字符void Disp_Ch(const u8 ch){w_1byte(1, ch);}//汉字和字符混合显示void disp_lcd_str(u8 x, u8 y, const u8 *str, u8 len) {u8 i;lcd_pos(x, y);for(i = 0;i < len && *str; ){if(*(str) >= 0x80){w_1byte(1,*(str++));w_1byte(1,*(str++));i++;i++;}else{w_1byte(1,*(str++));i++;}}}。
lcd12864的驱动
/*****************************************************************12864的驱动显示源文件=====LCD12864.c*****************************************************************/#include <reg52.h>#include <intrins.h>/*-------- 12864的接口设置 --------*/#define LCD_DATA_PORT P2sbit LCD_RS =P1^1;sbit LCD_RW = P1^2;sbit LCD_EN = P1^3;sbit LCD_PSB =P1^4;//===================================================================== ============////============================控制基础函数=========================================////===================================================================== ============///***********************************************函数名:LCD_wait入口参数:无功能:LCD12864读忙等待的操作***********************************************/void LCD_Wait(void){LCD_DATA_PORT=0xff;LCD_RS=0;LCD_RW=1;LCD_EN=1;_nop_();while( LCD_DA TA_PORT&0x80 );LCD_EN=0;}/***********************************************函数名:LCD_write_comm入口参数:content:内容功能:向LCD12864写命令***********************************************/void LCD_WriteCommand(unsigned char content){LCD_RS=0;LCD_RW=0;LCD_DATA_PORT=content;_nop_();LCD_EN=1;_nop_();LCD_EN=0;}/*********************************************** 函数名:LCD_WriteByte入口参数:content:内容功能:向LCD12864写数据***********************************************/ void LCD_WriteData(unsigned char content){LCD_Wait();LCD_RS=1;LCD_RW=0;LCD_DATA_PORT=content;_nop_();LCD_EN=1;_nop_();LCD_EN=0;}/*********************************************** 函数名:LCD_ReadData入口参数:无功能:从LCD12864读数据***********************************************/ unsigned char LCD_ReadData(void){unsigned char dat=0;LCD_Wait();LCD_DATA_PORT=0xff;LCD_RS=1;LCD_RW=1;LCD_EN=0;LCD_EN=1;_nop_();dat=LCD_DA TA_PORT;return dat;}//===================================================================== ============////=======================液晶的初始化设置==========================================////===================================================================== ============///***********************************************函数名:LCD_Init入口参数:无功能:LCD12864的初始化设置***********************************************/void LCD_Init(void){unsigned char i=0xff;LCD_PSB=1; //控制方式选择并口while(i--); //启动需要一定的延时LCD_WriteCommand ( 0x30 ); //中文模式LCD_WriteCommand ( 0x30 );LCD_WriteCommand ( 0x0c ); //显示设置LCD_WriteCommand ( 0x06 );LCD_WriteCommand ( 0x01 ); //清屏}//===================================================================== ============////==================文本模式下有关的驱动控制=======================================////===================================================================== ============///***********************************************函数名:LCD_Clear入口参数:无功能:LCD12864的清屏函数***********************************************/void LCD_Clear(void){LCD_WriteCommand(0x01);}/***********************************************函数名:LCD_Locate入口参数:y:行;x:列功能:定位光标***********************************************/void LCD_Locate(unsigned char y,unsigned char x){switch( y ){case 0 :LCD_WriteCommand ( 0x80+x );break;case 1 :LCD_WriteCommand ( 0x90+x );break;case 2 :LCD_WriteCommand ( 0x88+x );break;case 3 :LCD_WriteCommand ( 0x98+x );break;default :break;}}/***********************************************函数名:LCD_PutString入口参数:*ptr:数据指针;功能:显示字符串***********************************************/void LCD_PutString(unsigned char *ptr){while(*ptr != '\0'){LCD_WriteData(*ptr++);}}/***********************************************函数名:LCD_PutString_Add入口参数:*ptr:数据指针;功能:指定位置显示字符串***********************************************/void LCD_PutString_Add(unsigned char y,unsigned char x,unsigned char *ptr) {LCD_Locate(y,x);LCD_PutString(ptr);}/***********************************************函数名:LCD_ClearScreen入口参数:无功能:图形模式下的清屏函数***********************************************/void LCD_ClearScreen(void){unsigned char i;unsigned char j;LCD_WriteCommand( 0x34 );LCD_WriteCommand( 0x36 );for(j=0;j<64;j++){LCD_WriteCommand( 0x80+j ) ; //yLCD_WriteCommand( 0x80 ) ; //xfor(i=0;i<16;i++){LCD_WriteData( 0x00 ) ;LCD_WriteData( 0x00 ) ;}}LCD_WriteCommand( 0x30 ); //返回文本模式}/***********************************************函数名:LCD_DrawPixel入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawPixel(unsigned char x, unsigned char y, unsigned char Color) {unsigned char Row , Tier , Tier_bit ;unsigned char temp_h, temp_l ;if((x>127)||(y>63)) //超范围{return ;}LCD_WriteCommand( 0x34 ) ; //图形模式LCD_WriteCommand( 0x36 ) ; //开图形显示Tier = x>>4;Tier_bit = x&0x0f;if(y < 32){Row = y;}else{Row = y - 32 ;Tier += 8 ;}LCD_WriteCommand( Row + 0x80 ) ;LCD_WriteCommand( Tier + 0x80 ) ;LCD_ReadData() ; //假读temp_h = LCD_ReadData() ;temp_l = LCD_ReadData() ;LCD_WriteCommand( Row + 0x80 ) ;LCD_WriteCommand( Tier + 0x80 ) ;if( Tier_bit < 8 ){switch( Color){case 0 : temp_h &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;case 1 : temp_h |= ( 0x01 << ( 7 - Tier_bit )) ; break ;case 2 : temp_h ^= ( 0x01 << ( 7 - Tier_bit )) ; break ;default : break ;}}else{switch(Color){case 0 : temp_l &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;case 1 : temp_l |= ( 0x01 << ( 15 - Tier_bit )) ; break ;case 2 : temp_l ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;default : break ;}}LCD_WriteData( temp_h ) ;LCD_WriteData( temp_l ) ;LCD_WriteCommand( 0x30 ) ; //返回文本模式}/***********************************************函数名:LCD_DrawLine_X入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawLine_X(unsigned char y0, unsigned char x0, unsigned char x1, unsigned char fColor){unsigned char n;if(x0 > x1){n = x1;x1 = x0;x0 = n;}if(fColor==2){for(n=x0; n <= x1; n++){if(n%2==0){LCD_DrawPixel(n, y0, 0);}else{LCD_DrawPixel(n, y0, 1);}}}else{for(n=x0; n <= x1; n++){LCD_DrawPixel(n, y0, fColor);}}}/***********************************************函数名:LCD_DrawLine_Y入口参数:无功能:图形模式下的画点函数***********************************************/void LCD_DrawLine_Y(unsigned char x0, unsigned char y0, unsigned char y1, unsigned char fColor){unsigned char n;if(y0 > y1){n = y1;y1 = y0;y0 = n;}if(fColor==2){for(n=y0; n <= y1; n++){if(n%2==0){LCD_DrawPixel(x0, n, 1);}else{LCD_DrawPixel(x0, n, 0);}}}else{for(n=y0; n <= y1; n++){LCD_DrawPixel(x0, n, fColor);}}}/***********************************************函数名:LCD_DrawLine入口参数:无功能:图形模式下的画线函数***********************************************/void LCD_DrawLine(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char Color ){/*根据屏幕大小改变变量类型(如改为int 型)*/unsigned char t, distance;unsigned char x=0, y=0;char delta_x, delta_y ;char incx, incy;if((x0>127)||(x1>127)||(y0>63)||(y1>63)) //超出显示范围{return ;}delta_x = x1 - x0;delta_y = y1 - y0;//=================================//if(delta_x > 0){incx = 1;}else if(delta_x == 0){LCD_DrawLine_Y(x0, y0, y1, Color);return;}else{delta_x = -delta_x; //绝对值incx = -1 ;}//=================================//if(delta_y > 0){incy = 1;}else if(delta_y == 0){LCD_DrawLine_X(y0, x0, x1, Color);return;}else{delta_y = -delta_y; //绝对值incy = -1;}//=================================//if(delta_x > delta_y){distance = delta_x ;}else{distance = delta_y ;}//=================================///* Draw Line*/for(t=0; t <= distance+1; t++ ){LCD_DrawPixel(x0, y0, Color) ;x += delta_x ;y += delta_y ;if(x > distance){x -= distance ;x0 += incx ;}if(y > distance){y -= distance ;y0 += incy ;}}}/*************************** 结束*********************************/。
12864液晶屏驱动程序
BMPwith=*PicData;
PicData++;
BMPheight=(*PicData)/8;
PicData++;
//BMPLen=BMPheight/8*BMPwith
for(BMPheightLen=0;BMPheightLen<BMPheight;BMPheightLen++)
Series = Series << 1;
}
}
/***********************************
** 函数名称: Write_Data
** 功能描述: 传送数据
** 输 入: dat
** 输 出 : 无
** 全局变量:无
** 调用模块: Busy,
******************************************/
//图像反色显示 0 否 1是
bit LCD_DisplayReserve_Driver;
//定义LCD显示的全局变量
#define CS_Port P3_0
#define A0_Port P3_1
#define SI_Port P3_2
{
switch (PIN)
{
case CS :
CS_Port=1;
break;
case A0 :
A0_Port=1;
break;
case SI :
SI_Port=1;
break;
case SCL :
SCL_Port=1;
LCD12864液晶驱动编程指南
LCD12864液晶驱动编程指南
1.连接硬件:
2.初始化液晶:
在开始使用液晶之前,需要进行初始化。
初始化过程包括设置液晶的
工作模式、显示模式和其他参数。
通过向液晶发送一系列的指令,可以完
成初始化过程。
3.编写驱动程序:
液晶驱动程序的主要目的是将需要显示的内容以及液晶的控制指令发
送给液晶屏。
根据液晶屏的通信方式,可以采用单片机的IO口直接控制
液晶屏,也可以通过SPI或I2C等接口芯片间接控制。
4.显示图形:
5.显示文本:
除了图形外,液晶还可以显示文本。
可以通过设置显示位置和发送需
要显示的文本来实现。
6.更新显示:
当需要更新液晶上的内容时,可以通过重新设置显示的内容和刷新液
晶来实现。
可以定时刷新液晶,或者通过检测外部事件来触发刷新。
7.扩展功能:
除了基本功能外,还可以实现一些扩展功能,如显示动画、滚动显示、倒计时等。
只需要根据需求编写相应的代码即可实现。
总结:
注意事项:
在编写驱动程序时,需要注意及时更新液晶上的内容,避免频繁刷新导致的卡顿现象。
同时,为了保证程序的可移植性,可以将液晶驱动程序与其他功能模块进行分离,便于代码的维护和移植。
LCD12864驱动程序
#define uint unsigned int
//引脚定义
#define CS P2_0 //片选 高电平有效 单片LCD使用时可固定高电平
#define SID P2_1 //数据
#define SCLK P2_2 //时钟
}
void write(bit start, unsigned char ddata) //写指令或数据
{
unsigned char start_data,Hdata,Ldata;
if(start==0) start_data=0xf8; //写指令
else start_data=0xfa; //写数据
delaynms(N); //延时是必须的
sendbyte(Ldata); //发送低四位
delaynms(N); //延时是必须的
}
void sendbyte(unsigned char bbyte) //发送一个字节
{
unsigned char i;
for(i=0;i<8;i++)
}
for(i=0;i<32;i++)
{ write(0,0x80+i);write(0,0x88);
for(j=0;j<16;j++) write(1,0xff);
}
}*/
void lcdcls(void) //图形方式下清屏
{
unsigned char i,j;
RESET=0; delaynms(N); RESET=1; // 复位LCD
LCD12864显示程序
本例程为通过用A T89C52芯片操作LCD12864显示的程序,使用的晶振为12M。
/**********************************************************程序说明:LCD12864显示主程序程序调试员:莫剑辉调试时间:2010-6-7**********************************************************/#include<reg52.h>#include"12864.c"void main(){Ini_Lcd(); //液晶初始化子程序Disp(1,0,6,"莫剑辉"); //显示数据到LCD12864子程序while(1);}这里我们通过调用下面的头文件就可以了,这样的做法方便我们以后要用到LCD12864的程序的调用。
/**********************************************************程序说明:LCD12864显示头文件程序调试员:莫剑辉调试时间:2010-6-7**********************************************************///#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define DATA P2 //数据输出端0~7sbit RS=P0^0; //LCD12864 RS端sbit RW=P0^1; //LCD12864 RW端sbit E =P0^2; //LCD12864 E 端sbit PSB =P0^3;/*********************************************延时子程序*********************************************/void Delay_1ms(uint x){uint j,i;for(j=0;j<x;j++){for(i=0;i<120;i++); //延时X乘以120}}/*********************************************LCD12864液晶测忙子程序(读状态)*********************************************/void Busy(){uchar busy;do{E = 0; //0为关闭使能端,1为打开使能端RS = 0; //1为指令,0为数据RW = 1; //1为读,0为写Delay_1ms(20); //延时20乘以120时间E = 1; //0为关闭使能端,1为打开使能端busy=P1; //读取P2状态Delay_1ms(20); //延时20乘以120时间E = 0; //0为关闭使能端,1为打开使能端}while(busy&0x80); //判断BUSY位是否工作:1为内部在工作,0为正常状态}/*********************************************LCD12864液晶数据写入子程序*********************************************/void Write_Data(uchar k){Busy(); //测忙E =1; //0为关闭使能端,1为打开使能端RS=1; //1为指令,0为数据RW=0; //1为读,0为写DA TA=k; //输入数据K到DA TADelay_1ms(20); //延时20乘以120时间E =0; //0为关闭使能端,1为打开使能端Delay_1ms(20); //延时20乘以120时间}/*********************************************LCD12864液晶命令写入子程序*********************************************/void Write_Cmd(uchar cmd){Busy(); //测忙E=1; //0为关闭使能端,1为打开使能端RS=0; //1为指令,0为数据RW=0; //1为读,0为写DA TA=cmd; //输入命令cmd到DATADelay_1ms(20); //延时20乘以120时间E=0; //0为关闭使能端,1为打开使能端Delay_1ms(20); //延时20乘以120时间}/*********************************************LCD12864液晶数据显示子程序*********************************************/void Disp(uchar y,uchar x,uchar i,uchar *z){uchar Address;if(y==1){Address=0x80+x;} //Y判断第几行,X判断第几列,0x80为液晶行初始地址if(y==2){Address=0x90+x;}if(y==3){Address=0x88+x;}if(y==4){Address=0x98+x;}Write_Cmd(Address); //写入地址命令到LCD12864while(i) //写入显示数据的大小{Write_Data(*(z++)); //写入显示数据到LCD12864i--;}}/*********************************************LCD12864液晶初始化子程序*********************************************/void Ini_Lcd(void){PSB=1;Delay_1ms(20);Write_Cmd(0x30); //基本指令集Delay_1ms(20);Write_Cmd(0x02); // 地址归位Delay_1ms(20);Write_Cmd(0x0c); //整体显示打开,游标关闭Delay_1ms(20);Write_Cmd(0x06); //游标右移Delay_1ms(20);Write_Cmd(0x80); //设定显示的起始地址Delay_1ms(20);Write_Cmd(0x01); //清除显示}。
LCD12864原理与应用(源程序+原理图+proteus仿真)
LCD12864原理与应用1、LCD12864简介:LCD12864分为两种,带字库的和不带字库的,不带字库的液晶显示汉字的时候可以选择自己喜欢的字体。
而带字库的液晶,只能显示GB2312字体,当然也可以显示其他的字体,不过是用图片的形式显示。
下面介绍不带字库的LCD12864,以Proteus中的AMPIRE128×64为例,如下图所示,它的液晶驱动器为KS0108。
引脚功能:引脚符号状态引脚名称功能,输入芯片片选端,都是低电平有效CS1=0开左屏幕,CS1=1关左屏幕CS2=0开右屏幕,CS2=1关右屏幕RS 输入数据/命令选择信号RS=1为数据操作,RS=0为写指令或读状态RW 输入读写选择信号R/W=1为读选通,R/W=0为写选通E 输入读写使能信号在E下降沿,数据被锁存(写)入液晶,在E高电平期间,数据被读出DB0—DB7 三态数据总线数据或指令的传送通道输入复位信号,低电平时复位复位时,关闭液晶显示,使显示起始行为0,可以跟单片机的复位引脚RST相连,也可以直接接VCC,使之不起作用V0 液晶显示器驱动电压-Vout -10V LCD驱动负电压与带字库的液晶不同,此块液晶含有两个液晶驱动器,每块驱动器都控制64*64个点,分为左右两个屏幕显示,总共为128*64个点(即有128×64个点)。
这就是为什么AMPIRE128*64有CS1和CS2两个片选端的原因。
此液晶有8页,一页有8行点阵点,左右各64列,共128列。
如下图所示:2、LCD12864中的几条重要指令(一)行(line)设置命令:由此可见显示的起始行地址为0XC0,共64行,有规律地改变起始行号,可以实现滚屏效果。
(二)页(page)设置指令:起始页地址为0XB8,因为液晶有64行点,分为8页,每页就有8行点。
(三)列(column)地址设置指令每块驱动器的列地址都是从0X40到0X7F,共64列,所以此液晶共有128列点。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
D5_LOW() FIO2CLR |= D5
D5_STATUS() (FIO2PIN &= D5)
#define #define #define #define #define #define
D6 (1<<8)
D6_IN()
FIO2DIR &= ~D6
D6_OUT() FIO2DIR |= D6
D6_HIGH() FIO2SET |= D6
程序结构 接线原理图
// 说明: // 接线说明:
// 数据:
OCM12864-5(KS0108)并行显示程序(LPC2366)
VO 不接 RS:0.8 RW:0.9 EN:2.13
DB0:2.2 DB1:2.3 DB2:2.4 DB3:2.5 DB4:2.6 DB5:2.7 DB6:2.8 DB7:2.9
// 复位和串并行设置: CS1:0.6 CS2:0.7
******************************************************************************* ************************/
#include "config.h"
#define D0_STATUS() (FIO2PIN &= D0) //可能存在问题
#define #define #define #define #define #define
D1 (1<<3)
D1_IN()
FIO2DIR &= ~D1
D1_OUT() FIO2DIR |= D1
D1_HIGH() FIO2SET |= D1
D4_LOW() FIO2CLR |= D4
D4_STATUS() (FIO2PIN &= D4)
#define #define #define #define #define #define
D5 (1<<7)
D5_IN()
FIO2DIR &= ~D5
D5_OUT() FIO2DIR |= D5
D5_HIGH() FIO2SET |= D5
*****/
//P241 有另一种写法
#define D0 (1<<2)
#define D0_IN()
FIO2DIR &= ~D0
#define D0_OUT() FIO2DIR |= D0
#define D0_HIGH() FIO2SET |= D0
#define D0_LOW() FIO2CLR |= D0
D7_LOW() FIO2CLR |= D7
D7_STATUS() (FIO2PIN &= D7)
#define #define #define #define
CS1 (1<<6) CS1_INIT() CS1_HIGH() CS1_LOW()
IO0DIR |= CS1 IO0SET |= CS1 IO0CLR |= CS1
#define D2_STATUS() (FIO2PIN &= D2)
#define #define #define #define #define #define
D3 (1<<5)
D3_IN()
FIO2DIR &= ~D3
D3_OUT() FIO2DIR |= D3
D3_HIGH() FIO2SET |= D3
//#define RS_L IO0CLR = 0x00000100; //P0.8
//#define RS_H IO0SET = 0x00000100;
#define #define #define #define
RW (1<<9) RW_INIT() RW_HIGH() RW_LOW()
IO0DIR |= RW IO0SET |= RW IO0CLR |= RW
char hz12[]={ /*-- 宋体 12; 此字体下对应的点阵为:宽 x 高=16x16 --*/ /*-- 文字: 有 --*/ 0x00,0x04,0x84,0x44,0xE4,0x34,0x2C,0x27,0x24,0x24,0x24,0xE4,0x04,0x04,0x04,0x00, 0x02,0x01,0x00,0x00,0xFF,0x09,0x09,0x09,0x29,0x49,0xC9,0x7F,0x00,0x00,0x00,0x00, /*-- 文字: 限 --*/ 0xFE,0x02,0x32,0x4E,0x82,0x00,0xFE,0x4A,0xCA,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00, 0xFF,0x00,0x02,0x04,0x03,0x00,0xFF,0x40,0x20,0x03,0x0C,0x12,0x21,0x60,0x20,0x00, /*-- 文字: 公 --*/ 0x00,0x00,0x80,0x40,0x30,0x0E,0x84,0x00,0x00,0x0E,0x10,0x60,0xC0,0x80,0x80,0x00, 0x00,0x01,0x20,0x70,0x28,0x24,0x23,0x31,0x10,0x10,0x14,0x78,0x30,0x01,0x00,0x00, /*-- 文字: 司 --*/ 0x00,0x10,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0x12,0x02,0x02,0xFE,0x00,0x00, 0x00,0x00,0x1F,0x04,0x04,0x04,0x04,0x04,0x04,0x0F,0x00,0x20,0x40,0x3F,0x00,0x00,
0x3e 0x3f 0xb8 0xc0 0x40
char hz11[]={ /*-- 宋体 12; 此字体下对应的点阵为:宽 x 高=16x16 --*/ /*-- 文字: 金 --*/ 0x40,0x40,0x20,0x20,0x50,0x48,0x44,0xC3,0x44,0x48,0x50,0x50,0x20,0x60,0x20,0x00, 0x40,0x40,0x42,0x42,0x4A,0x72,0x42,0x7F,0x42,0x62,0x5A,0x42,0x42,0x40,0x40,0x00, /*-- 文字: 鹏 --*/ 0x00,0xFE,0x12,0xFE,0x00,0xFE,0x12,0xFE,0x00,0xFC,0x0E,0x35,0x44,0x7C,0x00,0x00, 0x20,0x1F,0x21,0x7F,0x20,0x1F,0x41,0x7F,0x08,0x09,0x09,0x29,0x49,0x21,0x1F,0x00, /*-- 文字: 科 --*/ 0x10,0x12,0x92,0x72,0xFE,0x51,0x91,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00, 0x04,0x02,0x01,0x00,0xFF,0x00,0x04,0x04,0x04,0x02,0x02,0x02,0xFF,0x01,0x01,0x00, /*-- 文字: 技 --*/
//#define RS_L //#define RS_H
IO0CLR = 0x00000100; //P0.8 IO0SET = 0x00000100;
//#define RW_L IO0CLR = 0x00000200; //P0.9 //#define RW_H IO0SET = 0x00000200;
(1 << 27)
// P0.7 控制蜂鸣器,低电平蜂鸣
IO0CLR = 0x00000002;
IO0SET = 0x00000002;
//#define CS_ON IO0CLR = 0x00000001; //#define CS_OFF IO0SET = 0x00000001;
//#define IO_OUTPUT FIO2DIR = 0x000003FC; //P2.2-P2.9 //#define IO_INTPUT IO0DIR = 0x00000000FF;
D1_LOW() FIO2CLR |= D1