lcd12864c语言编程详解

合集下载

12864C程序及注释

12864C程序及注释

#include <avr/io.h>#include <util/delay.h>#define uchar unsigned char#define uint unsigned int#define LCD_data PORTAsbit LCD_RS =P2^5;//数据命令选择端:H为数据;L为命令sbit LCD_RW =P2^6;//读写选择端:H为读;L为写sbit LCD_EN =P2^7;//使能信号端:高脉冲完成操作sbit LCD_PSB =P2^4;//串并选择端:H为并行;L为串行sbit LCD_RST =P2^2; //复位,低电平有效sbit qq=P3^2;unsigned char code pic2[];uchar code dis1[]={"0123456789 "};uchar code IC_DA T2[]={" 白日依山尽,"//0x80" 黄河入海流。

"//0x90欲穷千里目," 欲穷千里目,"//0x88" 更上一层楼。

"//0x98};/********************************延时误差:每秒0.005秒*********************************/void delayms(uint z){uint i,j;for(i=z;i>0;i--)for(j=113;j>0;j--);}void delay(unsigned int m) //延时程序{unsigned int i,j;for(i=0;i<m;i++)for(j=0;j<10;j++);}/*******************************12864写命令函数RS=L、RW=L,EN高脉冲D0-D7指令码******************************/void L12864_writecmd(uchar cmd){LCD_RS=0;LCD_RW=0;LCD_EN=0;LCD_data=cmd;delayms(5);LCD_EN=1;delayms(5);LCD_EN=0;}/********************************12864初始化函数********************************/void L12864_init_1(){LCD_PSB=1;LCD_RST=0;delay(1);LCD_RST=1;L12864_writecmd(0x30);// 功能设定:基本功能,关图片显示L12864_writecmd(0x0c);//开显示,开游标L12864_writecmd(0x01);//清屏显示}/********************************************************************* 名称: 12864初始化函数***********************************************************************/void L12864_initi_2(void) //LCD显示图片(扩展)初始化程序{//delay(40); //大于40MS的延时程序LCD_PSB=1; //设置为8BIT并口工作模式delay(1); //延时LCD_RST=0; //复位delay(1); //延时LCD_RST=1; //复位置高delay(10);L12864_writecmd(0x36); //Extended Function Set RE=1: extended instruction//delay(100); //大于100uS的延时程序//L12864_writecmd(0x36,0); //Extended Function Set:RE=1: extended instruction set//L12864_writecmd(37); ////大于37uS的延时程序L12864_writecmd(0x3E); //EXFUNCTION(DL=8BITS,RE=1,G=1)//delay(100); //大于100uS的延时程序L12864_writecmd(0x01); //CLEAR SCREEN//delay(100); //大于100uS的延时程序}/***************************12864写数据函数RS=H、RW=L、EN高脉冲D0-D7数据信息**************************/void L12864_writedat(uchar dat){LCD_RS=1;LCD_RW=0;LCD_EN=0;LCD_data=dat;delayms(5);LCD_EN=1;delayms(5);LCD_EN=0;}/***********************12864设定初始显示位置***********************/void L12864_focuspos(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-1;L12864_writecmd(pos);}void L12864_displayline(uchar hang1, uchar hang2, uchar code *adder1) { uchar X,Y,i;X=hang1;Y=hang2;if(X==1) X=0x80;else if(X==2) X=0x90;else if(X==3) X=0x88;else if(X==4) X=0x98;L12864_writecmd(X);if(Y==1){for(i=0;i<16;i++){L12864_writedat(*adder1);adder1++;}}if(Y==2){for(i=0;i<16;i++)adder1++;for(i=16;i<32;i++){L12864_writedat(*adder1);adder1++;}}if(Y==3){for(i=0;i<32;i++)adder1++;for(i=32;i<48;i++){L12864_writedat(*adder1);adder1++;}}if(Y==4){for(i=0;i<48;i++)adder1++;for(i=48;i<64;i++){L12864_writedat(*adder1);adder1++;}}}void L12864_displaypage( uchar code *adder1){unsigned char i;L12864_writecmd(0x80);delay(100);for(i=0;i<32;i++){L12864_writedat(*adder1);adder1++;}L12864_writecmd(0x90);delay(100);for(i=32;i<64;i++){L12864_writedat(*adder1);adder1++;}}void L12864_displaypicture( uchar code *adder){int a,b;//*******显示上半屏内容设置for(a=0;a<32;a++) //{L12864_writecmd((0x80 + a)); //SET 垂直地址VERTICAL ADDL12864_writecmd(0x80); //SET 水平地址HORIZONTAL ADD for(b=0;b<16;b++){L12864_writedat(*adder);adder++;}}//*******显示下半屏内容设置for(a=0;a<32;a++) //{L12864_writecmd((0x80 + a)); //SET 垂直地址VERTICAL ADDL12864_writecmd(0x88); //SET 水平地址HORIZONTAL ADDfor(b=0;b<16;b++){L12864_writedat(*adder);adder++;}}}void main(){while(1){L12864_writecmd(0x01);delay(10);L12864_writecmd(0x30);delay(10);L12864_displayline(2,3,IC_DA T2);delayms(500);L12864_writecmd(0x01);L12864_writecmd(0x36);//L12864_displaypicture(pic2);//delayms(500);}}unsigned char code pic2[]={ /*-- 调入了一幅图像:C:\Users\Administrator\Desktop\889.bmp --*//*-- 宽度x高度=128x64 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xDC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xDE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x3F,0x80,0x01,0xCE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x7F,0xF0,0x01,0xCE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x0F,0xFF,0xFF,0x81,0xCE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xFF,0xF1,0xFF,0xC1,0xCF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x03,0xFF,0xE0,0x3F,0xF9,0xCF,0x00,0x00,0x3F,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xFC,0x00,0x01,0xFF,0xC7,0x00,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xE0,0x00,0x00,0x3F,0xFF,0x80,0x3F,0xFF,0xE0,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xE0,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xC0,0xF0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xE0,0x00,0x00,0x01,0xFF,0xFF,0xFF,0x00,0xF0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xF0,0x00,0x00,0x01,0xC7,0xFF,0xF0,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xF0,0x00,0x00,0x01,0xC7,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC7,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC7,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC7,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x01,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x03,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x03,0xC3,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x03,0x83,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x70,0x00,0x00,0x03,0x83,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x03,0x83,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x03,0x83,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x83,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x03,0x80,0x00,0x00,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x03,0x80,0x00,0x00,0x78,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x03,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0x00,0x07,0x03,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3C,0x00,0x00,0x07,0x03,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3F,0xFF,0x80,0x07,0x03,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0xFF,0xFF,0x07,0x03,0xFF,0xFF,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x3C,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xDC,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x80,0x00,0xFF,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x03,0x80,0x00,0x07,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x07,0x80,0x00,0x00,0x38,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xF7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x1F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x0F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x07,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x07,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};。

单片机制作的12864液晶万年历_C语言程序

单片机制作的12864液晶万年历_C语言程序

#include<reg52.H>#include<intrins.h>#include<math.h>////////////////////////////////////////DS18B20#define uchar unsigned char#define uint unsigned intsbit DQ = P1 ^ 0; // 定义DS18B20的单总线#define Lcd_Bus P0sbit LCD_RS=P2^7; //数据/命令选择sbit LCD_RW=P2^6; //读写控制sbit LCD_EN=P2^5; //片选信号#define LCD_DA TA P0 //8 bit数据线#define LOW 0#define HIGH 1//初始化指令#define CLEAR_SCREEN 0x01 //清屏指令:清屏且AC值为00H#define AC_INIT 0x02 //将AC设置为00H。

且游标移到原点位置#define CURSE_ADD 0x06 //设定游标移到方向及图像整体移动方向(默认游标右移,图像整体不动)#define FUN_MODE 0x30 //工作模式:8位基本指令集#define DISPLAY_ON 0x0c //显示开,显示游标,且游标位置反白#define DISPLAY_OFF 0x08 //显示关#define CURSE_DIR 0x14 //游标向右移动:AC=AC+1#define SET_CG_AC 0x40 //设置AC,范围为:00H~3FH#define SET_DD_AC 0x80#define FUN_MODEK 0x36 //扩展指令集,8位指令#define X1address 0x80 //上半屏X轴起始地址#define X2address 0x88 //下半屏X轴起始地址#define Y address 0x80 //Y轴起始地址#define Set_Column 0x40#define Set_Page 0xB8uchar code shu[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code xingqi[]="星期";uchar code hanzishu[]="一二三四五六日";unsigned char TempData = 0;double DS18B20Data;uint jiemian=0;//////////////////////////////////////////DS1302sbit DS1302_RST = P1^4;sbit DS1302_IO = P1^3;sbit DS1302_SCK = P1^2;unsigned char table[]={0X00,0X18,0X0c,0X15,0X06,0X01,0X0a};//0s 24min 12hour 14ri 5yue 5zhou 2010nianunsigned char data table1[7];//uchar code table2[]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};uchar code shuzi[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,};unsigned char aa,bb;uchar miaoge,miaoshi,fenge,fenshi,shige,shishi,rige,rishi,yuege,yueshi,zhou,niange,nianshi;uchar shezhinum=0;//unsigned char shi,ge;////////////////////////////////////////////////键盘扫描sbit key_mnue = P3^7;sbit key_jia = P2^0;sbit key_jian = P2^1;sbit key_enter= P2^2;uchar key_number=0;//int nian,yue,ri,shi,fen;/////////////////////////////////////////////////红外sbit HW_IRQ = P3 ^ 2; // 定义38KHz一体化红外接收头与CPU的连接unsigned char DT;static unsigned char data IRCode[3],IRCON,IRCON2;//////////////////////////////////////////////////蜂鸣器sbit BEEP =P1^1;/****************************************************************************** *************** 函数名称:DS18B20_Delay()* 功能:DS18B20软件延时专用* 入口参数:count 延时参数,值越大,延时越长* 出口参数:无******************************************************************************* **************/void DS18B20_Delay(uint count) //延时函数{while(count--);}/****************************************************************************** *************** 函数名称:DS18B20_Init()* 功能:DS18B20初始化* 入口参数:无* 出口参数:返回值为1则初始化成功* 返回值为0则初始化失败******************************************************************************* **************/uchar DS18B20_Init(void){uchar x = 0;DQ = 1; // DQ复位DS18B20_Delay(8); // 稍做延时DQ = 0; // 单片机将DQ拉低DS18B20_Delay(80); // 精确延时,大于480usDQ = 1; // 拉高总线DS18B20_Delay(14); // 稍做延时后x = DQ; // 若x=0则初始化成功,若x=1则初始化失败DS18B20_Delay(20);return (~x);}/****************************************************************************** *************** 函数名称:DS18B20_Read1Byte()* 功能:从DS18B20读一个字节* 入口参数:无* 出口参数:从DS18B20读出的一个字节******************************************************************************* **************/uchar DS18B20_Read1Byte(void){uchar i = 0;uchar dat = 0;for(i=8;i>0;i--){DQ = 0; // 给脉冲信号dat >>= 1;DQ = 1; // 给脉冲信号if(DQ) dat |= 0x80;DS18B20_Delay(4);}return (dat);}/****************************************************************************** *************** 函数名称:DS18B20_Write1Byte()* 功能:向DS18B20写一个字节* 入口参数:dat 要写入DS18B20的一字节数据* 出口参数:无******************************************************************************* **************/void DS18B20_Write1Byte(uchar dat){uchar i = 0;for(i=8;i>0;i--){DQ = 0;DQ = dat&0x01;DS18B20_Delay(5);DQ = 1;dat>>=1;}}/****************************************************************************** *************** 函数名称:Read_Disp_Temperature()* 功能:读取并显示温度* 入口参数:无* 出口参数:无******************************************************************************* **************/double Read_Disp_Temperature(void){uint a = 0, b = 0, c = 0,d = 0,e = 0, t = 0;double tt = 0;DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0x44); // 启动温度转换DS18B20_Init();DS18B20_Write1Byte(0xCC); // 跳过读序号列号的操作DS18B20_Write1Byte(0xBE); // 读取温度寄存器a = DS18B20_Read1Byte();b = DS18B20_Read1Byte();t = b;t <<= 8;t = t | a;//tt = t * 0.0625;return t;}//***************************************************************** //函数名称:delay(uint t)延时函数。

