LCD12864驱动源代码

合集下载

51单片机LCD_12864驱动

51单片机LCD_12864驱动
delay(1); //延时
LCD_RST=0; //复位
delay(1); //延时
LCD_RST=1; //复位置高
delay(10);
}
/*********************************************************
* *
* 清屏函数 *
/* */
/* LCD初始化设定 */
/* */
* *
*********************************************************/
void LCD_ClearScreen()
{
LCD_wcmd(0x34); //扩充指令操作
lcd_delay(5);
LCD_wcmd(0x30); //基本指令操作
lcd_delay(5);
LCD_wcmd(0x01); //清屏
lcd_delay(5);
}
/*******************************************************************/
LCD_wcmd(0x30); //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFF
delay(100); //大于100uS的延时程序
LCD_wcmd(0x30); //Function Set
/*写指令数据到LCD */
/*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */
/* */
lcd_delay(3);

LCD12864驱动程序(带字库的)

LCD12864驱动程序(带字库的)
/*void delayuS(uchar buf)
{
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;

FPGA控制LCD12864

FPGA控制LCD12864
begin
state <= SETFUNCTION;
LCD_D <= 8'bzzzzzzzz;
end
SETFUNCTION:
begin
state <= SETFUNCTION2;
LCD_D <= 8'h30; // 8-bit 控制界面,基本指令集动作
坛子里有很多单片机驱动LCD12864的代码,但用FPGA来驱动的比较少。
今天做了FPGA驱动LCD12864的实验,把代码发上来,与大家分享。
PS:仿佛这样的任务不适合用FPGA来做。
代码如下:
module LCD12864(
input CLK, //系统时钟输入
end
CLEAR:
begin
state <= SETMODE;
LCD_D <= 8'h01;
end
SETMODE:
begin
state <= SETDDRAM;
LCD_D <= 8'h06; // 输入方式设置: 数据读写后,地址自动加1,画面不动
if(!RST_N)
LCD_RS <= 1'b0;
else if(state == WRITERAM)
LCD_RS <= 1'b1;
else
LCD_RS <= 1'b0;
end
// State Machine
always @(posedge CLK_LCD or negedge RST_N)
6'd7: data_disp = "o"; // 容

12864驱动

12864驱动

LCD12864底层驱动#include<at89x52.h>#include<intrins.h>#define uint unsigned int#define uchar unsigned char#define out0 P0 //定义out0为P0口sbit LCD_RST=P1^0;sbit LCD_CS2=P1^1;sbit LCD_CS1=P1^2;sbit LCD_E=P1^3;sbit LCD_WR=P1^4;sbit LCD_RS=P1^5;uchar code hanzi_ZM[][32]={/*-- 0 文字: 欢--*/0x14,0x24,0x44,0x84,0x64,0x1C,0x20,0x18,0x0F,0xE8,0x08, 0x08,0x28,0x18,0x08,0x00,0x20,0x10,0x4C,0x43,0x43,0x2C,0x20,0x10,0x0C,0x03,0x06, 0x18,0x30,0x60,0x20,0x00,};uchar code shuzi_ZM[][16]={/*-- 文字: 0 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10, 0x20,0x20,0x10,0x0F,0x00,};void delayms(uint x) //延时毫秒函数{uchar i;while(x--)for(i=0;i<123;i++);}void busy() //读忙信号{uchar mang; //忙变量LCD_E=0; //使能端无效LCD_RS=0; //指令LCD_WR=1; //读do{out0=0xff;LCD_E=1; //使能端有效_nop_(); //等待一段时间让信号稳定后再读mang=out0;LCD_E=0; //使能端无效}while(mang&0x90); //若不忙则退出循环}void writeData(uchar x) //写数据{busy(); //读忙out0=x; //将x写入TG12864中_nop_();LCD_RS=1; //数据LCD_WR=0; //写LCD_E=1; //使能端有效_nop_();LCD_E=0; //使能端无效LCD_WR=1;}void writeOrder(uchar x) //写指令{busy();out0=x;_nop_();LCD_RS=0; //指令LCD_WR=0; //写LCD_E=1; //使能端有效_nop_();LCD_E=0; //使能端无效LCD_WR=1;}void lcd_x(uchar x) //定位x坐标{writeOrder(0xb8|x); //设置页地址}void lcd_y(uchar y) //定位y坐标{writeOrder(0x40|y); //设置Y地址}void lcd_xy(uchar x,y) //定位{if(y<64) //若列小于64在左半屏显示{LCD_CS1=1; //左半屏片选有效LCD_CS2=0; //右半屏片选无效lcd_y(y); //写入y地址}else //若列大于64在右半屏显示{LCD_CS1=0; //左半屏片选无效LCD_CS2=1; //右半屏片选有效lcd_y(y-64); //写入y地址}lcd_x(x); //写入x地址}void qingpin() //清屏函数{uchar i,j;LCD_CS1=LCD_CS2=1; //片选有效for(i=0;i<8;i++) //写8页{lcd_y(0); //从第0列开始lcd_x(i); //从i页开始for(j=0;j<128;j++) //写128列{writeData(0x00); //输出数据0x00 }}LCD_CS1=LCD_CS2=0; //片选无效}void initTG12864() //初始化12864{LCD_RST=0; //TG12864复位delayms(15);LCD_RST=1;LCD_CS1=LCD_CS2=1;writeOrder(0x3e); //关显示writeOrder(0xb8); //页地址出初始化从0页开始writeOrder(0x40); //列地址出初始化从列开始writeOrder(0xc0); //显示开始线从第一行开始writeOrder(0x3f); //开显示LCD_CS1=LCD_CS2=0;}void writeHan(uchar x,y,z,uchar code *p)//写一个汉字16*16{uint t=0;uchar i,j;for(i=x;i<x+2;i++) //显示一个汉字占两页{for(j=y;j<y+16;j++) //显示一个汉字占16列{lcd_xy(i,j);//定位坐标位i页j列if(z==0) // 反白0;正常1writeData(p[t++]);//输出正常字模数据elsewriteData(~p[t++]); //输出反白字模数据}}LCD_CS1=LCD_CS2=0;}void writeAscii(uchar x,y,z,uchar code *p)//写一个字符8*16{uint t=0;uchar i,j;for(i=x;i<x+2;i++){for(j=y;j<y+8;j++) //显示一个字符占8列{lcd_xy(i,j);if(z==0)writeData(p[t++]);elsewriteData(~p[t++]);}}LCD_CS1=LCD_CS2=0;}void main() //主函数{initTG12864(); //初始化TG12864qingpin(); //清屏writeHan(2,32,0,hanzi_ZM[0]); //欢writeAscii(4,80,0,shuzi_ZM[0]);while(1);}。

基于STC89C52RC的LCD12864模块调试源码

基于STC89C52RC的LCD12864模块调试源码

///////////////////////////////////////////////////////CONFIG.H引脚配置文件:///////////////////////////////////////////////////////#ifndef _CONFIG_H#define _CONFIG_H/* 通用头文件*/#include <reg52.h>#include <intrins.h>/* 数据类型定义*//*typedef signed char int8; // 8位有符号整型数typedef signed int int16; //16位有符号整型数typedef signed long int32; //32位有符号整型数*/typedef unsigned char u8; // 8位无符号整型数typedef unsigned int u16; //16位无符号整型数typedef unsigned long u32; //32位无符号整型数/* 全局运行参数定义*/#define SYS_MCLK (11059200/12) //系统主时钟频率,即振荡器频率÷12 /* IO引脚分配定义*/sbit KEY_IN_1 = P2^4; //矩阵按键的扫描输入引脚1sbit KEY_IN_2 = P2^5; //矩阵按键的扫描输入引脚2sbit KEY_IN_3 = P2^6; //矩阵按键的扫描输入引脚3sbit KEY_IN_4 = P2^7; //矩阵按键的扫描输入引脚4sbit KEY_OUT_1 = P2^3; //矩阵按键的扫描输出引脚1sbit KEY_OUT_2 = P2^2; //矩阵按键的扫描输出引脚2sbit KEY_OUT_3 = P2^1; //矩阵按键的扫描输出引脚3sbit KEY_OUT_4 = P2^0; //矩阵按键的扫描输出引脚4sbit ADDR0 = P1^0; //LED位选译码地址引脚0sbit ADDR1 = P1^1; //LED位选译码地址引脚1sbit ADDR2 = P1^2; //LED位选译码地址引脚2sbit ADDR3 = P1^3; //LED位选译码地址引脚3sbit ENLED = P1^4; //LED显示部件的总使能引脚#define LCD12864_DB P0 //1602液晶数据端口sbit LCD12864_RES = P1^0; //1602液晶指令/数据选择引脚sbit LCD12864_RW = P1^1; //1602液晶读写引脚sbit LCD12864_EN = P1^5; //1602液晶使能引脚sbit DS1302_CE = P1^7; //DS1302片选引脚sbit DS1302_CK = P3^5; //DS1302通信时钟引脚sbit DS1302_IO = P3^4; //DS1302通信数据引脚sbit I2C_SCL = P3^7; //I2C总线时钟引脚sbit I2C_SDA = P3^6; //I2C总线数据引脚sbit BUZZER = P1^6; //蜂鸣器控制引脚sbit IO_18B20 = P3^2; //DS18B20通信引脚sbit IR_INPUT = P3^3; //红外接收引脚#include "LCD12864.H"#include "TIME.H"#include "DHT21.h"#endif//////////////////////////////////////////////////////////////LCD12864.C源码/////////////////////////////////////////////////////////////#include "config.h"u8 zhbuf[]={"预览"}; //中文数组u8 ehbuf[]={"yulan"}; //英文字符数组u8 code imbuf[]={ //图片码128*64 宽16,高320x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, };/*写等待*/void Write_Ready(){u8 sta=0;LCD12864_RES = 0;LCD12864_RW = 1;do{LCD12864_EN = 1;sta = P0;LCD12864_EN = 0;}while(sta&0x80);}/*读RAM中数据*/u8 Read_12864_RAM(){u8 ram=0;LCD12864_RES = 1;LCD12864_RW = 1;LCD12864_EN = 1;ram = P0;LCD12864_EN = 0;return ram;}/*写指令*/void Write_12864_Cmd(u8 cmd) {Write_Ready();LCD12864_RES = 0;LCD12864_RW = 0;P0 = cmd;LCD12864_EN = 1;LCD12864_EN = 0;}/*写数据*/void Write_12864_Dat(u8 dat){Write_Ready();LCD12864_RES = 1;LCD12864_RW = 0;P0 = dat;LCD12864_EN = 1;LCD12864_EN = 0;}/*设置起始坐标*/void Set_DDRAM_XY(u8 x,u8 y){if(x>=7)x=7;if(y>=3)y=3;switch(y){case 0:Write_12864_Cmd(0x80+x);break;case 1:Write_12864_Cmd(0x90+x);break;case 2:Write_12864_Cmd(0x88+x);break;case 3:Write_12864_Cmd(0x98+x);break;default : break;}}/*显示连续的2个字符*/void Show_Double_12864_Char(u8 x,u8 y,u8 *c) {Set_DDRAM_XY(x,y);Write_12864_Dat(*c);Write_12864_Dat(*(c+1));}/*显示单个字符*/void Show_Single_12864_Char(u8 x,u8 y,u8 *c) {Set_DDRAM_XY(x,y);Write_12864_Dat(*c);}/*显示中文字符串*/void Show_12864_ZH(u8 x,u8 y,u8 *zh){u8* p=zh;Set_DDRAM_XY(x,y);while((*p)!='\0'){Write_12864_Dat(*p++);}}/*显示一串数值*//*u8 dec 小数位为0不显示小数*/void Show_12864_NUM(u8 x,u8 y,u8 dec,u16 num) {u8 i;u8 numbuf[6];for(i=0;num;i++){numbuf[i]=num%10+'0';num/=10;}Set_DDRAM_XY(x,y);for(;i;i--){if(i==dec){Write_12864_Dat(0X2E); //显示小数点}Write_12864_Dat(*(numbuf+(i-1))); //显示数值}}/*显示英文字符串*/void Show_12864_EH(u8 x,u8 y,u8 *eh){u8* p=eh;Set_DDRAM_XY(x,y);while((*p)!='\0'){Write_12864_Dat(*p++);}}/*显示图案*/void Show_12864_IM(u8 code *im){unsigned char x,y,i;unsigned int tmp=0;for(i=0;i<9;){ //分两屏,上半屏和下半屏,因为起始地址不同,需要分开for(x=0;x<32;x++){ //32行Write_12864_Cmd(0x34);Write_12864_Cmd(0x80+x);//列地址Write_12864_Cmd(0x80+i); //行地址,下半屏,即第三行地址0X88Write_12864_Cmd(0x30);for(y=0;y<16;y++)Write_12864_Dat(im[tmp+y]);//读取数据写入LCDtmp+=16;}i+=8;}Write_12864_Cmd(0x36); //扩充功能设定Write_12864_Cmd(0x30);}/*初始化12864*/void Init_Lcd12864(){Read_12864_RAM();Show_Single_12864_Char(0,0,'A');Show_Double_12864_Char(0,0,"AB");Show_12864_NUM(0,0,1,123);Show_12864_ZH(0,0,"预览");Show_12864_EH(0,0,"yulan");Show_12864_IM(imbuf);Write_12864_Cmd(0X30); //8位数据,基本指令Write_12864_Cmd(0X0C); //开显示,关游标Write_12864_Cmd(0X01); //清屏Write_12864_Cmd(0X02); //地址归位Write_12864_Cmd(0X80); //设置DDRAM地址}////////////////////////////////////////////////////////////////////////////////////// MAIN.C文件//////////////////////////////////////////////////////////////////////////////////////////////*主测试函数*/void main(){Init_Lcd12864();Read_12864_RAM();Show_12864_IM(imbuf);Show_12864_EH(0,0,ehbuf);Show_12864_ZH(1,1,zhbuf);while(1);}///////////////////////////////////////////////////////////////。

LCD12864驱动程序(STM32F103RCT6)

LCD12864驱动程序(STM32F103RCT6)
u8 i = 0;
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 并口液晶驱动

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液晶驱动程序

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);

