在12864显示任意图片及参考程序
12864液晶图像显示图文教程——最全版
由图可以看到水平坐标一个单位是两字节(即 16 位 D15~D0),X 地址会自动加 1,是直接加一个单位 (即两字节 16 位),比如 0001(也即 0X80+000X80+01),从第一行第一列跳到第一行第二列。 代码: void display_image(uchar *p) { uchar i,j; write_cmd(0x34);//扩充指令集动作 write_cmd(0x34);//关绘图显示功能 /*上半屏显示设置*/ for(i=0;i<32;i++)//上半屏 { write_cmd(0x80+i);//垂直地址 write_cmd(0x80); //水平地址 for(j=0;j<16;j++) { write_data(*p);//连续写入 16 个字节 p++; } } /*下半屏半屏显示设置*/ for(i=0;i<32;i++)//下半屏 { write_cmd(0x80+i);//垂直地址 write_cmd(0x88);//水平地址 for(j=0;j<16;j++)//连续写入 16 个字节 { write_data(*p); p++; } } write_cmd(0x36);//开绘图显示 write_cmd(0x30);//回到基本指令集 } 源程序: #include <reg52.h> #include "12864.h" X 坐标(水平)方向以 2 字节 Byte 为单位,Y 坐标(垂直) 方向以 1 位 Bit 为单位,先连续写入垂直与水平坐标,再写入 两字节数据到 GDRAM。 这里是这样进行的:i=0 时,j=0,1 时,写入两字节到垂直 (0X80+00)水平(0X80+00)这格(D15~D0)里;然后 X 坐标地址自增 1, 地址变为垂直 (0X80+00) , 水平 (0X80+01) 这格,在 j=2,3 时写入两字节,………一直到垂直(0X80+00) 水平(0X80+07)这格,在 j=14,15 时写入两字节,此时循环 for(j=0;j<16;j++)结束跳出,刚好第一行 128 位写完数据;然后 i++,开始写第二行……
带字库LCD12864自定义图形、汉字显示
带字库的LCD12864自定义图片、汉字显示
一、将图片修改成128*64像素
1、打开win7自带的画图软件,载入图片(图片不满足128*64)
2、点击重新调整大小(或者图片处右击鼠标),如下设置,保持纵横比不勾选。
3、图片另存为,选择单色位图。
二、LCD12864用ZIMO21软件取模(BMP图片)
1、基本设置里面设置LCD的大小(如果图片像素就是128*64就不需要设置,直接打开)
2、打开BMP图片(黑白)
3、发现图片偏小,不足128*64,此时生成的数据就缺少128*64个点,显示会照成错误,需要修改一下图片大小。
改成128*64
3、直接调入128*64图片
4、设置参数,如下
5、取模选择C51格式
6、显示效果
三、PCtoLCD2002图片取模设置
四、PCtoLCD2002汉字取模设置(根据程序而定)
1、汉字取模参数设置
2、显示效果如下。
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 );//提示信息显示}。
12864显示文字+图像
引用12864液晶原理分析3他山之石2010-07-21 20:52:05 阅读7 评论0 字号:大中小小峰的12864液晶原理分析3一、ST7920控制IC的LCD12864实现反白显示从使用手册上可知,扩展指令里的0x03+行号即可实现反白对应行。
但是ST7920 控制器的128×64 点阵液晶其实原理上等同256×32 点阵,第三行对应的DDRAM 地址紧接第一行;第四行对应的DDRAM 地址紧接第二行。
所以128×64 点阵的液晶执行反白功能时实用意义不大,因为用户对第一行执行反白显示操作时,第三行必然也反白显示;第二行反白,第四行也必然反白。
其实还是有办法做到单行反白的,解决方法就是混用图形显示和字符显示。
其理论支持在于:在ST7920中,字符显示的DDRAM和图形的GDRAM是相互独立的,而最后显示到液晶上的结果,是两个RAM中数据的异或。
具体来说:假如某个点上,绘图RAM的没有绘图(数据为0),而字符RAM上有点阵(数据为1),那么异或的结果就是1,也就是说正常显示字符;当字符上RAM没有点阵的时候,异或的结果是0,自然也就不显示了。
假如该点上绘图RAM绘图了(数据为1),当字符RAM上有点阵(数据为1时),异或的结果为0,效果就是反白显示;如果字符RAM没有点阵(数据为0时),异或结果为1,效果就是显示绘图的背景。
所以,如果要在某个地方反白显示,那么就在该点绘图并且写字,如果要取消反白,就重新用全0擦掉那个地方的绘图!这样一来可以实现任何地方、任意大小的反白显示,反而比原指令中的单行反白的功能更好更强大。
二、对于整屏既有图象又有文本,则可以用两种方式实现:1、首先文本DDRAM写入要写的字符,其余全部空格(即0X00),然后再在没有字符的地方(即非点亮的晶格中,0X00)绘入图象。
DDRAM与GDRAM异或后就可以整屏实现图象与文本。
参见程序实例1。
12864显示图形和文字
/*******************************************************/
void lcd_out(unsigned char send_byte)
/*******************************************************/
void lcd_control()
{
WR_control(0x30);
WR_control(0x0C);
}
/*******************************************************/
/****** 参 数: 无 ******/
/****** 返回值 : 无 ******/
/*******************************************************/
{
bcd &= 0x0F;
if(bcd > 9)
bcd +=('7'); // 将A~F转换为ASCII
else
bcd += '0'; // 将0~9转换为ASCII 0~9
return(bcd);
{
unsigned char i,s;
for (i=0;i<8;i++)
{
if((send_byte&0x80)==0)
{
LCD_DATAL;
}
else
{
LCD_DATAH;
} //送数据
LCD12864显示图形程序
COM
EQU 20H ;指令数据寄存器
DAT
EQU 21H ;显示数据寄存器
;********************************变量定义结束**********************************
;*********************************程序开始************************************
指令和数据;BF=0时,模块为准备状态,随时可接受外部指令和数据。利用状态 读指令,可以将BF读到DB7总线,从而检验LCD的工作状态 4. 显示控制触发器DFF
此触发器是用于模块屏幕显示开和关的控制。DFF=1为开显示,DISPLAY OFF DDRAM的内容就显示在屏幕上;DFF=0为关显示。DISPLAY OFF DDRAM的状态是指 令显示ON/OFF和RST信号控制的。 5. XY地址计数器
2.2 程序功能
LCD 会每隔 1 秒显示一个画面,共 3 个画面,一直循环下去。 第 1 秒:
第 2 秒: 第 3 秒:
8
嵌入式应用软件园,版权所有,请勿转载/销售。
第 3 章程序代码
3.1 文本版代码
我们的辛勤付出,需要您的肯定,请访问: 嵌入式应用软件园。
;******************************************************************************
第 3 章程序代码 .....................................................................................9 3.1 文本版代码 ................................................................................ 9 3.2 图片版代码 .............................................................................. 21
用12864做示波器(程序和图)
#include <reg51.h>#include <intrins.h>#include <ADC0808.c>sbit DI=P2^2; // 数据\指令选择sbit RW=P2^1; // 读\写选择sbit E=P2^0; // 读\写使能sbit CS1=P2^4; // 片选1sbit CS2=P2^3; // 片选2sbit busy=P1^7;sbit jia=P3^7;sbit jian=P3^3;sbit jia1=P3^0;sbit jian1=P3^1;unsigned int i;unsigned char ye,lei,shu; unsigned char a[94];char code t[]={0x00,0x00,0x08,0x00,0x04,0x00,0x02,0x00,0x01,0x80,0x40,0x60,0x80,0x00,0x7F,0xFF, //小0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x80,0x01,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x82,0x00,0x82,0x00,0x82,0x40,0x82,0x80,0x82,0x7F,0xE2, //子0x00,0xA2,0x00,0x92,0x00,0x8A,0x00,0x86,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,0x40,0x00,0x60,0x3F,0x5E,0x01,0x48,0x01,0x48,0xFF,0xFF,0x11,0x48,0x21,0x4C, //制0x1F,0x68,0x00,0x40,0x07,0xF8,0x40,0x00,0x80,0x00,0x7F,0xFF,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x40,0x00,0x20,0xFF,0xF8,0x00,0x87,0x00,0x40,0x00,0x30,0x00,0x0F, //作0xFF,0xF8,0x08,0x88,0x08,0x88,0x08,0xC8,0x0C,0x88,0x08,0x0C,0x00,0x08,0x00,0x00,};void checkstate(){//bit dat;DI=0;RW=1;//P1=0x00;do{E=1;E=0;//仅当第7位为0时才可操作(判别busy信号)}while(busy==1);}void writecommand(unsigned char command) //写命令{checkstate();DI=0;RW=0;P1=command;E=1;E=0;}void writedate(unsigned char date) //写数据{checkstate();DI=1;RW=0;P1=date;E=1;E=0;}void pianxuan(unsigned int i){if(i==1)CS1=0,CS2=1;if(i==2)CS1=1,CS2=0;if(i==3)CS1=0,CS2=0;}void cleanscreen() //清屏{unsigned char page,i;for(page=0xb8;page<0xc0;page++){writecommand(page);writecommand(0x40);for(i=0;i<64;i++)writedate(0x00);}}void init(void) //开显示,起始行0行{writecommand(0xc0);writecommand(0x3f);}void delay_50us(uint t){uchar j;for(;t>0;t--)for(j=19;j>0;j--);}void shuju(){pianxuan(i); writecommand(ye); writecommand(lei); writedate(shu);}void qing(){uchar i;for(i=0xb8;i<=0xbf;i++) {ye=i;shu=0x00;shuju();}}void main(){uint r,j,g=0,q,dianya=1,k,p;uchar U,m,l;pianxuan(3);cleanscreen();init();pianxuan(2);l=0xb8;for(k=0;k<4;k++,l=l+0x02){ye=l;lei=0x70;for(r=0;r<16;r++){shu=t[2*r+1+32*k];shuju();lei++;}ye=l+0x01;lei=0x70;for(r=0;r<16;r++){shu=t[2*r+32*k];shuju();lei++;}}while(1){uchar d1,d2,d3,d4,d5;aaa:do{adc();}while((AD!=128)&&(AD!=129)&&(AD!=130));U=AD;adc();if(U>AD)goto aaa;while(jia==0){while(jia==0);g=g+1;}while(jian==0){while(jian==0);if(g!=0) g=g-1;}while(jia1==0){while(jia1==0);dianya=dianya+1;}while(jian1==0){while(jian1==0);if(dianya!=1) dianya=dianya-1;}for(j=0;j<94;j++) //AD采样{adc();a[j]=AD;delay_50us(g);}lei=0x40;for(r=0,j=0;r<94;r++,j++){if(j<64) i=1;if(j==64) lei=0x40;if(j>=64)i=2;qing(); //清掉之前的内容AD=a[j]*0.196/dianya; //计算在12864的电压值if(AD<=7) ye=0xbf,shu=(0x80>>AD); else if(AD<=15) ye=0xbe,shu=0x80>>(AD-8); else if(AD<=23) ye=0xbd,shu=0x80>>(AD-16); else if(AD<=31) ye=0xbc,shu=0x80>>(AD-24); else if(AD<=39) ye=0xbb,shu=0x80>>(AD-32); else if(AD<=47) ye=0xba,shu=0x80>>(AD-40); else if(AD<=55) ye=0xb9,shu=0x80>>(AD-48); else if(AD<=63) ye=0xb8,shu=0x80>>(AD-56);if(r==0){d1=shu;d2=ye;}if(r!=0){d3=shu;d4=ye;if(ye==d2){if(shu>d1){d5=shu;d5=d5>>1;while(d5!=d1){d5=d5>>1;shu=shu|(shu>>1);}}if(shu<d1){d5=shu;d5=d5<<1;while(d5!=d1){d5=d5<<1;shu=shu|(shu<<1);}}if(ye<d2){for(q=0;q<7;q++){shu=shu|(shu<<1);}shuju();ye++;while(ye<d2) {shu=0xff,shuju(),ye++;}if(ye==d2){shu=0x01;if(shu<d1){d5=shu;d5=d5<<1;while(d5!=d1){d5=d5<<1;shu=shu|(shu<<1);}}}}if(ye>d2){for(q=0;q<7;q++){shu=shu|(shu>>1);}shuju();ye--;while(ye>d2) {shu=0xff,shuju(),ye--;}if(ye==d2){shu=0x80;if(shu>d1){d5=shu;d5=d5>>1;while(d5!=d1){d5=d5>>1;shu=shu|(shu>>1);}}}}}if(r!=0)d1=d3;d2=d4;}shuju();if(lei!=0x7f) lei++; }}}。
12864显示任意128 64像素图片
工具箱旁边那个LCD12864很久没用了(当初买回来用的时候只是简单地测试了一下),于是萌生了重新写一次接口程序的想法(而且这次要给它加个图片显示的功能),好,说做就做,就用Atmega16和ICCAVR来做吧,最近这MCU 和平台用得比较熟练。
马上从书堆里把当初打印出来的中文datasheet给翻了出来,依葫芦画瓢地写了个初始化程序。
好,OK。
编译通过。
于是又写了一个可以自定义从XY 坐标值开始输出显示的函数,再次编译,也通过,OK。
于是呼马上写了四行简单的字符烧到单片机上试了一下,嘿嘿,一次通过。
如下图:后来在进一步测试的时候也出了点小问题。
就是我是使用USBISP 烧写器把程序烧写进AVR的(此时实验板由USBISP烧写器供电),想要实现从第一行的第一个字符开始连续显示"0123456789"。
刚烧写完程序后能看到LCD12864上正常显示"0123456789",但是把烧写器从实验板上断开连接,单独用USB给实验板供电的时候,LCD的第一行只是显示"123456789",第一个字符消失了……,左思右想地弄了一个多小时后,终于把问题给解决了,就是把初始化程序的延时适当增加了些,真是奇怪。
刚开始一直想不通为什么在烧写器供电的情况下就正常显示,而换到USB供电后就出了问题。
后来再想想,估计是跟供电有关。
在使用USBISP烧写器供电的时候,LCD的背光灯明显比用USB供电的时候来得亮,而且对比度也高很多,看来是因为换到USB供电后,供电不怎么充足,以至于LCD在上电初始化的时候花上了更多的时间去初始化(因为供电低了,功率小了,跑起来有点力不从心,用的时间就久了嘛……我是觉得可以这样去理解的)接下来呢,就到了有点难度的画图了。
当初刚买到12864的时候只是简单测试了字符显示功能,除了因为画图还不需要用到,另外一个原因就是那datasheet上关于画图那部分的内容不怎么看得懂……。
[原创]12864 LCD图形显示程序例子
这是一个在LCD128*64上显示图形的一个程序,一直以来都总是不知道怎么搞,现在终于都通了,想当初在网上总找,要不是程序不全,就是无法运行,或者是C51汇编语言,让人不爽,这样的痛苦不可以再让别人难受了。
在LCD上显示一幅图,是“我的电脑,我的文档”。
IC用PIC16F877A,晶振4MHZ,采用并行8线,LCD:TS12864-3,接法在程序中有定义,只要将此程序COPY到你的PICC里编译下载后,在目标板上即可以看到图画了!不知道可不可以加酷?#include "pic.h"#define RS RC0#define RW RC1#define E RC2#define PSB RC3#define RST RC4//PORTD=DATA;unsigned char COUNT3,COUNT2,COUNT1,COUNT,LCD_X,LCD_Y,LCD_DATA1,LCD_D ATA2,LCD_DATA,F3,R1,F0;const unsigned char TU_TAB1[]={// 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 10xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0xF0,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x18,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xDC,0x00, 0x01,0x80,0x00,0x1F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0xBF,0xFF,0xBC,0x00,0 x01,0x80,0x00,0x30,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0xB8,0x00,0 x01,0x80,0x00,0x30,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0x78,0x00,0 x01,0x80,0x00,0x19,0xFF,0xFE,0xC0,0x00,0x00,0x00,0x00,0x02,0xFF,0xFF,0x70,0x00,0 x01,0x80,0x00,0x18,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xFF,0xFE,0xF0,0x00,0 x01,0x80,0x00,0x0C,0x01,0xFF,0x60,0x00,0x00,0x00,0x00,0x05,0xFF,0xFE,0xE0,0x00, 0x01,0x80,0x00,0x0C,0x7F,0xD0,0x20,0x00,0x00,0x00,0x00,0x05,0xFF,0xFD,0xE0,0x00,0x 01,0x80,0x00,0x06,0x00,0x0F,0xB0,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFD,0xC0,0x00,0x 01,0x80,0x00,0x06,0x03,0xFC,0x10,0x00,0x00,0x00,0x00,0x0B,0xFF,0xFB,0xC0,0x00,0x 01,0x80,0x00,0x03,0x1F,0x00,0x18,0x00,0x00,0x00,0x00,0x17,0xFF,0xFB,0x80,0x00,0x0 1,0x80,0x00,0x03,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x80,0x00,0x0 1,0x80,0x00,0x01,0x80,0x00,0x0C,0x00,0x00,0x00,0x00,0x17,0xFF,0xF7,0x00,0x00,0x 01,0x80,0x00,0x01,0x80,0x00,0x04,0x00,0x00,0x00,0x00,0x09,0xFF,0xEF,0x00,0x00,0x0 1,0x80,0x00,0x00,0xC0,0x00,0xF6,0x00,0x00,0x00,0x00,0x06,0x7F,0xEE,0x00,0x00,0x 01,0x80,0x00,0x00,0xC0,0x03,0xC2,0x00,0x00,0x00,0x00,0x01,0x9F,0xDE,0x00,0x00,0x 01,0x80,0x00,0x00,0x60,0x00,0x3B,0x00,0x00,0x00,0x00,0x00,0x67,0xDF,0x00,0x00,0x 01,0x80,0x00,0x00,0x60,0x00,0xE3,0x00,0x00,0x00,0x00,0x00,0x19,0xBF,0x00,0x00,0x 01,0x80,0x00,0x00,0x30,0x03,0x8E,0x00,0x00,0x00,0x00,0x00,0x06,0x3F,0x00,0x00,0x0 1,0x80,0x00,0x00,0x30,0x06,0x3C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x00,0x00,0x 01,0x80,0x00,0x00,0x18,0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x0 1,0x80,0x00,0x00,0x18,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x0F,0x7F,0x80,0x00,0x0 1,0x80,0x00,0x00,0x0C,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x1F,0xC0,0x00,0 x01,0x80,0x00,0x00,0x0C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x07,0xE0,0x00,0x 01,0x80,0x00,0x00,0x06,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x1F,0xE0,0x00,0x 01,0x80,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x3F,0xC0,0x00,0x 01,1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x00,0x00,0x 01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x00,0x00,0x0 1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x 01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 1,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0 1,0x80,0x05,0x40,0x88,0x04,0x01,0x08,0x00,0x00,0x0A,0x81,0x10,0x04,0x00,0x20,0x0 1,0x80,0x79,0x21,0x08,0x02,0x21,0x49,0x00,0x00,0xF2,0x42,0x10,0x04,0x47,0x10,0x0 1,0x80,0x09,0x07,0xDF,0x7F,0xF7,0xAA,0x00,0x00,0x12,0x0F,0xBE,0x7F,0xE5,0xFE,0 x01,0x80,0x7F,0xF4,0x51,0x08,0x81,0x2C,0x00,0x00,0xFF,0xE8,0xA2,0x44,0x47,0x00,0x 01,0x80,0x09,0x04,0x61,0x08,0x81,0x7F,0x00,0x00,0x12,0x08,0xC2,0x7F,0xC5,0x4A,0x 01,0x80,0x0B,0x24,0x51,0x08,0x83,0x81,0x00,0x00,0x16,0x48,0xA2,0x44,0x45,0x6A,0x 01,0x80,0x1D,0x47,0xC9,0x05,0x05,0x01,0x00,0x00,0x3A,0x8F,0x92,0x44,0x47,0x52,0x 01,0x80,0x68,0x84,0x49,0x05,0x05,0x7F,0x00,0x00,0xD1,0x08,0x92,0x7F,0xC5,0x6A,0x 01,0x80,0x09,0x94,0x41,0x02,0x01,0x01,0x00,0x00,0x13,0x28,0x82,0x44,0x05,0x4A,0 x01,0x80,0x0E,0x57,0xC1,0x0D,0x81,0x01,0x00,0x00,0x1C,0xAF,0x82,0x04,0x29,0x42,0x 01,0x80,0x38,0x34,0x4E,0x70,0x71,0x7F,0x00,0x00,0x70,0x68,0x9C,0x03,0xEB,0x7E, 0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0 xFF};//*************delay_ms********************************void delay_10us(unsigned char x){while(x--);}void delay_ms(unsigned char cnt){unsigned char i;do {i = 4;do {delay_10us(39);} while(--i);} while(--cnt);}//***********检查是否LCD忙碌的子程序**********************void check_busy(void){TRISD=0xff;//在此处设为输入。
12864显示任意128 64像素图片
工具箱旁边那个LCD12864很久没用了(当初买回来用的时候只是简单地测试了一下),于是萌生了重新写一次接口程序的想法(而且这次要给它加个图片显示的功能),好,说做就做,就用Atmega16和ICCAVR来做吧,最近这MCU 和平台用得比较熟练。
马上从书堆里把当初打印出来的中文datasheet给翻了出来,依葫芦画瓢地写了个初始化程序。
好,OK。
编译通过。
于是又写了一个可以自定义从XY 坐标值开始输出显示的函数,再次编译,也通过,OK。
于是呼马上写了四行简单的字符烧到单片机上试了一下,嘿嘿,一次通过。
如下图:后来在进一步测试的时候也出了点小问题。
就是我是使用USBISP 烧写器把程序烧写进AVR的(此时实验板由USBISP烧写器供电),想要实现从第一行的第一个字符开始连续显示"0123456789"。
刚烧写完程序后能看到LCD12864上正常显示"0123456789",但是把烧写器从实验板上断开连接,单独用USB给实验板供电的时候,LCD的第一行只是显示"123456789",第一个字符消失了……,左思右想地弄了一个多小时后,终于把问题给解决了,就是把初始化程序的延时适当增加了些,真是奇怪。
刚开始一直想不通为什么在烧写器供电的情况下就正常显示,而换到USB供电后就出了问题。
后来再想想,估计是跟供电有关。
在使用USBISP烧写器供电的时候,LCD的背光灯明显比用USB供电的时候来得亮,而且对比度也高很多,看来是因为换到USB供电后,供电不怎么充足,以至于LCD在上电初始化的时候花上了更多的时间去初始化(因为供电低了,功率小了,跑起来有点力不从心,用的时间就久了嘛……我是觉得可以这样去理解的)接下来呢,就到了有点难度的画图了。
当初刚买到12864的时候只是简单测试了字符显示功能,除了因为画图还不需要用到,另外一个原因就是那datasheet上关于画图那部分的内容不怎么看得懂……。
12864LCD显示图形文字程序代码--STC89C52
/********函数声明*************************************************************/ void WriteDataLCD(unsigned char WDLCD); void WriteCommandLCD(unsigned char WCLCD,BuysC); unsigned char ReadDataLCD(void); unsigned char ReadStatusLCD(void); void LCDInit(void); void LCDClear(void); void LCDFlash(void); void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData); void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData); void DisplayImage (unsigned char code *DData); void Delay5Ms(void); void Delay400Ms(void);
sbit LCD_RS=P1^0;
sbit LCD_RW=P1^1;
sbit LCD_E=P1^2; sbit PSB =P1^6;
//PSB 脚为 12864-12 系列的串、并通讯功能切换,我们使用 8 位义***********************************************************/ #define LCD_Data P0 #define Busy 0x80 //用于检测 LCD 状态字中的 Busy 标识
12864显示汉字,图型,任意点,任意直线程序(绝对能用)
#include<stdio.h>#include<reg52.h>#include<math.h>#include<intrins.h>sbit RS=P0^0;sbit RW=P0^1;sbit E=P0^2;sbit PSB=P0^3;sbit RES=P0^4;#define LCD12864_DatePort P2unsigned char lcd_x,lcd_y;unsigned char h[]={"aaaaaaaaaaaaaaaa"};unsigned char code image[1024]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0xFF,0xE0,0x00,0x00,0x00,0x1F,0xC1,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x07,0xFF,0xF8,0x00,0x00,0x00,0xFF,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x1F,0xFF,0xFC,0x00,0x00,0x01,0xFF,0xFE,0x1F,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,0x3F,0xFF,0xFF,0x00,0x00,0x07,0xFF,0xFF,0x9E,0xC0,0x00,0x00,0x00,0x00, 0x00,0x00,0x7F,0xFF,0xFF,0x80,0x00,0x0F,0xFF,0xFF,0xEC,0x60,0x00,0x00,0x00,0x00, 0x00,0x00,0xFF,0xFF,0xFF,0xC0,0x00,0x0F,0xFF,0xFF,0xE0,0x40,0x00,0x00,0x00,0x00, 0x00,0x01,0xFF,0x3E,0x3F,0xC0,0x00,0x1F,0xE3,0xE7,0xF0,0x80,0x00,0x00,0x00,0x00, 0x00,0x01,0xFE,0x1E,0x1F,0xE0,0x00,0x3F,0xE3,0xC3,0xF9,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0xFC,0x1C,0x1F,0xE0,0x00,0x3F,0xC1,0xC3,0xFC,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0xFC,0x6D,0x9F,0xF0,0x00,0x7F,0xC1,0x81,0xFE,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0xFC,0x6D,0x8F,0xF0,0x00,0x7F,0xCD,0xB1,0xFE,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0xFC,0x6D,0x9F,0xF0,0x00,0x7F,0xCF,0xB1,0xFF,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0xFC,0x1C,0x1F,0xF0,0x00,0xFF,0xC5,0xF3,0xFF,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0xFE,0x1E,0x1F,0xF8,0x00,0xFF,0xE3,0xC3,0xFF,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0xFF,0x3E,0x3F,0xF8,0x00,0xFF,0xE3,0xE7,0xFF,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0xFF,0xF3,0xFF,0xF8,0x00,0xFF,0xFE,0x7F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0xC1,0xCF,0xFC,0x00,0xFF,0x9C,0x38,0xFF,0x80,0x00,0x00,0x00,0x00, 0x00,0x0F,0xE0,0x7F,0x83,0xFC,0x01,0xFE,0x0F,0xF0,0x3F,0x80,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0x00,0x3F,0xFC,0x01,0xFF,0xE0,0x07,0xFF,0x80,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0xFB,0xFF,0xFC,0x01,0xBF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00, 0x00,0x1F,0xFF,0xFF,0xFF,0xFC,0x01,0xDF,0xFF,0xFF,0xFB,0x80,0x00,0x00,0x00,0x00, 0x00,0x3F,0xFF,0xFF,0xFF,0xFC,0x03,0xC7,0xFF,0xFF,0xE7,0x80,0x00,0x00,0x00,0x00, 0x00,0x7F,0xFF,0xFF,0xFF,0xFC,0x07,0xC1,0xFF,0xFF,0x8F,0xC0,0x00,0x00,0x00,0x00, 0x00,0xFF,0xFF,0xFF,0xFF,0xFE,0x0F,0xE0,0x3F,0xFC,0x3F,0xC0,0x00,0x00,0x00,0x00, 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x1F,0xF8,0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00, 0x01,0xFC,0x7F,0xFF,0xFF,0x3F,0x1F,0x8E,0x00,0x00,0xE3,0xF0,0x00,0x00,0x00,0x00, 0x03,0xF8,0x7F,0xFF,0xFC,0x1F,0xBF,0x87,0xC8,0x1F,0x83,0xF0,0x00,0x00,0x00,0x00, 0x03,0xF8,0x7F,0xFF,0xE0,0x1F,0xFF,0x87,0xFF,0xFC,0x01,0xF8,0x00,0x00,0x00,0x00, 0x03,0xF8,0x7F,0x00,0x00,0x1F,0xFF,0x04,0xE0,0x00,0x01,0xF8,0x00,0x00,0x00,0x00, 0x07,0xF8,0x7F,0x00,0x00,0x0F,0xFF,0x04,0x60,0x00,0x01,0xF8,0x00,0x00,0x00,0x00, 0x07,0xF8,0x7F,0x00,0x00,0x0F,0xFF,0x0C,0x60,0x00,0x01,0xFC,0x00,0x00,0x00,0x00, 0x07,0xF8,0x7F,0x00,0x00,0x0F,0xFF,0x0C,0x60,0x00,0x01,0xFC,0x00,0x00,0x00,0x00, 0x07,0xF8,0x7F,0x00,0x00,0x0F,0xFF,0x06,0x60,0x00,0x01,0xFC,0x00,0x00,0x00,0x00, 0x07,0xB8,0x3E,0x00,0x00,0x19,0xF3,0x87,0xE0,0x00,0x01,0xBC,0x00,0x00,0x00,0x00, 0x07,0x18,0x00,0x00,0x00,0x18,0xE3,0x80,0x00,0x00,0x01,0x18,0x00,0x00,0x00,0x00, 0x00,0x1C,0x00,0x00,0x00,0x10,0x01,0x80,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00, 0x00,0x0C,0x00,0x00,0x00,0x30,0x01,0xC0,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00, 0x00,0x06,0x00,0x00,0x00,0x60,0x00,0xE0,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x00,0x00,0x00,0x40,0x00,0x70,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00, 0x00,0x03,0x80,0x00,0x00,0xC0,0x00,0x78,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00, 0x00,0x0D,0xE0,0x00,0x03,0xB8,0x01,0x9C,0x00,0x00,0x3B,0x00,0x00,0x00,0x00,0x00, 0x00,0x18,0x78,0x00,0x0F,0x7C,0x03,0xCF,0x00,0x00,0xE7,0x80,0x00,0x00,0x00,0x00, 0x00,0x10,0x1C,0x00,0x3E,0xFC,0x03,0xF3,0xE0,0x03,0xDF,0x80,0x00,0x00,0x00,0x00, 0x00,0x1A,0x0B,0xC1,0xE3,0xF8,0x01,0xF8,0xFC,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00, 0x00,0x0F,0xF1,0x80,0xEF,0xE0,0x00,0x7F,0xF0,0x1F,0xFC,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};void delay_ms(unsigned char z) //延时{unsigned i,j;for(i=0;i<z;i++)for(j=0;j<110;j++);}void LCD12864_WriteCmd(unsigned int cmd) //写命令{RS=0;RW=0;E=0;LCD12864_DatePort=cmd;delay_ms(5);E=1;delay_ms(5);E=0;}void LCD12864_WriteDate(unsigned char dat) //写数据{RS=1;RW=0;E=0;LCD12864_DatePort=dat;delay_ms(5);E=1;delay_ms(5);E=0;}void LCD12864_Init(){PSB=1; //1并行,0串行LCD12864_WriteCmd(0x30); //基本指令操作//delay_ms(5);LCD12864_WriteCmd(0x0c); //显示开,关光标//delay_ms(5);LCD12864_WriteCmd(0x01); //清除led的显示内容//delay_ms(5);LCD12864_WriteCmd(0x06);}/*====================================================函数功能:清除GCROM的内容,如果不清除会出现花屏现象清除方法:向GCROM中写入0x00来清除内========================================================*/ void LCD12864_ClearGDRAM(){unsigned char i,j,k;lcd_x=0x80;lcd_y=0x80;LCD12864_WriteCmd(0x34);for(i=0;i<2;i++){for(j=0;j<32;j++){LCD12864_WriteCmd(lcd_y+j);LCD12864_WriteCmd(lcd_x);for(k=0;k<16;k++){LCD12864_WriteDate(0x00);}}lcd_x=0x88;}LCD12864_WriteCmd(0x36);LCD12864_WriteCmd(0x30);}/*================================================================ 函数功能:向12864中写入一幅图片函数参数:lcd_x为水平显示位置,lcd_y为垂直显示位置,函数将12864屏分成上下两屏写入,上半屏LCD_x=0x80,下半屏lcd_x=0x88=================================================================*/ void LCD12864_WriteImage(unsigned char *p){unsigned char i,j,k;lcd_x=0x80;lcd_y=0x80;LCD12864_WriteCmd(0x34);for(i=0;i<2;i++) //分为上下两屏{for(j=0;j<32;j++){LCD12864_WriteCmd(lcd_y+j);LCD12864_WriteCmd(lcd_x);for(k=0;k<16;k++) //写入显示数据{LCD12864_WriteDate(*p++);}}lcd_x=0x88;}LCD12864_WriteCmd(0x36);LCD12864_WriteCmd(0x30);}bit LCD12864_CheckBusy() //读忙碌状态{bit i;RS=0;RW=1;E=1;LCD12864_DatePort=0xff;delay_ms(1);i=(bit)(LCD12864_DatePort&0x80);E=0;return(i);}unsigned char LCD12864_ReadByte( void ){unsigned char ReturnValue ;LCD12864_CheckBusy() ;LCD12864_DatePort = 0xff ;RS=1;RW=1;E=0;E=1;ReturnValue =LCD12864_DatePort;E=0;return ReturnValue ;}void LCD12864_DrawPoint( unsigned char X, unsigned char Y, unsigned char Color ) {unsigned char Row , Tier , Tier_bit ;unsigned char ReadOldH, ReadOldL ;LCD12864_WriteCmd( 0x34 ) ;LCD12864_WriteCmd( 0x36 ) ;Tier = X >> 4 ;Tier_bit = X & 0x0f ;if( Y < 32 ){Row = Y ;}else{Row = Y - 32 ;Tier += 8 ;}LCD12864_WriteCmd( Row + 0x80 ) ;LCD12864_WriteCmd( Tier + 0x80 ) ;LCD12864_ReadByte();ReadOldH = LCD12864_ReadByte() ;ReadOldL = LCD12864_ReadByte() ;LCD12864_WriteCmd( Row + 0x80 ) ;LCD12864_WriteCmd( Tier + 0x80 ) ;if( Tier_bit < 8 ){switch( Color){case 0 : ReadOldH &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;case 1 : ReadOldH |= ( 0x01 << ( 7 - Tier_bit )) ; break ;case 2 : ReadOldH ^= ( 0x01 << ( 7 - Tier_bit )) ; break ;default : break ;}LCD12864_WriteDate( ReadOldH ) ;LCD12864_WriteDate( ReadOldL ) ;}else{switch(Color){case 0 : ReadOldL &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;case 1 : ReadOldL |= ( 0x01 << ( 15 - Tier_bit )) ; break ;case 2 : ReadOldL ^= ( 0x01 << ( 15 - Tier_bit )) ; break ;default : break ;}LCD12864_WriteDate( ReadOldH ) ;LCD12864_WriteDate( ReadOldL ) ;}LCD12864_WriteCmd( 0x30 ) ;}void LCD12864_DrawLine_X( unsigned char X0, unsigned char X1, unsigned char Y, unsigned char Color ){ unsigned char Temp ;if( X0 > X1 ){Temp = X1 ;X1 = X0 ;X0 = Temp ;}for( ; X0 <= X1 ; X0++ )LCD12864_DrawPoint( X0, Y, Color ) ;}void LCD12864_DrawLine_Y( unsigned char X, unsigned char Y0, unsigned char Y1, unsigned char Color ){unsigned char Temp ;if( Y0 > Y1 ){Temp = Y1 ;Y1 = Y0 ;Y0 = Temp ;}for(; Y0 <= Y1 ; Y0++)LCD12864_DrawPoint( X, Y0, Color) ;}void LCD12864_DrawLine( unsigned char StartX, unsigned char StartY, unsigned char EndX, unsigned char EndY, unsigned char Color ){int t, distance; /*根据屏幕大小改变变量类型(如改为int型)*/int x = 0 , y = 0 , delta_x, delta_y ;char incx, incy ;delta_x = EndX - StartX ;delta_y = EndY - StartY ;if( delta_x > 0 ){incx = 1;}else if( delta_x == 0 ){LCD12864_DrawLine_Y( StartX, StartY, EndY, Color ) ;return ;}else{incx = -1 ;}if( delta_y > 0 ){incy = 1 ;}else if(delta_y == 0 ){LCD12864_DrawLine_X( StartX, EndX, StartY, Color ) ;return ;}else{incy = -1 ;}delta_x = abs( delta_x );//求绝对值delta_y = abs( delta_y );if( delta_x > delta_y ){distance = delta_x ;}else{distance = delta_y ;}LCD12864_DrawPoint( StartX, StartY, Color ) ;/* Draw Line*/for( t = 0 ; t <= distance+1 ; t++ ){LCD12864_DrawPoint( StartX, StartY, Color ) ;x += delta_x ;y += delta_y ;if( x > distance ){x -= distance ;StartX += incx ;}if( y > distance ){y -= distance ;StartY += incy ;}}}void LCD12864_DrawCross(){LCD12864_DrawLine_X( 0, 127 , 0, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 7, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 15, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 23, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 31, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 39, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 47, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 55, 1 ) ;LCD12864_DrawLine_X( 0, 127 , 63, 1 ) ;LCD12864_DrawLine_Y( 0, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 15, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 31, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 47, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 63, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 79, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 95, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 111, 0 , 63, 1 ) ;LCD12864_DrawLine_Y( 127, 0 , 63, 1 ) ;}void LCD12864_Draw_ObliqueLine(){LCD12864_DrawLine( 0, 0, 127, 63, 1 ) ;LCD12864_DrawLine( 0, 63, 127, 0 , 1 ) ;LCD12864_DrawLine( 12, 0, 127, 63, 1 ) ;LCD12864_DrawLine( 52, 63, 127, 0 , 1 ) ;LCD12864_DrawLine( 32, 63, 98, 0, 1 ) ;LCD12864_DrawLine( 67, 0, 127, 63 , 1 ) ;}void LCD12864_DisplayOneChar(unsigned char X, unsigned char Y, unsigned char Data) {switch(Y){case 0:Y=0X80;break; //根据行数来选择相应地址case 1:Y=0X90;break;case 2:Y=0X88;break;case 3:Y=0X98;break;}LCD12864_WriteCmd( Y+X ); //这里不检测忙信号,发送地址码LCD12864_WriteDate(Data);}void LCD12864_DisplayListChar(unsigned char X, unsigned char Y, unsigned char *Data) {switch(Y){case 0:Y=0X80;break; //根据行数来选择相应地址case 1:Y=0X90;break;case 2:Y=0X88;break;case 3:Y=0X98;break;}LCD12864_WriteCmd( Y+X ); //这里不检测忙信号,发送地址码X = X*2;Y = 0;while( Data[Y] != 0 ) //若到达字串尾则退出{if (X <= 0x0F) //X坐标应小于0xF{LCD12864_WriteDate(Data[Y]);X++;Y++;}else break;}}void main(){LCD12864_Init();// write_com(0x1c);LCD12864_ClearGDRAM();//LCD12864_WriteImage(image);//LCD12864_Draw_ObliqueLine();LCD12864_DrawCross();//LCD12864_DisplayListChar(0,0,h);while(1);}。
12864画圆程序 12864显示任意图形和字符
uchar Read_data()
{
uchar shuju;
P0=0xff;
rs=1;
// D/I=1,代表数据
rw=1;
// R/W=1.读取
delayms(10);
en=1;
delayms(100); shuju=P0; //读取当前显示的数据
en=0;
return(shuju);
}
/******************************************* 函数名称:Draw_TX 功 能:显示一个 16*16 大小的图形 参 数:Yaddr--Y 地址
uchar i,j,k;
Write_com(0x34);
//打开扩展指令集
i=0x80;
for(j=0;j<32;j++)
{
Write_com(i++);
Write_com(0x80);
for(k=0;k<16;k++)
{
Write_data(0x00);
}
}
i=0x80;
for(j=0;j<32;j++)
{
Write_com(i++);
Write_com(0x88);
for(k=0;k<16;k++)
{
Write_data(0x00);
}
} Write_com(0x30);
//回到基本指令集
}
/****************************
画点函数:Write_Point() x 表示列,y 表示为行。 ******************************/
12864的程序
[资料教程]玩转12864液晶(1)--显示字符12864本帖最后由无语于2009-8-11 12:14 编辑在我们常用的人机交互显示界面中,除了数码管,LED,以及我们之前已经提到的LCD1602之外,还有一种液晶屏用的比较多。
相信接触过单片机的朋友都知道了,那就是12864液晶。
顾名思义,12864表示其横向可以显示128个点,纵向可以显示64个点。
我们常用的12864液晶模块中有带字库的,也有不带字库的,其控制芯片也有很多种,如KS0108T6963,ST7920等等。
在这里我们以ST7920为主控芯片的12864液晶屏来学习如何去驱动它。
(液晶屏采用金鹏的OCMJ4X8C)关于这个液晶屏的更多信息,请参考它的DATASHEET,附件中有下载。
我们先来了解一下它的并行连接情况。
下面是电路连接图从上面的图可以看出,液晶模块和单片机的连接除了P0口的8位并行数据线之外,还有RS,RW,E等几根线。
其中R/S是指令和数据寄存器的选择控制线(串行模式下为片选),R/W是读写控制线(串行模式下是数据线),E是使能线(串行模式下为时钟线)。
通过这几根控制线和数据线,再结合它的时序图,我们就可以编写出相应的驱动程序啦。
看看并行模式下的写时序图:根据这个时序图,我们就可以写出写数据或者写命令到LCD12864液晶的子程序。
读时序图如下:根据这个时序图我们就可以从LCD12864液晶模块内部RAM中读出相应的数据,我们的忙检测函数就是根据这个时序图写出来的。
以及后面章节中讲的画点函数等都要用到读时序。
有了这两个时序图,然后我们再看看OCMJ4X8C的相关指令集,就可以编写出驱动程序了。
这里要注意的是指令集分为基本指令集和扩充指令集,其中扩充指令集主要是与绘图相关,在此后的章节中会有相应的介绍。
下面让我们根据这些编写出它的驱动程序吧。
我的硬件测试条件为:STC89C516(11.0592MHz) + OCMJ4X8C实际显示效果图片如下:程序部分如下,请结合液晶模块的DATASHEET看程序,这样能够更加快速的弄懂程序的流程。
12864液晶图像显示图文教程——最全版
uchar i,j; write_cmd(0x34);//扩充指令集动作 write_cmd(0x34);//关绘图显示功能 for(i=0;i<32;i++)//上半屏 { write_cmd(0x80+i);//垂直地址 write_cmd(0x80); //水平地址,水平地址自动加 1 for(j=0;j<16;j++) { write_data(0x00); } } for(i=0;i<32;i++)//下半屏 { write_cmd(0x88+i);//垂直地址 write_cmd(0x88);//水平地址,水平地址自动加 1 for(j=0;j<16;j++) { write_data(0x00); } } write_cmd(0x36);//开绘图显示 write_cmd(0x30);//回到基本指令集 } //函数名称:display_image(uchar *p) //函数功能:显示图片 void display_image(uchar *p) { uchar i,j; write_cmd(0x34);//扩充指令集动作 write_cmd(0x34);//关绘图显示功能 /*上半屏显示设置*/ for(i=0;i<32;i++)//上半屏 { write_cmd(0x80+i);//垂直地址 write_cmd(0x80); //水平地址,水平地址自动加 1
12864各种画图程序(带字库修改)
/****************************************************************************** ******************************************************************************* *********///程序说明:本程序为12864(st7920)驱动程序,只实现了最简单的显示功能//端口设置:RS、RW、EN分别为P0口的0、1、2,数据口为P2口//注意:1.要想在液晶屏上同时显示自定义字库和绘图,必须先显示自定义字库// 2.本程序所有函数均有用且正确,由于我的keil未破解不能编译,所以将其注释了// 3.用取模软件取的图形或汉字必须是逐行取的,因为本函数是在液晶上逐行打点的/****************************************************************************** *****************************************************************************/ #include<reg51.h>#include<intrins.h> //内含-NOP-函数#include<stdlib.h> //内含rand()函数#define uchar unsigned char#define uint unsigned int//**********宏定义所需指令#define BASIC_SET 0x30#define EXTEND_SET 0x34#define DRAW_ON 0x36#define DRAW_OFF 0x34//*************端口定义sbit LCD_RS = P0^0;sbit LCD_RW = P0^1;sbit LCD_EN = P0^2;//************变量定义//uchar dis1[10];//****************短延时void delay(uint k){uint i;uchar j;for(i = 0; i < k ;i ++)for(j = 0; j < 10 ;j ++);}//***********ms级延时函数/*void delay_1ms(uint x){uint i,j;for(j = 0;j < x; j++)for(i = 0;i < 110; i++);} *///***********12864写指令函数void write_com(uchar cmd){LCD_RS = 0;LCD_RW = 0;P2 = cmd;delay(5);LCD_EN = 1;delay(5);LCD_EN = 0;}//********12864写数据函数void write_dat(uchar dat){LCD_RS = 1;LCD_RW = 0;P2 = dat;delay(5);LCD_EN = 1;delay(5);LCD_EN = 0;}//****************从LCD中读数据uchar read_dat(void){uchar temp;P2 = 0XFF; //释放数据线LCD_RS = 1; //数据LCD_RW = 1; // 读模式LCD_EN = 1; //E为高电平进行读数据或指令delay(1);temp = P2;LCD_EN = 0;return temp;}//********************************************************//设置光标(地址)函数//参数说明:x---为行号,y为列号//********************************************************void set_cursor(unsigned char x, unsigned char y){unsigned char i;switch(x) //确定行号{case 0x00: i=0x80; break; //第一行case 0x01: i=0x90; break; //第二行case 0x02: i=0x88; break; //第三行case 0x03: i=0x98; break; //第四行default : break;}i = y+i; //确定列号write_com(i);}//********************************************************//显示字符函数//********************************************************void display_char(unsigned char Alphabet){write_dat(Alphabet); //写入需要显示字符的显示码}//********************************************************//指定位置显示字符串函数//参数说明:x为行号,y为列号//********************************************************void display_string(unsigned char x,unsigned char y,unsigned char *Alphabet) {unsigned char i=0;set_cursor(x,y); //设置显示的起始地址while(Alphabet[i]!='\0'){write_dat(Alphabet[i]); //写入需要显示字符的显示码i++;}}//***********************以下为GDRAM绘图部分***************************////*********************绘图显示的清屏函数(因清屏指令在画图时不能用)------------------------------------------------------------------------------注意!!!!!!!void gui_clear(){uchar i , j , k;write_com(EXTEND_SET);//扩展指令集,8位数据传输write_com(DRAW_OFF);//绘图显示关闭for(i = 0; i < 2; i ++)//分上下两屏写{for(j = 0; j < 32; j ++){write_com(0x80 + j);//写y坐标delay(1);if(i == 0) //写x坐标{write_com(0x80);delay(1);}else //写下半屏{write_com(0x88);delay(1);}for(k = 0; k < 16; k ++)//写一整行数据{write_dat(0x00);//写高字节write_dat(0x00);//写低字节delay(1);}}}write_com(DRAW_ON);//打开绘图显示write_com(BASIC_SET);//打开基本指令集}//******************************************************************//*****有反白显示功能的打点函数***********//参数:color=1,该点填充1;color=0,该点填充白色0;//*******************************************************************void GUI_Point(unsigned char x,unsigned char y,unsigned char color){unsigned char x_Dyte,x_byte; //定义列地址的字节位,及在字节中的哪1位unsigned char y_Dyte,y_byte; //定义为上下两个屏(取值为0,1),行地址(取值为0~31)unsigned char GDRAM_hbit,GDRAM_lbit;write_com(0x36); //扩展指令命令/***X,Y坐标互换,即普通的X,Y坐标***/x_Dyte=x/16; //计算在16个字节中的哪一个x_byte=x&0x0f; //计算在该字节中的哪一位y_Dyte=y/32; //0为上半屏,1为下半屏y_byte=y&0x1f; //计算在0~31当中的哪一行write_com(0x80+y_byte); //设定行地址(y坐标),即是垂直地址write_com(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标),并通过8*y_Dyte选定上下屏,即是水平地址read_dat(); //预读取数据GDRAM_hbit= read_dat(); //读取当前显示高8位数据GDRAM_lbit= read_dat(); //读取当前显示低8位数据delay(1);write_com(0x80+y_byte); //设定行地址(y坐标)write_com(0x80+x_Dyte+8*y_Dyte); //设定列地址(x坐标),并通过8*y_Dyte选定上下屏delay(1);if(x_byte<8) //判断其在高8位,还是在低8位{if(color==1){write_dat(GDRAM_hbit|(0x01<<(7-x_byte))); //置位GDRAM区高8位数据中相应的点}elsewrite_dat(GDRAM_hbit&(~(0x01<<(7-x_byte)))); //清除GDRAM区高8位数据中相应的点write_dat(GDRAM_lbit); //显示GDRAM区低8位数据}else{write_dat(GDRAM_hbit);if(color==1)write_dat(GDRAM_lbit|(0x01<<(15-x_byte))); //置位GDRAM区高8位数据中相应的点elsewrite_dat(GDRAM_lbit&(~(0x01<<(15-x_byte))));//清除GDRAM区高8位数据中相应的点}write_com(0x30); //恢复到基本指令集}//***********(给定坐标并打点的)任意位置打点函数void lcd_set_dot(uchar x,uchar y){uchar x_byte,x_bit;//确定在坐标的那一字节哪一位uchar y_ping , y_bit;//确定在坐标的哪一屏哪一行uchar tmph , tmpl;//定义两个临时变量,用于存放读出来的数据write_com(EXTEND_SET);//扩展指令集write_com(DRAW_OFF);//绘图显示关闭x_byte = x / 16;//算出在哪一字节,注意一个地址是16位的x_bit = x % 16;//& 0x0f;//算出在哪一位y_ping = y / 32;//确定在上半屏还是下半屏,0代表上半屏,1代表下半屏y_bit = y % 32;//& 0x1f;//确定在第几行write_com(0X80 + y_bit);//先写垂直地址(最高位必须)write_com(0x80 + x_byte + 8 * y_ping);//水平坐标,下半屏坐标起始地址为0x88,(+8*y_ping)就是用来确定上半屏还是下半屏read_dat();//预读取数据tmph = read_dat();//读取当前显示高8位数据tmpl = read_dat();//读取当前显示低8位数据delay(1);write_com(0x80 + y_bit);//读操作会改变AC,所以重新设置一下write_com(0x80 + x_byte + 8 * y_ping);delay(1);if(x_bit < 8){write_dat(tmph | (0x01 << (7 - x_bit)));//写高字节,因为坐标是从左向右的,GDRAM 高位在昨,低位在右write_dat(tmpl);//原低位数据送回}else{write_dat(tmph);//原高位数据送回write_dat(tmpl | (0x01 << (15 - x_bit)));}write_com(DRAW_ON); //打开绘图显示write_com(BASIC_SET);//回到基本指令集}//************画水平线函数**********************************////x0、x1为起始点和终点的水平坐标,y为垂直坐标***************////**********************************************************//void gui_hline(uchar x0, uchar x1, uchar y){uchar bak;//用于对两个数互换的中间变量,使x1为大值if(x0 > x1){bak = x1;x1 = x0;x0 = bak;}do{lcd_set_dot(x0 , y);//从左到右逐点显示x0 ++;}while(x1 >= x0);}//***********画竖直线函数***********************************////x为起始点和终点的水平坐标,y0、y1为垂直坐标***************////**********************************************************//void gui_rline(uchar x, uchar y0, uchar y1)uchar bak;//用于对两个数互换的中间变量,使y1为大值if(y0 > y1){bak = y1;y1 = y0;y0 = bak;}do{lcd_set_dot(x , y0);//从上到下逐点显示y0 ++;}while(y1 >= y0);}//*********任意两点间画直线*********************************// //x0、y0为起始点坐标,x1、y1为终点坐标**********************// //**********************************************************// void gui_line(uchar x0 , uchar y0 , uchar x1 , uchar y1){char dx;//直线x轴差值char dy;//直线y轴差值char dx_sym;//x轴增长方向,为-1时减值方向,为1时增值方向char dy_sym;//y轴增长方向,为-1时减值方向,为1时增值方向char dx_x2;//dx*2值变量,用于加快运算速度char dy_x2;//dy*2值变量,用于加快运算速度char di; //决策变量if(x0 == x1)//判断是否为垂直线{gui_rline(x0 , y0 , y1);//画垂直线return;}if(y0 == y1)//判断是否为水平线{gui_hline(x0 , x1 , y0);//画水平线return;}dx = x1 - x0;//求取两点之间的差值dy = y1 - y0;//****判断增长方向,或是否为水平线、垂直线、点*// if(dx > 0)//判断x轴方向dx_sym = 1;else{if(dx < 0)dx_sym = -1;else{gui_rline(x0 , y0 , y1);return;}}if(dy > 0)//判断y轴方向dy_sym = 1;else{if(dy < 0)dy_sym = -1;else{gui_hline(x0 , x1 , y0);return;}}/*将dx、dy取绝对值***********/dx = dx_sym * dx;dy = dy_sym * dy;/****计算2倍的dx、dy值*******/dx_x2 = dx * 1;//我改为了一倍,这样才跟真实的两点对应dy_x2 = dy * 1;/***使用bresenham法进行画直线***/if(dx >= dy)//对于dx>=dy,使用x轴为基准{di = dy_x2 - dx;while(x0 != x1){lcd_set_dot(x0,y0);x0 +=dx_sym;if(di < 0)di += dy_x2;//计算出下一步的决策值else{di += dy_x2 - dx_x2;y0 += dy_sym;}}lcd_set_dot(x0, y0);//显示最后一点}else //对于dx<dy使用y轴为基准{di = dx_x2 - dy;while(y0 != y1){lcd_set_dot(x0, y0);y0 += dy_sym;if(di < 0)di += dx_x2;else{di += dx_x2 - dy_x2;x0 += dx_sym;}}lcd_set_dot(x0, y0);//显示最后一点}}//***************************************************************************// //*******************画指定宽度的任意两点之间的直线**************************// //参数说明:x0、y0为起始点坐标,x1、y1为终点坐标,with为线宽*****************// //***************************************************************************// void gui_linewith(uchar x0 , uchar y0 , uchar x1 , uchar y1 , uchar with){char dx; // 直线x轴差值变量char dy; // 直线y轴差值变量char dx_sym; // x轴增长方向,为-1时减值方向,为1时增值方向char dy_sym; // y轴增长方向,为-1时减值方向,为1时增值方向char dx_x2; // dx*2值变量,用于加快运算速度char dy_x2; // dy*2值变量,用于加快运算速度char di; // 决策变量char wx, wy; // 线宽变量char draw_a, draw_b;// 参数过滤if(with==0) return;if(with>50) with = 50;dx = x1-x0; // 求取两点之间的差值dy = y1-y0;wx = with/2;wy = with-wx-1;//判断增长方向,或是否为水平线、垂直线、点if(dx>0) // 判断x轴方向{dx_sym = 1; // dx>0,设置dx_sym=1 }else{if(dx<0){dx_sym = -1; // dx<0,设置dx_sym=-1 }else{//dx==0,画垂直线,或一点wx = x0-wx;if(wx<0) wx = 0;wy = x0+wy;while(1){x0 = wx;gui_rline(x0, y0, y1);if(wx>=wy) break;wx++;}return;}}if(dy>0) // 判断y轴方向{dy_sym = 1; // dy>0,设置dy_sym=1}else{if(dy<0){dy_sym = -1; // dy<0,设置dy_sym=-1 }else{//dy==0,画水平线,或一点wx = y0-wx;if(wx<0) wx = 0;wy = y0+wy;while(1){y0 = wx;gui_hline(x0, x1, y1);if(wx>=wy) break;wx++;}return;}}// 将dx、dy取绝对值dx = dx_sym * dx;dy = dy_sym * dy;//计算2倍的dx及dy值dx_x2 = dx*2;dy_x2 = dy*2;//使用Bresenham法进行画直线if(dx>=dy) // 对于dx>=dy,则使用x轴为基准{di = dy_x2 - dx;while(x0!=x1){//x轴向增长,则宽度在y方向,即画垂直线draw_a = y0-wx;if(draw_a<0) draw_a = 0;draw_b = y0+wy;gui_rline(x0, draw_a, draw_b);x0 += dx_sym;if(di<0){di += dy_x2; // 计算出下一步的决策值}else{di += dy_x2 - dx_x2;y0 += dy_sym;}}draw_a = y0-wx;if(draw_a<0) draw_a = 0;draw_b = y0+wy;gui_rline(x0, draw_a, draw_b);}else // 对于dx<dy,则使用y轴为基准{di = dx_x2 - dy;while(y0!=y1){//y轴向增长,则宽度在x方向,即画水平线draw_a = x0-wx;if(draw_a<0) draw_a = 0;draw_b = x0+wy;gui_hline(draw_a, y0, draw_b);y0 += dy_sym;if(di<0){di += dx_x2;}else{di += dx_x2 - dy_x2;x0 += dx_sym;}}draw_a = x0-wx;if(draw_a<0) draw_a = 0;draw_b = x0+wy;gui_hline(draw_a, y0, draw_b);}//***********画矩形函数*************************************// //x0、y0为矩形左上角坐标值,x1、y1为矩形右下角坐标值********// //**********************************************************// void gui_rectangle(uchar x0 , uchar y0 , uchar x1 , uchar y1){gui_hline(x0 , x1 , y0);gui_rline(x0 , y0 , y1);gui_rline(x1 , y0 , y1);gui_hline(x0 , x1 , y1);}//****************画填充矩形函数****************************// //x0、y0为矩形左上角坐标值,x1、y1为矩形右下角坐标值********// //**********************************************************// /*void gui_rectangle_fill(uchar x0 , uchar y0 , uchar x1 , uchar y1){uchar i;//转换数据的中间变量,使x1、y1大if(x0 > x1){i = x0;x0 = x1;x1 = i;}if(y0 > y1){i = y0;y0 = y1;y1 = i;}//***判断是否是直线***//* if(y0 == y1)//画水平线{gui_hline(x0 , x1 , y0);return;}if(x0 == x1)//画竖直线gui_rline(x0 , y0 , y1);return;}while(y0 <= y1)//画填充矩形{gui_hline(x0 , x1 , y0);y0 ++;}} *///*******************画正方形函数*************************// //x0、y0为正方形左上角坐标,with正方形边长****************// //********************************************************// /*void gui_square(uchar x0 , uchar y0 , uchar with){if(with == 0)return;if((x0 + with) > 127)//横轴超出液晶边界return;if((y0 + with) > 63)return;gui_rectangle(x0 , y0 , x0 + with , y0 + with);} *///****************画填充正方形函数*************************// //x0、y0为正方形左上角坐标,with正方形边长*****************// //*********************************************************// /*void gui_square_fill(uchar x0 , uchar y0 , uchar with){if(with == 0)return;if((x0 + with) > 127)//横轴超出液晶边界return;if((y0 + with) > 63)return;gui_rectangle_fill(x0 , y0 , x0 + with , y0 + with);} *///****************画圆函数*********************************////x0、y0为圆心坐标,r为圆的半径****************************////*********************************************************///*void gui_circle(uchar x0 , uchar y0 , uchar r){char a , b;char di;if(r > 31 || r == 0)//圆大于液晶屏或者没半径则返回return;a = 0;b = r;di = 3 - 2 * r;//判断下个点位置的标志while(a <= b){lcd_set_dot( x0 - b , y0 - a);//3lcd_set_dot( x0 + b , y0 - a); //0lcd_set_dot( x0 - a , y0 + b); //1lcd_set_dot( x0 - b , y0 - a); //7lcd_set_dot( x0 - a , y0 - b); //2lcd_set_dot( x0 + b , y0 + a); //4lcd_set_dot( x0 + a , y0 - b); //5lcd_set_dot( x0 + a , y0 + b); //6lcd_set_dot( x0 - b , y0 + a);a ++;//***使用bresenham算法画圆********//* if(di < 0)di += 4 * a + 6;else{di += 10 + 4 * (a - b);b --;}lcd_set_dot( x0 + a , y0 + b);}} *///***************************************************************************// //***************************画正椭圆函数************************************// //说明:给定椭圆的四个点的参数,最左、最右点的x轴坐标值为x0、x1,最上、最下点// 的y轴坐标为y0、y1.//说明:----------------------------显示效果不好//***************************************************************************// /*void gui_ellipse(char x0, char x1, char y0, char y1){char draw_x0, draw_y0; // 刽图点坐标变量char draw_x1, draw_y1;char draw_x2, draw_y2;char draw_x3, draw_y3;char xx, yy; // 画图控制变量char center_x, center_y; // 椭圆中心点坐标变量char radius_x, radius_y; // 椭圆的半径,x轴半径和y轴半径int radius_xx, radius_yy; // 半径乘平方值int radius_xx2, radius_yy2; // 半径乘平方值的两倍char di; // 定义决策变量/* 参数过滤*//* if( (x0==x1) || (y0==y1) ) return; *//* 计算出椭圆中心点坐标*//* center_x = (x0 + x1) >> 1;center_y = (y0 + y1) >> 1; *//* 计算出椭圆的半径,x轴半径和y轴半径*//* if(x0 > x1){ radius_x = (x0 - x1) >> 1;}else{ radius_x = (x1 - x0) >> 1;}if(y0 > y1){ radius_y = (y0 - y1) >> 1;}else{ radius_y = (y1 - y0) >> 1;} *//* 计算半径平方值*//* radius_xx = radius_x * radius_x;radius_yy = radius_y * radius_y; *//* 计算半径平方值乘2值*//* radius_xx2 = radius_xx<<1;radius_yy2 = radius_yy<<1; *//* 初始化画图变量*//* xx = 0;yy = radius_y;di = radius_yy2 + radius_xx - radius_xx2*radius_y ; // 初始化决策变量/* 计算出椭圆y轴上的两个端点坐标,作为作图起点*//* draw_x0 = draw_x1 = draw_x2 = draw_x3 = center_x;draw_y0 = draw_y1 = center_y + radius_y;draw_y2 = draw_y3 = center_y - radius_y;lcd_set_dot(draw_x0, draw_y0); // 画y轴上的两个端点lcd_set_dot(draw_x2, draw_y2);while( (radius_yy*xx) < (radius_xx*yy) ){ if(di<0){ di+= radius_yy2*(2*xx+3);}else{ di += radius_yy2*(2*xx+3) + 4*radius_xx - 4*radius_xx*yy;yy--;draw_y0--;draw_y1--;draw_y2++;draw_y3++;}xx ++; // x轴加1draw_x0++;draw_x1--;draw_x2++;draw_x3--;lcd_set_dot(draw_x0, draw_y0);lcd_set_dot(draw_x1, draw_y1);lcd_set_dot(draw_x2, draw_y2);lcd_set_dot(draw_x3, draw_y3);}di = radius_xx2*(yy-1)*(yy-1) + radius_yy2*xx*xx + radius_yy + radius_yy2*xx - radius_xx2*radius_yy;while(yy>=0){ if(di<0){ di+= radius_xx2*3 + 4*radius_yy*xx + 4*radius_yy - 2*radius_xx2*yy;xx ++; // x轴加1draw_x0++;draw_x1--;draw_x2++;draw_x3--;}else{ di += radius_xx2*3 - 2*radius_xx2*yy;}yy--;draw_y0--;draw_y1--;draw_y2++;draw_y3++;lcd_set_dot(draw_x0, draw_y0);lcd_set_dot(draw_x1, draw_y1);lcd_set_dot(draw_x2, draw_y2);lcd_set_dot(draw_x3, draw_y3);}} *///******************************************************************* //*******画满屏图片-----本程序为逐行写,因此图片数据也应该是逐行取的//参数:dat为填充的数据------用本程序时需要满屏图的数组//******************************************************************* /*void gui_draw_full_picture (unsigned char *dat){unsigned char i;unsigned char j;unsigned char k;unsigned char bGDRAMAddrX = 0x80; //GDRAM水平地址unsigned char bGDRAMAddrY = 0x80; //GDRAM垂直地址for(i = 0; i < 2; i++){for(j = 0; j < 32; j++){for(k = 0; k < 8; k++){write_com(0x34); //设置为8位MPU接口,扩充指令集,关闭绘图显示write_com(bGDRAMAddrY+j); //垂直地址Ywrite_com(bGDRAMAddrX+k); //水平地址Xwrite_dat(*dat++); //写数据高字节write_dat(*dat++); //写数据低字节}}bGDRAMAddrX = 0x88; //写下半屏幕}write_com(0x36); //打开绘图模式write_com(0x30); //恢复基本指令集,关闭绘图模式} */unsigned char code DCB2HEX_TAB[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; //****************************输出一行数据函数,此行可任意长,不必非得是8的倍数**和下个函数合用画任意大小(矩形)的图形或汉字//参数:flag反显标志,1为反显,x、y为指定显示位置的起始点,*dat要输出的点阵数组,no显示此行所需的点个数,即图形一行的点数void gui_loadline(unsigned char x,unsigned char y,unsigned char *dat,unsigned char no,unsigned char flag){unsigned char bit_dat;unsigned char i;/* 参数过滤,若指定显示位置超出液晶屏则返回*/if(x>127) return;if(y>63) return;for(i=0; i<no; i++)//超出本行所规定的点数则本行显示完成{/* 判断是否要读取点阵数据,每字节的开始读取一次点阵数组即i为8的倍数时*/if( (i%8)==0 ) bit_dat = *dat++;/* 对相应的点打1或打0,i&0x07意思是对8求余*/if( (bit_dat&DCB2HEX_TAB[i&0x07])==0 )//取出i对应的位,并判断是否为0{if(flag==0) //判断是否反显,该位取出的数据为0,反显要打为1,flag==0代表不反显GUI_Point(x,y,0); //正常显示0,GUI_Point(x,y,0)代表在x、y处打0elseGUI_Point(x,y,1); //将0反显}else{if(flag==0)GUI_Point(x,y,1);elseGUI_Point(x,y,0);}if( (++x)>127) return;//若显示超出了液晶屏则返回}}//*********************************************************************//********在自定义大小的区域内画图或画字函数****************************//参数说明:x、y指定显示区域的起始点坐标// dat 要输出显示的图形或汉字点阵数组。
12864液晶程序+仿真图
/**********************************************************12864是由两块64*64的液晶屏组成的。
当中页是通过自己去定义的。
**********************************************************/#include"reg51.h"#define uchar unsigned char#define uint unsigned intsbit lcdrst=P3^0;sbit cs2=P3^5;sbit cs1=P3^4;sbit e=P3^2;sbit rw=P3^3;sbit rs=P3^1;/************************************************代码:字模生成可以在取模软件生成。
方法是阴码列行式逆向************************************************/uchar code qin[]={0x04,0x04,0xC4,0x5F,0x54,0xF4,0x54,0x5F,0xC4,0x14,0x10,0xFF,0x10,0x10,0xF0,0x00,0x00,0x80,0x95,0x95,0x95,0x7F,0x55,0x55,0x95,0x60,0x1C,0x03,0x20,0x60,0x3F,0x00};// 勤uchar code mian[]={0x00,0xF0,0x2C,0x27,0xE4,0x34,0x2C,0xE4,0x08,0x08,0xFF,0x08,0x08,0xF8,0x00,0x00,0x40,0x21,0x11,0x0F,0x01,0x3F,0x41,0x49,0x44,0x43,0x40,0x44,0x48,0x47,0x70,0x00};//勉uchar code li[]={0x44,0x44,0xFC,0x44,0x44,0x00,0xFE,0x92,0x92,0xFE,0x92,0x92,0x92,0xFE,0x00,0x00,0x10,0x10,0x0F,0x08,0x48,0x40,0x45,0x44,0x44,0x7F,0x44,0x44,0x44,0x45,0x40,0x00};//理uchar code gong[]={0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xFE,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00 }; //工uchar code xue[]={0x40,0x30,0x10,0x12,0x5C,0x54,0x50,0x51,0x5E,0xD4,0x50,0x18,0x57,0x32,0x10,0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00};//学uchar code yuan[]={0xFE,0x02,0x32,0x4A,0x86,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x0C,0x04,0x00,0xFF,0x00,0x02,0x04,0x83,0x41,0x31,0x0F,0x01,0x01,0x7F,0x81,0x81,0x81,0xF1,0x00};//院uchar code dian[]={0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00};//电uchar code zi[]={0x00,0x00,0x02,0x02,0x02,0x02,0x02,0xE2,0x12,0x0A,0x06,0x02,0x00,0x80,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x41,0x81,0x7F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00};//子uchar code cheng[]={0x10,0x12,0xD2,0xFE,0x91,0x11,0x80,0xBF,0xA1,0xA1,0xA1,0xA1,0xBF,0x80,0x00,0x00,0x04,0x03,0x00,0xFF,0x00,0x41,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x40,0x00};//程uchar code tong[]={0x40,0x41,0xC6,0x00,0x00,0xF2,0x52,0x52,0x56,0xFA,0x5A,0x56,0xF2,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x5F,0x42,0x42,0x42,0x5F,0x4A,0x52,0x4F,0x40,0x40,0x00};//通uchar code xin[]={0x80,0x40,0x30,0xFC,0x07,0x0A,0xA8,0xA8,0xA9,0xAE,0xAA,0xA8,0xA8,0x08,0x08,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x7E,0x22,0x22,0x22,0x22,0x22,0x7E,0x00,0x00,0x00};//信uchar codeban[]={0x42,0x42,0xFE,0x42,0x42,0xE0,0x00,0xFF,0x00,0x42,0x42,0xFE,0x42,0x42,0x42,0x00,0x10,0x10,0x0F,0x88,0x49,0x20,0x18,0x07,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x00};//班uchar code ling[]={0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00};//0uchar code ba[]={0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00};//8uchar code yi[]={0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00};//1uchar code kongge[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//不显示任何内容uchar code kong[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //不显示任何内容uchar code huo[]={0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0xFF,0x02,0x40,0x20,0x18,0x10,0x00,0x00,0x00,0x00,0x80,0x41,0x20,0x10,0x0C,0x03,0x00,0x03,0x04,0x18,0x30,0x60,0x20,0x00,0x00};//火uchar code yun[]={0x40,0x40,0x44,0x44,0x44,0x44,0xC4,0xC4,0x44,0x44,0x46,0x46,0x64,0x60,0x40,0x00,0x00,0x20,0x70,0x38,0x2C,0x27,0x23,0x31,0x10,0x12,0x14,0x18,0x70,0x20,0x00,0x00};//云uchar code xie[]={0x00,0x22,0x3E,0x22,0x22,0xA2,0xFE,0x22,0x00,0xFE,0x02,0x22,0x5A,0x86,0x02,0x00,0x10,0x10,0x08,0x04,0x23,0x40,0x3F,0x00,0x00,0xFF,0x00,0x04,0x08,0x08,0x07,0x00};//邪uchar code shen[]={0x08,0x08,0x89,0xCE,0xA8,0x18,0x00,0xF8,0x48,0x48,0xFF,0x48,0x48,0xF8,0x00,0x00,0x02,0x01,0x00,0xFF,0x00,0x03,0x00,0x07,0x02,0x02,0xFF,0x02,0x02,0x07,0x00,0x00};//神/*************************************************延时函数**************************************************/void delay(uchar z){uchar i,j;for(i=z;i>0;i--)for(j=110;j>0;j--);}/********************************************检查状态*********************************************/void checkbusy(){uchar dat;rs=0; //数据\指令选择rw=1; //允许读do{P2=0x00; //清零P2口delay(5);e=1;dat=P2; //读P2口e=0;dat>>=7; //仅当第7位为0时才可操作(判别busy信号) }while(!(dat==0x00));}/*************************************写命令***********************************/void write_com(uchar com){checkbusy(); //检查是否忙rs=0; //写命令rw=0;P2=com;e=1;e=0;}/*************************************写数据***********************************/void write_data(uchar date){checkbusy(); //检查是否忙rs=1; //写数据rw=0;P2=date;e=1;e=0;}/*************************************显示汉字***********************************/void hanzi(uchar ye,uchar lie,uchar *daima){uchar i,j;for(i=0;i<2;i++){write_com(0xb8+ye+i); // ye页与ye+1页write_com(0x40+lie); //确定初始行for(j=0;j<16;j++){write_data(daima[i*16+j]); //写数据(汉字)}}}/*************************************显示数字***********************************/void shuzi(uchar ye,uchar lie,uchar *daima){uchar i,j;for(i=0;i<2;i++){write_com(0xb8+ye+i); // ye页与ye+1页write_com(0x40+lie); //确定初始行for(j=0;j<8;j++){write_data(daima[i*8+j]); //写数据(数字)}}}/***************************************清屏***************************************/void clearlcd(){uchar i,j;cs1=0; //清全屏有cs1=0 cs2=0 与无cs1=0 cs2=0 效果不同cs2=0;for(i=0;i<8;i++)write_com(0xb8+i);write_com(0x40);for(j=0;j<64;j++)write_data(0x00);}}/**************************************** 初始化LCD****************************************/ void init(){write_com(0x3e); //关显示delay(1);write_com(0x3f); //开显示write_com(0xc0); //行初始地址write_com(0xb8); //页初始地址write_com(0x40); //列初始地址}/**************************************** 显示数据****************************************/ void display()cs1=0; //左半屏cs1=0 cs2=1cs2=1;hanzi(0,0,qin);hanzi(0,16,mian);hanzi(0,32,li);hanzi(0,48,gong);cs1=1; //右半屏cs1=1 cs2=0cs2=0;hanzi(0,0,xue);hanzi(0,16,yuan);//hanzi(0,32,kongge); // 如果清屏时加上cs1=0 cs2=0则可以不用,否则要加上//hanzi(0,48,kongge);cs1=0;cs2=1;hanzi(2,0,dian);hanzi(2,16,zi);hanzi(2,32,gong);hanzi(2,48,cheng);cs1=1;cs2=0;hanzi(2,0,xue);hanzi(2,16,yuan);//hanzi(2,32,kongge);//hanzi(2,48,kongge); cs1=0;cs2=1;shuzi(4,0,ling); shuzi(4,8,ba);hanzi(4,16,tong); hanzi(4,32,xin); hanzi(4,48,gong);cs1=1;cs2=0;hanzi(4,0,cheng); shuzi(4,16,yi);hanzi(4,24,ban);//hanzi(4,40,kongge); shuzi(4,56,kong);cs1=0;cs2=1;hanzi(6,0,huo); hanzi(6,16,yun); hanzi(6,32,xie); hanzi(6,48,shen);cs1=1;cs2=0;//hanzi(6,0,kongge);//hanzi(6,16,kongge);//hanzi(6,32,kongge);//hanzi(6,48,kongge);}/**************************************** 主函数****************************************/ void main(){init();clearlcd();while(1){display();}}。
在12864显示任意图片及参考程序
用12864显示单色图片首先介绍本12864液晶显示器:型号:QC12864B因为单片机读取的是数据,而不是直接的图片。
得将图片进行取模,图片应该是单色图片,像素128*64。
下面我为大家介绍个实例。
①、在电脑附件画图,首先设置属性开始画图保存文件,注意格式:②、然后进行取模。
③、编程:#include<reg51.h>#define uchar unsigned char#define uint unsigned int //宏定义#define lcd P2 //数据端口sbit rs=P1^2; //指令/数据选择信号sbit rw=P1^1; //读写选择信号sbit e=P1^0; //使能端sbit psb=P1^3; //串并选择端,高电平为并行,低电平为串行uchar code ai[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xCE,0x00,0x00,0x00,0x00,0x00,0x01,0xC1,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC7,0x00,0x00,0x00,0x00,0x00,0x03,0x31,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x0E,0xC0,0x00,0x00,0x00,0x00,0x00,0x03,0x9B,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x82,0x08,0x00,0x00,0x00, 0x00,0x00,0x00,0x78,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0xEF,0x00,0x00,0x00,0x00,0x00,0x1B,0xFC,0x1E,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0xFE,0x00,0x00,0x00,0x00,0x00,0x1E,0x60,0x38,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x38,0x70,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x00,0x00,0x00,0x00,0x00,0x30,0x7F,0xE0,0x00,0x00,0x00, 0x00,0x00,0x03,0xF8,0x73,0x00,0x00,0x00,0x00,0x00,0x33,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0x37,0x00,0x00,0x00,0x00,0x00,0x06,0xE0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0xC7,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0x1C,0x00,0x00,0x00,0x00,0x00,0x01,0x83,0x80,0x00,0x00,0x00, 0x00,0x00,0x0F,0xD8,0x7C,0x00,0x00,0x00,0x00,0x00,0x03,0xC7,0x00,0x00,0x00,0x00, 0x00,0x00,0x0F,0x18,0xE6,0x00,0x00,0x00,0x00,0x00,0x06,0x7E,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0x87,0x10,0x00,0x00,0x00,0x00,0x0E,0x1C,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0x03,0x90,0x00,0x00,0x00,0x00,0x18,0x3E,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x78,0x01,0xF8,0x00,0x00,0x00,0x00,0x30,0xE3,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0xF8,0x00,0x00,0x00,0x00,0x67,0x01,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x10,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, 0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3C,0x0F,0x00,0x00,0x07,0xD0,0x00,0x01,0xF1,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x0E,0x00,0x00,0x0C,0x38,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x1E,0x00,0x00,0x1C,0x38,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x38,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x38,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x30,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x2E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1B,0xEE,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1B,0xEE,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xEE,0x00,0x00,0x38,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xCE,0x00,0x00,0x38,0x00,0x00,0x00,0x60,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xCE,0x00,0x00,0x38,0x18,0x00,0x00,0x60,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0xCE,0x00,0x00,0x1C,0x10,0x00,0x00,0x71,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0x8E,0x00,0x00,0x0E,0x70,0x00,0x00,0x71,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x3E,0x1F,0x00,0x00,0x07,0xE0,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; //图片数据void delay(uint z)//延时函数{uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void xiezhiling(uchar a)//写指令函数{rs=0;rw=0;lcd=a;delay(5);e=1;delay(5);e=0;}void xieshuju(uchar a)//写数据函数{rs=1;rw=0;lcd=a;delay(5);e=1;delay(5);e=0;}void qingping() //清除DDRAM的数据:送入0{uchar x,y,a,b,c;x=0x80;y=0x80;xiezhiling(0x34);//关闭绘图功能for(a=0;a<2;a++){for(b=0;b<32;b++){xiezhiling(y+b);xiezhiling(x);for(c=0;c<16;c++)xieshuju(0x00);}x=0x88;}xiezhiling(0x36);//打开绘图功能xiezhiling(0x30);}void tupian(uchar *p) //图片数据提取函数{uchar x,y,a,b,c;xiezhiling(0x34); //关闭绘图功能x=0x80;y=0x80;for(c=0;c<2;c++){for(a=0;a<32;a++){xiezhiling(y+a);xiezhiling(x);for(b=0;b<16;b++)xieshuju(*p++);}x=0x88;}xiezhiling(0x36); //打开绘图功能xiezhiling(0x30);}void init() //初始化函数{xiezhiling(0x30);//功能设定为基本指令xiezhiling(0x0c);//显示开,游标关xiezhiling(0x01);//清除显示qingping(); //清屏}void main(){init();tupian(ai);while(1);}④、作品展示:谢谢!!!。
12864液晶显示资料及程序
12864液晶显示资料及程序硬件连接方式是:并口直接访问。
这是汉字显示程序:#include<reg51.h>#include<absacc.h>#define uchar unsigned char#define datawr 0x1200 //写数据通道#define comwr 0x1000 //写控制命令通道#define datare 0x1300 //读数据通道#define comre 0x1100 //读忙通道uchar code disp_data[]={" 浙江大学" //第一行,第一页"04级通信工程一班" //第三行" 宁波理工学院" //第二行" 竞赛小组" //第四行"128X64液晶显示器" //第一行,第二页" 测试程序" //第三行" 07年07月25日" //第二行" Tornado "}; //第四行void set12864();void write_command(uchar command);void write_page(uchar data_add);void read_page(uchar data_add);void delays(uchar cont);void main(){while(1){set12864(); //初始化12864write_page(0); //写入一页数据read_page(0x30); //读出一页数据到内部RAMdelays(2); //延时2swrite_page(64); //写入下一页数据delays(2); //延时2s}}//初始化12864子程序void set12864(){write_command(0x30); //功能设定控制字write_command(0x0c); //显示开关控制字write_command(0x01); //清除屏幕控制字write_command(0x06); //进入设定点控制字}//写控制命令子程序void write_command(uchar command){bit flag=1; //12864空闲标志位while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[comwr]=command; //空闲传送控制字}//写一页子程序void write_page(uchar data_add){bit flag=1; //12864空闲标志位uchar num=64; //64个循环,连续写入32个汉字或是64个西文字符write_command(0x80);for(;num>0;num--){while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据}}//读一页子程序void read_page(uchar data_add){bit flag=1; //12864空闲标志位uchar num=64; //64个循环,连续写入32个汉字或是64个西文字符write_command(0x80);for(;num>0;num--){while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;DBYTE[data_add++]=XBYTE[datare]; //空闲传送数据}}//延时cont秒子程序void delays(uchar count){unsigned char h,i,j,k;do{for(h=5;h>0;h--)for(i=4;i>0;i--)for(j=116;j>0;j--)for(k=214;k>0;k--);}while(--count);}这是图象显示程序:#include<reg51.h>#include<absacc.h>#define uchar unsigned char#define uint unsigned int#define datawr 0x1200 //写数据通道#define comwr 0x1000 //写控制命令通道#define datare 0x1300 //读数据通道#define comre 0x1100 //读忙通道uchar code disp_data[] = // 数据表{0x00,0x01,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00 ,0x00,0x00,0x00,0x00,0x01,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00 ,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00 ,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00 ,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00 ,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00 ,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x0 0,0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x8 0,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0 3,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x0 0,0x07,0xFF,0xFF,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x8 0,0x00,0x0B,0xFF,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x8 0,0x00,0x00,0x1F,0x01,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC 0,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xF3,0x79,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC 0,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xE6,0x62,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE 1,0x60,0x00,0x68,0x01,0xFF,0xFF,0xFE,0x00,0x60,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE1 ,0x00,0x00,0x0E,0x01,0xFF,0xFF,0xF8,0x00,0x4B,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0 ,0x8E,0x08,0x79,0x07,0xFF,0xFF,0xF0,0x00,0x41,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE6 ,0xC0,0x07,0x61,0xC3,0xFF,0xFE,0xC0,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xED,0xEF,0x3F,0x83,0xFF,0xFE,0x60,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xC0,0xFF,0xFD,0xFC,0x6C,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFF,0xFF,0xFF,0xF0,0x7F,0xF3,0xFF,0xFE,0x60,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFF,0xFF,0xF3,0xFF,0xFF,0x50,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFF,0xFF,0xC9,0xFB,0xFF,0xF1,0xF8,0x8C,0xD8,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFB,0x6F,0xD9,0xC2,0x3F,0xF8,0x40,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF6 ,0xDF,0x1E,0xFF,0xFF,0x7F,0xFC,0x38,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x64 ,0x2F,0x6F,0xFF,0xFD,0x7B,0xFC,0x1F,0xE0,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0x5 F,0x7C,0xEE,0xFF,0xC7,0xFF,0xBC,0x0F,0xFF,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xD F,0xFE,0xEF,0xFF,0xFF,0xE7,0xDC,0x07,0xE7,0xF8,0x12,0x7F,0xFF,0xFF,0xFF,0xFF,0x4 7,0xFF,0xFF,0xFF,0xFF,0xE7,0x80,0x03,0xF4,0x00,0x00,0x5F,0xFF,0xFF,0xFE,0xFE,0xE30xFF,0xFE,0xC0,0x01,0xC0,0x00,0x00,0x1B,0xFF,0xFF,0xFB,0xFF,0xF F,0xFF,0xFF,0xFF,0x7F,0xEE,0xC0,0x00,0xC0,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF ,0xFF,0xFF,0xFF,0xFE,0x98,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xEF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x20,0x0E,0x60,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0x8F,0xFF,0xFF, 0xFF,0xFF,0xFF,0x05,0x80,0xE0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFD,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0x09,0x80,0xA0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x7F,0xFF,0xFF, 0xFF,0xFF,0xFF,0x85,0x2A,0xC0,0x00,0x00,0x00,0x00,0x01,0xFF,0xFB,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFE,0xBF,0xF3,0xC0,0x00,0x00,0x00,0x00,0x00,0xFF,0xF7,0xFF,0xFF,0xFF, 0xFF,0xFF,0xF8,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0xFF,0xFF,0xFF, 0xFF,0xFF,0x00,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0xFF,0xC0,0xFF,0xFF,0xFF, 0xFF,0xC0,0x1F,0xFF,0xFF,0x80,0x00,0x40,0x00,0x00,0x00,0xFF,0x80,0xFF,0xFF,0xFF, 0x80,0x07,0xFF,0xFF,0xFF,0xC0,0x00,0xC0,0x00,0x00,0x01,0xFF,0x01,0xFF,0xFF,0xF8 ,0x00,0xFF,0xFF,0xFF,0xFF,0xE0,0x63,0x80,0x00,0x00,0x01,0xFE,0x01,0xFF,0x18,0x00, 0x3F,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x01,0xCC,0x01,0xFE,0x00,0x07, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x07,0xA0,0x03,0xFC,0x00,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x05,0xC0,0x03,0xC8,0x00,0x7F, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x88,0x0C,0x07, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x0C,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0xC0, 0x7F,0xFF,0xFF,0xFF,0xFF,0xF8,0x07,0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0 x0F,0xFF,0xFE,0xFF,0xFF,0xD0,0x07,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F, 0x03,0xFF,0xF8,0xFF,0xFC,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x3F,0xFF,0xC0,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,00xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0 x00,0x1F,0xFE,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x78,0x02,0x00,0x00,0x00,0x00,0 x00,0x0F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x03,0xF0,0x78,0x00,0x00,0x00,0x00,0 x00,0x02,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xF0,0x00,0x00,0x00,0x00, 0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xC0,0x00,0x00,0x00,0x00, 0x00,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x80,0x00,0x00,0x00,0x00,0 x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x27,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0xFC,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x04,0x80,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0 x00,0x00,0x01};void set12864();void setxy(uchar x,uchar y);void write_command(uchar command);void write_16byte(uint data_add);void delays(uchar count);void main(){uchar x,y,i;while(1){y="0x80"; //设置液晶上半部分坐标x="0x80";delays(2); //延时2sset12864(); //初始化12864delays(2);for(i=0;i<32;i++) //写入液晶上半图象部分{ //写入坐标setxy(x,y);write_16byte(i*16); //连续写入16字节数据y++; //y轴地址加1}y="0x80"; //设置液晶下半部分坐标x="0x88";for(i=0;i<32;i++) //写入液晶下半图象部分{setxy(x,y); //写入坐标write_16byte((32+i)*16);//连续写入16字节数据y++; //y轴地址加1}write_command(0x34); //写入扩充指令命令write_command(0x36); //显示图象}}//初始化12864子程序void set12864(){write_command(0x30); //功能设定控制字write_command(0x0c); //显示开关控制字write_command(0x01); //清除屏幕控制字write_command(0x06); //进入设定点控制字}//设置绘图坐标void setxy(uchar x,uchar y){write_command(0x34); //写入扩充指令命令write_command(y); //写入y轴坐标write_command(x); //写入x轴坐标write_command(0x30); //写入基本指令命令}//写控制命令子程序void write_command(uchar command){bit flag="1"; //12864空闲标志位while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[comwr]=command; //空闲传送控制字}void write_16byte(uint data_add){bit flag="1"; //12864空闲标志位uchar num="16"; //16个循环,连续写入16个字节for(;num>0;num--){while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据}}//延时count秒子程序void delays(uchar count){unsigned char h,i,j,k;do{for(h=5;h>0;h--)for(i=4;i>0;i--)for(j=116;j>0;j--)for(k=214;k>0;k--);}while(--count);}圣斗士之家2009-07-28 23:13:30#include#include#define uchar unsigned char#define datawr 0x1200 //写数据通道#define comwr 0x1000 //写控制命令通道#define datare 0x1300 //读数据通道#define comre 0x1100; //读忙通道uchar code disp_data[]={" 浙江大学 " //第一行,第一页"04级通信工程一班" //第三行" 宁波理工学院 " //第二行" 竞赛小组 " //第四行"128X64液晶显示器" //第一行,第二页" 测试程序 " //第三行" 07年07月25日 " //第二行 " Tornado "}; //第四行void set12864();void write_command(uchar command);void write_page(uchar data_add);void read_page(uchar data_add);void delays(uchar cont);void main(){while(1){set12864(); //初始化12864write_page(0); //写入一页数据read_page(0x30); //读出一页数据到内部RAMdelays(2); //延时2swrite_page(64); //写入下一页数据delays(2); //延时2s}}//初始化12864子程序void set12864(){write_command(0x30); //功能设定控制字write_command(0x0c); //显示开关控制字write_command(0x01); //清除屏幕控制字write_command(0x06); //进入设定点控制字}//写控制命令子程序void write_command(uchar command){bit flag="1"; //12864空闲标志位while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[comwr]=command; //空闲传送控制字}//写一页子程序void write_page(uchar data_add){bit flag="1"; //12864空闲标志位uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符 write_command(0x80);for(;num>0;num--){while(flag)//检查12864是否空闲flag="XBYTE"[comre]&0x80;XBYTE[datawr]=disp_data[data_add++]; //空闲传送数据}}//读一页子程序void read_page(uchar data_add){bit flag="1"; //12864空闲标志位uchar num="64"; //64个循环,连续写入32个汉字或是64个西文字符 write_command(0x80);for(;num>0;num--){while(flag) //检查12864是否空闲flag="XBYTE"[comre]&0x80;DBYTE[data_add++]=XBYTE[datare]; //空闲传送数据}}//延时cont秒子程序void delays(uchar count){unsigned char h,i,j,k;do{for(h=5;h>0;h--)for(i=4;i>0;i--)for(j=116;j>0;j--)for(k=214;k>0;k--);}while(--count);}这是图象显示程序:#include#include#define uchar unsigned char#define uint unsigned int#define datawr 0x1200 //写数据通道#define comwr 0x1000 //写控制命令通道#define datare 0x1300 //读数据通道#define comre 0x1100 //读忙通道uchar code disp_data[] = // 数据表{0x00,0x01,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x00,0x00, 0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00, 0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00, 0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x00, 0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x80,0x00,0x00, 0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF F,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xFF,0xF F,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x07,0xF F,0xFF,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x0 B,0xFF,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0x00, 0x1F,0x01,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xC0,0x00,0x0 0,0x00,&nb14#inc lude <stdio.h>#inc lude <conio.h>int main(void){int c;int a;a = getchar();printf ("%c",a);/* Note that getc har reads from stdin andis line buffered; this means it w illnot return until you press ENTER. */while ((c = getc har()) != '\n'){printf("%c", c);}return 0;}注:可以利用getchar()函数让程序调试运行结束后等待编程者按下键盘才返回编辑界面,用法:在主函数结尾,return 0;之前加上getchar();即可getchar 的用途是从从标准输入流读取一个字符,读回车符时退出getchar();永远只向缓存中输入一个字符,getchar();的用法很多;一种就是清空回车符这种情况一般发生在在循环中涉及到输入的情况还有一种是某些编译平台(IDE)在运行程序时并没有在程序运行后给人看结果的时间这时候在程序最后加上getchar()就能造成程序的暂停给程序员度结果的机会用getchar时,在键盘上按一个字符后,要按回车才能读取进去;用getch时,在键盘上按一个字符马上就被读取进去,不用按回车,因此可以作为“按任意键继续”的执行语句。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
用12864显示单色图片首先介绍本12864液晶显示器:型号:QC12864B因为单片机读取的是数据,而不是直接的图片。
得将图片进行取模,图片应该是单色图片,像素128*64。
下面我为大家介绍个实例。
①、在电脑附件画图,首先设置属性开始画图保存文件,注意格式:②、然后进行取模。
③、编程:#include<reg51.h>#define uchar unsigned char#define uint unsigned int //宏定义#define lcd P2 //数据端口sbit rs=P1^2; //指令/数据选择信号sbit rw=P1^1; //读写选择信号sbit e=P1^0; //使能端sbit psb=P1^3; //串并选择端,高电平为并行,低电平为串行uchar code ai[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x01,0xCE,0x00,0x00,0x00,0x00,0x00,0x01,0xC1,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xC7,0x00,0x00,0x00,0x00,0x00,0x03,0x31,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x0E,0xC0,0x00,0x00,0x00,0x00,0x00,0x03,0x9B,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x01,0x82,0x08,0x00,0x00,0x00, 0x00,0x00,0x00,0x78,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFC,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0xEF,0x00,0x00,0x00,0x00,0x00,0x1B,0xFC,0x1E,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0xFE,0x00,0x00,0x00,0x00,0x00,0x1E,0x60,0x38,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x38,0x70,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x63,0x00,0x00,0x00,0x00,0x00,0x30,0x7F,0xE0,0x00,0x00,0x00, 0x00,0x00,0x03,0xF8,0x73,0x00,0x00,0x00,0x00,0x00,0x33,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0x37,0x00,0x00,0x00,0x00,0x00,0x06,0xE0,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0xC7,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0x1C,0x00,0x00,0x00,0x00,0x00,0x01,0x83,0x80,0x00,0x00,0x00, 0x00,0x00,0x0F,0xD8,0x7C,0x00,0x00,0x00,0x00,0x00,0x03,0xC7,0x00,0x00,0x00,0x00, 0x00,0x00,0x0F,0x18,0xE6,0x00,0x00,0x00,0x00,0x00,0x06,0x7E,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0x87,0x10,0x00,0x00,0x00,0x00,0x0E,0x1C,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xF8,0x03,0x90,0x00,0x00,0x00,0x00,0x18,0x3E,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x78,0x01,0xF8,0x00,0x00,0x00,0x00,0x30,0xE3,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x38,0x00,0xF8,0x00,0x00,0x00,0x00,0x67,0x01,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x10,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, 0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x3C,0x0F,0x00,0x00,0x07,0xD0,0x00,0x01,0xF1,0xE0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x0E,0x00,0x00,0x0C,0x38,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1C,0x1E,0x00,0x00,0x1C,0x38,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x38,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x38,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1E,0x1E,0x00,0x00,0x30,0x18,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x3E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1F,0x2E,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1B,0xEE,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x1B,0xEE,0x00,0x00,0x70,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xEE,0x00,0x00,0x38,0x00,0x00,0x00,0xE0,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xCE,0x00,0x00,0x38,0x00,0x00,0x00,0x60,0xC0,0x00,0x00,0x00, 0x00,0x00,0x00,0x19,0xCE,0x00,0x00,0x38,0x18,0x00,0x00,0x60,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0xCE,0x00,0x00,0x1C,0x10,0x00,0x00,0x71,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x18,0x8E,0x00,0x00,0x0E,0x70,0x00,0x00,0x71,0x80,0x00,0x00,0x00, 0x00,0x00,0x00,0x3E,0x1F,0x00,0x00,0x07,0xE0,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; //图片数据void delay(uint z)//延时函数{uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}void xiezhiling(uchar a)//写指令函数{rs=0;rw=0;lcd=a;delay(5);e=1;delay(5);e=0;}void xieshuju(uchar a)//写数据函数{rs=1;rw=0;lcd=a;delay(5);e=1;delay(5);e=0;}void qingping() //清除DDRAM的数据:送入0{uchar x,y,a,b,c;x=0x80;y=0x80;xiezhiling(0x34);//关闭绘图功能for(a=0;a<2;a++){for(b=0;b<32;b++){xiezhiling(y+b);xiezhiling(x);for(c=0;c<16;c++)xieshuju(0x00);}x=0x88;}xiezhiling(0x36);//打开绘图功能xiezhiling(0x30);}void tupian(uchar *p) //图片数据提取函数{uchar x,y,a,b,c;xiezhiling(0x34); //关闭绘图功能x=0x80;y=0x80;for(c=0;c<2;c++){for(a=0;a<32;a++){xiezhiling(y+a);xiezhiling(x);for(b=0;b<16;b++)xieshuju(*p++);}x=0x88;}xiezhiling(0x36); //打开绘图功能xiezhiling(0x30);}void init() //初始化函数{xiezhiling(0x30);//功能设定为基本指令xiezhiling(0x0c);//显示开,游标关xiezhiling(0x01);//清除显示qingping(); //清屏}void main(){init();tupian(ai);while(1);}④、作品展示:谢谢。