12864液晶经典驱动程序,一看就懂,有详细的注释(C语言编写,不看后悔)

12864液晶经典驱动程序,一看就懂,有详细的注释(C语言编写,不看后悔)

这个程序写得很好,自己也是看的别人写的很好的程序,但是它代码不够完整,注释不详细,经过自己的修改加以完善。

另外我发现很多的测试代码都没有附上测试代码效果图,在本人的代码下面有自己拍的效果图,填补不足之处。

自己在找资料的过程中花掉很多的财富值,如果大家看得起该代码请评五分加以下载,在下感激不尽!/*******************************************程序名称:12864液晶经典驱动程序(带中文字库)功能:12864测试程序修改作者:王程修改时间:2014年2月5日23:22:32********************************************/#include<reg52.h>#define uchar unsigned char#define uint unsigned int// P0 为数据口sbit LCD_RS=P2^0; //数据、命令选择端口sbit LCD_RW=P2^1; //液晶读写控制sbit LCD_EN=P2^2; //液晶使能控制sbit PSB = P2^4; //模式选择1为并行0为串行sbit RES = P2^5;//复位端口低电平复位,上电之前进行复位,为了稳定!unsigned char code DAT[] = "我爱我家"; //测试显示的汉字,下面的A为测试显示的英文/*******************************************函数名称:Delay_1ms (晶振为12M)功能:延时约1ms的时间参数:无返回值:无********************************************/void delay_1ms(uint x){uint i,j;for(j = 0;j < x;j++)for(i=0;i<110;i++);}/*******************************************函数名称:write_cmd功能:向液晶中写控制命令参数:cmd--控制命令返回值:无********************************************/void write_cmd(uchar cmd){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式,精简{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RW=0;P0 = cmd;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:write_data功能:向液晶中写显示数据参数:dat--显示数据返回值:无********************************************/ void write_data(uchar dat){uchar lcdtemp = 0;LCD_RS=0;LCD_RW=1;do //经典判忙方式{LCD_EN=1;delay_1ms(2);lcdtemp = P0;LCD_EN=0;}while(lcdtemp & 0x80);LCD_RS=1;LCD_RW=0;P0 = dat;LCD_EN=1;delay_1ms(5);LCD_EN=0;}/*******************************************函数名称:lcd_int功能:初始化液晶模块参数:无返回值:无********************************************/void lcd_int(void){delay_1ms(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delay_1ms(1); //延时RES=0; //复位delay_1ms(1); //延时RES=1; //复位置高delay_1ms(10);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x30); //基本指令集delay_1ms(5);write_cmd(0x08); // 地址归位delay_1ms(5);write_cmd(0x10); //光标设置delay_1ms(5);write_cmd(0x0c); //整体显示打开,游标关闭delay_1ms(5);write_cmd(0x01); //清除显示delay_1ms(5);write_cmd(0x06); //游标右移delay_1ms(5);write_cmd(0x80); //设定显示的起始地址delay_1ms(5);}函数名称:main功能:测试1602初始化函数模块参数:无返回值:无********************************************/void main(){uchar i;char *a = DAT;//使用指针,指向字符串地址lcd_int();write_data('A'); //每个显示都是用的两个字节,必须写两次write_data(' ');//再写一次,不然乱显示(如果不加就再显示一个别的字母)for(i=0;i<8;i++){write_data(*a);//将地址当作数据传给12864a++;//一个汉字传送两次,因为一个汉字占用两个字节,两次传完}write_cmd(0x90);//一行显示八个汉字,第一行0x80-87,第二行0x90开始a = DAT;for(i=0;i<8;i++){write_data(*a);a++;}while(1); //停住,不然重复的初始化显示,作为测试用}/*******************************************代码测试效果图片两两张由于曝光度影响,拍了两张********************************************/。

12864LCD串行操作C程序

12864LCD串行操作C程序

12864LCD串行控制C程序下面是一个最简单的12864液晶串行控制程序,没什么花样,只是想帮助大家学习掌握控制一个串行的12864液晶的基本原理。

无论是12864的并行操作还是串行操作,12864液晶与12232液晶的操作时序几乎完全一样,打家学习的时候可以参考一下12232的时序图(方便理解),郭天祥的《51单片机C语言教程》156页中就讲到了12232液晶的使用例程。

一、时序图1、12232时序图2、12864时序图二、液晶引脚对应图三、12864液晶与单片机接口(程序中PSB没接,RST接高电平,NC悬空)四、程序:#include<reg52.h>#define uint unsigned int#define uchar unsigned charsbit CS=P2^6;//片选信号线,接12864的RS端sbit SID=P2^5;//串行数据线,接12864的RW端sbit SCLK=P2^7;//串行时钟信号线,接12864的EN端//uchar a;uchar code word[]={"我好喜欢你啊"};//12864LCD显示内容//函数声明void lcd_init();//声明液晶初始化函数void write_com(uchar com);//声明'写入命令控制字节'函数void write_date(uchar dat);//声明'写入数据控制字节'函数void delayms(uint x);//声明延时函数//液晶初始化函数void lcd_init(){delayms(10);write_com(0x30);//基本指令操作write_com(0x0c); //显示开,关光标write_com(0x10);//设置地址计数器AC为00H,并将游标移到开头原点位置write_com(0x06);//游标及显示右移一位write_com(0x01);//清除液晶显示内容}//向12864写入命令函数/* 串行数据由三个字节构成,第一个为命令控制字节,第二个为由命令字节高四位低四位补零构成的字节,第三个为由命令字节低四位左移四位低四位补零后构成的字节*/void write_com(uchar com){uchar i;uchar i_data;i_data=0xf8;//0xf8是命令控制字节,它比表示写入的内容com是一个命令CS=1;//写入之前令片选信号CS为1(这是时序要求的)SCLK=0;//写入之前令时钟信号CLK为1(这也是时序要求的)for(i=0;i<8;i++)//写入命令控制字节{SID=(bit)(i_data&0x80);SCLK=1;SCLK=0;i_data=i_data<<1;}i_data=com;i_data&=0xf0;for(i=0;i<8;i++)//写入命令的高四位{SID=(bit)(i_data&0x80);//取得命令的最高位给液晶串行总线SCLK=1;SCLK=0; //每写一位SCLK都要有一个下降沿(时序要求)i_data=i_data<<1; //命令字节左移一位(取命令的次高位给液晶串行总线)}i_data=com;i_data<<=4;//命令字节左移4位,即把低四位移到高四位for(i=0;i<8;i++)//写入命令的低四位{SID=(bit)(i_data&0x80);//取得命令字节移位后的最高位给液晶串行总线SCLK=1;SCLK=0;i_data=i_data<<1; //移位后命令字节左移一位(每一次移位前的次高位给液晶串行总线)}CS=0; //写入命令控制字节后令片选信号CS为0delayms(10);}//向12864写入数据函数void write_date(uchar dat){uchar i;//第三个为由数据低四位左移四位后低四位补零构成的字节uchar i_data;i_data=0xfa;//(数据控制字节为0xfa)CS=1;SCLK=0;for(i=0;i<8;i++)//写入数据控制字节{SID=(bit)(i_data&0x80);//取得数据控制字节的最高位给液晶串行总线SCLK=1;SCLK=0;//每写一位SCLK都要有一个下降沿(时序要求)i_data=i_data<<1;//数据控制字节左移一位(取命令控制字节的次高位给液晶串行总线)}i_data=dat;i_data&=0xf0;//取数据字节的高四位for(i=0;i<8;i++)//写入数据的高四位{SID=(bit)(i_data&0x80);//(以下跟写入命令函数的注释同理)SCLK=1;SCLK=0;i_data=i_data<<1;}i_data=dat;i_data<<=4;for(i=0;i<8;i++)//写入数据的低四位{SID=(bit)(i_data&0x80);SCLK=1;SCLK=0;i_data=i_data<<1;}CS=0;delayms(10);}//延时函数void delayms(uint x) //延时x ms{uint i,j;for(j=x;j>0;j--)for(i=110;i>0;i--);}//主函数void main(){uchar b; //定义计算写入显示内容数量的变量lcd_init(); //初始化液晶write_com(0x90); //写入显示位置for(b=0;b<12;b++) //b要12是因为要显示6个中文{write_date(word[b]); //写入要显示的内容}while(1);}。

12864图形液晶显示器c程序

12864图形液晶显示器c程序