12864液晶代码(很实用的)

12864液晶代码(很实用的)

#include<reg52.h>#include<intrins.h>#include<stdlib.h>#define uchar unsigned char#define uint unsigned int/*端口定义*/#define LCD_data P0sbit LCD_RS=P3^5;sbit LCD_RW=P3^6;sbit LCD_EN=P3^4;sbit LCD_PSB=P3^7;uchar dis1[10];uchar code dis2[]={"XXXXXXXXXXX@"};uchar code dis3[]={"XXXXXXXX"};uchar code dis4[]={"-------"};void delay_ms(uint x){int i,j;for(j = 0; j < x; j++){for(i = 0; i < 110; i++){;}}}/*写指令数据到LCDRS=L——表示DB0-DB7为显示指令数据RW=L——表示DB0-DB7数据被write(当E=“H-L”,指令数据被写到IR或DR) E=高脉冲此时DB0-DB7=指令码*/void write_cmd(uchar cmd){LCD_RS=0;LCD_RW=0;LCD_EN=0;P0=cmd;delay_ms(5);delay_ms(5);LCD_EN=0;}/*设定显示位置*/void lcd_pos(uchar X, uchar Y){uchar pos;if(X == 0){X = 0x80;}else if(X == 1){X = 0x90;}else if(X == 2){X = 0x88;}else if(X == 3){X = 0x98;}pos = X + Y;write_cmd(pos); //显示地址}/*写显示数据到LCD*//*RS=H ——表示DB0-DB7为显示数据RW=L ——RW=L,E='H-L',DB0-DB7数据被写到IR或DR E=高脉冲DB0-DB7=显示数据*/void write_dat(uchar dat){LCD_RS=1;LCD_RW=0;LCD_EN=0;P0=dat;delay_ms(5);delay_ms(5);LCD_EN=0;}/*随机数发生函数*/void randmaker(){uint ran;ran=rand();dis1[0]=ran/10000+0x30;dis1[1]=ran%10000/1000+0x30;dis1[2]=ran%1000/100+0x30;dis1[3]=ran%100/10+0x30;dis1[4]=ran%10+0x30;ran=rand();dis1[5]=ran/10000+0x30;dis1[6]=ran%10000/1000+0x30;dis1[7]=ran%1000/100+0x30;dis1[8]=ran%100/10+0x30;dis1[9]=ran%10+0x30;}/*LCD初始化*/void lcd_init(){LCD_PSB=1;//并口方式write_cmd(0x30);//基本操作指令delay_ms(5);write_cmd(0x0c);//打开显示,光标关闭delay_ms(5);write_cmd(0x01);//清除LCD显示类容delay_ms(5);}/*主程序*/main(){uchar i;delay_ms(10);lcd_init();lcd_pos(1,0);i=0;while(dis2[i]!='\0'){write_dat(dis2[i]);i++;}lcd_pos(2,0);i=0;while(dis3[i]!='\0'){write_dat(dis3[i]);i++;}lcd_pos(3,0);i=0;while(dis4[i]!='\0'){write_dat(dis4[i]);i++;}while(1){lcd_pos(0,0);randmaker();for(i=0;i<10;i++){write_dat(dis1[i]);}}}。

