微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 12864无字库液晶显示

12864无字库液晶显示

时间:08-04 来源:互联网 点击:


这篇文章主要来写一下12864液晶显示的程序,至于一些寄存器的设置,和12864液晶的资料介绍,大家可以参看12864液晶的datesheet,上面一般都很全面,一些具体注意事项请大家参看:http://hi.baidu.com/echoas 他的空间里面介绍的比较清楚,我在这里也没必要浪费时间重复了。

我在这里直接贴出程序,程序注释比较清楚,相信大家对照dateshee可以看明白。

/************************************程序功能:无字库12864液晶的显示编译环境:keil4运行环境:proteus7.7整理人:张家越  QQ:435835181整理时间:2011-04-28取模软件使用的是:ZM201***********************************/#includereg52.h>#define uchar unsigned char#define uint unsigned int#define port P0  //DB0~DB7数据口sbit e=P2^0;//使能sbit rw=P2^1;//读写sbit rs=P2^2;//数据/命令sbit cs2=P2^3;//片选sbit cs1=P2^4;sbit busy=P0^7;//检测忙uchar code hz[][32]={/*--  文字:  书  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0x10,0x10,0x10,0xFF,0x88,0x88,0xFA,0x82,0x84,0x8C,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x7F,0x00,0x00,0x08,0x10,0x0C,0x03,0x00,0x00,0x00},/*--  文字:  山  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x20,0x20,0x20,0x1F,0x10,0x10,0x10,0x10,0x3F,0x00,0x00,0x00},/*--  文字:  有  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x10,0x10,0x90,0x50,0xF0,0x4C,0x4B,0x28,0x28,0x28,0xE8,0x08,0x08,0x00,0x00,0x00,0x02,0x01,0x00,0x00,0x7F,0x0A,0x0A,0x05,0x05,0x20,0x7F,0x00,0x00,0x00,0x00},/*--  文字:  路  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x3C,0x24,0xE2,0x9E,0x20,0x18,0x97,0x64,0x54,0x8C,0x00,0x00,0x00,0x00,0x00,0x10,0x1F,0x08,0x0F,0x04,0x02,0x7D,0x24,0x22,0x12,0x1E,0x01,0x01,0x01,0x00},/*--  文字:  勤  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x08,0x88,0xBF,0xE4,0x54,0x5F,0xC4,0x44,0xC0,0x3F,0x20,0xE0,0x00,0x00,0x00,0x00,0x20,0x2B,0x2A,0x1F,0x15,0x55,0x31,0x0C,0x23,0x40,0x30,0x0F,0x00,0x00,0x00},/*--  文字:  为  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0x40,0x44,0x58,0xC0,0x38,0x27,0x20,0x20,0xE0,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x06,0x01,0x10,0x21,0x46,0x30,0x0F,0x00,0x00,0x00,0x00},/*--  文字:  径  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x10,0x88,0xC4,0x33,0x40,0x44,0x24,0x22,0x12,0x9A,0xA6,0xA0,0x40,0x00,0x00,0x02,0x01,0x00,0x7F,0x00,0x20,0x21,0x21,0x21,0x1F,0x10,0x10,0x10,0x10,0x00,0x00},/*--  文字:  ,  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*--  文字:  学  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x60,0x20,0xA0,0xA2,0xAC,0x51,0x56,0xD0,0x5C,0x13,0x10,0x30,0x10,0x00,0x00,0x00,0x04,0x04,0x04,0x04,0x24,0x44,0x3F,0x02,0x02,0x02,0x02,0x02,0x02,0x00,0x00},/*--  文字:  海  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x20,0x40,0x04,0xC8,0x20,0x10,0xCC,0x4B,0xA8,0x28,0x24,0xE4,0x04,0x00,0x00,0x00,0x00,0x10,0x3E,0x01,0x02,0x1A,0x17,0x12,0x2E,0x49,0x39,0x0F,0x09,0x01,0x00,0x00},/*--  文字:  无  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x40,0x44,0x44,0x44,0xC4,0x3C,0xE2,0x22,0x22,0x22,0x20,0x00,0x00,0x00,0x00,0x40,0x20,0x10,0x08,0x06,0x01,0x00,0x1F,0x20,0x20,0x20,0x20,0x3C,0x00,0x00},/*--  文字:  涯  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x20,0x40,0x02,0xC4,0x00,0xFC,0x24,0x24,0xFC,0x92,0x92,0x82,0x00,0x00,0x00,0x00,0x10,0x3C,0x43,0x30,0x4E,0x41,0x49,0x49,0x3F,0x24,0x24,0x20,0x20,0x00,0x00},/*--  文字:  苦  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x80,0x88,0x88,0x88,0x9E,0x84,0xE4,0x44,0x5F,0x44,0x44,0x44,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x44,0x44,0x23,0x22,0x22,0x3E,0x00,0x00,0x00,0x00,0x00},/*--  文字:  作  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x80,0x40,0x20,0xF8,0x07,0x40,0x30,0x1C,0xF3,0x90,0x90,0x48,0x48,0x08,0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x7F,0x04,0x04,0x02,0x02,0x02,0x00,0x00},/*--  文字:  舟  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0x00,0xF8,0x88,0x8C,0x9B,0xA4,0x84,0xFC,0x40,0x40,0x40,0x00,0x00,0x01,0x41,0x21,0x19,0x07,0x00,0x02,0x04,0x10,0x20,0x7F,0x00,0x00,0x00,0x00,0x00},/*--  文字:  。  --*//*--  仿宋_GB231212;  此字体下对应的点阵为:宽x高=16x16   --*/{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x24,0x24,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},{0x02,0xFE,0x92,0x92,0x92,0xFE,0x12,0x11,0x12,0x1C,0xF0,0x18,0x17,0x12,0x10,0x00,0x08,0x1F,0x08,0x08,0x04,0xFF,0x05,0x81,0x41,0x31,0x0F,0x11,0x21,0xC1,0x41,0x00},//"联",14{0x00,0x00,0x02,0x22,0xB2,0xAA,0x66,0x62,0x22,0x11,0x4D,0x81,0x01,0x01,0x00,0x00,0x00,0x40,0x21,0x13,0x09,0x05,0x41,0x81,0x7F,0x01,0x05,0x09,0x13,0x62,0x00,0x00},//"系",15{0x08,0x08,0x08,0x08,0x08,0x08,0xF9,0x4A,0x4C,0x48,0x48,0xC8,0x08,0x08,0x08,0x00,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x20,0x40,0x40,0x3F,0x00,0x00,0x00,0x00},//"方",16{0x00,0x08,0x88,0x88,0x88,0x88,0x88,0x08,0xFF,0x08,0x09,0x0E,0x0A,0x08,0x00,0x00,0x00,0x20,0x60,0x30,0x1F,0x10,0x08,0x08,0x00,0x07,0x18,0x20,0x40,0x80,0x70,0x00},//"式",17};uchar code num[][16]={{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},//"0",0{0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},//"1",1{0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},//"2",2{0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},//"3",3{0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},//"4",4{0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},//"5",5{0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},//"6",6{0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},//"7",7{0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},//"8",8{0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00} //"9",9};uchar code sign[][16]={{0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00},//"!",0{0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},//":",1{0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00}//"Q",2};//延时void delay(uint n){uint i;for(;n>0;n--)for(i=200;i>0;i--);}//判断是否忙void check(){rs=0;  rw=1;   //读 e=1;port=0x00;e=1; while(busy);e=0;}//写指令void sendcommand(uchar command){check();rs=0;  //指令rw=0;  //写 e=0;port=command;e=1;e=0; //写入指令}//写数据void writedata(uchar dat){check();rs=1;    //数据rw=0;port=dat;e=1;e=0;}//选屏幕 0--全屏,1--左屏,2--右屏;void select(uint n){switch(n){case 0:cs1=0;cs2=0;break;   //低电平选中case 1:cs1=0;cs2=1;break;   //cs1左屏case 2:cs1=1;cs2=0;break;   //cs2右屏}  }//页void setpage(uchar page){page=page0x07;page=page|0xb8;sendcommand(page);}//列void setcolumn(uchar column){column=column0x3f;column=column|0x40;sendcommand(column);}//起始行void setline(uchar line){line=line0x3f;line=line|0xc0;sendcommand(line);}//屏幕开关显示 0--关,1--开;void seton(uint n){n=n|0x3e;sendcommand(n);}//清屏 0--全屏,1--左屏,2--右屏;void clear(uint n){uchar i,j;select(n);for(i=0;i8;i++){setpage(i);setcolumn(0);for(j=0;j64;j++)writedata(0);  //置0清空}}//初始化void init(uchar i){check();seton(1);select(0);//clear(0);setline(i);}//显示汉字 16*16显示void show16(uchar page,uchar column,uchar screen,uchar method,uchar *str)  //页,列,{uchar i,j;select(screen);j=0;setpage(page);setcolumn(column);for(i=0;i16;i++){  if(method==1)   writedata(~str[j++]); //method为显示方式。当等于1时,反白。else            writedata(str[j++]);     }setpage(page+1);setcolumn(column);for(i=0;i16;i++){  if(method==1)   writedata(~str[j++]);else            writedata(str[j++]);     }} //显示数字 8*16显示void show8(uchar page,uchar column,uchar screen,uchar method,uchar *str){uchar i,j;select(screen);j=0;setpage(page);setcolumn(column);for(i=0;i8;i++){  if(method==1)   writedata(~str[j++]);else            writedata(str[j++]);     }setpage(page+1);setcolumn(column);for(i=0;i8;i++){  if(method==1)   writedata(~str[j++]);else            writedata(str[j++]);     }}void welcome(){uint i=0,j;for(j=0;j3;j++,j++)for(i=0;i4;i++){  show16(j,16*i,1,0,hz[i+j*4]);    //写左屏数据//    if(i+4+j*416)show16(j,16*i,2,0,hz[i+4+j*4]);   //写右屏数据}//  show8(2,32,2,0,sign[0]); //!for(i=0;i4;i++){show16(4,16*i,1,0,hz[16+i]);}show8(4,0,2,0,sign[1]); //:show8(6,0,1,0,sign[2]); //Qshow8(6,8,1,0,sign[2]); //Qshow8(6,16,1,0,sign[1]); //://以下数字均为反白显示。show8(6,32,1,1,num[4]); //4show8(6,40,1,1,num[3]);  //3show8(6,48,1,1,num[5]); //5show8(6,56,1,1,num[8]); //8show8(6,0,2,1,num[3]);   //3show8(6,8,2,1,num[5]); //5show8(6,16,2,1,num[1]); //1show8(6,24,2,1,num[8]); //8show8(6,32,2,1,num[1]); //1}void main(){uchar j;clear(0);while(1){for(j=0;j63;){j=j+16;if(j>60)j=0;init(j);//   delay(200);welcome();delay(500);}}}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top