lcd12864图形液晶显示器c程序#define _LCD12864_E//#include"lcd12864.h"#include"dtype.h"#include<reg52.h>sbit lcd_rw=P2^0;sbit lcd_rs=P2^1;sbit lcd_cs2=P2^2;sbit lcd_cs1=P2^3;sbit lcd_e=P3^0;sbit lcd_busy=P0^7;INT8U lcd_page_grobal,lcd_line_grobal; /** 函数名称:lcd_LScreen()* 函数功能:选择显示屏的左半屏*/ void lcd_LScreen(){lcd_cs2=0;lcd_cs1=1;}/** 函数名称:lcd_RScreen()* 函数功能:选择显示屏的右半屏*/ void lcd_RScreen(){lcd_cs1=0;lcd_cs2=1;}/** 函数名称:lcd_ChkBusy()* 函数功能:查询忙状态*/void lcd_ChkBusy(){while(lcd_busy){lcd_e=0;lcd_rs=0;lcd_rw=1;P0=0xff;lcd_e=1;lcd_e=0;}}/* 函数名称:lcd_WriteCmd()* 函数功能:写命令cmd--待写命令*/void lcd_WriteCmd(const INT8U cmd){lcd_ChkBusy();lcd_rs=0;lcd_rw=0;P0=cmd;lcd_e=1;lcd_e=0;}/* 函数名称:lcd_WriteData()* 函数功能:写数据dat--待写数据*/void lcd_WriteData(const INT8U dat){lcd_ChkBusy();lcd_rs=1;lcd_rw=0;P0=dat;lcd_e=1;lcd_e=0;}/* 函数名称:lcd_StartLine()* 函数功能:设定起始行line--列号* 说明:用户需自己保证行号的有效性*/ void lcd_StartLine(INT8U line){INT8U tmp;tmp=line;tmp=tmp|0x40;lcd_WriteCmd(tmp);}/* 函数名称:lcd_StartPage()* 函数功能:设定起始页* 入口参数:page--页号* 说明:用户需自己保证页号的有效性*/ void lcd_StartPage(INT8U page){INT8U tmp;tmp=page;tmp|=0xb8;lcd_WriteCmd(tmp);}/* 函数名称:lcd_Ready()* 函数功能:显示屏初始化*/void lcd_Ready(){INT8U i,j;lcd_LScreen();lcd_WriteCmd(0x3f); //开显示lcd_RScreen();lcd_WriteCmd(0x3f); //开显示lcd_LScreen();for(i=0;i<8;i++){lcd_StartPage(i);lcd_StartLine(0);for(j=0;j<64;j++){lcd_WriteData(0);}}lcd_RScreen();for(i=0;i<8;i++){lcd_StartPage(i);lcd_StartLine(0);for(j=0;j<64;j++){lcd_WriteData(0);}}}/** 函数名称:lcd_Display(INT8U *ptr) * 函数功能:16*16显示* 入口参数:*ptr--图片数据指针lcd_page_grobal--页地址lcd_line_grobal--列地址调用方法:lcd_page_grobal=xx;lcd_line_grobal=xx;ptr=&picture;lcd_Ready();lcd_Display(ptr);*/void lcd_Display(INT8U *ptr){INT8U i,j;lcd_StartPage(lcd_page_grobal);lcd_StartLine(lcd_line_grobal);for(i=0;i<16;i++){lcd_WriteData(*ptr);ptr++;}lcd_StartPage(lcd_page_grobal+1);lcd_StartLine(lcd_line_grobal);for(j=0;j<16;j++){lcd_WriteData(*ptr);ptr++;}}void main( void ){lcd_page_grobal=xx;lcd_line_grobal=xx;ptr=&picture;lcd_Ready();lcd_Display(ptr);}。

LCD12864显示中文及图片C程序

LCD12864显示中文及图片C程序

/****************************************屏幕显示驱动*****************************************/#include "GT23L24T3Y.h"#include "print.h"#include <stdio.h>#include <string.h>#include "bmp_picture.h"#include "lcd_12864.h"#include "..\user\rtc.h"u8 comTable[]={4,5,6,7,3,2,1,0};extern void Setlcd_Addr ( u8 row,u8 column );//外部函数调用声明extern u8 Num_Code[];//字库获得函数extern u8 Big_Num_Code[];//字库获得函数extern u8 Picture_Code[];//字库获得函数extern u8 arrow1[];extern u8 arrow2[];u8 testlcd[]="测试数据";/************************************************************************//显示中文输出//函数名:print_16//功能:显示16x16点阵字符串。

// 函数名:print_16// 功能:显示16点阵字符串// 形参:// row:x轴// column:y轴// *lcd:显示字符串// logic:显示取反// wei.显示位值// len长度*************************************************************************/void _print_15 ( u8 row,u8 column,const char *lcd,u8 logic ,u8 wei,u8 len){u8 w=0,x=0,y=0,l=0,read_data=0;u8 Length=0;GT_cs1;//字库片选至高for ( l=len; l>0; l=l-2 ) //总字节{w=*lcd;if ( w&0x80 ) //为1则为汉字,为0则为ASCII码{GT_cs0; //字库片选选定GT23_Write ( GT23_write_15 ( lcd ) ); //写入字库指令以及文字地址for ( x=0; x<2; x++ ){Setlcd_Addr (row,column);for(y=0;y<16;y++){read_data=GT23_Read();if(logic == true){// read_data = ~read_data;}WriteData(read_data );}row++;}GT_cs1;//字库片选至高row-=2;column+=16;if(column>=128){row+=2;column=0;}lcd=lcd+2;}}}/************************************************************************//描述:显示中文输出//使用:顶层函数调用参数:row 行column 列*lcd 字符串logic 反白*************************************************************************/ void print_15 ( u8 row,u8 column,const char *lcd,u8 logic ){u8 c=strlen ( lcd );_print_15(row,column,lcd,logic,0,c);}/************************************************************************ //描述:显示图片输出//使用:顶层函数调用参数:row 行column 列*lcd 字符串logic 反白*************************************************************************/ void print_array(u16 row,u16 column,u16 size_x,u16 size_y,const u8 *ptr, u8 logic){u8 w=0,x=0,y=0,l=0,read_data=0;u8 Length=0;for( x=0;x<size_x/8;x++){Setlcd_Addr (row,column);for(y=0;y<size_y;y++){read_data=*( ptr + (y+x*size_y) );if(logic == true){read_data = ~read_data;}WriteData1(read_data);// WriteData1(0XFF);}row++;}}u8 OpMgsCode[][10] ={"病人信息","循环播放","房号与床号","从机音量","对比度","广播""恢复","音乐","主机音量","时间"};u8 DayCode[][7]={"星期天","星期一","星期二","星期三","星期四","星期五","星期六"};void PrintMainFace(time mytime,u8 PeopleNum){//待机界面函数u8 Hrd,Ten,One;Lcd_Clr();//清屏print_15 ( 0,16, "月",false );print_15 ( 0,48, "日",false );print_15 ( 0,70, &DayCode[mytime.day][0],false );//显示星期//日期显示Ten=mytime.month/10;One=mytime.month%10;print_array(0 , 0, 16 , 7 , &Num_Code[Ten*14], false);print_array(0 , 8, 16 , 7 , &Num_Code[One*14], false);Ten=mytime.date/10;One=mytime.date%10;print_array(0 , 32, 16 , 7 , &Num_Code[Ten*14], false);print_array(0 , 40, 16 , 7 , &Num_Code[One*14], false);//时间显示Ten=mytime.hour/10;One=mytime.hour%10;print_array(2 , 20, 32 , 21 , &Big_Num_Code[Ten*84], false);print_array(2 , 42, 32 , 21 , &Big_Num_Code[One*84], false);Ten=mytime.minute/10;One=mytime.minute%10;print_array(2 , 68, 32 , 21 , &Big_Num_Code[Ten*84], false);print_array(2 , 90, 32 , 21 , &Big_Num_Code[One*84], false);//住院人数显示print_15 ( 6,32, "住院人数",false );Hrd=PeopleNum/100;PeopleNum=PeopleNum%100;Ten=PeopleNum/10;One=PeopleNum%10;if(Hrd ){print_array(6 , 96, 16 , 7 , &Num_Code[Hrd*14], false);}print_array(6 , 102, 16 , 7 , &Num_Code[Ten*14], false);print_array(6 , 110, 16 , 7 , &Num_Code[One*14], false);}void PrintPictureFace(u8 Index){time mytime;Lcd_Clr();//清屏mytime.month = 10;mytime.date = 16;mytime.hour = 12;mytime.minute = 15;mytime.day =3;PrintMainFace(mytime,96);//print_array(0 , 10, 48 , 8 , arrow1, false);//左箭头显示// print_array(0,38 ,48 ,48 , &Picture_Code[288*Index], false);//图片显示// print_array(0,108, 48 , 8 , arrow2, false); //右箭头显示//print_15 ( 6,33, &OpMgsCode[0][Index],false );//提示信息显示}。

LCD12864串行显示文件

LCD12864串行显示文件