液晶显示屏LCD12864驱动解析

液晶显示屏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的驱动

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液晶屏驱动程序

12864液晶屏驱动程序
unsigned char BMPheight;
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驱动程序
#define uchar unsigned char
#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

12864 LCD驱动程序

12864 LCD驱动程序

/*LCD.C128×64 LCD驱动程序*/#include <INTRINS.H>#include <ABSACC.H>#include "LCD.H"//定义屏幕光标(取值0~63,光标本身不可见)unsigned char LcdCursor;/*函数:LcdLightOn()功能:点亮背光灯*/void LcdLightOn(){LCD_BL = 1;}/*函数:LcdLightOff()功能:熄灭背光灯*/void LcdLightOff(){LCD_BL = 0;}/*函数:LcdGetBF()功能:读出状态位BF返回:BF=1,表示忙,不可进行任何操作BF=0,表示不忙,可以进行正常操作*/bit LcdGetBF(){unsigned char dat;dat = XBYTE[0xD002]; //XBYTE的定义见<ABSACC.H>return (bit)(dat & 0x80);}/*函数:LcdWriteCmd()功能:向LCD发送命令参数:cmd:命令字,详见器件的数据手册*/void LcdWriteCmd(unsigned char cmd){while ( LcdGetBF() );XBYTE[0xD000] = cmd;}/*函数:LcdWriteDat()功能:向LCD写入数据参数:dat,要写入的数据说明:目标地址由地址计数器AC隐含指定,写完后AC自动加1*/void LcdWriteDat(unsigned char dat){while ( LcdGetBF() );XBYTE[0xD001] = dat;}/*函数:LcdReadDat()功能:从LCD读出数据返回:读出的数据*//*unsigned char LcdReadDat(){volatile unsigned char dat;while ( LcdGetBF() );dat = XBYTE[0xD003];dat = XBYTE[0xD003]; //需要连续执行两次才能够读出真正的数据return dat;}*//*函数:LcdSetAC()功能:设置DDRAM(显示数据RAM)的AC(地址计数器)值参数:ac:地址计数器值,范围0~63*/void LcdSetAC(unsigned char ac){ac &= 0x3F;ac |= 0x80;LcdWriteCmd(ac);}/*函数:LcdClear()功能:LCD清屏,并使光标回到0*/void LcdClear(){LcdWriteCmd(0x01); //清屏命令LcdCursor = 0;}/*函数:LcdDelay()功能:延时(t*100)个机器周期*/void LcdDelay(unsigned char t){unsigned char n;do{n = 49;while ( --n != 0 );} while ( --t != 0 );}/*函数:LcdInit()功能:LCD初始化*/void LcdInit(){LcdWriteCmd(0x30); //设置基本指令集LcdDelay(3);LcdWriteCmd(0x30); //设置基本指令集(需要再执行一次)LcdDelay(1);LcdWriteCmd(0x0C); //开启显示LcdDelay(3);LcdClear(); //清屏LcdDelay(250);LcdWriteCmd(0x06); //设置进入点LcdDelay(10);}/*函数:LcdCheckAC()功能:根据光标位置调整AC*/void LcdCheckAC(){switch ( LcdCursor ){case 16:LcdSetAC(16);break;case 32:LcdSetAC(8);break;case 48:LcdSetAC(24);break;case 64:LcdCursor = 0;LcdSetAC(0);break;default:break;}/*函数:LcdPutChar()功能:显示ASCII码参数:c为可显示的ASCII码(0x20~0x7F)*/void LcdPutChar(unsigned char c){LcdWriteDat(c);LcdCursor++;LcdCheckAC();}/*函数:LcdPutHZ()功能:显示汉字参数:ch,cl:汉字编码*/void LcdPutHZ(unsigned char ch, unsigned char cl){if ( LcdCursor & 0x01 ){//显示汉字时,必须偶地址对准,即光标位置不能是奇数LcdPutChar(' '); //额外输出一个空格}LcdWriteDat(ch);LcdWriteDat(cl);LcdCursor += 2;LcdCheckAC();}/*函数:LcdPuts()功能:显示字符串参数:*s:要显示的字符串(可同时包含ASCII码和汉字)*/void LcdPuts(unsigned char *s){unsigned char ch, cl;for (;;){ch = *s++;if ( ch == '\0' ) break;if ( ch < 0x80 ){LcdPutChar(ch);}else{cl = *s++;LcdPutHZ(ch,cl);}}}。

