2021年LCD12864显示程序
lcd12864.h是液晶显示的程序
void clrram_lcd (void)
{
wr_i_lcd(0x30);
wr_i_lcd(0x01);
}
//********************************
//指定要显示字符的坐标
//*******************************
#define uint unsigned int
#define uchar unsigned char
//****************************************
//12864液晶显示部分子程序模块
//****************************************
case 2 : readOldL ^= ( 0x01 << ( 15 - tier_bit ));break ;
default : break ;
}
wr_d_lcd(readOldH);
wr_d_lcd(readOldL);
}
//wr_i_lcd(0x36);
wr_i_lcd(0x30);
}
default : break ;
}
wr_d_lcd( readOldH ) ;
wr_d_lcd( readOldL ) ;
}
else
{
switch(color)
{
case 0 : readOldL &= (~( 0x01 << ( 15 - tier_bit )));break ;
case 1 : readOldL |= ( 0x01 << ( 15 - tier_bit ));break ;
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程序
/****************************************屏幕显示驱动*****************************************/#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 程序流程图
我们常用的人机交互显示界面中,除了数码管,LED,以及我们之前已经提到的LCD1602 之外,还有一种液晶屏用的比较多。
相信接触过单片机的朋友都知道了,那就是12864 液晶。
顾名思义,12864 表示其横向可以显示128 个点,纵向可以显示64 个点。
我们常用的12864 液晶模块中有带字库的,也有不带字库的,其控制芯片也有很多种,如KS0108 、T6963,ST7920 等等。
在这里我们以ST7920 为主控芯片的12864 液晶屏来学习如何去驱动它。
(液晶屏采用金鹏的OCMJ4X8C)。
lcd12864 液晶说明:
我们先来了解一下它的并行连接情况。
下面是电路连接图:
上面的图可以看出,液晶模块和单片机的连接除了P0 口的8 位并行数据线之外,还有RS,RW,E 等几根线。
其中R/S 是指令和数据寄存器的选择控制线(串行模式下为片选),R/W 是读写控制线(串行模式下是数据线),E 是使能线(串行模式下为时钟线)。
通过这几根控制线和数据线,再结合它的时序图,我们就可以编写出相应的驱动程序啦。
看看并行模式下的写时序图:。
LCD12864液晶显示原理电路图程序
LCD12864系列点阵型液晶显示模块使用说明书一、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补充说明:外观尺寸可根据用户的要求进展适度调整。
二、最大工作X围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.75VminH H D7 D6 D5 D4 D3 D2 D1 D0功能:从DD RAM读数据,读指令执行后Y地址计数器自动加1。
从DD RAM读数据前要先执行“设置页地址〞及“设置列地址〞命令。
六、接口时序1.写操作时序时序11.读操作时序时序2时序参数表:名称符号最小值典型值最大值单位E周期时间Tcyc 1000 nsE高电平宽度Pweh 450 nsE低电平宽度Pwel 450 nsX=7Line60 1/0 1/0 1/0 1/0 ………… 1/0 1/0 1/0 DB4 Line61 1/0 1/0 1/0 1/0 ………… 1/0 1/0 1/0 DB5 Line62 1/0 1/0 1/0 1/0 ………… 1/0 1/0 1/0 DB6 Line631/0 1/0 1/0 1/0…………1/0 1/0 1/0 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 〕VEE ’V0第三脚VEE 第18脚可调10K〔三极管内置〕MOV A, #0B8HLCALL INST ;置页地址为0页MOV A, #40HLCALL INST ;置列地址为0列MOV R2,#40HMOV R1,#00HMOV DPTR,#ADDRLOOP:MOV A, R1MOVC A, A+DPTRLCALL DATAINC R1DJNZ R2, LOOP带中文字库的128X64是一种具有4位/8位并行、2线或3线串行多种接口方式,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块;其显示分辨率为128×64, 内置8192个16*16点汉字,和128个16*8点ASCII字符集.利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互图形界面。
lcd12864显示程序
/*************************************************名称:LCD12864_ST7920并行测试程序试验功能:测试基于ST7920控制芯片的LCD12864的显示并行方式连接;晶振11.0592M编写:*************************************************/#include <reg52.h>#include <ziku.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned int //宏定义/*****LCD接口定义*****/sbit LCD_RS = P2^0; //1:输入数据;0:输入命令sbit LCD_RW = P2^1; //1:读数据0:写数据sbit LCD_EN = P2^2; //LCM使能端sbit LCD_PSB = P2^3; //串并口选择1:并口模式; 0:串口模式;#define LCD_DATA P0 //LCD总线端口/*****LCD功能初始化指令*****/#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/*****汉字地址表*****/uchar code 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,//第四行汉字位置};/*****n(ms)延时子程序*****/void delayms(uint t) //约延时n(ms){uint i;while(t--){for(i=0;i<125;i++);}}/*****等待LCD忙*****/void WaitBusy(void) //延时一小段时间,等待LCD空闲{uchar i=5;while(i--);}/*****写指令代码*****/void Lcd_WriteCmd(uchar cmdcode){LCD_RS = 0;LCD_RW = 0;LCD_EN = 1;WaitBusy();LCD_DATA = cmdcode;LCD_EN = 0;}/*****写数据*****/void Lcd_WriteData(uchar dispdata){LCD_RS = 1;LCD_RW = 0;LCD_EN = 1;WaitBusy();LCD_DATA = dispdata;LCD_EN = 0;}/*****初始化LCD*****/void Lcd_Init(){LCD_PSB = 1;delayms(50);Lcd_WriteCmd(0x30); //选择基本指令集delayms(1);Lcd_WriteCmd(0x30); //选择8bit数据流delayms(1);Lcd_WriteCmd(0x0c); //开显示(无游标、不反白)delayms(1);Lcd_WriteCmd(0x01); //清除显示,并且设定地址指针为00Hdelayms(20);}/*****显示汉字*****/void hanzi_Disp(uchar x,uchar y,uchar code *s){ //x、y为汉字坐标Lcd_WriteCmd(addr_tab[8*x+y]); //写地址while(*s>0){Lcd_WriteData(*s); //写数据s++;}}/*****显示图片(显示Gdram内容)*****//*绘图显示的步骤1 关闭绘图显示功能2 先将垂直的坐标(Y)写入绘图RAM地址3 再将水平的位元组坐标(X)写入绘图RAM地址4 将D15-D8写入RAM中5 将D7-D0写入到RAM中6 打开绘图显示功能*///图片取模方式:横向取模,字节正序void pic_Disp(uchar *pic) //显示Gdram内容(显示图片){uchar x,y,i;for(i=0;i<9;i=i+8)for(y=0;y<32;y++){for(x=0;x<8;x++){Lcd_WriteCmd(0x36); //扩充指令,开绘图显示Lcd_WriteCmd(0x80+y); //行地址Lcd_WriteCmd(0x80+x+i); //列地址Lcd_WriteData(*pic++); //写数据D15-D8Lcd_WriteData(*pic++); //写数据D7-D0Lcd_WriteCmd(0x30);}}}/*****整屏显示竖条*****///当i=0时显示上面128×32,当i=8时显示下面128×32//当i=0时显示上面128×32,当i=8时显示下面128×32void LcdFill_Vertical(){uchar x,y,i;for(i=0;i<9;i=i+8)for(y=0;y<0x20;y++){for(x=0;x<8;x++){Lcd_WriteCmd(0x36); //扩充指令绘图显示Lcd_WriteCmd(y+0x80); //行地址Lcd_WriteCmd(x+0x80+i); //列地址Lcd_WriteData(0x55); //写数据D15-D8Lcd_WriteData(0x55); //写数据D7-D0Lcd_WriteCmd(0x30);}}}/*****整屏显示横条*****/void LcdFill_Level(){uchar x,y,i;uchar k;for(i=0;i<9;i+=8)for(y=0;y<0x20;y++){if((y%2)==1) k=0xff;else k=0;for(x=0;x<8;x++){Lcd_WriteCmd(0x36); //扩充指令绘图显示Lcd_WriteCmd(y+0x80); //行地址Lcd_WriteCmd(x+0x80+i); //列地址Lcd_WriteData(k);Lcd_WriteData(k);Lcd_WriteCmd(0x30);}}}/*****整屏充满亮点或暗点*****///当i=0时显示上面128×32,当i=8时显示下面128×32 //当i=0时显示上面128×32,当i=8时显示下面128×32 void Lcd_Fill(uchar test){for(i=0;i<9;i=i+8)for(y=0;y<0x20;y++){for(x=0;x<8;x++){Lcd_WriteCmd(0x36); //扩充指令绘图显示Lcd_WriteCmd(y+0x80); //行地址Lcd_WriteCmd(x+0x80+i); //列地址Lcd_WriteData(test); //写数据D15-D8Lcd_WriteData(test); //写数据D7-D0 Lcd_WriteCmd(0x30);}}}/*****主函数*****/void main(void){Lcd_Init();while(1){Lcd_Init();hanzi_Disp(0,0,"ST7920型液晶模块");hanzi_Disp(1,1,"并行测试程序");hanzi_Disp(2,0,"");hanzi_Disp(3,3,"");delayms(2000);Lcd_Init();// Lcd_Fill(0xff);hanzi_Disp(1,2,"坏点检测");delayms(500);Lcd_Init();Lcd_Fill(0xff);delayms(1500);Lcd_Init();LcdFill_Vertical();delayms(750);Lcd_Init();LcdFill_Level();delayms(750);hanzi_Disp(1,2,"显示汉字");delayms(500);Lcd_Init();hanzi_Disp(0,0,tangshi);delayms(1500);Lcd_Init();hanzi_Disp(1,2,"显示图片");delayms(500);Lcd_Init();pic_Disp(LCDsheji);delayms(1000);Lcd_Init();pic_Disp(rmb);delayms(1000);Lcd_Init();pic_Disp(qiche);delayms(1000);Lcd_Init();pic_Disp(gongji);delayms(1000);Lcd_Fill(0x00); //清显示RAMdelayms(500);}}以下是字库头文件:ziku.hunsigned char code tangshi[]={"黄河远上白云间,羌笛何须怨杨柳,一片孤城万仞山。
LCD12864带中文字库图形显示单片机程序多图
LCD12864带中文字库图形显示-单片机程序(多图)代码:#include ;#define uchar unsigned charsbit rs=P2^2;//写指令/数据sbit rw=P2^3;//读状态/写sbit e=P2^4;//使能端sbit psb=P2^5;//串/并输入//校徽unsigned char code image[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x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0xBC,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x7E,0x9F,0xF0,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x0F,0xFF,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};void delay(int i){uchar j;while(i--)for(j=110;j>;0;j--);}//读状态,检测忙void check_busy(){rs=0;rw=1;e=1;P0=0xff;while((P0&0x80)==0x80);e=0;}//写指令void write_com(uchar com) {check_busy();rs=0;rw=0;e=1;P0=com;delay(5);e=0;delay(5);}//写数据void write_data(uchar _data) {check_busy();rs=1;rw=0;e=1;P0=_data;delay(5);e=0;delay(5);}//初始化lcdvoid init(){rw=0;psb=1;//选择为并行输入delay(50);write_com(0x30);//基本指令操作delay(5);write_com(0x0c);//显示开,关光标delay(5);write_com(0x06);//写入一个字符,地址加1 delay(5);write_com(0x01);delay(5);}void wstring(uchar *str){while(*str){write_data(*str);delay(5);str++;}}void lcd_draw(unsigned char code *pic) {unsigned i,j,k;write_com(0x34);//扩充指令集for(i=0;i绘图更好的一个算法:(可以绘分块,也可绘全屏)void lcd_block(char num,char flag){//x1:列数,yl:行数,x:列坐标,//sx:该图形距离第一幅图的距离//此函数也可以用来画全屏图unsigned i,j,k,xl,yl,x,y,sx;unsigned char code *pic;switch(num){case 0: j=0;pic=image0;xl=5;yl=12;sx=3;x=0x80|sx;break;case 1:j=13;pic=image4;xl=4;yl=37;sx=0;x=0x80|sx;break; case 2:j=13;pic=image4;xl=4;yl=37;sx=3;x=0x80|sx;break; case 3:j=13;pic=image4;xl=4;yl=12;sx=6;x=0x80|sx;break; case 4: j=7;pic=image4;xl=4;yl=31;sx=0;x=0x88|sx;break;case 5: j=7;pic=image5;xl=4;yl=31;sx=3;x=0x88|sx;break;case 6: j=7;pic=image5;xl=4;yl=31;sx=6;x=0x88|sx;break;case 7: j=0;pic=image7;xl=16;yl=64;sx=0;x=0x80|sx;break;}write_com(0x34);for(j;j;31) {y=j-32;x=0x88|sx;} else y=j;write_com(0x80+y);write_com(x);for(k=0;k<xl;k++){if(flag)write_data(*pic++);else write_data(~(*pic++));}}/*for(j;j<yl;j++){write_com(0x80+j);write_com(x);for(k=0;k<xl;k++){if(flag)write_data(*pic++);else write_data(~(*pic++));}}*/write_com(0x36);//显示图形write_com(0x30);//基本指令集}。
12864LCD显示倒计时程序
简介:第一行显示,距离系统爆炸时间第二行显示,还剩第三行显示,00时,00分,00秒第四行显示,周林按下旋钮开关,开始设定秒,秒编辑位闪动。
左右旋转设定数值,在按下开关,秒确定,设定分,分编辑位闪动左右调数值,再按下,分确定,小时位闪动。
左右转调小时,再按一下。
时间确定,开始倒计时。
到达定时时间后停止,并闪动。
#include <reg52.h>#include <intrins.h>/********************* 定义********************************/#define LCD_data P0 //数据口sbit LCD_RS = P2 ^ 0; //寄存器选择输入sbit LCD_RW = P2 ^ 1; //液晶读/写控制sbit LCD_EN = P2 ^ 2; //液晶使能控制sbit LCD_PSB = P2 ^ 3; //串/并方式控制sbit LCD_RST = P2 ^ 5; //液晶复位端口sbit sset=P3^4;//设置按钮sbit spk=P1^4;sbit sadd=P2^7;sbit sdel=P2^6;signed char second=0,minute=0,hour=0,count=0,keycount=0;signed char key=0;unsigned char code DIS1[] ={"距离系统爆炸时间"};unsigned char code DIS2[] ={"还剩:"};unsigned char code DIS31[] ={"时"};unsigned char code DIS32[] ={"分"};unsigned char code DIS33[] ={"秒"};unsigned char code DIS4[] ={"周林"};unsigned char code table2[]="0123456789";char code reserve[3]_at_ 0x3b; //保留0x3b开始的3个字节/*********************延时子函数**************************/void delayNOP()//us延时子函数(4.34us){_nop_();_nop_();_nop_();_nop_();}void delayms(unsigned int ms)//ms延时子函数{unsigned char y;while (ms--){for (y = 0; y < 114; y++);}}//******************检查LCD忙状态**************************bit lcd_busy()//检查LCD忙状态1忙,0闲{bit result;LCD_RS = 0;LCD_RW = 1;LCD_EN = 1;delayNOP();result = (bit)(P0 &0x80);LCD_EN = 0;return (result);//***********************写指令数据***********************void lcd_wcmd(unsigned char cmd)//写指令数据到LCD{while (lcd_busy()){;}LCD_RS = 0;LCD_RW = 0;LCD_EN = 1;P0 = cmd;delayNOP();LCD_EN = 0;}void lcd_wdat(unsigned char dat)//写显示数据到LCD{while (lcd_busy());LCD_RS = 1;LCD_RW = 0;LCD_EN = 1;P0 = dat;delayNOP();LCD_EN = 0;}void writesmh(unsigned char add,unsigned char date)//显示个位和十位数据{unsigned char shi,ge;shi=date/10;ge=date%10;lcd_wcmd(0x80+add);delayms(5);lcd_wdat(table2[shi]);delayms(5);lcd_wdat(table2[ge]);delayms(5);}//*********************初始化设定****************************void lcd_init(){LCD_PSB = 1; //并口方式LCD_RST = 0; //液晶复位delayms(5); //液晶复位LCD_RST = 1; //液晶复位delayms(5); //液晶复位lcd_wcmd(0x34); //扩充功能设定,扩充指令,选8位数据delayms(5);lcd_wcmd(0x30); //功能设定,基本指令操作,选8位数据delayms(5);lcd_wcmd(0x0C); //显示开,关光标,关光标反白允许。
LCD12864显示程序
本例程为通过用AT89C52芯片把持LCD12864显示的法式, 使用的晶振为12M.之马矢奏春创作/**********************************************************法式说明:LCD12864显示主法式法式调试员:莫剑辉调试时间:2010-6-7**********************************************************/#include<reg52.h>#include"12864.c"void main(){Ini_Lcd(); //液晶初始化子法式Disp(1,0,6,"莫剑辉"); //显示数据到LCD12864子法式while(1);}这里我们通过调用下面的头文件就可以了, 这样的做法方便我们以后要用到LCD12864的法式的调用./**********************************************************法式说明:LCD12864显示头文件法式调试员:莫剑辉调试时间:2010-6-7********************************************************* *///#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define DATA P2 //数据输出端0~7sbit RS=P0^0; //LCD12864 RS端sbit RW=P0^1; //LCD12864 RW端sbit E =P0^2; //LCD12864 E 端sbit PSB =P0^3;/*********************************************延时子法式*********************************************/void Delay_1ms(uint x){uint j,i;for(j=0;j<x;j++){for(i=0;i<120;i++); //延时X乘以120}}/*********************************************LCD12864液晶测忙子法式(读状态)*********************************************/void Busy(){uchar busy;do{E = 0; //0为关闭使能端,1为翻开使能端RS = 0; //1为指令,0为数据RW = 1; //1为读,0为写Delay_1ms(20); //延时20乘以120时间E = 1; //0为关闭使能端,1为翻开使能端busy=P1; //读取P2状态Delay_1ms(20); //延时20乘以120时间E = 0; //0为关闭使能端,1为翻开使能端}while(busy&0x80); //判断BUSY位是否工作:1为内部在工作,0为正常状态}/********************************************* LCD12864液晶数据写入子法式*********************************************/ void Write_Data(uchar k){Busy(); //测忙E =1;//0为关闭使能端,1为翻开使能端RS=1;//1为指令,0为数据RW=0;//1为读,0为写DATA=k;//输入数据K到DATADelay_1ms(20);//延时20乘以120时间E =0; //0为关闭使能端,1为翻开使能端Delay_1ms(20); //延时20乘以120时间}/********************************************* LCD12864液晶命令写入子法式*********************************************/ void Write_Cmd(uchar cmd){Busy(); //测忙E=1;//0为关闭使能端,1为翻开使能端RS=0; //1为指令,0为数据RW=0;//1为读,0为写DATA=cmd; //输入命令cmd到DATADelay_1ms(20);//延时20乘以120时间E=0;//0为关闭使能端,1为翻开使能端Delay_1ms(20);//延时20乘以120时间}/*********************************************LCD12864液晶数据显示子法式*********************************************/void Disp(uchar y,uchar x,uchar i,uchar *z){uchar Address;if(y==1){Address=0x80+x;} //Y判断第几行,X判断第几列,0x80为液晶行初始地址if(y==2){Address=0x90+x;}if(y==3){Address=0x88+x;}if(y==4){Address=0x98+x;}Write_Cmd(Address); //写入地址命令到LCD12864while(i) //写入显示数据的年夜小{Write_Data(*(z++)); //写入显示数据到LCD12864i--;}}/********************************************* LCD12864液晶初始化子法式*********************************************/ void Ini_Lcd(void){PSB=1;Delay_1ms(20);Write_Cmd(0x30); //基本指令集Delay_1ms(20);Write_Cmd(0x02); // 地址归位Delay_1ms(20);Write_Cmd(0x0c); //整体显示翻开,游标关闭 Delay_1ms(20);Write_Cmd(0x06); //游标右移Delay_1ms(20);Write_Cmd(0x80); //设定显示的起始地址Delay_1ms(20);Write_Cmd(0x01); //清除显示}。
LCD12864(并口)显示程序
#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显示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显示程序(成功版)
#include<reg51.h>#include<intrins.h>#define uint unsigned int#define uchar unsigned char//--定时使用的IO口--//#define DATA_PORT P0sbit LCD12864_CS = P3^2;sbit LCD12864_RSET = P3^3;sbit LCD12864_RS = P2^6;sbit LCD12864_RW = P2^7;sbit LCD12864_RD = P2^5;//--定义全局函数--//void LcdSt7565_WriteCmd(cmd);void LcdSt7565_WriteData(dat);void Lcd12864_Init();void Lcd12864_ClearScreen(void);void Lcd12864_Write16CnCHAR(uchar x, uchar y,uchar k);void Delay10ms(unsigned int c);unsigned char code table[40][32]={/*-- 文字: 。
--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,/*-- 文字: 都--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x06,0xDA,0x22,0x02,0xFE,0x20,0x26,0x28,0x34,0x24,0x7F,0xA4,0x24,0x24,0x20, 0x00,0x07,0x08,0x10,0x08,0xFF,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x02,0x04,/*-- 文字: 皇--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x7C,0x54,0x54,0x54,0x54,0x55,0x56,0x54,0x7C,0x00,0x00,0x00, 0x00,0x40,0x41,0x49,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x49,0x41,0x40,/*-- 文字: 满--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x24,0x24,0x2F,0xE4,0x24,0x24,0xE4,0x2F,0x24,0x24,0x00,0x8C,0x02,0x60,0x10, 0x00,0x7F,0x91,0x49,0x07,0x09,0x19,0x07,0x09,0x11,0xFF,0x00,0x01,0x7E,0x04,0x04,/*-- 文字: 柳--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFC,0x04,0x04,0xFC,0x00,0xF8,0x02,0x04,0xFC,0x10,0x90,0xFF,0xD0,0x10,0x10, 0x00,0x07,0x08,0x04,0xFF,0x00,0x0F,0x32,0x44,0x8F,0x01,0x00,0xFF,0x00,0x03,0x04,/*-- 文字: 烟--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0xFE,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0xFE,0x08,0x10,0xFF,0x00,0x70,0x80, 0x00,0xFF,0x40,0x4C,0x42,0x41,0x46,0x48,0x50,0xFF,0x10,0x08,0x07,0x18,0x60,0x80,/*-- 文字: 胜--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x10,0x10,0x10,0xFF,0x10,0x10,0x3C,0x40,0x00,0xFE,0x22,0x22,0xFE,0x00, 0x00,0x40,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x40,0x00,0xFF,0x82,0x02,0x7F,0x80,/*-- 文字: 绝--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0xE0,0x2C,0x34,0xE4,0x24,0x27,0xE8,0x10,0x20,0x10,0x63,0xAC,0x30,0x20, 0x00,0x70,0x43,0x42,0x42,0x43,0x42,0x42,0x3F,0x00,0x00,0x12,0x12,0x22,0x67,0x22,/*-- 文字: ,--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x58,0x00,0x00,/*-- 文字: 处--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x80,0x40,0x20,0x10,0xFF,0x00,0x00,0xF8,0x08,0x08,0x9F,0x60,0x80,0x00, 0x00,0x40,0x41,0x40,0x40,0x40,0x5F,0x40,0x20,0x20,0x13,0x0C,0x13,0x20,0x40,0x81,/*-- 文字: 好--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x80,0x86,0x8A,0x92,0xE2,0x82,0x82,0x80,0x00,0xF0,0x10,0x1F,0xF0,0x10,0x10, 0x00,0x00,0x00,0x00,0x00,0x7F,0x80,0x40,0x00,0x00,0x61,0x16,0x08,0x15,0x22,0x40,/*-- 文字: 春--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x40,0x44,0x54,0x54,0xD4,0x54,0x54,0x5F,0x74,0x54,0xD4,0x54,0x54,0x44,0x40, 0x00,0x04,0x04,0x02,0x01,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x01,0x02,0x04,0x04,/*-- 文字: 年--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x04,0x44,0x44,0x44,0x44,0xFC,0x44,0x44,0x44,0x44,0xC7,0x18,0x20,0x00, 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x07,0x04,0x04,0x04,/*-- 文字: 一--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*-- 文字: 是--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x00,0x00,0x00,0x7F,0x49,0x49,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00, 0x00,0x81,0x81,0x89,0x89,0x89,0x89,0x89,0xFF,0x81,0x41,0x21,0x1D,0x21,0x41,0x81,/*-- 文字: 最--*//*-- 宋体12; 此字体下对应的点阵为:宽x高=16x16 --*/0x00,0x40,0x40,0x40,0x5F,0x55,0x55,0x55,0x55,0xD5,0x55,0x55,0x5F,0xC0,0x40,0x40, 0x00,0x80,0x80,0x43,0x2D,0x11,0x29,0x47,0x90,0xFF,0x15,0x15,0x25,0x3F,0x60,0x20,/*-- 文字: 。
LCD12864液晶驱动编程指南
LCD12864液晶驱动编程指南
1.连接硬件:
2.初始化液晶:
在开始使用液晶之前,需要进行初始化。
初始化过程包括设置液晶的
工作模式、显示模式和其他参数。
通过向液晶发送一系列的指令,可以完
成初始化过程。
3.编写驱动程序:
液晶驱动程序的主要目的是将需要显示的内容以及液晶的控制指令发
送给液晶屏。
根据液晶屏的通信方式,可以采用单片机的IO口直接控制
液晶屏,也可以通过SPI或I2C等接口芯片间接控制。
4.显示图形:
5.显示文本:
除了图形外,液晶还可以显示文本。
可以通过设置显示位置和发送需
要显示的文本来实现。
6.更新显示:
当需要更新液晶上的内容时,可以通过重新设置显示的内容和刷新液
晶来实现。
可以定时刷新液晶,或者通过检测外部事件来触发刷新。
7.扩展功能:
除了基本功能外,还可以实现一些扩展功能,如显示动画、滚动显示、倒计时等。
只需要根据需求编写相应的代码即可实现。
总结:
注意事项:
在编写驱动程序时,需要注意及时更新液晶上的内容,避免频繁刷新导致的卡顿现象。
同时,为了保证程序的可移植性,可以将液晶驱动程序与其他功能模块进行分离,便于代码的维护和移植。
LCD12864程序
}
/*======================================
显示框架函数
=======================================*/
void disp_frame(void)
wr_lcd (dat,0x11);
}
else if((i%2==1)&&(i!=7)&&(j%4==0))
{
wr_lcd (dat,0x00);
wr_lcd (dat,0x01);
}
else
{
wr_lcd (dat,0x00);
wr_lcd (dat,0x00);
}
}
}
//wr_lcd (comm,0x36);//扩展功能:绘图显示开
wr_lcd (comm,0x30); //进入基本指令动作,8位MPU
wr_lcd (comm,0x01); //清DDRAM
wr_lcd (comm,0x06); //光标左移,AC自动加一
wr_lcd (comm,0x0c); //开显示,关游标
clear_Wdisp();//清除GDRAM
disp_frame();
wr_lcd (comm,0x30);//确保在基本指令模式,此模式下所写的数据存在DDRAM中
wr_lcd (comm,r); //列地址
wr_lcd (comm,c); //行地址,此处的行地址只能是0x80或0x90
wr_lcd (dat,word1); //以(x,y)为起点的8*16区域内显示一个字符,格式为'字符',如显示a则写为'a'。
LCD12864显示程序之欧阳歌谷创作
本例程为通过用AT89C52芯片操作LCD12864显示的程序,使用的晶振为12M。
欧阳歌谷(2021.02.01)/******************************************************** **程序说明:LCD12864显示主程序程序调试员:莫剑辉调试时间:67********************************************************* */#include<reg52.h>#include"12864.c"void main(){Ini_Lcd(); //液晶初始化子程序Disp(1,0,6,"莫剑辉"); //显示数据到LCD12864子程序while(1);}这里我们通过调用下面的头文件就可以了,这样的做法方便/******************************************************** **程序说明:LCD12864显示头文件程序调试员:莫剑辉调试时间:67********************************************************* *///#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define DATA P2 //数据输出端0~7sbit RS=P0^0; //LCD12864 RS端sbit RW=P0^1; //LCD12864 RW端sbit E =P0^2; //LCD12864 E 端sbit PSB =P0^3;/*********************************************延时子程序*********************************************/void Delay_1ms(uint x){uint j,i;for(j=0;j<x;j++){for(i=0;i<120;i++); //延时X乘以120}}/*********************************************LCD12864液晶测忙子程序(读状态)*********************************************/void Busy(){uchar busy;do{E = 0; //0为关闭使能端,1为打开使能端RS = 0; //1为指令,0为数据RW = 1; //1为读,0为写Delay_1ms(20); //延时20乘以120时间E = 1; //0为关闭使能端,1为打开使能端busy=P1; //读取P2状态Delay_1ms(20); //延时20乘以120时间E = 0; //0为关闭使能端,1为打开使能端}while(busy&0x80); //判断BUSY位是否工作:1为内部在工}/*********************************************LCD12864液晶数据写入子程序*********************************************/ void Write_Data(uchar k){Busy(); //测忙E =1; //0为关闭使能端,1为打开使能端RS=1; //1为指令,0为数据RW=0; //1为读,0为写DATA=k; //输入数据K到DA TADelay_1ms(20); //延时20乘以120时间E =0; //0为关闭使能端,1为打开使能端Delay_1ms(20); //延时20乘以120时间}/*********************************************LCD12864液晶命令写入子程序*********************************************/ void Write_Cmd(uchar cmd){Busy(); //测忙E=1; //0为关闭使能端,1为打开使能端 RS=0; //1为指令,0为数据RW=0; //1为读,0为写DATA=cmd; //输入命令cmd到DATADelay_1ms(20); //延时20乘以120时间E=0; //0为关闭使能端,1为打开使能端Delay_1ms(20); //延时20乘以120时间}/*********************************************LCD12864液晶数据显示子程序*********************************************/void Disp(uchar y,uchar x,uchar i,uchar *z){uchar Address;if(y==1){Address=0x80+x;} //Y判断第几行,X判断第几列,0x80为液晶行初始地址if(y==2){Address=0x90+x;}if(y==3){Address=0x88+x;}if(y==4){Address=0x98+x;}Write_Cmd(Address); //写入地址命令到LCD12864while(i) //写入显示数据的大小{Write_Data(*(z++)); //写入显示数据到LCD12864i;}}/********************************************* LCD12864液晶初始化子程序*********************************************/ void Ini_Lcd(void){PSB=1;Delay_1ms(20);Write_Cmd(0x30); //基本指令集Delay_1ms(20);Write_Cmd(0x02); // 地址归位Delay_1ms(20);Write_Cmd(0x0c); //整体显示打开,游标关闭Delay_1ms(20);Write_Cmd(0x06); //游标右移Delay_1ms(20);Write_Cmd(0x80); //设定显示的起始地址Delay_1ms(20);Write_Cmd(0x01); //清除显示}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
本例程为通过用AT89C52芯片操作LCD12864显示的程序,使用的晶振为12M。
欧阳光明(2021.03.07)
/********************************************************** 程序说明:LCD12864显示主程序
程序调试员:莫剑辉
调试时间:2010-6-7
**********************************************************/ #include<reg52.h>
#include"12864.c"
void main()
{
Ini_Lcd(); //液晶初始化子程序
Disp(1,0,6,"莫剑辉"); //显示数据到LCD12864子程序
while(1);
}
这里我们通过调用下面的头文件就可以了,这样的做法方便我们以后要用到LCD12864的程序的调用。
/**********************************************************程序说明:LCD12864显示头文件
程序调试员:莫剑辉
调试时间:2010-6-7
**********************************************************/ //#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define DATA P2 //数据输出端0~7
sbit RS=P0^0; //LCD12864 RS端
sbit RW=P0^1; //LCD12864 RW端
sbit E =P0^2; //LCD12864 E 端
sbit PSB =P0^3;
/*********************************************
延时子程序
*********************************************/
void Delay_1ms(uint x)
{
uint j,i;
for(j=0;j<x;j++)
{
for(i=0;i<120;i++); //延时X乘以120
}
}
/*********************************************
LCD12864液晶测忙子程序(读状态)
*********************************************/
void Busy()
{
uchar busy;
do
{
E = 0; //0为关闭使能端,1为打开使能端
RS = 0; //1为指令,0为数据
RW = 1; //1为读,0为写
Delay_1ms(20); //延时20乘以120时间
E = 1; //0为关闭使能端,1为打开使能端
busy=P1; //读取P2状态
Delay_1ms(20); //延时20乘以120时间
E = 0; //0为关闭使能端,1为打开使能端
}
while(busy&0x80); //判断BUSY位是否工作:1为内部在工作,0为正常状态
}
/*********************************************
LCD12864液晶数据写入子程序
*********************************************/
void Write_Data(uchar k)
Busy(); //测忙
E =1;//0为关闭使能端,1为打开使能端
RS=1;//1为指令,0为数据
RW=0;//1为读,0为写
DATA=k;//输入数据K到DATA
Delay_1ms(20);//延时20乘以120时间
E =0; //0为关闭使能端,1为打开使能端
Delay_1ms(20); //延时20乘以120时间
}
/********************************************* LCD12864液晶命令写入子程序
*********************************************/ void Write_Cmd(uchar cmd)
{
Busy(); //测忙
E=1;//0为关闭使能端,1为打开使能端
RS=0; //1为指令,0为数据
RW=0;//1为读,0为写
DATA=cmd; //输入命令cmd到DATA
Delay_1ms(20);//延时20乘以120时间
E=0;//0为关闭使能端,1为打开使能端
Delay_1ms(20);//延时20乘以120时间
/*********************************************
LCD12864液晶数据显示子程序
*********************************************/
void Disp(uchar y,uchar x,uchar i,uchar *z)
{
uchar Address;
if(y==1){Address=0x80+x;} //Y判断第几行,X判断第几列,0x80为液晶行初始地址
if(y==2){Address=0x90+x;}
if(y==3){Address=0x88+x;}
if(y==4){Address=0x98+x;}
Write_Cmd(Address); //写入地址命令到LCD12864
while(i) //写入显示数据的大小
{
Write_Data(*(z++)); //写入显示数据到LCD12864
i--;
}
}
/*********************************************
LCD12864液晶初始化子程序
*********************************************/
void Ini_Lcd(void)
PSB=1;
Delay_1ms(20);
Write_Cmd(0x30); //基本指令集
Delay_1ms(20);
Write_Cmd(0x02); // 地址归位
Delay_1ms(20);
Write_Cmd(0x0c); //整体显示打开,游标关闭 Delay_1ms(20);
Write_Cmd(0x06); //游标右移
Delay_1ms(20);
Write_Cmd(0x80); //设定显示的起始地址 Delay_1ms(20);
Write_Cmd(0x01); //清除显示
}。