LCD12864串行显示文件1、LCD12864.c文件//===================================== ==========================#include "LCD12864.h"#include/**** 串行控制 *****************/sbit RS = P1^0;sbit RW = P1^1;sbit EN = P1^2;/*-----LCD12864相关声明---------*/#define com_byte 0#define dat_byte 1uchar lcdPosX, lcdPosY; //X,Y坐标uchar halfScr, halfLineCnt, basicBlock; //半屏,半屏行数,N*8块/************************************************************** 函数名称:void LCD12864_Delay_Ms (uchar ms)函数功能: LCD12864延时函数**************************************************************/ void LCD12864_Delay_Ms (uchar ms){uchar i;while (--ms){for (i = 0; i < 125; i++);}/************************************************************** 函数名称:void LCD12864_Write_Byte(uchar byte)函数功能: 写字节**************************************************************/ void LCD12864_Write_Byte(uchar byte){uchar i;for(i = 0; i < 8; i++){EN = 0;byte <<= 1;RW = CY;EN = 1;}}/************************************************************** 函数名称:uchar LCD12864_Read_Byte(void)函数功能: 读字节*************************************************************** /uchar LCD12864_Read_Byte(void){uchar i,temp1,temp2;temp1 = 0;temp2 = 0;for(i = 0; i < 8; i++)temp1 = temp1 << 1;EN = 0;EN = 1;EN = 0;if(RW) temp1++;}for(i=0;i<8;i++){temp2=temp2<<1;EN = 0;EN = 1;EN = 0;if(RW) temp2++;}return ((0xf0 & temp1) + (0x0f & temp2));}/************************************************************** 函数名称:void LCD12864_Is_Busy( void )函数功能: 检测忙函数**************************************************************/ void LCD12864_Is_Busy( void ){doLCD12864_Write_Byte(0xfc); //11111,RW(1),RS(0),0while(0x80 & LCD12864_Read_Byte());}/**************************************************************函数名称:void LCD12864_Write(bit dat_byte_com_byte,uchar byt)函数功能: 写入函数*************************************************************** /void LCD12864_Write(bit dat_byte_com_byte, uchar byt){uchar temp;if(dat_byte_com_byte == 0) //为零,写入指令temp = 0xf8; //11111,RS(0),RW(0),0else //否则,写入数据temp = 0xfa; //11111,RS(1),RW(0),0RS = 1;LCD12864_Is_Busy();LCD12864_Write_Byte(temp);LCD12864_Write_Byte(byt & 0xf0); //写入高四位LCD12864_Write_Byte(byt << 4); //写入低四位RS = 0;}/************************************************************** 函数名称:void LCD12864_Clear_Display (void)函数功能: LCD12864 显示清屏*************************************************************** /void LCD12864_Clear_Display (void){LCD12864_Write(com_byte,0x01);}/**************************************************************函数名称:void LCD12864_Write_Position (void)函数功能: LCD12864 显示位置*************************************************************** /void LCD12864_Write_Position (void){LCD12864_Write(com_byte,0x34);LCD12864_Write(com_byte,lcdPosY);LCD12864_Write(com_byte,lcdPosX);LCD12864_Write(com_byte,0x30);}/************************************************************** 函数名称:void LCD12864_DisplayPhoto (uchar *bmp, uchar bmpCls)函数功能: LCD12864 显示一张图片*************************************************************** /void LCD12864_DisplayPhoto (uchar *bmp, uchar bmpCls) {lcdPosX = 0x80;halfScr = 2;for (; halfScr != 0; halfScr--){lcdPosY = 0x80;halfLineCnt = 32;for (; halfLineCnt != 0; halfLineCnt--){basicBlock = 16;LCD12864_Write_Position();for (; basicBlock != 0; basicBlock--){if (bmpCls == 0){LCD12864_Write(dat_byte, *bmp++);}else if (bmpCls == 1){LCD12864_Write(dat_byte, 0x00);}}lcdPosY++;}lcdPosX = 0x88;}LCD12864_Write(com_byte, 0x36);LCD12864_Write(com_byte, 0x30);}/************************************************************** 函数名称:void convertChar (uchar CX, CY, width)* 字符反白显示* 输入参数:CX=要反白字符的行(0-3)* CY=要反白字符的列(0-7)* width=要反白字符的长度(1-16)函数功能: 转换成字符*************************************************************** /void convertChar (uchar CX, CY, width){LCD12864_DisplayPhoto(0,1);lcdPosY = 0x80;if (CX == 0){CX = 0x80;halfLineCnt = 16;}else if (CX == 1){CX = 0x80;halfLineCnt = 32;}else if (CX == 2){CX = 0x88;halfLineCnt = 16;}else if (CX == 3){CX = 0x88;halfLineCnt = 32;}lcdPosX = CX + CY;for (; halfLineCnt != 0; halfLineCnt--){basicBlock = width;LCD12864_Write_Position();for (; basicBlock != 0; basicBlock--){if (halfLineCnt > 16){LCD12864_Write(dat_byte, 0x00);}else{LCD12864_Write(dat_byte, 0xff);}}lcdPosY++;}LCD12864_Write(com_byte, 0x36);LCD12864_Write(com_byte, 0x30);}/************************************************************** 函数名称:void LCD12864_Display_String(uchar X, uchar Y, uchar speed, uchar *msg)函数功能: LCD12864 显示字符串/void LCD12864_Display_String(uchar X, uchar Y, uchar speed, uchar *msg){if (X == 0){X = 0x80;}else if (X == 1){X = 0x90;}else if (X == 2){X = 0x88;}else if (X == 3){X = 0x98;}Y = X + Y;LCD12864_Write(com_byte, Y);while (*msg){LCD12864_Write(dat_byte, *msg++);LCD12864_Delay_Ms(speed);}}函数名称:void init_12864(void)函数功能:初始化12864*************************************************************** /void init_12864(void){LCD12864_Write(com_byte, 0x30); //基本指令功能.LCD12864_Write(com_byte, 0x0c); //显示打开,关光标,反白关.LCD12864_Write(com_byte, 0x01); //清屏指令.LCD12864_Write(com_byte, 0x06); //AC自动加一LCD12864_Write(com_byte, 0x80);}2、LCD12864.h文件//===================================== ==========================#ifndef __LCD12864_H__#define __LCD12864_H__#define uchar unsigned char#define uint unsigned int/************************************************************** 函数名称:void LCD12864_Write(bit dat_byte_com_byte,uchar byt)函数功能: 写入函数*************************************************************** /void LCD12864_Write(bit dat_byte_com_byte, uchar byt);/************************************************************** 函数名称:void LCD12864_Clear_Display (void)函数功能: LCD12864 显示清屏*************************************************************** /void LCD12864_Clear_Display (void);/************************************************************** 函数名称:void LCD12864_Write_Position (void)函数功能: LCD12864 显示位置*************************************************************** /void LCD12864_Write_Position (void);/************************************************************** 函数名称:void LCD12864_DisplayPhoto (uchar *bmp, uchar bmpCls)函数功能: LCD12864 显示一张图片*************************************************************** /void LCD12864_DisplayPhoto (uchar *bmp, uchar bmpCls);/************************************************************** 函数名称:void LCD12864_Display_String(uchar X, uchar Y, uchar speed, uchar *msg)函数功能: LCD12864 显示字符串*************************************************************** /void LCD12864_Display_String(uchar X, uchar Y, uchar speed, uchar *msg);/************************************************************** 函数名称:void init_12864(void)函数功能:初始化12864*************************************************************** /void init_12864(void);#endif。

LCD12864画点,画线,定点写入等子函数

LCD12864画点,画线,定点写入等子函数

#define LCD12864_GLOBAL#include"lcd12864.h"void delay_10us(unsigned char del){while(del--){_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}}///////////////////////////////////////读忙函数//操作方式RS>L RW>H E>低脉冲//输入://输出:忙标志1:忙0:闲/////////////////////////////////////void Lcd12864_ChkBusy(void){RS = 0;RW = 1;E = 1;L_PORT = 0XFF;while((L_PORT & 0X80) == 0X80); //忙了,则等待E = 0;}///////////////////////////////////////写指令//操作方式RS>L RW>H E>高电平//输入://输出://///////////////////////////////////void Lcd12864_WrCom(uchar com){Lcd12864_ChkBusy();RS = 0;RW = 0;E = 1;L_PORT = com;delay_10us(1);E = 0;}///////////////////////////////////////写数据//操作方式RS>L RW>H E>高电平//输入:写入数据//输出://///////////////////////////////////void Lcd12864_WrData(uchar dat){Lcd12864_ChkBusy();RS = 1;RW = 0;E = 1;L_PORT = dat;delay_10us(1);E = 0;}///////////////////////////////////////字库初始化函数//输入://输出://///////////////////////////////////void Lcd12864_WordInit(void){PSB = 1; //8位并行数据传输方式RET = 0; //复位函数delay_10us(1); //延时下RET = 1; //复位无效Lcd12864_WrCom(0x30);Lcd12864_WrCom(0x30);Lcd12864_WrCom(0x0c);Lcd12864_WrCom(0x01);Lcd12864_WrCom(0x06);}///////////////////////////////////////定位写入字符串函数//输入:参数1:行(1~4),参数2:列(0~7)参数3,字符串参数4,写入字节数//输出://///////////////////////////////////void Lcd12864_WrString(uchar x,uchar y,uchar *str,uchar num){uchar i;y = y % 7 ; //舍去大于八的数据switch(x){case 1:Lcd12864_WrCom(0x80 + y);break;case 2:Lcd12864_WrCom(0x90 + y);break;case 3:Lcd12864_WrCom(0x88 + y);break;case 4:Lcd12864_WrCom(0x98 + y);break;default:Lcd12864_WrCom(0x80 + y);}for(i = 0;i < num;i ++){Lcd12864_WrData(*str++); //写入对应点的数据}}///////////////////////////////////////图片初始化函数//输入://输出://///////////////////////////////////void Lcd12864_PhotoInit(void){PSB = 1; //8位并行数据传输方式RET = 0; //复位函数delay_10us(1); //延时下RET = 1; //复位无效Lcd12864_WrCom(0x36);Lcd12864_WrCom(0x36);Lcd12864_WrCom(0x3e);Lcd12864_WrCom(0x01);}///////////////////////////////////////图片打印函数//输入:图片数组的指针//输出://///////////////////////////////////void Lcd12864_PhotoPrint(uchar *photo){uchar i,j,k;for(i = 0;i < 2;i ++)for(j = 0;j < 32;j ++){Lcd12864_WrCom(0x80 + j); //纵坐标if(i == 0){Lcd12864_WrCom(0x80); //上半屏}else{Lcd12864_WrCom(0x88); //下半屏}for(k = 0;k < 16;k ++){Lcd12864_WrData(*photo ++ );}}}///////////////////////////////////////清楚GDRAM函数//输入://输出://///////////////////////////////////void Lcd12864_ClrGdRam(void){uchar x,y;for(y = 0;y < 64;y ++)for(x = 0;x < 16;x ++){Lcd12864_WrCom(0x34); //开指令扩充Lcd12864_WrCom(0x80 + y); //行坐标Lcd12864_WrCom(0x80 + x); //列坐标Lcd12864_WrCom(0x30); //关指令扩充Lcd12864_WrData(0x00); //高字节Lcd12864_WrData(0x00); //低字节}}///////////////////////////////////////读出数据函数//输入://输出:读出的数据/////////////////////////////////////uchar Lcd12864_ReData(void){uchar Temp;Lcd12864_ChkBusy();RS = 1;RW = 1;L_PORT = 0XFF; //准备读入数据E = 1;Temp = L_PORT; //读出数据E = 0;return Temp;}///////////////////////////////////// 0 63------------------------- 127 63//画对应点函数||//输入:参数1:列(0 ~ 127)参数2:行(0~63)参数3:改点的颜色||//输出:||///////////////////////////////////// 0 0------------------------- 127 0void Lcd12864_DrawPoint(uchar x,uchar y,uchar color){uchar Row,Tier,TierBit;uchar ReadDatH,ReadDatL;Lcd12864_WrCom(0x36);Tier = x >> 4; //取出对应层数TierBit = x & 0x0f; //取出对应层数的位if(y < 32){Row = ((~y) & 0x1f); //取32的补码Tier += 8; //下半屏}else{Row = ((~(y - 32)) & 0x1f);}//选取位置读出数据Lcd12864_WrCom(Row + 0x80); // 行Lcd12864_WrCom(Tier + 0x80); // 列Lcd12864_ReData();ReadDatH = Lcd12864_ReData(); //读取高八位ReadDatL = Lcd12864_ReData(); //读取低八位//定位位置准备写入数据Lcd12864_WrCom(Row + 0x80); // 行Lcd12864_WrCom(Tier + 0x80); // 列if(TierBit < 8){switch(color){case 0:ReadDatH &= (~(0x01 << (7 - TierBit))); //置零break;case 1:ReadDatH |= (0x01 << (7 - TierBit)); //置一break;case 2:ReadDatH ^= (0x01 << (7 - TierBit)); //异或取反break;}}else{switch(color){case 0:ReadDatL &= (~(0X01 << (15 - TierBit)));break;case 1:ReadDatL |= (0x01 << (15 - TierBit));break;case 2:ReadDatL ^= (0x01 << (15 - TierBit));}}Lcd12864_WrData(ReadDatH); //先写高位字节Lcd12864_WrData(ReadDatL);}///////////////////////////////////////画水平直线函数//输入:参数1:起始横坐标参数2:终止横坐标参数3:纵坐标参数4:显示状态//输出://///////////////////////////////////void Lcd12864_DrawLine_Level(uchar x0,uchar x1,uchar y,uchar color){uchar i,Temp;if(x0 > x1) //保证x1 > x0{Temp = x0;x0 = x1;x1 = Temp;}for(i = x0;i < x1;i ++){Lcd12864_ChkBusy();Lcd12864_DrawPoint(i,y,color);}}///////////////////////////////////////画垂直线函数///输入:参数1:定位横坐标参数2:起始纵坐标参数3:终止纵坐标参数4:显示状态//输出://///////////////////////////////////void Lcd12864_DrawLine_Vertical(uchar x,uchar y0,uchar y1,uchar color){uchar i,Temp;if(y0 > y1) //保证x1 > x0{Temp = y0;y0 = y1;y1 = Temp;}for(i = y0;i < y1;i ++){Lcd12864_ChkBusy();Lcd12864_DrawPoint(x,i,color);}}///////////////////////////////////////画垂直线函数///输入:参数1, 参数2:起始横纵坐标参数3:参数4:终止横纵坐标参数5:显示状态//输出://///////////////////////////////////void Lcd12864_DrawLine_Arbitrary(uchar x0,uchar y0,uchar x1,uchar y1,uchar color){int i,Distance;int x = 0,y = 0,DeltaX,DeltaY;char IncX,IncY; //取出斜率DeltaX = x1 - x0;DeltaY = y1 - y0;if(DeltaX > 0){IncX = 1;}else{IncX = -1;DeltaX = -DeltaX;}if(DeltaY > 0){IncY = 1;}else{IncY = -1;DeltaY = -DeltaY;}if(DeltaX > DeltaY){Distance = DeltaX;}else{Distance = DeltaY;}Lcd12864_DrawPoint(x0,y0,color);for(i = 0;i <= Distance + 1;i ++){Lcd12864_DrawPoint(x0,y0,color);x += DeltaX;y += DeltaY;if(x > Distance){x -= Distance;x0 += IncX;}if(y > Distance){y -= Distance;y0 += IncY;}}///////////////////////////////////////点位花图片函数(图片格式为横坐标32纵坐标30)///输入:参数1,图片指针,参数2,定位显示(固定)//输出://///////////////////////////////////void Lcd12864_PosDrawPhoto(uchar *photo,uchar pos){uchar Temp;uchar i,j;switch(pos){case 1: Temp = 0x80;break;case 2: Temp = 0x83;break;case 3: Temp = 0x86;break;case 4: Temp = 0x88;break;case 5: Temp = 0x8b;break;case 6: Temp = 0x8e;break;}for(i = 1;i < 31;i ++){Lcd12864_WrCom(0x80 + i); //纵坐标Lcd12864_WrCom(Temp); //横坐标for(j = 0;j < 4;j ++){Lcd12864_WrData(*photo ++);}}}。