stm32驱动lcd12864程序

stm32驱动lcd12864程序

stm32驱动lcd12864程序编辑整理:尊敬的读者朋友们:这里是精品文档编辑中心,本文档内容是由我和我的同事精心编辑整理后发布的,发布之前我们对文中内容进行仔细校对,但是难免会有疏漏的地方,但是任然希望(stm32驱动lcd12864程序)的内容能够给您的工作和学习带来便利。

同时也真诚的希望收到您的建议和反馈,这将是我们进步的源泉,前进的动力。

本文可编辑可修改,如果觉得对您有帮助请收藏以便随时查阅,最后祝您生活愉快业绩进步,以下为stm32驱动lcd12864程序的全部内容。

#include ”12864.h"#include "sys.h"#include ”delay.h”#include "usart。

h”void p_out(void) //把PB命令端口配置成输出{rs();wr();en();psb();}void wr_outite_cmd(u8 cmd) //写命令{p_out();data_out(); //把PB数据端口配置成输出rs_out=0;wr_out=0;en_out=0;GPIOB—〉ODR=((GPIOB—〉ODR&0X00FF)|(cmd〈<8));delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void wr_outite_data(u8 dat) //写数据{p_out();data_out();rs_out=1;wr_out=0;en_out=0;GPIOB—〉ODR=((GPIOB—>ODR&0X00FF)|(dat<〈8)); //把dat给PB高八位delay_ms(10);en_out=1;delay_ms(10);en_out=0;}void LCDClear(void){wr_outite_cmd(0x01); //显示清屏delay_ms(5);wr_outite_cmd(0x34); // 显示光标移动设置delay_ms(5);wr_outite_cmd(0x30); // 显示开及光标设置delay_ms(5);}void locate_x_y(u8 x,u8 y)//指定显示坐标{u8 x2=0;x2=x;if(y<1) y=1;if(y>4) y=4;x&=0x0f;switch(y){case 1:x2|=0x80;break;case 2:x2|=0x90;break;case 3:x2|=0x88;break;case 4:x2|=0x98;break;}wr_outite_cmd(x2);delay_ms(10);}void lcd_init(void){wr_outite_cmd(0x30);delay_ms(10);wr_outite_cmd(0x01);delay_ms(10);wr_outite_cmd(0x06);delay_ms(10);wr_outite_cmd(0x0c);delay_ms(10);}void DisInt(u8 x,u8 y,int fnum) //显示整型变量的函数,最多显示16位的整数。

