串行LCM12864驱动程序收藏

合集下载

12864液晶串行驱动函数

12864液晶串行驱动函数
12864 液晶串行驱动函数
#include <reg52.h> #include <intrins.h> #include <stdio.h> #include <math.h> #define uchar unsigned char #define uint unsigned int sbit CS = P2^4; sbit SCK = P2^6; sbit SID = P2^5; sbit RST =P2^3; sbit PSB= P2^1; sbit key=P3^0; uchar code AC_TABLE[]={ 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, };
********************** * 函数名称 :WriteCommand ********************************************************************* *********************/ void WriteCommand(uchar Cbyte ) { CS = 1; CheckBusy(); SendByte(0xf8); //11111,RW(0),RS(0),0 SendByte(0xf0&Cbyte); //高四位 SendByte(0xf0&Cbyte<<4);//低四位(先执行<<) CS = 0; } /******************************************************************** ********************** * 函数名称 :WriteData ********************************************************************* *********************/ void WriteData(uchar Dbyte ) { CS = 1; CheckBusy(); SendByte(0xfa); //11111,RW(0),RS(1),0 SendByte(0xf0&Dbyte); //高四位 SendByte(0xf0&Dbyte<<4);//低四位(先执行<<) CS = 0; } /******************************************************************** ********************** * 函数名称 :ReadData ********************************************************************* *********************/ uchar ReadData( void ) { CheckBusy(); SendByte(0xfe); //11111,RW(1),RS(1),0 return ReceiveByte(); } /***************************************** Fucntion: delay10US(char x) Description: delay for 10 us Parameter: x Author: kassey@ Date: July,7th,2005

12864液晶屏幕使用说明及程序

12864液晶屏幕使用说明及程序

12864使用说明一、串/并接口1.1 串口接口管脚信号*注释1:如在实际应用中仅使用并口通讯模式,可将PSB 接固定高电平。

*注释2:模块内部接有上电复位电路,因此在不需要经常复位的场合可将该端悬空。

*注释3:如背光和模块共用一个电源,可以将模块上的JA、JK 用焊锡短接。

1.2 并行接口管脚信号*注释1:如在实际应用中仅使用并口通讯模式,可将PSB 接固定高电平。

*注释2:模块内部接有上电复位电路,因此在不需要经常复位的场合可将该端悬空。

*注释3:如背光和模块共用一个电源,可以将模块上的JA、JK 用焊锡短接。

二、模块主要硬件构成说明控制器接口信号说明:2.1、RS,R/W的配合选择决定控制界面的4种模式:2.2、E信号●忙标志BFBF 标志提供内部工作情况.BF=1 表示模块在进行内部操作,此时模块不接受外部指令和数据.BF=0 时, 模块为准备状态,随时可接受外部指令和数据.利用STATUS RD 指令,可以将BF 读到DB7 总线,从而检验模块之工作状态.●字型产生ROM(CGROM)字型产生ROM(CGROM)提供8192 个此触发器是用于模块屏幕显示开和关的控制。

DFF=1 为开显示(DISPLAY ON),DDRAM 的内容就显示在屏幕上,DFF=0 为关显示(DISPLAY OFF)。

DFF 的状态是指令DISPLAY ON/OFF 和RST 信号控制的。

●显示数据RAM(DDRAM)模块内部显示数据 RAM 提供 64×2 个位元组的空间,最多可控制 4 行 16 字(64 个字)的中文字型显示,当写入显示数据 RAM 时,可分别显示 CGROM 与CGRAM 的字型;此模块可显示三种字型,分别是半角英、数字型(16*8)、CGRAM 字型及 CGROM 的中文字型。

三种字型的选择,由在 DDRAM 中写入的编码选择,在0000H—0006H 的编码中(其代码分别是0000、0002、0004、0006 共4 个)将选择 CGRAM 的自定义字型,02H—7FH 的编码中将选择半角英数字的字型,至于A1 以上的编码将自动的结合下一个位元组,组成两个位元组的编码形成中文字型的编码BIG5(A140—D75F),GB(A1A0-F7FFH)。

12864液晶屏(带字库)51单片机3线串口驱动程序

12864液晶屏(带字库)51单片机3线串口驱动程序

#include<reg51.h>typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uitn32;sbit CS = P1^0;//片选信号引脚sbit SDA = P1^1;//数据线sbit SCK = P1^2;//串行时钟线//sbit RST = P1^3;//复位引脚//sbit PSB = P1^4;//串并控制引脚code uint8 strint1[] = "I Love You !";/*void delay5ms(void) //误差0us {unsigned char a,b;for(b=185;b>0;b--)for(a=12;a>0;a--);}*///发送一个字节void Send_Byte(uint8 dat){uint8 i;SCK = 0;for(i=0;i<8;i++){SDA = dat&0x80;SCK = 1;dat <<= 1;SCK = 0;}}//读取一个字节数据uint8 Read_Byte(void){uint8 i;uint16 byte = 0;SCK = 0;for(i=0;i<16;i++){byte <<= 1;SCK = 1;if(SDA)byte |= 0x0001;SCK = 0;}byte = ((byte>>4)|(byte>>8))&0x00ff;return ((uint8)(byte));}//读忙标志void Read_Busy(void){uint8 temp;CS = 1;do{Send_Byte(0xfc);//发送读命令temp = Read_Byte();//读取数据}while(temp&0x80);CS = 0;}//发送命令void Write_Cmd(uint8 cmd){uint8 temph = 0;uint8 templ = 0;//制作发送命令格式temph = cmd & 0xf0;templ = (cmd & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XF8);//发送命令命令//发送命令Send_Byte(temph);Send_Byte(templ);CS = 0;}//发送数据void Write_Dat(uint8 dat){uint8 temph = 0;uint8 templ = 0;//制作发送数据格式temph = dat & 0xf0;templ = (dat & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XFA);//发送数据命令Send_Byte(temph);//发送数据Send_Byte(templ);CS = 0;}//在指定位置显示半字宽字符void Dis_HCGROM(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat);}//指定位置显示字符串void Dis_String(uint8 x, uint8 y, uint8 len, uint8 *dat) {uint8 addr,i;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);for(i = 0;i < len;i++){Write_Dat(*dat++);}}//制定位置显示8位无符号数字void Dis_UNum8(uint8 x,uint8 y,uint8 dat){uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//制定位置显示16位无符号数字void Dis_UNum16(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/10000%10+'0');Write_Dat(dat/1000%10+'0');Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//在指定位置显示汉字//x范围:0-7,y范围:0-3//dat:汉字字形码void Dis_GB(uint8 x,uint8 y,uint16 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat((uint8)(dat >> 8));Write_Dat((uint8)(dat));}//LCD初始化void LCD_Init(void){/*RST = 0;delay5ms();delay5ms();RST = 1;PSB = 0;*/Write_Cmd(0X30);Write_Cmd(0X01);Write_Cmd(0X02);Write_Cmd(0X0C);}void main(void){LCD_Init();while(1){Dis_GB(0,0,0xc9b5);Dis_HCGROM(1,0,0x03);Dis_String(0,1,13,strint1);Dis_UNum8(0,2,250);} }。

STM32串行驱动12864液晶

STM32串行驱动12864液晶

STM32串⾏驱动12864液晶⾃⼰参考⼤神们的程序改写的液晶驱动,希望对有需要的⼈能有帮助#include "stm32f10x.h"static __IO uint32_t TimingDelay;void RCC_Configuration(void);void Delay(__IO uint32_t nTime);#define Line1 0x80//液晶第⼀⾏#define Line2 0x90//液晶第⼆⾏#define Line3 0x88//液晶第三⾏#define Line4 0x98//液晶第四⾏#define LCD_IO GPIOE //我⽤的是E.2 E.3 E.4 E.5 E.6#define CS GPIO_Pin_2#define RW GPIO_Pin_3#define CLK GPIO_Pin_4#define PSB GPIO_Pin_5#define RST GPIO_Pin_6#define SET(n) GPIO_SetBits(GPIOE,n) //将对应管脚输出⾼电平#define RESET(n) GPIO_ResetBits(GPIOE,n)//输出低电平#define CMD (uint32_t)0xf8000000 //串⾏写⼊的是命令要先写⼊0xf8 #define DATE (uint32_t)0xfa000000 // 串⾏写⼊数据要先写⼊0xfavoid LCD_IOinit_OUT() //推挽输出模式,管脚配置,不多解释,库函数有{GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin =CS|RW|CLK|PSB|RST;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(LCD_IO, &GPIO_InitStructure);}void LCD_Write(uint32_t cmd,uint8_t ddata)//LCD 写函数{uint32_t temp=cmd;uint32_t i;RESET(CS); //⽚选拉低temp|=((uint32_t)(ddata&(uint8_t)0xf0)<<16)+((uint32_t)(ddata&(uint8_t)0x0f)<<12);SET(CS); //⽚选拉⾼,开始传输数据for(i=0;i<24;i++){if(temp&0x80000000)SET(RW); //取出最⾼位,如果是1,那么RW就写1 else RESET(RW); //如果是0 RW就写0SET(CLK);//向液晶写数据是在下降沿写⼊的Delay(2);//稍作延时RESET(CLK);//拉低产⽣下降沿,写⼊数据temp=temp<<1;//左移⼀位,写⼊下⼀位}RESET(CS); //拉低⽚选,写⼊数据完毕}void Display(uint8_t addr,uint8_t *hz){LCD_Write(CMD,addr);Delay(3);while(*hz!='\0'){LCD_Write(DA TE,*hz);hz++;Delay(3);}}void LCD_init()//液晶初始化{RESET(CS); //拉低⽚选RESET(PSB);//PSB拉低,表⽰是串⾏,拉⾼则是并⾏RESET(RST);//拉低RSTDelay(100);SET(RST);Delay(40);LCD_Write(CMD,0x30);//8位数据传输Delay(40);LCD_Write(CMD,0x0c);//显⽰开,游标开Delay(40);LCD_Write(CMD,0x01);//清屏Delay(40);LCD_Write(CMD,0x06);//进⼊点设定AC+1Delay(40);}int main(){RCC_Configuration();SysTick_Config(72000); //配置SYSTICK时钟节拍为1ms⼀次LCD_IOinit_OUT();LCD_init();while(1){Display(Line1,"你妹");Display(Line2,"你妹");Display(Line3,"你妹妹");Display(Line4,"完事了,哈哈哈哈哈");}}void RCC_Configuration(void){SystemInit();RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE , ENABLE); }void Delay(__IO uint32_t nTime){TimingDelay = nTime;while(TimingDelay != 0);}void TimingDelay_Decrement(void){if (TimingDelay != 0x00){TimingDelay--;}}/*temp|=((uint32_t)(ddata&(uint8_t)0xf0)<<16)+((uint32_t)(ddata&(uint8_t)0x0f)<<12);重点解释⼀下这⾥,从串⾏时序图中可以看出,发送⼀个指令需要三个字节,第⼀个是0xf8或者0xfa这个根据你要发送的是命令还是数据⽽定,然后发送下⼀个数据的⾼四位和第四位,但是数据都是在⾼四位上⾯,⽤51的话我们要分三次发送,但是32的话⼀个字节可以是32位的/所以我们⼀次就能完成,这也是为什么下⾯的i<24的原因因为最后的8位没有⽤,例如:我们发送指令0x35,则应该是这样0xf8然后0x30然后0x50,这个应该很好理解所以看⼀下上⾯的语句⾸先我们cmd的值应该为0xf8000000,这个宏定义有的,这是发送命令然后我们让cmd=temp;在把temp和后⾯的计算结果做按位或运算.⾸先看这个(uint32_t)(ddata&(uint8_t)0xf0)<<16)我们的ddtate是0x35他和0xf0按位与之后/变为0x30然后左移16位变成0x30 0000;再强制转换为32位,就把⾼位补零变为0x00 30 0000再看这句话(uint32_t) (ddata&(uint8_t)0x0f)<<12)我们的ddtate是0x35他和0x0f按位与/之后变为0x05,左移12位0x05 000 强制转换为32位⾼位补零0x000 05 000 /在和前⾯的相加就是0x00 30 0000+0x000 05 000=0x0030 5000然后在和前⾯的0xf8000000按位或变为0xf830 5000 液晶读这个数据的时候是⼋位⼋位的读取所以在液晶看来是分四次的0xf8 0x30 0x50 0x00显然后⼋位没⽤所以我们只取前⾯的24位//应该能看懂了把结合时序图还有延时⼀定要精确⼤家有看不懂的可以给我留⾔*/。

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位的整数。

12864LCD屏驱动程序

12864LCD屏驱动程序

#include<reg51.h>#include<intrins.h>#define S2 0x08#define S4 0x02#define S5 0x01#define S6 0x10#define S47 0x08#define S48 0x04#define S49 0x02#define S50 0x01#define S52 0x08#define S54 0x02/*------ 接口逻辑定义区-------------*/#define E P3_6#define RW P3_1#define EL P3_2#define CS1 P3_3 /* E1: IC1 片选端,E2:IC2 */#define CS2 P3_4#define RESET P3_5 /* RW=0,写数据;RW=1;读数据处理*/#define RS P3_0 /* RS = 1 ,指向数据;RSCS1 = 0 ,指向命令寄存器*/ #define TT 2uchar code Bet1[]="No Best";uchar code Bet2[]="only Better";static uchar H2=0x31; /* 时钟驱动数据缓冲区*/static uchar H1=0x30;static uchar M2=0x33;static uchar M1=0x30;uchar CLK=0;bit Flag=0; /* AM & PM */bit BL_FG=0; /* BackLight *//*------------------------- 延时子程序--------- */void delay(uint times){while(times)times--;}/* -------------------------忙音检测--------------*/void CheckBF(bit CS) /* cs=0,检查IC1 CS=1检查IC2 */ {bit temp;RS=0;RW=1;if(CS)CS2=1;else CS1=1;do {EL=1;temp=P1_7;EL=0;}while(temp);CS1=0; /* 总线释放,芯片处高阻状态*/CS2=0;}/*-----------写命令···寄存器------ -----------*/void Wcode(bit CC1,uchar dd1) /* 选择芯片、数据*/{CheckBF(CC1);RS=0;RW=0;if(CC1)CS2=1;else CS1=1;P1=dd1;EL=1;delay(TT);EL=0; /* 写入指令*/CS1=0; /* 总线释放,芯片处高阻状态*/CS2=0;}/* -------写显示数据·····to DDRAM --------*/void Wdata(bit CC2,uchar dd2){CheckBF(CC2);RS=1;RW=0;if(CC2)CS2=1;else CS1=1;P1=dd2;EL=1;delay(TT);EL=0; /* 数据写入RAM */CS1=0; /* 总线释放,芯片处高阻状态*/CS2=0;}/* ------------------------------显示一幅图片128 *64 ------------*/ void DisMap(uchar *Imp){uchar m;uchar n;for(n=0;n<=7;n++){Wcode(0,(0xb8+n)); /* Setting Page 0 -- 7*/Wcode(1,(0xb8+n));Wcode(0,0x40); /* 列=0 */Wcode(1,0x40);for(m=0;m<64;m++){ Wdata(0,(*Imp)); Imp++; }for(m=0;m<64;m++){ Wdata(1,(*Imp)); Imp++; }}}/*---------- 写指令------*/void Wcode2(uchar order){delay(TT);RS=0;RW=0;P1=order;E=1;_nop_();E=0; /* 启动写信号*/}/*################# 写数据############*/void Wdata2(uchar Data){delay(TT);RS=1;RW=0;P1=Data;E=1;_nop_();_nop_();E=0; /* 启动写信号*/}/* -----------------------中断Timer0 : 时钟显示驱动------------------ */void CLOCK0(){M1++;if(M1==0x3a){ M2++;M1=0x30; }if(M2==0x36){ H1++;M2=0x30; }if(H1==0x3a){ H2++;H1=0x30; }if((H2==0x31)&(H1==0x32)){ H2=0x30; H1=0x30; Flag=!Flag; }/* ------------ 根据以上时钟数据驱动显示时钟!*/Wcode2(0x38); /* RE 正常模式*/if(H2==0x30) { Wcode2(0xdc); Wdata2(0x20); } // H2else { Wcode2(0xdc); Wdata2(0x31); }Wcode2(0xdd);Wdata2(H1); // H1Wcode2(0xde);Wdata2(M2); // M2Wcode2(0xdf);Wdata2(M1); // M1Wcode2(0x3e); /* 扩展模式,图标闪闪发光!*/Wcode2(0x79);Wdata2(S50);{if(Flag) { Wcode2(0x79); Wdata2(S49); }else { Wcode2(0x79); Wdata2(S48); }}}/* -----------------------中断Timer0 : 背光源驱动------------------ */void BL() interrupt 1 using 1{CLK++;if(CLK==100){EA=0; /* 禁止再中断入*/ET0=0;TR0=0;BL_FG=!BL_FG;/* --------------- 允许继续中断计时--------*/if(BL_FG){ P3_7=1; CLK=20; }else { P3_7=0; CLK=60; }TH0=0;TL0=0;EA=1; /* 禁止再中断入*/ET0=1;TR0=1;}}/*================================================================ */ /*=============================== 显示主程序==========*//*================================================================ */void main(){uchar i;uchar *IP;/* --------- 初始化地区------------------------------------------*/RESET=0;delay(8000);RESET=1; /* 软件复位*/CS1=0; /* 总线释放,芯片处高阻状态*/CS2=0;RESET=0;delay(8000);RESET=1; /* 软件复位*/CS1=0; /* 总线释放,芯片处高阻状态*/CS2=0;/* ----------------------------OPEN BACKLIGHT----------- */TMOD=0x11; /* 定义Timer0 为16 位定时器*/TH0=0x0;TL0=0x0;ET0=1;EA=1;TR0=1; /* 开始中断计时*/CLK=0x0; /* 首次触发时钟显示*//*--------------以下是GS-C803301 字符首页测试区-----------------------*/ Wcode2(0x01);Wcode2(0x38); /* RE 正常模式*/Wcode2(0xc); /* Display On , Cursor Off */Wcode2(0x6); /* 设定输入模式++ */Wcode2(0xc4);Wdata2('G');Wcode2(0xcc);Wdata2('E');Wcode2(0xcd);Wdata2('N');Wcode2(0xce);Wdata2('D');Wcode2(0xcf);Wdata2('A'); // display " Genda ";IP=Bet1;Wcode2(0x80);for(;*IP!='\0';IP++)Wdata2(*IP); // No BestIP=Bet2;Wcode2(0x90);for(;*IP!='\0';IP++)Wdata2(*IP); // Only Better/* --------------------------------------------------- 128 *64 Area ---*/ Wcode(0,0xb8); /* 设置页面Page= 0 */Wcode(1,0xb8);Wcode(0,0xc0); /* 设置显示首行地址=00 ,(00 --63) */ Wcode(1,0xc0);Wcode(0,0x40); /* 设置x 轴地址= 00 ,(00-63) */ Wcode(1,0x40);Wcode(0,0x3f); /* 开屏显示*/Wcode(1,0x3f);DisMap(Map2); /* 显示图片*/Wcode2(0x3e); /*display ":" */Wcode2(0x7d);Wdata2(0xff);while(1){CLOCK0();Wcode2(0x70); Wdata2(0xc0|S2);delay(60000); delay(60000); /* 显示图标*/delay(60000); delay(60000); delay(60000); delay(60000);Wcode2(0x70); Wdata2(0);delay(60000);Wcode2(0x71); Wdata2(0xc0|S6); delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000); delay(60000); delay(60000);Wcode2(0x71); Wdata2(0);delay(60000);Wcode2(0x70); Wdata2(0xc0|S4); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);delay(60000);Wcode2(0x70); Wdata2(0);delay(60000);Wcode2(0x70); Wdata2(0xc0|S5); delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);delay(60000);Wcode2(0x70); Wdata2(0);delay(60000);Wcode2(0x7a); Wdata2(0xc0|S52); delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000); delay(60000);Wcode2(0x7a); Wdata2(0); delay(60000);if(Flag){Wcode2(0x79); Wdata2(0xc3);}else{Wcode2(0x79); Wdata2(0xc5);}delay(60000); delay(60000);delay(60000); delay(60000);if(Flag) { Wcode2(0x79); Wdata2(2); }else { Wcode2(0x79); Wdata2(4); }Wcode2(0x7a); Wdata2(0xc0|S54); delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);delay(60000);delay(60000);Wcode2(0x7a); Wdata2(0);delay(60000);for(i=0;i<13;i++) /* 全部点亮图标*/{Wcode2(0x70+i);Wdata2(0x3f);}if(Flag) { Wcode2(0x79); Wdata2(0x2); }else { Wcode2(0x79); Wdata2(0x4); }for(i=0;i<35;i++)delay(60000);for(i=0;i<13;i++) /* 全部Clear 图标*/{Wcode2(0x70+i);Wdata2(0x0);}if(Flag) { Wcode2(0x79); Wdata2(0x2); }else { Wcode2(0x79); Wdata2(0x4); }delay(60000); delay(60000);delay(60000); delay(60000);delay(60000); delay(60000);}} /* ----------------------程序到此结束啦!!*/。

12864液晶屏串口驱动程序

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驱动程序(无字库)

LCD12864驱动程序(无字库)

LCD12864驱动程序(无字库)电路图如下,本人亲自调试过,可用!程序如下:*******************************************************************************主程序:#include <reg52.h>#include <LCD_12864.h>main() //主程序{unsigned char i=0;while(1){init_lcd();display_imge1();delay(30000);Msg(0);delay(30000);display_imge2();delay(30000);Disp_H_Line();delay(10000);Disp_V_Line();delay(10000);Msg(1);delay(30000);}}驱动程序//**********************LCD——12864显示程序**************// #include <reg52.h>#include <string.h>#include <math.h>#include <LCD_12864.h>#include <LCD_12864_data.h>#define Disp_On 0x3f //开显示#define Disp_Off 0x3e //关显示#define Col_Add 0x40 //#define Page_Add 0xb8 //页起始地址#define Start_Line 0xc0 //行起始地址#define Lcd_Bus P0 // MCU P0<------> LCMsbit Di =P2^0; //Data or Instrument Select RSsbit RW =P2^1; //Write or Read R/Wsbit Enable =P2^2; //6800 mode Enable single Esbit Mcs =P2^3; //Master chip enable CS1sbit Scs =P2^4; //Slave chip enable CS2sbit Lcd_Rst=P2^5; //Lcm reset RSTvoid delay(unsigned int t) //延时子程序{unsigned int i,j;for(i=0;i<t;i++)for(j=0;j<10;j++);}void write_com(unsigned char cmdcode) //写指令{Di=0;RW=0;Lcd_Bus=cmdcode;delay(0);Enable=1;delay(0);Enable=0;}void write_data(unsigned char Dispdata) //写数据{Di=1;RW=0;Lcd_Bus=Dispdata;delay(0);Enable=1;delay(0);Enable=0;}void frame() // {unsigned char i;Mcs=1;Scs=1;write_com(Page_Add+0);write_com(Col_Add+0);for(i=0;i<64;i++) write_data(0x01);write_com(Page_Add+7);write_com(Col_Add+0);for(i=0;i<64;i++) write_data(0x80);for(i=0;i<8;i++){Mcs=1;Scs=1;write_com(Page_Add+i);write_com(Col_Add+63);write_data(0xff);Mcs=1;Scs=1;write_com(Page_Add+i);write_com(Col_Add+0);write_data(0xff);}}void Clr_Scr(){unsigned char j,k;Mcs=1;Scs=1;write_com(Page_Add+0);write_com(Col_Add+0);for(k=0;k<8;k++){write_com(Page_Add+k);for(j=0;j<64;j++)write_data(0x00);}}void Disp_Img(unsigned char code *img) //显示图片{unsigned char j,k;Clr_Scr();for(k=0;k<8;k++){Mcs=1;Scs=0;delay(10);write_com(Page_Add+k);write_com(Col_Add+0);for(j=0;j<64;j++) write_data(img[k*128+j]);Mcs=0;Scs=1; delay(10);write_com(Page_Add+k);write_com(Col_Add+0);for(j=64;j<128;j++) write_data(img[k*128+j]);}}void Disp_H_Line() //显示行线{unsigned char i,j;Mcs=1;Scs=1;write_com(Disp_On);write_com(Page_Add);write_com(Start_Line);write_com(Col_Add);for(j=0;j<8;j++){write_com(Page_Add+j);write_com(Col_Add+0);// write_com(Start_Line+0);for(i=0;i<64;i++)write_data(0x55);}}void Disp_V_Line() //显示列线{unsigned char i,j;write_com(Disp_On);write_com(Page_Add);write_com(Start_Line);write_com(Col_Add);for(j=0;j<8;j++){write_com(Page_Add+j);write_com(Col_Add+0);write_com(Start_Line+0);for(i=0;i<32;i++){write_data(0x00);write_data(0xff);}}}void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk) //行列显示{unsigned char j=0,i=0;for(j=0;j<2;j++){write_com(Page_Add+pag+j); //第3、4行write_com(Col_Add+col); //列选for(i=0;i<16;i++) write_data(hzk[16*j+i]);}}void init_lcd() //显示初始化{Lcd_Rst=0;delay(100);Lcd_Rst=1;delay(100);Mcs=1;Scs=1;delay(100);write_com(Disp_Off);write_com(Page_Add+0);write_com(Start_Line+0);write_com(Col_Add+0);write_com(Disp_On);}void Msg(int flg){Clr_Scr();frame();if(flg==0){ //显示“延安大学”Mcs=1;Scs=0;hz_disp16(3,32,yan);delay(4000);hz_disp16(3,48,an);delay(4000);Mcs=0;Scs=1;hz_disp16(3,0,da);delay(4000);hz_disp16(3,16,xue);delay(4000);}else if(flg==1){ //显示“测试完毕”Mcs=1;Scs=0;hz_disp16(3,32,ce);hz_disp16(3,48,shi);Mcs=0;Scs=1;hz_disp16(3,0,wan);hz_disp16(3,16,bi);}}void display_imge1(){Disp_Img(FirstPage);}void display_imge2(){Disp_Img(SecondPage);}字模数据#include <reg52.h>char code yan[]={0x02,0x22,0x72,0x2E,0xE2,0x00,0x04,0xE4,0x04,0x04,0xFC,0x42,0x42,0x42,0x00,0x00,0x40,0x23,0x14,0x08,0x17,0x20,0x20,0x47,0x44,0x44,0x47,0x44,0x44,0x44,0x44,0x00/*"延",0*/};char code an[]={0x80,0x90,0x8C,0x84,0x84,0xF4,0xA5,0x86,0x84,0x84,0x84,0x84,0x94,0x8C,0x84,0x00,0x80,0x80,0x80,0x40,0x47,0x28,0x28,0x10,0x28,0x24,0x43,0xC0,0x40,0x00,0x00,0x00/*"安",1*/};char code da[]={0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x7F,0xA0,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x01,0x06,0x08,0x30,0x60,0xC0,0x40,0x00/*"大",2*/};char code xue[]={0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00/*"学",3*/};char code ce[]={0x08,0x31,0x86,0x60,0x00,0xFE,0x02,0xF2,0x02,0xFE,0x00,0xF8,0x00,0x00,0xFF,0x00,0x04,0xFC,0x03,0x00,0x80,0x47,0x30,0x0F,0x10,0x67,0x00,0x07,0x40,0x80,0x7F,0x00,/*"测",0*/};char code shi[]={0x40,0x42,0xDC,0x08,0x00,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x12,0x1C,0x10,0x00,0x00,0x00,0x7F,0x20,0x10,0x20,0x20,0x1F,0x10,0x10,0x01,0x06,0x18,0x20,0x78,0x00,/*"试",0*/};char code wan[]={0x00,0x90,0x8C,0xA4,0xA4,0xA4,0xA5,0xA6,0xA4,0xA4,0xA4,0xA4,0x94,0x8C,0x04,0x00, 0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x70,0x00,0x00,/*"完",0*/};char code bi[]={0x00,0x00,0xFF,0x88,0x48,0x28,0x08,0x80,0x7F,0x88,0x88,0x88,0x84,0x84,0xE0,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,/*"毕",0*/};unsigned char code FirstPage[]={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,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,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,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,0x80,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x70,0xFC,0xFC,0x7C,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC0,0xF0,0xE0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF0,0xF0,0xC0,0x80,0xE0,0xFF,0xFF,0xFF,0xFF,0x78,0x78,0xF8,0xF0,0xE0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xF8,0xF8,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x06,0x3F,0x3F,0x9C,0x9C,0x3E,0x3C,0x38,0xF8,0xFC,0xFE,0xFE,0xFE,0xFE,0xFC,0xC0,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x7E,0xFF,0xE1,0x00,0xC0,0xF8,0xFC,0xFC,0xE4, 0xE2,0xC2,0xC2,0xE1,0xA1,0x33,0xF3,0xF3,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3B,0x38,0x38,0x1E,0x9F,0x87,0x81,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xC0,0xFF,0xFF,0xFF,0xFF,0xFB,0xF9,0xF8,0xF8,0xF8,0x78,0x78,0x30,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0xF8,0xFC,0xFF,0xFF,0x7F,0x3F,0x3F,0x1F,0x8F,0x8F,0xC3,0xC3,0xE3,0xE1,0xE1,0x31,0x31,0x73,0xE3,0xE3,0x7F,0x3F,0x00,0x00,0x00, 0x00,0x00,0x10,0x78,0xF8,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xDF,0xFF,0xBF,0xB3,0xB0, 0x99,0x9B,0x9F,0x9F,0x9F,0x9E,0x86,0x81,0x81,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x70,0x70,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0xF8,0xF8,0xF8,0xFF,0xBF,0x3F,0x3D,0xFC,0xFC,0xFC,0xFC,0x7F,0x1F,0x1F,0x1F,0x1E, 0x0F,0x0E,0x0E,0x1E,0x1F,0x0E,0x04,0x00,0x00,0x00,0x00,0x00,0x81,0x87,0xC7,0xE7, 0xFF,0xFF,0xFF,0xFF,0xFF,0x3F,0x1F,0x01,0x70,0xF0,0xF0,0xF0,0xF0,0xE0,0xC0,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x67,0xE3,0xE0,0xE0,0xE0,0xE1,0xE3, 0xF3,0xF8,0xFE,0xFF,0xFB,0xF0,0x70,0x70,0x70,0x70,0x60,0x00,0x00,0x00,0x00,0x00, 0x00,0x06,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x07,0x07,0x07,0x07,0x07,0x0F,0x0F,0x07,0x07,0x07,0x0F,0x0F,0x0F,0x0F,0x1F,0x1F,0x0F,0x0F,0x0F,0x07,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x0E,0x1E,0x1E,0x1E,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x07,0x07,0x07,0x07,0x0F,0x0F,0x1E,0x1E,0x3C,0x3C,0x18,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x07,0x07,0x07,0x07,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x07,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x1C,0x3C,0x3C,0x3C,0x3C,0x1F,0x0F,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,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,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,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,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,/*"C:\Documents and Settings\Administrator\桌面\延安大学字.bmp",0*/};unsigned char code SecondPage[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0x80,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0xC0,0xC0,0xC0,0xC0,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,0x01,0x03,0x03,0xC1,0xF1,0xFD,0xFF,0xDF,0xC7,0xC0,0x12,0xF3,0xF3,0xF3,0x03,0xFF,0xFF, 0xFF,0x41,0x41,0x41,0x41,0x00,0x00,0x00,0x00,0x00,0x1E,0x1E,0x1E,0x02,0x02,0x02,0xC2,0xF2,0xF2,0x73,0x23,0x03,0x02,0x02,0x02,0x02,0x02,0x3E,0x3E,0x3E,0x00,0x00, 0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0xFF,0xFF,0xFF,0xFF,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x78,0x78,0x78,0x78,0x8B,0x8B,0x8B,0x8A,0x88,0x89,0x8B,0x89,0x89,0x8C,0x8F,0x8F,0x8F,0x89,0x78,0x78,0x78,0x78,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,0x0C,0x1C,0xBC,0xF8,0xFE,0xFF,0x9F,0x81,0x20,0x3F,0x3F,0x3F,0x20,0x3F,0x3F, 0x3F,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x13,0x1F,0x3F,0x3F,0xB7,0xF3,0xE3,0xE3,0xF3,0xFF,0xFF,0x9F,0x87,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xC0,0xF0,0xF8,0x7E,0x3F,0x0F,0x0F,0x1F,0x7C,0xF8, 0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0xFC,0xFE,0xFE,0x17,0x13,0x13,0x11,0x11,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0xC0,0xC0,0x80, 0x00,0x06,0x07,0x07,0x03,0x01,0x81,0x81,0x83,0x83,0x83,0x83,0xC6,0xC6,0xC6,0x86,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x02,0x0E,0xCE,0xC6,0x07,0xC7, 0x83,0x03,0x03,0x01,0x01,0x80,0x81,0x01,0x03,0x03,0x07,0x87,0x87,0x02,0x00,0x00,0x00,0x02,0x07,0x07,0x87,0x83,0x81,0x81,0x80,0x80,0xC0,0xC0,0x80,0x80,0x80,0x80,0x81,0x81,0x03,0x07,0x07,0x03,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x07,0x07,0x07,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,0x80,0x80,0x80,0xFF,0xFF,0x8D,0x8D,0x8D,0x8C,0xFC,0xFC,0x8C,0x8C, 0x80,0x80,0x00,0x80,0x80,0x80,0xFF,0xFF,0x99,0x99,0x99,0x99,0xF8,0xF8,0x98,0x98,0x80,0x80,0x00,0x33,0x33,0xFF,0xFF,0x33,0x00,0x16,0x36,0xA6,0xFF,0xFF,0xC6,0x66,0x0C,0x00,0x00,0x00,0xA1,0xA1,0xAA,0xEA,0xFF,0xBF,0xAA,0xAA,0xFF,0xFF,0xAA,0xAA, 0xA1,0x81,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,0x01,0x19,0x19,0x0D,0x0D,0x07,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x07,0x05,0x0D,0x19,0x11,0x01,0x00,0x0C,0x0C,0x07,0x07,0x06,0x00,0x06,0x03,0x19,0x1F,0x0F,0x01,0x03,0x06,0x04,0x00,0x00,0x00,0x1F,0x1F,0x0C,0x06,0x06,0x00,0x0F,0x1F,0x18,0x18,0x18,0x1E,0x0C,0x00,0x00,0x00,0x10,0x10,0x1B,0x1B,0x0C,0x06,0x06,0x0C,0x8B,0x9B,0x18,0x10,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x00,0xC0,0xC0,0x00,0x00,0x00,0x80,0xC0,0x40,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,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0, 0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x18,0x18,0xF8,0xF9,0x03,0x00,0x01,0xF1,0xF1,0x31,0x31,0x31,0x3F,0x3F,0x00,0x00,0x00,0x30,0x18,0x3C,0x36,0xF3,0xF1,0x30,0x30,0x33,0xF7,0xFE,0x1C,0x38,0x10,0x00,0x00,0xFF,0xFF,0xD8,0xDF,0xDF,0x18,0x7F,0x7F,0xCB,0xFF,0xFF,0xCB,0x7F,0x7F,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,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,0x1F,0x1F,0x0C,0x06,0x00,0x0F,0x1F,0x18,0x18,0x18,0x18,0x1C,0x1C,0x00,0x00,0x08,0x18,0x0C,0x06,0x03,0x01,0x00,0x18,0x18,0x0F,0x07,0x00,0x00,0x00,0x00,0x18,0x0F,0x03,0x00,0x1F,0x1F,0x06,0x06,0x07,0x07,0x06,0x1F,0x1F,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,/*"C:\Documents and Settings\Administrator\桌面\乒乓球记分牌.bmp",0*/};/×××××××××××××××××××××××××××××××××××××××库函数.h××××××××××××××××××××××××××××××××××××××/ void delay(unsigned int t);void write_com(unsigned char cmdcode);void write_data(unsigned char Dispdata);void frame();void Clr_Scr();void Disp_Img(unsigned char code *img);void Disp_H_Line();void Disp_V_Line();void hz_disp16(unsigned char pag,unsigned char col, unsigned char code *hzk); void init_lcd();void Msg(int flg);void display_imge1(void);void display_imge2(void);。

12864液晶屏显示驱动程序

12864液晶屏显示驱动程序

//八位数据口是P0,RS是P1的0,RW是P1的1,en是P1的2,psb是P1的3#include"reg52.h"#define uint unsigned int#define uchar unsigned char/***********************************12864*************************************/ sbit rs=P1^0;sbit rw=P1^1;sbit en=P1^2;sbit psb=P1^3;#define uint unsigned int#define uchar unsigned charvoid busy(void){P0=0xff;rs=0;rw=1;en=1;while(P0&0x80);}void xie_zhi_ling(uchar dat){busy();rs=0;rw=0;en=1;P0=dat;en=0;}void xie_shu_ju(uchar dat){busy();rs=1;rw=0;en=1;P0=dat;en=0;}//1602初始化void lcd_init(){psb=1;xie_zhi_ling(0x30);xie_zhi_ling(0x0c);//开显示关光标xie_zhi_ling(0x01);//清屏xie_zhi_ling(0x06);//行数自加}void display_one_char(uchar L, uchar H, char num)//写入一个char{if(L<1)L=1;if(L>4)L=4;H=8*L+H-9+0x80;xie_zhi_ling(H); //发送地址码xie_shu_ju(num);}//显示num 其最大显示长度sizes固定长度小于等于5void display_uint(uint num,uchar L,uchar H)////显示num 前列后行无符号{uint sizes=1;while(sizes*10<=num){sizes=sizes*10;}xie_zhi_ling(8*L+H-9+0x80); //发送地址码while(sizes>=1){xie_shu_ju(num/sizes+48);num=num%sizes;sizes/=10;}}//显示num 其最大显示长度sizes固定长度小于等于5void display_int(int num,uchar L,uchar H)////显示num 前列后行{uint sizes=1;while(sizes*10<=num){sizes=sizes*10;}xie_zhi_ling(8*L+H-9+0x80); //发送地址码if(num<0){num=-num;xie_shu_ju(45); //显示符号-}else{xie_shu_ju(43); //显示符号+}while(sizes>=1){xie_shu_ju(num/sizes+48);num=num%sizes;sizes/=10;}}//显示num 其显示长度sizes固定void display_chars(char *num,uchar L,uchar H)////显示num 字符串(文字){xie_zhi_ling(8*L+H-9+0x80); //发送地址码while(*num!='\0'){xie_shu_ju(*num++);}}void display_long(long num,uchar L,uchar H,char sizes_b)////显示num 前行后列无符号{unsigned long sizes=1;uint i=1;while(sizes*10<=num){sizes=sizes*10;}xie_zhi_ling(8*L+H-9+0x80); //发送地址码if(num<0){num=-num;xie_shu_ju(45); //显示符号-}else{xie_shu_ju(43);; //显示符号+}while(sizes>=1){if(sizes_b==i-1){xie_shu_ju('.');//显示符号"."i++;continue;}i++;xie_shu_ju(num/sizes+48);num=num%sizes;sizes/=10;}}void display_long_int(long num,uchar L,uchar H)////??num ?? ?? ???{unsigned long sizes=1;while(sizes*10<=num){sizes=sizes*10;}xie_zhi_ling(8*L+H-9+0x80); //?????while(sizes>=1){xie_shu_ju(num/sizes+48);num=num%sizes;sizes/=10;}}//////////////////////////////////////////12864/////////////////////////////////////////////////// void main(void){psb=1;lcd_init();lcd_init();// Lcd initwhile(1){display_one_char(1, 2, 12);display_uint(1311,1,5);display_int(131,3,5);display_chars("kjdhv",2,1);display_long(873159,3,1,2); }}。

12864LCD驱动程序

12864LCD驱动程序

//----------------------------------------------------------------- // 名称: LGM12864LCD显示驱动程序(不带字库) //----------------------------------------------------------------- #include <pic.h>#include "LGM12864.h"//是否反相显示(白底黑字/黑底白字)INT8U Reverse_Display = 0;//----------------------------------------------------------------- // 等待液晶就绪//----------------------------------------------------------------- void Wait_LCD_Ready(){}//----------------------------------------------------------------- // 向LCD发送命令//----------------------------------------------------------------- void LCD_Write_Command(INT8U cmd){}//----------------------------------------------------------------- // 向LCD发送数据//----------------------------------------------------------------- void LCD_Write_Data(INT8U dat){}//----------------------------------------------------------------- // LCD初始化函数//----------------------------------------------------------------- void LCD_Initialize()RST = 0; __delay_ms(1); //复位LCDRST = 1; //恢复LCD正常工作LCD_Write_Command(0x30); __delay_ms(15); //基本指令操作LCD_Write_Command(0x01); __delay_ms(15); //清除显示LCD_Write_Command(0x06); __delay_ms(15); //光标移动方向LCD_Write_Command(0x0c); __delay_ms(15); //开显示,关光标,不闪烁}//-----------------------------------------------------------------//// 通用显示函数//// 从第P页第L列开始显示W个字节数据,数据在r所指向的缓冲// 每字节8位是垂直显示的,高位在下,低位在上// 每个8*128的矩形区域为一页// 整个LCD又由64x64的左半屏和64x64的右半屏构成//-----------------------------------------------------------------void Common_Show(INT8U P,INT8U L,INT8U W,INT8U *r){INT8U i;//显示在左半屏或左右半屏if( L < 64 ){}//全部显示在右半屏else{}}//-----------------------------------------------------------------// 显示一个8×16点阵字符//-----------------------------------------------------------------void Display_A_Char_8X16(INT8U P,INT8U L,INT8U *M)}//-----------------------------------------------------------------// 显示一个16×16点阵汉字//-----------------------------------------------------------------void Display_A_WORD(INT8U P,INT8U L,INT8U *M){}//-----------------------------------------------------------------// 显示一串16×16点阵汉字//-----------------------------------------------------------------void Display_A_WORD_String(INT8U P,INT8U L,INT8U C,INT8U *M) {}。

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;

128x64 LCD液晶显示屏接口定义和驱动程序

128x64 LCD液晶显示屏接口定义和驱动程序

DB7 X=0 DB0 ∫ PAGE1 DB7 X=1 ∷ ∷ ∷ ∷ DB0 ∫ PAGE6 DB7 X=7 DB0 ∫ PAGE7 DB7 X=8 4.设置列地址 CODE: R/W D/I DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 L L L H 列地址(0-63) 功能: DD RAM 的列地址存储在 Y 地址计数器中.读写数据对列地址有影响.在对 DD RAM 进行读写操作后.Y 地址自动加一. 5.状态检测 CODE: R/W D/I DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 H L BF L ON/OFF RST L L L L 功能:读忙信号标志位(BF).复位标志位(RST)以及显示状态位(ON/OFF). BF=H:内部正在执行操作, BF=L:空闲状态. RST=H:正处于复位初始化状态, RST=L:正常状态. ON/OFF=H:表示显示关闭, ON/OFF=L:表示显示开. 6.写显示数据 CODE: R/W D/I DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 L H D7 D6 D5 D4 D3 D2 D1 D0 功能:写数据到 DD RAM.DD RAM 是存储图形显示数据的.写指令执行后 Y 地址计数器自动 加 1.D7-D0 位数据为 1 表示显示.数据为 0 表示不显示.写数据到 DD RAM 前.要先执行[设置 页地址"及[设置列地址"命令. 7.读显示数据 CODE: RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 H H D7 D6 D5 D4 D3 D2 D1 D0 功能:从 DD RAM 读数据.读指令执行后 Y 地址计数器自动加 1.从 DD RAM 读数据前要先执 行[设置页地址" 及[设置列地址"命令. 六.接口时序 1.写操作时序 时序 1 4. 读操作时序 *************************************** ********************* 串行连接操作程序

STM32+lcd12864串行驱动

STM32+lcd12864串行驱动

/****************************************************************************** ****************名称:LCD12864-15B串行显示程序版本:V1.0功能:在显示屏任意位置显示内容软件协议:硬件环境: 主控STM32F103R8T6PB0->ENPB1->RWVCC->RS编写日期:20170812编写人员:NO WAY******************************************************************************* ********************更改日:更内容:更改人员:其它说明:******************************************************************************* ******************/#include "stm32f10x.h"#include "string.h"#include "delay.h"#include "lcd12864.h"int main(void){Delay_int();delay_ms(200);GPIO_Config2();Lcdint();while(1){LCD_Display(0,0,"什么问题导致!");LCD_Display(1,0,"时序不对!");LCD_Display(2,0,"少与了低四位");LCD_Display(3,0,"问题解决了!哈哈");//highlight(1,8,16,60);}}#include "lcd12864.h"char b;/*****LCD屏显示地址*****/uchar addr_tab[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行};/****************************************************************************** ** 函数名:GPIO_Config* 描述: IO配置* 输入:* 输出:* 返回:* 其它:******************************************************************************* /void GPIO_Config2(void){GPIO_InitTypeDef GPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin=RS|RW|EN;GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOB,&GPIO_InitStructure);}/****************************************************************************** ** 函数名:Writebyte* 描述:写一个字节函数* 输入:* 输出:* 返回:* 其它:******************************************************************************* /void Writebyte(u8 byte){int i;EN_L;for(i=0;i<8;i++){if(byte&0x80){RW_H;}else{RW_L;}byte=byte<<1;EN_L;EN_H;delay_us(700);}}/****************************************************************************** ** 函数名:Writebyte* 描述:写一个字节函数* 输入:* 输出:* 返回:* 其它:******************************************************************************* /void Writ(u8 cmd ,u8 data){char start_cmd=0,Hdata=0,Ldata=0;if(cmd==0){start_cmd=0xf8;}else{start_cmd=0xfa;}Hdata=data&0xf0;Ldata=(data<<4)&0xf0;Writebyte(start_cmd);Writebyte(Hdata);Writebyte(Ldata);}/****************************************************************************** ** 函数名:Lcdint* 描述:12864初始化程序* 输入:* 输出:* 返回:* 其它:******************************************************************************* /void Lcdint(void){delay_ms(2);Writ(0,0x30);Writ(0,0x0c);Writ(0,0x01);Writ(0,0x06);Writ(0,0x80);}/****************************************************************************** ** 函数名:LCD_Display* 描述:12864(带字库)显示函数* 输入: x,y,*s* 输出:* 返回:* 其它:******************************************************************************* /void LCD_Display(uchar x,uchar y,uchar *s){Writ(0,addr_tab[8*x+y]);while(*s>0){Writ(1,*s);s++;}}void highlight(char x,char y,char width,char mode ) {char i,j,flag=0x00;if(y>1){flag=0x08;y=y-2;}Writ(0,0x34);for(i=0;i<16;i++){Writ(0,0x80+(y<<4)+i);Writ(0,0x80+flag+x);for(j=0;j<width;j++){Writ(1,mode);}}Writ(0,0x36);Writ(0,0x30);}#ifndef _LCD12864_H#define _LCD12864_H#include "stm32f10x.h"#include "delay.h"#include "string.h"#define uint unsigned int#define uchar unsigned char#define RS GPIO_Pin_11#define RW GPIO_Pin_1#define EN GPIO_Pin_0#define RS_H GPIO_SetBits(GPIOB,RS)#define RS_L GPIO_ResetBits(GPIOB,RS)#define RW_H GPIO_SetBits(GPIOB,RW)#define RW_L GPIO_ResetBits(GPIOB,RW)#define EN_H GPIO_SetBits(GPIOB,EN)#define EN_L GPIO_ResetBits(GPIOB,EN)void GPIO_Config2(void);void Writebyte(u8 cmd);void Writ(u8 cmd ,u8 data);void Lcdint(void);void LCD_Display(uchar x,uchar y,uchar *s);void highlight(char x,char y,char width,char mode); #endif。

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

LCD12864(ST7920)串行驱动程序

LCD12864(ST7920)串行驱动程序
读写函数
0xf8为写命令的命令字;0xfa为写数据的命令字,这里用的是TI_F28027
在编写和调试过程中借鉴了一些网上的程序,在此表示感谢,
这里是已经调好的,在移植过程中,调试时注意先要通过示波器对函数
void send_data(Uint16 D_Ctrl,Uint16 D_data)
void send_data(Uint16 D_Ctrl,Uint16 D_data)
//LCD_CLK一个脉冲写一位
{
Uint16 i,j;
Uint16 temp;
//LCD_CS=1; //片选使能
GpioDataRegs.GPADAT.bit.GPIO16=1;
send_data (0xf8,y+j*2);
send_data (0xf8,x+i);
send_data (0xf8,0x30);
send_data (0xfa,data1);
send_data (0xfa,data1);
for(i=0;i<3;i++) // 串行数据的传送
{
if(i==0) //写第一个字节 格式1111 1ABC
{
temp=D_Ctrl;
}
if(i==1) //写第二个字节 第一次写 高四位放在第一次传送的高四位
{
temp=(D_data&0xf0);
功能:
实现在任意坐标写一个字
X列;Y行
===========================================================================*/
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

串行LCM12864驱动程序收藏.txt为什么我们在讲故事的时候总要加上从前?开了一夏的花,终落得粉身碎骨,却还笑着说意义。

串行LCM12864驱动程序收藏
//头文件
#include <AT89X52.h>
#include <string.h>
//引脚定义
sbit SID = P2^1; //数据
sbit SCLK = P2^2; //时钟
//函数声明
void lcm_w_word(unsigned char *str) ; //写字符例:lcm_w_word("您好!");
void lcm_w_test(bit start, unsigned char ddata); //(0,指令)(1,数据)
void lcm_w_byte(unsigned char bbyte); //写一个字节给lcm
void delaynms(unsigned int di); //延时
void lcm_init(void); //lcm初始化
void lcm_clr(void); //清屏
//初始化LCM
void lcm_init(void) {
delaynms(10); //启动等待,等LCM讲入工作状态
lcm_w_test(0,0x30); //8 位介面,基本指令集
lcm_w_test(0,0x0c); //显示打开,光标关,反白关
lcm_w_test(0,0x01); //清屏,将DDRAM的地址计数器归零
}
//写指令或数据(0,指令)(1,数据)
void lcm_w_test(bit start, unsigned char ddata) {
unsigned char start_data,Hdata,Ldata;
if(start==0)
start_data=0xf8; //0:写指令
else
start_data=0xfa; //1:写数据
Hdata=ddata&0xf0; //取高四位
Ldata=(ddata<<4)&0xf0; //取低四位
lcm_w_byte(start_data); //发送起始信号 delaynms(1); //延时是必须的
lcm_w_byte(Hdata); //发送高四位
delaynms(1); //延时是必须的
lcm_w_byte(Ldata); //发送低四位
delaynms(1); //延时是必须的
}
//发送一个字节(底层函数)
void lcm_w_byte(unsigned char bbyte) {
unsigned char i;
for(i=0;i<8;i++){
SID=bbyte&0x80; //取出最高位
SCLK=1;
SCLK=0;
bbyte<<=1; //左移
}
}
//延时(LCM占用)
void delaynms(unsigned int di) {
unsigned int da,db;
for(da=0;da<di;da++);
for(db=0;db<10;db++);
}
//清屏函数
void lcm_clr(void){
lcm_w_test(0,0x01);
}
//向LCM发送一个字符串,长度64字符之内。

//应用:lcm_w_word("您好!");
void lcm_w_word(unsigned char *str){
while(*str != '\0'){
lcm_w_test(1,*str);
*str++;
}
*str = 0;。

相关文档
最新文档