LCD12864解释

LCD12864解释

RE 为基本指令集与扩充指令集的选择控制位:RE=1:扩充指令集动作RE=0:基本指令集动作DL 为选择控制接口:DL=1:8-BIT 控制接口DL=0:4-BIT 控制接口G 绘图开关控制位:G=1 :绘图显示ONG=0 :绘图显示OFF在一个指令中不能同时改变“RE”和“DL”位的。

所以要分两次进行定义。

lcd_wcmd(0x34); //扩充指令操作是先确定“DL”“G”位。

“G”位的改变只能在扩充指令操作中进行。

lcd_wcmd(0x30); //基本指令操作是再确定“RE”位的。

SR=1允许输入垂直卷动地址SR=0允许输入IRAM地址SL=1脱离睡眠模式SL=0进入睡眠模式R/L=1右移R/L=1左移I/D-bit1:1 读写一个字符后指针+1,且光标+10 读写一个字符后指针-1,且光标-1// S-bit0:1 当写一个字符后,整屏显示左移(N=1)或右移(N=0),以得到光标不动而屏幕移动的效// S/C-bit3:1 画面平移一个字符位;0 光标平移一个字符位在仔细研究了上面关于它的 X啊 Y啊那些坐标的定位啊写满了哪些地址会自增啊哪些不会啊什么的,最后感觉脑袋里有了一种朦胧的概念……哟西,反正不会弄坏,就先随便写个程序试试。

于是乎,嘀咕嘀咕……捣鼓捣鼓……反反复复又弄了一个多小时后,终于摸清了它显示的规律……LCD12864实现画图功能的思路:首先,画图指令属于扩充指令集,要使用这些指令必须在12864初始化之后写命令字(0x34)进入扩充指令集设定状态。

接着要做的事就是指定我们的图片要从哪里写入(即写入的XY坐标,这个是最关键,也是最难理解的部分)。

因为我们这里是显示一整个画面的图片,所以我们就从12864的第一个点开始显示。

那这个点的坐标是怎么定位的呢?我们往这个点写入数据后,要是接着再写数据,那坐标值会怎样变化呢?首先我们要弄清楚12864究竟是怎么把数据写入到GDRAM(绘图显示RAM)中去的。

无字库LCD12864(无时钟芯片显示时间)

无字库LCD12864(无时钟芯片显示时间)

/************************************************************************** 在无字库的12864LCD上显示时、分、秒;没有用时钟芯片MCU:STC89C52晶振:11.0592MHz作者:罗元俊时间:2014.06.25**************************************************************************/ #include <reg52.h>typedef unsigned char uchar;typedef unsigned int uint;#define Port P0 // 数据端口#define Disp_On 0x3f // 开显示#define Disp_Off 0x3e // 关显示#define Col_Add 0x40 // 列地址#define Page_Add 0xb8 // 页地址#define Start_Line 0xc0 // 起始页sbit RS = P2^6;sbit RW = P2^5;sbit EN = P2^7;sbit CS1 = P3^2;sbit CS2 = P3^3;uint t = 0; //全局变量:秒表(用于计数时间的增量)uchar sec,min,hour; // 全局变量:秒、分、时uchar a,b,c,d,e,f; // 秒、分、时的个位和十位uchar code HZ_tab[][32] = {{/*-- 文字: 潜--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x20,0xC2,0x0C,0x80,0x10,0x94,0x54,0x3F,0x54,0x90,0x54,0x3F,0x54,0x94,0x10,0x00,0x04,0x04,0x7E,0x01,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x01,0x00},{/*-- 文字: 龙--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0xF0,0x10,0x11,0x16,0xD0,0x10,0x10,0x00,0x80,0x40,0x20,0x18,0x06,0x41,0x20,0x10,0x3F,0x44,0x42,0x41,0x40,0x40,0x78,0x00},{/*-- 文字: 花--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x04,0x04,0x04,0x84,0x6F,0x04,0x04,0x04,0xE4,0x04,0x8F,0x44,0x24,0x04,0x04,0x00,0x04,0x02,0x01,0xFF,0x00,0x10,0x08,0x04,0x3F,0x41,0x40,0x40,0x40,0x40,0x78,0x00},{/*-- 文字: 园--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFE,0x02,0x42,0x4A,0xCA,0x4A,0x4A,0xCA,0x4A,0x4A,0x42,0x02,0xFE,0x00,0x00,0x00,0xFF,0x40,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0xFF,0x00,0x00},{/*-- 文字: 输--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x88,0x68,0x1F,0xC8,0x08,0x10,0xC8,0x54,0x52,0xD1,0x12,0x94,0x08,0xD0,0x10,0x00,0x09,0x19,0x09,0xFF,0x05,0x00,0xFF,0x12,0x92,0xFF,0x00,0x5F,0x80,0x7F,0x00,0x00},{/*-- 文字: 入--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x00,0x01,0xE2,0x1C,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x03,0x0C,0x30,0x40,0x80,0x80,0x00},{/*-- 文字: 密--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x10,0x8C,0x44,0x04,0xE4,0x04,0x95,0xA6,0x44,0x24,0x14,0x84,0x44,0x94,0x0C,0x00,0x02,0x02,0x7A,0x41,0x41,0x43,0x42,0x7E,0x42,0x42,0x42,0x43,0xF8,0x00,0x00,0x00},{/*-- 文字: 码--*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/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}};uchar code SZ_tab[][16] = {{/*-- 文字: 0 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00}, //0 {/*-- 文字: 1 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00}, //1 {/*-- 文字: 2 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00}, //2 {/*-- 文字: 3 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00}, //3 {/*-- 文字: 4 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00}, //4{/*-- 文字: 5 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00}, //5 {/*-- 文字: 6 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00}, //6 {/*-- 文字: 7 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00}, //7 {/*-- 文字: 8 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00}, //8 {/*-- 文字: 9 --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00}, //9 {/*-- 文字: - --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, //10 {/*-- 文字: : --*//*-- 新宋体12; 此字体下对应的点阵为:宽x高=8x16 --*/0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00} //11 };void delayms(uint xms) //延时子程序{uint x,y;for(x = xms;x > 0;x--)for(y = 2;y > 0;y--);}void DetBusybit(void) //忙位检测子程序{Port = 0xff; //读状态值时,先给数据端口赋高电平RS = 0;RW = 1;EN = 1;while(Port & 0x80); //如果LCD处于忙状态,程序就此停止delayms(2);EN = 0;}void LCD_WrCom_L(uchar com) // 写左半屏指令子程序{DetBusybit();CS1 = 1; CS2 = 0;RS = 0;RW = 0;EN = 1;Port = com;delayms(5);EN = 0;}void LCD_WrCom_R(uchar com) // 写右半屏指令子程序{DetBusybit();CS1 = 0; CS2 = 1;RS = 0;RW = 0;EN = 1;Port = com;delayms(5);EN = 0;}void LCD_WrDat_L(uchar dat) // 写左半屏数据子程序{DetBusybit();CS1 = 1; CS2 = 0;RS = 1;RW = 0;EN = 1;Port = dat;delayms(5);EN = 0;}void LCD_WrDat_R(uchar dat) // 写右半屏数据子程序{DetBusybit();CS1 = 0; CS2 = 1;RS = 1;RW = 0;EN = 1;Port = dat;delayms(5);EN = 0;}void Clear_L(void) // 左半屏清屏{uchar i,j;CS1 = 1; CS2 = 0;LCD_WrCom_L(Page_Add + 0);LCD_WrCom_L(Col_Add + 0);for(j = 0; j < 8; j++)LCD_WrCom_L(Page_Add + j);for(i = 0; i < 64; i++)LCD_WrDat_L(0x00);}void Clear_R(void) // 右半屏清屏{uchar i,j;CS1 = 0; CS2 = 1;LCD_WrCom_R(Page_Add + 0);LCD_WrCom_R(Col_Add + 0);for(j = 0; j < 8; j++)LCD_WrCom_R(Page_Add + j);for(i = 0; i < 64; i++)LCD_WrDat_R(0x00);}void Disp_HZ_L(uchar pag,uchar col,uchar n) // 显示左半屏汉字16*16 {uchar i = 0,j = 0;CS1 = 1; CS2 = 0;for(i = 0; i < 2; i++){LCD_WrCom_L(Page_Add + pag + i);LCD_WrCom_L(Col_Add + col);for(j = 0; j < 16; j++)LCD_WrDat_L(HZ_tab[n][16*i+j]);}}void Disp_SZ_L(uchar pag,uchar col,uchar n) // 显示左半屏数字8*16 {uchar i = 0,j = 0,k = 0;CS1 = 1; CS2 = 0;for(i = 0; i < 2; i++){LCD_WrCom_L(Page_Add + pag + i);LCD_WrCom_L(Col_Add + col);for(j = 0; j < 8; j++){LCD_WrDat_L(SZ_tab[n][8*i+j]);}}}void Disp_HZ_R(uchar pag,uchar col,uchar n) // 显示右半屏汉字16*16 {uchar i = 0,j = 0;CS1 = 0; CS2 = 1;for(i = 0; i < 2; i++){LCD_WrCom_R(Page_Add + pag + i);LCD_WrCom_R(Col_Add + col);for(j = 0; j < 16; j++)LCD_WrDat_R(HZ_tab[n][16*i+j]);}}void Disp_SZ_R(uchar pag,uchar col,uchar n) // 显示右半屏数字8*16 {uchar i = 0,j = 0;CS1 = 0; CS2 = 1;for(i = 0; i < 2; i++){LCD_WrCom_R(Page_Add + pag + i);LCD_WrCom_R(Col_Add + col);for(j = 0; j < 8; j++){LCD_WrDat_R(SZ_tab[n][8*i+j]);}}}void TimerInit(void) //定时器初始化函数{TMOD = 0x02; //设置定时器0为工作模式2TH0 = 0x47; //装初值TL0 = 0x47; //设定时间为0.2msEA = 1;ET0 = 1;TR0 = 1; //启动定时器0}void LCD_Init(void) // LCD初始化子程序{delayms(10);LCD_WrCom_L(Disp_Off); LCD_WrCom_R(Disp_Off);LCD_WrCom_L(Page_Add + 0); LCD_WrCom_R(Page_Add + 0);LCD_WrCom_L(Start_Line + 0); LCD_WrCom_R(Start_Line + 0);LCD_WrCom_L(Col_Add + 0); LCD_WrCom_R(Col_Add + 0);LCD_WrCom_L(Disp_On); LCD_WrCom_R(Disp_On); }void main(void){LCD_Init();TimerInit();Clear_L();Clear_R();while(1){sec = t%60; //秒钟分离min = (t/60)%60; //分钟分离hour = (t/3600)%60; //时钟分离a = sec%10; //秒钟个位分离b = (sec/10)%10; //秒钟十位分离c = min%10; //分钟个位分离d = (min/10)%10; //分钟十位分离e = hour%10; //时钟个位分离f = (hour/10)%10; //时钟十位分?Disp_HZ_L(0,32,0); // 第0页,第16列,第0个字Disp_HZ_L(0,48,1);Disp_HZ_R(0,0,2);Disp_HZ_R(0,16,3);Disp_SZ_L(2,24,2);Disp_SZ_L(2,32,0);Disp_SZ_L(2,40,1);Disp_SZ_L(2,48,4);Disp_SZ_L(2,56,10);Disp_SZ_R(2,0,0);Disp_SZ_R(2,8,6);Disp_SZ_R(2,16,10);Disp_SZ_R(2,24,2);Disp_SZ_R(2,32,7);Disp_SZ_L(4,32,f);Disp_SZ_L(4,40,e);Disp_SZ_L(4,48,11);Disp_SZ_L(4,56,d);Disp_SZ_R(4,0,c);Disp_SZ_R(4,8,11);Disp_SZ_R(4,16,b);Disp_SZ_R(4,24,a);Disp_HZ_L(6,0,4);Disp_HZ_L(6,16,5);Disp_HZ_L(6,32,6);Disp_HZ_L(6,48,7);Disp_SZ_R(6,0,11);}}void timer0(void) interrupt 1{uint i;i++;if(i == 5000) //1s时间到{t++; //秒表计时开始i = 0;}}。