LCD12864驱动函数

LCD12864驱动函数
LCD_E = 0;
}
//写指令
void WriteCommandLCD(unsigned char WCLCD,BuysC) //BuysC为0时忽略忙检测
{
if (BuysC) ReadStatusLCD(); //根据需要检测忙
LCD_RS = 0;
LCD_RW = 0;
WriteCommandLCD((0x80+i),1); //行地址,下半屏,即第三行地址0X88
WriteCommandLCD(0x30,1);
for(y=0;y<16;y++)
WriteDataLCD(DData[tmp+y]);//读取数据写入LCD
tmp+=16;
case 2:X2|=0X90;break;
case 3:X2|=0X88;break;
case 4:X2|=0X98;break;
}
WriteCommandLCD(X2, 1); //发送地址码
while (DData[ListLength]>=0x20) //若到达字串尾则退出
/*屏幕闪动 */void LCDFlash(void);
/*显示一个字符*/void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);
/*显示一串字符*/void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);
{
unsigned char ListLength,X2;
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Transfer_command(0xc8); /*行扫描顺序:从上到下*/
Transfer_command(0xa0); /*列扫描顺序:从左到右*/
Transfer_command(0xaf); /*开显示*/
clear_screen();
}
//===============clear all dot martrics=============
Transfer_command(((column>>4)&0x0f)+0x10); //设置列地址的高4 位
Transfer_command(column&0x0f); //设置列地址的低4 位
}
/*=========延时=====================*/
void Delay(int i)
{
char i;
CS_0(); //CS_PIN=0
RS_0(); //CS_PIN=0
for(i=0;i<8;i++)
{
SCLK_0();
if(data1&0x80) DIN_1();
else DIN_0();
SCLK_1();
data1=data1<<=1;
void Initial_Lcd()
{
RST_0(); //reset=0
P2DIR |=RST_PIN | SPI_MOSI_PIN| SPI_CLK_PIN|RS_PIN|CS_PIN ;
Delay(50);
RST_1(); //reset=1
Delay(50);
{
CS_0(); //CS_PIN=0
Transfer_command(0xb0 + row * 2 + i); //设置“页”
Transfer_command(0x10 + (col_1 & 0x0f)); //设置“列”以及列的高四位
Transfer_command(0x00 + (col_0 & 0x0f)); //设置“列”以及列的低四位
Transfer_command(0x10);
Transfer_command(0x00);
for(j=0;j<132;j++)
{
Transfer_data(0x00);
}
}
}
/*=======写指令========*/
void Transfer_command(int data1)
unsigned int i, j; //计数器
unsigned char col_1 = col * CHAR_WIDTH >> 4; // 高四位
unsigned char col_0 = col * CHAR_WIDTH; // 高四位
unsigned char data_ori[NUM_CHAR][NUM_CHAR] = { 0 };
}
}
/*--------写数据------------*/
void Transfer_data(int data1)
{
char i;
CS_0(); //CS_PIN=0
RS_1();//RS=1
for(i=0;i<8;i++)
{
SCLK_0(); //SCLK_PIN=0
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<990;k++);
}
/*=========延时=====================*/
void Delay1(int i)
{
int j,k;
for(j=0;j<i;j++)
for(k=0;k<10;k++);
//----------------输入检测-------------
//-----------返回0表示输入出错------------
if (col > 112) {
return 0;
}
if (row > 3) {
return 0;
}
for (i = 0; i < 2; i++)
//--------------返回0表示输入出错---------------
if (col > 17) {
return 0;
}
if (row >7) {
return 0;
}
CS_0();
Transfer_command(0xb0 + row); //设置“页”
for(j=0;j<132;j++)
{
Transfer_data(0x00);
}
}
}
void clear_screen_menu()
{
unsigned char i,j;
for(Байду номын сангаас=1;i<9;i++)
{
CS_0(); //CS=0
Transfer_command(0xb0+i);
* @brief 对液晶的8*8字模矩阵做顺时针90度的旋转,来贴合液晶的显示模式
* @param c 需要显示的数字或字符
* @param row 字符显示的行数 取值范围0~7
* @param col 字符显示的列数 取值范围0~17
******************************************************************************/
#include "msp430G2553.h"
#include "LCD12864.h"
#include "PIX.h"
#include "stdbool.h"
#include "string.h"
unsigned int A0result;
//============initial=================0=//
}
/******************************************************************************
* @param index 需要显示的汉字在数组的位数
* @param row 字符显示的行数 取值范围0~3
* @param col 字符显示的列数 取值范围0~112
for (j = 0; j < NUM_CHAR; j++) {
data_cha[j][i] = data_ori[i][j];
}
}
for (i = 0; i < NUM_CHAR; i++) {
{
CS_0();
column=column; //我们平常所说的第1 列,在LCD 驱动IC 里是第0 列。所以在这里减去1.
page=page;
Transfer_command(0xb0+page); //设置页地址。每页是8 行。一个画面的64 行被分成8 个页。我们平常所说的第1 页,在LCD 驱动IC 里是第0 页,所以
unsigned char data_cha[NUM_CHAR][NUM_CHAR] = { 0 };
unsigned char show_chr[NUM_CHAR] = { 0 };
unsigned char ori_chr[NUM_CHAR] = { 0 };
//----------------输入检测-------------
* @param 正确返回1
******************************************************************************/
unsigned char LCD_Draw_Chinese_16x16(unsigned char index, unsigned char row,unsigned char col) {
void clear_screen()
{
unsigned char i,j;
for(i=0;i<9;i++)
{
CS_0(); //CS=0
Transfer_command(0xb0+i);
Transfer_command(0x10);
Transfer_command(0x00);
unsigned char * chinese = CHINESE_MATRIX + 32 * index;
unsigned int i, j; //计数器
unsigned char col_0 = col; //列低四位
unsigned char col_1 = col >> 4; //列高四位
unsigned char LCD_Draw_Char_8x8(char c, unsigned char row, unsigned char col,
bool IsReverse) {
const unsigned char * add = acFont8ASCII[c - 0x20];
相关文档
最新文档