LCD12864(并口)显示程序

LCD12864(并口)显示程序

#ifndef jh_f330#define jh_f330#include<c8051f330.h>#endiftypedef unsigned char uint8;typedef unsigned int uint16;/*************端口配置**************///******************************************************sbit CS =P0^4;sbit RSET=P0^3;sbit A0 =P0^2;sbit WR =P0^1;sbit RD =P0^0;#define DATAPORT P1 //数据口uint8 code word1[]={0x04,0x44,0x84,0x04,0xE4,0x1F,0x84,0x44,0xA4,0x3F,0xA4,0xA4,0x64,0x06,0x04,0x00, 0x20,0x10,0x09,0x04,0xFF,0x04,0x04,0x14,0x26,0x05,0x84,0xFF,0x04,0x06,0x04,0x00 };/**********预定义数据*********/#define LCD_X 128-1 //屏幕的X轴的物理宽度#define LCD_Y 64-1 //屏幕的Y轴的物理宽度/***********LCD指令集***************///LCD开关命令#define LCD_ON() Wr_Com(0xaf)#define LCD_OFF() Wr_Com(0xae)//设置显示起始行#define LCD_START_LINE 0x40 //起始行地址为,0x40+(0-63)//页地址设置#define LCD_Page 0xb0 //页地址为:0xb0+(0-8)//列地址设置#define LCD_Ad_H 0x10 //列高四位地址:0x10+()#define LCD_Ad_L 0x00 //列低四位地址:0x00+()//行列地址方向设置#define ADC_Norm() Wr_Com(0xa0);#define ADC_Reve() Wr_Com(0xa1);#define Com_Norm() Wr_Com(0xc0);#define Com_Reve() Wr_Com(0xc8);void Init_f330(){/*****内部振荡器配置******/OSCICL=OSCICL+4; //设置系统时钟为24MHZ,ΔT=(0.005*ΔOSCICL)/fbase // OSCICL=OSCICL+22; //设置系统时钟为22.1184MHZ// OSCICL=OSCICL+45; //设置系统时钟为20MHZ //15MHZ--24.5MHZ/********设置分频*********/// OSCICN|=0x00; //设置时钟为八分频,OSCIN复位值为1100000//00:8分频,01:4分频,10:2分频,11:不分频// OSCICN|=0x01; //设置系统时钟4分频// OSCICN|=0x02; //设置系统时钟2分频OSCICN|=0x03; //设置系统时钟不分频// RSTSRC=0x04;// OSCLCN = 0x82; // 设置内部L-F振荡器为40kHZ// CLKSEL = 0x02; // 内部低频振荡器while(OSCLCN&0x40 == 0); // 等待振荡器频率稳定/*****设置看门狗*****/PCA0MD &=~0x40; // 禁止看门狗定时器EA=1;/*****端口初始化******/P0MDIN = 0xff; //复位值为11111111P1MDIN = 0xff; //1为数字输入,0为模拟输入P0MDOUT = 0xff; //复位值为11111111P1MDOUT = 0xff; //1为推挽输出,0为漏极输出XBR0 = 0x00; // 交叉开关使能XBR1 = 0x40; //交叉开关允许,T0接到引脚//XBR1 = 0x48; // ECI连到端口引脚//XBR1 |= 0x08; // PCA0 外部计数输入使能}/****************************************函数名:Wr_com**功能:LCD12864写命令程序**输入:uint8 com***************************************/void Wr_Com(uint8 com){A0=0; //命令数据选通,H:数据,L:命令CS=0; //芯片选通,低电平有效RD=1; //L:读信号WR=0; //L:写信号//nop();Data=com;WR=1;CS=1;}/****************************************函数名:Wr_Dat**功能:LCD12864写数据程序**输入:uint8 dat***************************************/void Wr_Dat(uint8 dat){A0=1; //命令数据选通,H:数据,L:命令CS=0; //芯片选通,低电平有效RD=1; //L:读信号WR=0; //L:写信号//nop();Data=dat;WR=1;CS=1;}/***************************************函数名称:LCD_Fill()**功能:LCD全屏显示数据程序**输入:8位数据**输出:无************************************/void LCD_Fill(uint8 dat){uint8 page;uint8 colume;for(page=0;page<8;page++){Wr_Com(LCD_Page+page);Wr_Com(LCD_Ad_H);Wr_Com(LCD_Ad_L);for(colume=0;colume<LCD_X;colume++)Wr_Dat(dat);}}/***************************************函数名称:LCD_Clear()**功能:LCD清屏程序(全屏填充0x00)**输入:8位数据**输出:无************************************/void LCD_Clear(){LCD_Fill(0x00);}/******************************************************* ** 函数名称: LCD12864_Init** 功能: LCD1286初始化程序** 输入: 无TimeDelay ** 输出: 无********************************************************/ void TimeDelay(int Time){int i;while(Time > 0){for(i = 0;i < 8000;i++){}Time --;}}void LCD_Init(void){LCD_RST=0;TimeDelay(200);LCD_RST=1;TimeDelay(200);ADC_Norm();Com_Reve();Wr_Com(0xa2);Wr_Com(0x2c); //vc onTimeDelay(200);Wr_Com(0x2e); //vr onTimeDelay(200);Wr_Com(0x2f); //internal booster,follower,divided onWr_Com(0x24); //set rb/ra=5.29Wr_Com(0x81); //set reference voltage selectWr_Com(0x1d);LCD_ON();Wr_Com(LCD_START_LINE);}/***********************************************************************函数名称:LCD_Word()**功能:输入单个汉字(16x16符号)**输入:页地址,列地址、字符数组**输出:无***********************************************************************/ void LCD_Word(unsigned char row,unsigned char colume,unsigned char *pword){unsigned char page= row;unsigned char col_high=colume>>4;unsigned char col_low =colume&0x0f;unsigned char i;Wr_Com(LCD_Page+page);Wr_Com(LCD_Ad_H+col_high);Wr_Com(LCD_Ad_L+col_low);for(i=0;i<16;i++){Wr_Dat(*(pword+i));}Wr_Com(LCD_Page+page+1);Wr_Com(LCD_Ad_H+col_high);Wr_Com(LCD_Ad_L+col_low);for(i=0;i<16;i++){Wr_Dat(*(pword+16+i));}main(){Init_f330();LCD_Init();LCD_Clear();LCD_Word(1,1,word1);while(1);}。

液晶显示屏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显示C程序

LCD12864显示C程序

/*注:不同开发板,LCD数据显示口不同,Y51最小系统板数据口为P2口*//*注:不同开发板,LCD数据显示口不同,Y51最小系统板数据口为P2口*//*注:不同开发板,LCD数据显示口不同,Y51最小系统板数据口为P2口*//*注:不同开发板,LCD数据显示口不同,Y51最小系统板数据口为P2口(即dat口)否则LCD12864不能正常显示!*/#include<reg52.h>/*端口定义*/#define LCD_data P0 //数据口#define uchar unsigned char#define uint unsigned intsbit LCD_RS = P0^7; //寄存器选择输入sbit LCD_RW = P0^6; //寄存器读写控制sbit LCD_EN = P0^5; //液晶使能控制sbit LCD_PSB = P0^4; //串并方式控制void delay_1ms(uint x); //延时子程序void write_cmd(uchar cmd); //写指令子程序void write_dat(uchar dat); //写数据子程序void lcd_pos(uchar X, uchar Y); //设定位置子程序void lcd_init(); //LCD初始化uchar dis1[] = {"成功显示咯!"};uchar dis2[] = {"迈出第一步!"};uchar dis3[] = {"加油!加油!"};uchar dis4[] = {"最大功率跟踪!"};/*主程序*/void main(){uchar i;lcd_init();while(1){lcd_pos(0,0); //第一行i = 0;while(dis1[i] != '\0'){write_dat(dis1[i]);i++;}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++;}}}/*延时子程序*/void delay_1ms(uint x){uint i,j;for(j = 0; j < x; j++){for(i = 0; i < 110; i ++);}}/*写指令子程序*/void write_cmd(uchar cmd){LCD_RS = 0;LCD_RW = 0;LCD_EN = 0;P2 = cmd;delay_1ms(5);LCD_EN = 1; //高脉冲delay_1ms(5);LCD_EN = 0;}/*写数据子程序*/void write_dat(uchar dat) {LCD_RS = 1;LCD_RW = 0;LCD_EN = 0;P2 = dat;delay_1ms(5);LCD_EN = 1; //高脉冲delay_1ms(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初始化*/void lcd_init(){LCD_PSB = 1; //设置并行方式write_cmd(0x30);delay_1ms(5);write_cmd(0x0C); //显示开,光标关delay_1ms(5);write_cmd(0x01); //清除LCD显示内容delay_1ms(5);}。

LCD12864显示C程序

LCD12864显示C程序

#include<reg51.h>#include<intrins.h>#define uchar unsigned char#define uint unsigned intsbit CLK= P1^2 ; //串行时钟信号提供高低电平sbit RW = P1^1 ; //串行数据口高电平:读数据;低电平:写数据sbit CS= P1^0 ; //串行片选信号高电平时全屏//sbit PSB = P0^4 ; //串行/并行口选择//sbit RST = P0^3 ; //复位低电平有效sbit Up=P2^1;sbit DN=P2^2;sbit Buffer=P1^4;uint fanye=0;uint CH=0;void DelayMs(uchar n) //延时{uchar i;while(n--){for(i=0; i<200; i++)_nop_();}}//延时函数void Delay(){uchar i,j;for(i = 0; i < 100;i++)for(j = 0; j < 50;j++);}void Write_LCD(unsigned char com_dat,unsigned char value) //LCD写数据{uchar i,j;uchar temp;DelayMs(1);temp = value;CS = 1;CLK = 0;RW= 1;for(i = 0 ; i < 5 ; i++) //5个高电平{CLK = 1; CLK = 0;}RW= 0; //1个低电平MCU往LCD写数据CLK = 1;CLK = 0; //配合RW=0 MCU往LCD写数据if(com_dat){RW = 1;} // com_dat==1 写数据停止else{RW= 0; //一直写数据} // 命令CLK = 1;CLK = 0; //低电平RW = 0; //固定为低写数据CLK = 1;CLK = 0;for(i = 0 ; i < 2 ; i++){ //写两个字节for(j = 0 ; j < 4 ; j++){temp <<= 1; //左移一位RW= CY;CLK = 1; CLK = 0;}RW = 0;for(j = 0 ; j < 4 ; j++){CLK = 1; CLK = 0;}}}/********************确定显示字符串的地址同时写字符串******************/ //写字符串显示地址的子程序//x取0~7共八列,y取0~3共四行。

lcd12864c语言编程详解

lcd12864c语言编程详解

12864系列点阵型液晶显示模块使用说明书一、OCM12864液晶显示模块概述1.OCM12864液晶显示模块是128×64点阵型液晶显示模块,可显示各种字符及图形,可与CPU直接接口,具有8位标准数据总线、6条控制线及电源线。

采用KS0107控制IC。

2.外观尺寸:113×65×11mm(ocm12864-1), 93×70×10mm(ocm12864-2)78×70×10mm(ocm12864-3),3.视域尺寸:73.4×38.8mm(ocm12864-1) 70.7×38mm(ocm12864-2),64×44mm(ocm12864-3)4.重量:大约g补充说明:外观尺寸可根据用户的要求进行适度调整。

二、最大工作范围1、逻辑工作电压(Vcc):4.5~5.5V2、电源地(GND):0V3、LCD驱动电压(Vee):0~-10V4、输入电压:Vee~Vdd5、工作温度(Ta):0~55℃(常温) / -20~70℃(宽温)6、保存温度(Tstg):-10~65℃三、电气特性(测试条件 Ta=25,Vdd=5.0+/-0.25V)1、输入高电平(Vih):3.5Vmin2、输入低电平(Vil):0.55Vmax3、输出高电平(Voh):3.75Vmin4、输出低电平(Vol):1.0Vmax5、工作电流:2.0mAmax四、接口说明12864-3A接口说明表五、指令描述1、显示开/关设置CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:设置屏幕显示开/关。

DB0=H,开显示;DB0=L,关显示。

不影响显示RAM(DD RAM)中的内容。

2、设置显示起始行CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2DB1 DB0功能:执行该命令后,所设置的行将显示在屏幕的第一行。

LCD12864原理与应用(源程序+原理图+proteus仿真)

LCD12864原理与应用(源程序+原理图+proteus仿真)

LCD12864原理与应用1、LCD12864简介:LCD12864分为两种,带字库的和不带字库的,不带字库的液晶显示汉字的时候可以选择自己喜欢的字体。

而带字库的液晶,只能显示GB2312字体,当然也可以显示其他的字体,不过是用图片的形式显示。

下面介绍不带字库的LCD12864,以Proteus中的AMPIRE128×64为例,如下图所示,它的液晶驱动器为KS0108。

引脚功能:引脚符号状态引脚名称功能,输入芯片片选端,都是低电平有效CS1=0开左屏幕,CS1=1关左屏幕CS2=0开右屏幕,CS2=1关右屏幕RS 输入数据/命令选择信号RS=1为数据操作,RS=0为写指令或读状态RW 输入读写选择信号R/W=1为读选通,R/W=0为写选通E 输入读写使能信号在E下降沿,数据被锁存(写)入液晶,在E高电平期间,数据被读出DB0—DB7 三态数据总线数据或指令的传送通道输入复位信号,低电平时复位复位时,关闭液晶显示,使显示起始行为0,可以跟单片机的复位引脚RST相连,也可以直接接VCC,使之不起作用V0 液晶显示器驱动电压-Vout -10V LCD驱动负电压与带字库的液晶不同,此块液晶含有两个液晶驱动器,每块驱动器都控制64*64个点,分为左右两个屏幕显示,总共为128*64个点(即有128×64个点)。

这就是为什么AMPIRE128*64有CS1和CS2两个片选端的原因。

此液晶有8页,一页有8行点阵点,左右各64列,共128列。

如下图所示:2、LCD12864中的几条重要指令(一)行(line)设置命令:由此可见显示的起始行地址为0XC0,共64行,有规律地改变起始行号,可以实现滚屏效果。

(二)页(page)设置指令:起始页地址为0XB8,因为液晶有64行点,分为8页,每页就有8行点。

(三)列(column)地址设置指令每块驱动器的列地址都是从0X40到0X7F,共64列,所以此液晶共有128列点。

12864液晶显示C程序

12864液晶显示C程序

#include <reg51.h>#include <intrins.h>//_nop_();延时函数用#define unchar unsigned char#define unint unsigned intsbit E=P3^0;sbit RW=P3^1;sbit RS=P3^2;sbit CS1=P3^6;sbit CS2=P3^7;char code tablenum[][16]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, // 0 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, //1 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, //2 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, //3 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, //4 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, //5 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, //6 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, //7 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, //8 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, //9 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, //: 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20, //R 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00, //S 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, //.};char code tablesnum[][4]={0x00,0x7c,0x44,0x7c,//小00x00,0x00,0x7c,0x00,//小10x00,0x74,0x54,0x5c,//小20x00,0x54,0x54,0x7c,//小30x00,0x3c,0x20,0x7c,//小40x00,0x5c,0x54,0x74,//小50x00,0x7c,0x54,0x74,//小60x00,0x04,0x04,0x7c,//小70x00,0x7c,0x54,0x7c,//小80x00,0x5c,0x54,0x7c,//小90x08,0x08,0x08,0x08,};//void delay(unint i)//{//while(--i);//}void readbusy()//是否忙碌{P0=0x00;RS=0;RW=1;E=1;while(P0&0x80);E=0;}void writecommand(unchar command) //写命令{readbusy();RS=0;RW=0;P0=command;E=1;_nop_();_nop_();E=0;}void writedate(unchar date) //写数据{readbusy();RS=1;RW=0;P0=date;E=1;_nop_();_nop_();E=0;}void setpage(unchar page)//设置页{page=0xb8|page;writecommand(page);}void setline(unchar line)//设置行{line=0xc0|line;writecommand(line);}void setcolumn(unchar column)//设置列{column=column&0x3f;column=0x40|column; writecommand(column);}void setonoff(unchar onoff){onoff=0x3e|onoff;writecommand(onoff);}void selectscreen(unchar screen)//选屏{switch(screen){case 0:CS1=0;CS2=0;break;case 1:CS1=0;CS2=1;break;case 2:CS1=1;CS2=0;break; default: break;}}void clearscreen(unchar screen)//清屏{unchar i,j;selectscreen(screen);for(i=0;i<8;i++){setpage(i);setcolumn(0);for(j=0;j<64;j++){writedate(0x00);}}}void InitLCD()//初始化readbusy();selectscreen(0);setonoff(0);selectscreen(0);setonoff(1);selectscreen(0);clearscreen(0);setline(0);}void display(unchar ss,unchar page,unchar column,unchar j)//显示数据{unchar i;selectscreen(ss);setpage(page);setcolumn(column);for(i=0;i<8;i++){writedate(tablenum[j][i]);}setpage(page+1);setcolumn(column);for(i=0;i<8;i++){writedate(tablenum[j][i+8]);}}void displays(unchar ss,unchar page,unchar column,unchar j)//显示小数据{unchar i;selectscreen(ss);setpage(page);setcolumn(column);for(i=0;i<4;i++){writedate(tablesnum[j][i]);}}void disnum()//显示数据{display(1,0,1*8,11);display(1,0,2*8,10);display(1,0,3*8,1);display(1,0,4*8,1);display(1,0,5*8,13);display(1,0,6*8,1);display(2,0,1*8,12);display(2,0,2*8,10);display(2,0,3*8,1);display(2,0,4*8,1);display(2,0,5*8,13);display(2,0,6*8,1);}void dissnum()//显示坐标数据{//displays(1,2,0*4,9);//displays(1,2,1*4,0); displays(1,3,0*4,7); displays(1,3,1*4,5);//displays(1,4,0*4,6);//displays(1,4,1*4,0); displays(1,5,0*4,4); displays(1,5,1*4,5);//displays(1,6,0*4,3);//displays(1,6,1*4,0); displays(1,7,0*4,1); displays(1,7,1*4,5);}void diszhou()//坐标轴{unchar i,j,a,b; selectscreen(1);for(i=2;i<7;i++){setcolumn(11);setpage(i);writedate(0xff);}setcolumn(11);setpage(7);writedate(0x0f);for(j=3;j<16;j++){displays(1,7,j*4,10); }for(b=2;b<7;b++){setcolumn(12);setpage(b);writedate(0x08);}setcolumn(12);setpage(7);writedate(0x08); for(a=0;a<16;a++) {displays(2,7,a*4,10); }}void main(){InitLCD(); clearscreen(0); writecommand(0xc0); disnum();dissnum();diszhou();while(1); }。

LCD12864显示程序(汇编语言)

LCD12864显示程序(汇编语言)

;实验目的:熟悉12864LCD的使用;12864LCD带中文字库;编程让12864LCD显示公司名称“深圳乾龙盛电子”,公司电话“5”,公司传真“6”;硬件设置:;关断所有拨码开关。

#include<p16f877a.inc>;__CONFIG_DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_H S_OSC;芯片配置字,看门狗关,上电延时开,掉电检测关,低压编程关,加密,4M晶体HS振荡 #define RS PORTA,5 ;命令/数据选择#DEFINE RW PORTA,4 ;读/写选择#DEFINE E PORTA,3 ;使能信号#DEFINE PSB PORTA,2 ;并口/串口选择(H/L)#DEFINE RST PORTA,0 ;复位信号;-----------------------------------------------LCD_X EQU 30H ;页地址LCD_Y EQU 31H ;Y地址COUNT EQU 32H ;循环计数用COUNT1 EQU 33H ;循环计数用COUNT2 EQU 34H ;循环计数用POINT EQU 35H ;查表偏移地址POINT1 EQU 36H ;查表偏移地址POINT2 EQU 37H ;查表偏移地址TEMP EQU 38H ;临时寄存器TEMP1 EQU 39H ;临时寄存器;-----------------------------------------------ORG 0000H ;复位地址NOP ;ICD需要的空指令GOTO MAIN ;跳转到主程序;**********************主程序************************MAINBANKSEL TRISACLRF TRISA ;A口输出CLRF TRISD ;D口输出BANKSEL ADCON1MOVLW 06HMOVWF ADCON1 ;A口全为数字口CLRF STATUSBCF RST ;复位LCDCALL DELAY ;延时一段时间BSF RST ;清除复位信号NOPBSF PSB ;并口通讯;**************************初始化**********************MOVLW 30H ;基本指令操作CALL SEND_IMOVLW 01H ;清除显示CALL SEND_IMOVLW 06H ;指定在写入或读取时,光标的移动方向 CALL SEND_IMOVLW 0CH ;开显示,关光标,不闪烁CALL SEND_I;***********************显示汉字************************HAN_WR2CALL CLEAR_P ;清屏HAN_WR2A ;“深圳乾龙盛电子”MOVLW LOW(TAB1A)MOVWF POINTMOVLW HIGH(TAB1A)MOVWF POINT1 ;获取表格的首地址MOVLW 0eH ;数数据字节个数(7个汉字共14字节) MOVWF COUNTMOVLW 81H ;页地址CALL SEND_ICALL QUSHUHAN_WR2B ;“。

lcd12864c语言显示任意位置

lcd12864c语言显示任意位置

#include<pic.h>#define uint unsigned int#define uchar unsigned char#include<pic.h>#define RS RD2#define CS2 RD1#define CS1 RD0#define E RD4#define RW RD3#define BUSY RB7uchar (*p)[32];uchar tab3[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x 20,/*"a",0*/0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x 00/*"b",1*/};uchar tab0[]={0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x 00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x 00,/*"电",0*/0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x 00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00/*"子",1*/};uchar tab1[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x 00,/*"0",0*/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x 00,/*"1",1*/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x 00,/*"2",2*/0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x 00,/*"3",3*/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x 00/*"4",4*/};/*"4",3*/uchar tab2[]={0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x 00,/*"5",0*/0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x 00,/*"6",1*/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x 00,/*"7",2*/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x 00,/*"8",3*/0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x 00/*"9",4*/};//写指令代码(左)void l_w_code(char l_code){//check_busy();PORTD=0x12;PORTB=l_code;E=1;E=0;asm("nop");}//写显示数据(左)void l_w_data(char l_data){//check_busy();PORTD=0x16;PORTB=l_data;E=1;E=0;asm("nop");}//写指令代码(右)void r_w_code(charr_code) {//check_busy();PORTD=0x11;PORTB=r_code;E=1;E=0;//asm("nop");}//写显示数据(右)void r_w_data(char r_data) {//check_busy();PORTD=0x15;PORTB=r_data;E=1;E=0;asm("nop");}void initializeLCD(void){l_w_code(0x3f);l_w_code(0xc0);l_w_code(0xb8);l_w_code(0x40);r_w_code(0x3f);r_w_code(0xc0);r_w_code(0xb8);r_w_code(0x80);}void c_display(uintq,uintw,uint e) {ucharm,n;uchari,x,y=0x40;uint k=0,j=1;if(w>8){w=w-8;j=0;}for(i=1;i<w;i++){y=y+0x08;}switch(q){case 1:x=0xb8;break;case 2:x=0xba;break;case 3:x=0xbc;break;case 4:x=0xfe;break; default:break;}switch(e){case 0:k=0;break;case 1:k=16;break;case 2:k=32;break;case 3:k=48;break;case 4:k=64;break;case 5:k=0;break;case 6:k=16;break;case 7:k=32;break;case 8:k=48;break;case 9:k=64;break; default:k=0;break;}if(j){for (m=0;m<2;m++){for(n=0;n<8;n++){l_w_code(x); //写入页地址l_w_code(y);if((e<10)&&(e>4)){ l_w_data(tab2[k++]);}else if(e<5){ l_w_data(tab1[k++]);}else{ l_w_data((*p)[k++]);}y=y+0x01;}y=y-0x08;x+=0x01;}}else{for (m=0;m<2;m++){for(n=0;n<8;n++){r_w_code(x); //写入页地址r_w_code(y);if((e<10)&&(e>4)){ r_w_data(tab2[k++]);}else if(e<5){ r_w_data(tab1[k++]);}else{ r_w_data((*p)[k++]);}y=y+0x01;}y=y-0x08;x+=0x01;}}}void l_display(uintq,uint w){ucharm,n;uchari,x,y=0x40;uint k=0,j=1;if(w>8){w=w-8;j=0;}for(i=1;i<w;i++){y=y+0x08;}switch(q){case 1:x=0xb8;break;case 2:x=0xba;break;case 3:x=0xbc;break;case 4:x=0xbe;break; default:break;}if(j){for (m=0;m<2;m++){for(n=0;n<16;n++){l_w_code(x); //写入页地址l_w_code(y);l_w_data((*p)[k++]);y=y+0x01;}y=y-0x10;x+=0x01;}}else{for (m=0;m<2;m++){for(n=0;n<16;n++){r_w_code(x); //写入页地址r_w_code(y);r_w_data((*p)[k++]);y=y+0x01;}y=y-0x10;x+=0x01;}}}void delaycnt(unsigned intcnt) {while(--cnt);}void main(void){TRISD=0X00;TRISB=0X00; initializeLCD();while(1){p=&tab0[0]; //显示电子l_display(3,3);p=&tab0[32];l_display(3,5);c_display(3,7,1); //显示1202 c_display(3,8,2);c_display(3,9,0);c_display(3,10,2);p=&tab3[0]; //显示abc_display(2,11,10);p=&tab3[16];c_display(2,12,10);}}/*x=4,0<y<16c_display(x,y,z);表示在第x行,第Y列,显示z(数字1-9).如果要显示其他字符,z=10,每个字母16个字符,p=&tab3[0];表示显示第一个字母,p=&tab3[16];表示显示第二个字母P=&tab0[0];l_display(x,y);这里y不能为8和16,表示在第X行,第Y列和Y+1列显示tab0[]的第一个汉子,每个汉子32个字符,显示tab0[]里面的第二个就是从p=&tab2[32]开始*/。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

12864系列点阵型液晶显示模块
使用说明书
一、OCM12864液晶显示模块概述
1.OCM12864液晶显示模块是128×64点阵型液晶显示模块,可显示各种字符及图形,可与CPU
直接接口,具有8位标准数据总线、6条控制线及电源线。

采用KS0107控制IC。

2.外观尺寸:113×65×11mm(ocm12864-1), 93×70×10mm(ocm12864-2)
78×70×10mm(ocm12864-3),
3.视域尺寸:73.4×38.8mm(ocm12864-1) 70.7×38mm(ocm12864-2),
64×44mm(ocm12864-3)
4.重量:大约g
补充说明:外观尺寸可根据用户的要求进行适度调整。

二、最大工作范围
1、逻辑工作电压(Vcc):4.5~5.5V
2、电源地(GND):0V
3、LCD驱动电压(Vee):0~-10V
4、输入电压:Vee~Vdd
5、工作温度(Ta):0~55℃(常温) / -20~70℃(宽温)
6、保存温度(Tstg):-10~65℃
三、电气特性(测试条件 Ta=25,Vdd=5.0+/-0.25V)
1、输入高电平(Vih):3.5Vmin
2、输入低电平(Vil):0.55Vmax
3、输出高电平(Voh):3.75Vmin
4、输出低电平(Vol):1.0Vmax
5、工作电流:2.0mAmax
四、接口说明
12864-3A接口说明表
五、指令描述
1、显示开/关设置
CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2
DB1 DB0
功能:设置屏幕显示开/关。

DB0=H,开显示;DB0=L,关显示。

不影响显示RAM(DD RAM)中的内容。

2、设置显示起始行
CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2
DB1 DB0
功能:执行该命令后,所设置的行将显示在屏幕的第一行。

显示起始行是由Z地址计数器控制的,该命令自动将A0-A5位地址送入Z地址计数器,起始地址可以是0-63范围内任意一行。

Z 地址计数器具有循环计数功能,用于显示行扫描同步,当扫描完一行后自动加一。

3、设置页地址
CODE:R/W D/I DB7 DB6 DB5 DB4 DB3 DB2
DB1 DB0
功能:执行本指令后,下面的读写操作将在指定页内,直到重新设置。

页地址就是DD RAM 的行地址,页地址存储在X地址计数器中,A2-A0可表示8页,读写数据对页地址没有影响,除本指令可改变页地址外,复位信号(RST)可把页地址计数器内容清零。

DD RAM地址映像表
Y 地址
0 1 2 ………………………61 62 63
4、设置列地址
CODE : R/W
D/I DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
功能: DD RAM 的列地址存储在Y 地址计数器中,读写数据对列地址有影响,在对DD RAM 进行读写操作后,Y 地址自动加一。

5、状态检测
CODE : R/W D/I DB7 DB6 DB5
DB4 DB3 DB2 DB1 DB0
功能:读忙信号标志位(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
功能:写数据到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
功能:从DD RAM读数据,读指令执行后Y地址计数器自动加1。

从DD RAM读数据前要先执行“设置页地址”及“设置列地址”命令。

六、接口时序
1.写操作时序
时序1
1. 读操作时序
时序2 时序参数表:
七、屏幕显示与DD RAM 地址映射关系
Y1
Y2
Y3
Y4
………… Y62 Y63 Y64 X=0
Line 0 DB0 Line 1 DB1 Line 2 DB2 Line 3 DB3 Line 4 DB4 Line 5 DB5 Line 6 DB6 Line 7
DB7
………… ………… …………
八、测试硬件电路
●写指令子程序(INST)
SETB E
CLR D_I
CLR R_W
MOV P1, A
CLR E
RET
●写数据子程序(DATA)
SETB E
SETB D_I
CLR R_W
MOV P1, A
CLR E
RET
●写一页显示RAM数据(假设指令子程序为INST,数据子程序为DATA)
MOV A,#0B8H
LCALL INST ;置页地址为0页
MOV A,#40H
LCALL INST ;置列地址为0列
MOV R2,#40H
MOV R1,#00H
MOV DPTR,#ADDR
LOOP:MOV A,R1
MOVC A,@A+DPTR
LCALL DATA
INC R1
DJNZ R2, LOOP。

相关文档
最新文档