12864带字库程序
PG12864F汉字显示程序
PG12864F汉字显示程序Proteus仿真图:汉字用取模软件取得地址程序:#include <reg51.h>#define uchar unsigned char #define uint unsigned intsbit wr=P2^0;sbit rd=P2^1;sbit ce=P2^2;sbit cd=P2^3;sbit rst=P2^4;void delay(uint t);void init_12864();void write_data(uchar dat); void write_cmd1(uchar cmd); void write_cmd2(uchar dat,uchar cmd);void write_cmd3(uchar data1,uchar data2,uchar cmd);uchar read_status();void check_status();void clear_screen();void display_char(uchar x,uchar y,uchar ch);//注意汉字数组要加code放到外部存储器中,如果不加code则空间不够uchar code HZ0[6][32]={{/*-- 文字: 华 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/0x11,0x00,0x11,0x10,0x21,0x20,0x61,0xC0,0xA3,0x00,0x2D,0x08,0x21,0x0 8,0x20,0xF8,0x22,0x00,0x02,0x00,0xFF,0xF8,0x02,0x00,0x02,0x00,0x02,0x00}, /*-- 文字: 东 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x04,0x00,0x04,0x00,0x7F,0xF0,0x08,0x00,0x12,0x00,0x22,0x00,0x3F,0x E0,0x02,0x00,0x02,0x00,0x22,0x40,0x22,0x20,0x42,0x10,0x82,0x10,0x0E,0x00}, /*-- 文字: 交 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x04,0x00,0x02,0x00,0xFF,0xF8,0x00,0x00,0x10,0x40,0x20,0x20,0x40,0x 10,0x10,0x40,0x08,0x80,0x05,0x00,0x02,0x00,0x05,0x00,0x18,0xC0,0xE0,0x38},/*-- 文字: 通 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x47,0xF0,0x21,0x20,0x20,0xC0,0x07,0xF0,0x04,0x90,0xE4,0x90,0x27,0x F0,0x24,0x90,0x24,0x90,0x27,0xF0,0x24,0x90,0x24,0xB0,0x50,0x00,0x8F,0xF8}, /*-- 文字: 大 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0xFF,0xF8,0x02,0x00,0x05,0x 00,0x05,0x00,0x05,0x00,0x08,0x80,0x08,0x80,0x10,0x40,0x20,0x20,0xC0,0x18}, /*-- 文字: 学 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x24,0x20,0x12,0x40,0x00,0x80,0xFF,0xF8,0x80,0x08,0x80,0x08,0x3F,0x C0,0x00,0x80,0x03,0x00,0xFF,0xF8,0x02,0x00,0x02,0x00,0x02,0x00,0x0E,0x00}};uchar code HZ1[4][32]={/*-- 文字: 电 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x02,0x00,0x02,0x00,0x02,0x00,0x7F,0xF0,0x42,0x10,0x42,0x10,0x7F,0x F0,0x42,0x10,0x42,0x10,0x7F,0xF0,0x42,0x00,0x02,0x08,0x02,0x08,0x01,0xF8},/*-- 文字: 气 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x20,0x00,0x20,0x00,0x3F,0xF8,0x40,0x00,0x9F,0xE0,0x00,0x00,0x7F,0x E0,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x28,0x00,0x18,0x00,0x08}, /*-- 文字: 学 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x24,0x20,0x12,0x40,0x00,0x80,0xFF,0xF8,0x80,0x08,0x80,0x08,0x3F,0x C0,0x00,0x80,0x03,0x00,0xFF,0xF8,0x02,0x00,0x02,0x00,0x02,0x00,0x0E,0x00}, /*-- 文字: 院 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x00,0x80,0xF0,0x40,0x97,0xF8,0x94,0x08,0xA0,0x00,0xA3,0xF0,0x90,0x 00,0x90,0x00,0x97,0xF8,0x91,0x20,0xE1,0x20,0x82,0x20,0x84,0x28,0x88,0x18}};uchar code HZ2[6][32]={{/*-- 文字: 零 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/0x3F,0xE0,0x02,0x00,0xFF,0xF8,0x82,0x08,0xBA,0xE8,0x02,0x00,0x3A,0xE 0,0x0D,0x80,0x30,0x60,0xC2,0x18,0x1F,0xC0,0x00,0x80,0x1D,0x00,0x03,0x00},/*-- 文字: 七 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x78,0x07,0x80,0xFC,0x 00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x00,0x04,0x08,0x04,0x08,0x03,0xF8}, /*-- 文字: 电 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x02,0x00,0x02,0x00,0x02,0x00,0x7F,0xF0,0x42,0x10,0x42,0x10,0x7F,0x F0,0x42,0x10,0x42,0x10,0x7F,0xF0,0x42,0x00,0x02,0x08,0x02,0x08,0x01,0xF8}, /*-- 文字: 牵 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x02,0x00,0x3F,0xE0,0x05,0x00,0x08,0x80,0x10,0x40,0xFF,0xF8,0x80,0x 08,0x22,0x00,0x3F,0xE0,0x42,0x00,0x02,0x00,0xFF,0xF8,0x02,0x00,0x02,0x00}, /*-- 文字: 二 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x00,0x00,0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x 00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xF8,0x00,0x00},/*-- 文字: 班 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x01,0x00,0xF9,0x78,0x21,0x20,0x25,0x20,0x25,0x20,0xFD,0x20,0x25,0x 78,0x25,0x20,0x29,0x20,0x21,0x20,0x3A,0x20,0xE2,0x20,0x04,0xF8,0x08,0x00}};uchar code HZ3[3][32]={{/*-- 文字: 占 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/0x04,0x00,0x04,0x00,0x04,0x00,0x07,0xF8,0x04,0x00,0x04,0x00,0x04,0x0 0,0x7F,0xE0,0x40,0x20,0x40,0x20,0x40,0x20,0x40,0x20,0x7F,0xE0,0x40,0x20},/*-- 文字: 俊 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x10,0x80,0x11,0x00,0x12,0x20,0x27,0xF0,0x20,0x10,0x62,0x20,0xA4,0x 10,0x29,0x08,0x21,0xE0,0x22,0x20,0x25,0x40,0x20,0x80,0x23,0x60,0x2C,0x18},/*-- 文字: 龙 --*//*-- 楷体_GB231211; 此字体下对应的点阵为:宽x高=14x14 --*//*-- 宽度不是8的倍数,现调整为:宽度x高度=16x14 --*/{0x04,0x00,0x04,0x80,0x04,0x40,0x04,0x00,0xFF,0xF8,0x05,0x00,0x09,0x 10,0x09,0x20,0x09,0x40,0x11,0x80,0x11,0x00,0x23,0x08,0x4D,0x08,0x80,0xF8}}; //汉字显示函数,处在x y处显示汉字hzvoid display_HZ(uchar x,uchar y,uchar *hz)////x 0-3 y 0-7 {uchar i,j=0;for(i=0;i<16;i++){write_cmd3(((j/2)<<4)|(y*2),x,0x24);//地址指针设置..低地址,高地址,命令write_cmd2(hz[j++],0xc0);write_cmd2(hz[j++],0xc0);}}void main(){uchar i,j=0;init_12864();for(i=0;i<6;i++)display_HZ(0,1+i,HZ0[i]);//显示:华东交通大学 for(i=0;i<4;i++)display_HZ(1,1+i,HZ1[i]);显示:电气学院 for(i=0;i<6;i++)display_HZ(2,1+i,HZ2[i]);显示:零七电牵二班 for(i=0;i<3;i++)display_HZ(3,2+i,HZ3[i]);显示:占俊龙//for(i=0;i<128;i++) //{// display_char(i/16,i%16,'0'+i);//}//clear_screen(); }//显示字符函数,处在x y处显示chvoid display_char(uchar x,uchar y,uchar ch)//x 0-7 y 0-15{write_cmd3((((x*2)<<4)+y),0x00,0x24);//地址指针位置 write_cmd2(ch-32,0xc0);//t6963c字符表与ASCII差32@@@@@@@@@@@@@@@@}void delay(uint t) {uint i,j;for(i=0;i<t;i++)for(j=0;j<50;j++); }void init_12864() {rst=1;delay(10);rst=0;wr=1;rd=1;ce=1;cd=1;rst=1;check_status();write_cmd3(0x01,0x00,0x21);//光标指针设置 check_status();write_cmd3(0x00,0x00,0x42);//图形区首地址 check_status();write_cmd3(16,0x00,0x43);//图形区宽度 check_status();write_cmd1(0x80);//显示方式设置,正常显示 check_status();//write_cmd1(0x94);//。
12864ZB带中文字库的液晶C程序,12864lcd
带中文字库的液晶12864的C程序(C12864ZB-1)带中文字库的液晶12864的C程序(C12864ZB-1)!并口连接液晶!ftinc1ude<reg52.h>#inc1ude<math.h>void1cd_init(void);voidc1r1cd(void);voidsendcom(unsignedcharcmd);voidsenddata(unsignedchardat);voidchekbusy(void);voidsetxy(unsignedcharxpos,unsignedcharypos);voidprint(unsignedcharx,unsignedchary,char*str);voidprintstr(unsignedcharxpos,unsignedcharypos,unsignedcharstr[],unsignedcha:unsignedcharcodebuf[4]={0xbb,0xb6,0xd3,0xad};〃欢迎/********************测忙碌**********************/〃测忙碌子程序/∕RS=O,RW=I,E=H,DO-D7二状态字voidchekbusy(void){unsignedchartempi;〃状态信息(判断是否忙)C1RB(CONTRO1,RS); 〃RS=0;SETB(CONTRO1,RW); //RW=1;SETB(CONTRO1,E); //E=1;do{tempi=DATA;DATA=O X FF;}whi1e(temp1&0x80);//SETB(CONTRO1,E); //E=1;DATA=O X FF;) 口〃写命令子程序//voidsend_com(unsignedcharCmd)/*写命令*/{chek_busyO;C1R B 7C ONTRO1,RS);//RS=0;C1RB(CONTRO1,RW);//RW=0;DATA=cmd;SETB(CONTRO1,E);//E=1;C1RB(CONTRO1,E);//E=0;voidsend_data(unsignedchardat){chek_busyO;SETBteONTRO1,RS);//RS=1;C1RB(CONTRO1,RW);//RW=0;DATA=dat;SETB(CONTRO1,E);//E=1;C1RB(CONTRO1,E);//E=0;}〃复位、通讯方式选择void1cd_init(void)SETB(CONTRO1,RST);〃复位RST=I?SETB(CONTRO1,PSB); 〃通讯方式为并口PSB=1//send_com(0x34);//34H 一扩充指令操作一次送8位数据,基本指令集整体显示,游标。
12864液晶屏(带字库)51单片机3线串口驱动程序
#include<reg51.h>typedef unsigned char uint8; typedef unsigned int uint16; typedef unsigned long uitn32;sbit CS = P1^0;//片选信号引脚sbit SDA = P1^1;//数据线sbit SCK = P1^2;//串行时钟线//sbit RST = P1^3;//复位引脚//sbit PSB = P1^4;//串并控制引脚code uint8 strint1[] = "I Love You !";/*void delay5ms(void) //误差0us {unsigned char a,b;for(b=185;b>0;b--)for(a=12;a>0;a--);}*///发送一个字节void Send_Byte(uint8 dat){uint8 i;SCK = 0;for(i=0;i<8;i++){SDA = dat&0x80;SCK = 1;dat <<= 1;SCK = 0;}}//读取一个字节数据uint8 Read_Byte(void){uint8 i;uint16 byte = 0;SCK = 0;for(i=0;i<16;i++){byte <<= 1;SCK = 1;if(SDA)byte |= 0x0001;SCK = 0;}byte = ((byte>>4)|(byte>>8))&0x00ff;return ((uint8)(byte));}//读忙标志void Read_Busy(void){uint8 temp;CS = 1;do{Send_Byte(0xfc);//发送读命令temp = Read_Byte();//读取数据}while(temp&0x80);CS = 0;}//发送命令void Write_Cmd(uint8 cmd){uint8 temph = 0;uint8 templ = 0;//制作发送命令格式temph = cmd & 0xf0;templ = (cmd & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XF8);//发送命令命令//发送命令Send_Byte(temph);Send_Byte(templ);CS = 0;}//发送数据void Write_Dat(uint8 dat){uint8 temph = 0;uint8 templ = 0;//制作发送数据格式temph = dat & 0xf0;templ = (dat & 0x0f) << 4;Read_Busy();CS = 1;Send_Byte(0XFA);//发送数据命令Send_Byte(temph);//发送数据Send_Byte(templ);CS = 0;}//在指定位置显示半字宽字符void Dis_HCGROM(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat);}//指定位置显示字符串void Dis_String(uint8 x, uint8 y, uint8 len, uint8 *dat) {uint8 addr,i;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);for(i = 0;i < len;i++){Write_Dat(*dat++);}}//制定位置显示8位无符号数字void Dis_UNum8(uint8 x,uint8 y,uint8 dat){uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//制定位置显示16位无符号数字void Dis_UNum16(uint8 x,uint8 y,uint8 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat(dat/10000%10+'0');Write_Dat(dat/1000%10+'0');Write_Dat(dat/100%10+'0');Write_Dat(dat/10%10+'0');Write_Dat(dat/1%10+'0');}//在指定位置显示汉字//x范围:0-7,y范围:0-3//dat:汉字字形码void Dis_GB(uint8 x,uint8 y,uint16 dat) {uint8 addr;switch(y){case 0:addr = 0x80 + x;break;case 1:addr = 0x90 + x;break;case 2:addr = 0x88 + x;break;case 3:addr = 0x98 + x;break;default:break;}Write_Cmd(addr);Write_Dat((uint8)(dat >> 8));Write_Dat((uint8)(dat));}//LCD初始化void LCD_Init(void){/*RST = 0;delay5ms();delay5ms();RST = 1;PSB = 0;*/Write_Cmd(0X30);Write_Cmd(0X01);Write_Cmd(0X02);Write_Cmd(0X0C);}void main(void){LCD_Init();while(1){Dis_GB(0,0,0xc9b5);Dis_HCGROM(1,0,0x03);Dis_String(0,1,13,strint1);Dis_UNum8(0,2,250);} }。
带字库12864液晶显示程序
#include <reg52.h>#include <intrins.h>#define uint unsigned int#define uchar unsigned char#define LCDdata P0//采用并行模式sbit E = P2^7;sbit RW = P2^6;sbit RS = P2^5;sbit RST = P2^4;sbit key1 = P2^0; //时、分、秒选择键sbit key2 = P2^1; //加一键sbit key3 = P2^2; //减一键void init();//void check_busy();void delayms(uint x);void write_com(uchar com);void write_data(uchar date);//void delay(uchar y);void t_bcd();void disp_time();void t_time();uchar code string[]={"00时00分00秒"}; uchar code tab[] ={"长春工业大学"}; uchar code tab1[]={"人文信息学院"}; uchar code tab2[]={"electronic 沈琦"};uchar time[6];//显示缓冲区uchar count;char sec,min,hour;//--------------主函数-----------------void main(){init();while(1){if(count == 200){count = 0;sec++;if(sec == 60){sec = 0;min++;if(min == 60){min = 0;hour++;if(hour == 24){hour = 0;}}}t_bcd();disp_time();}t_time();}}//-------------初始化----------------void init(){uchar i;// RST = 0;// delayms(1);// RST = 1;// delayms(40);write_com(0x30);write_com(0x0f);write_com(0x01);write_com(0x81);for(i=0;i<12;i++){write_data(string[i]);delayms(5);}write_com(0x90);for(i=0;i<16;i++){write_data(tab[i]);delayms(5);}write_com(0x8a);for(i=0;i<12;i++){write_data(tab1[i]);delayms(5);}write_com(0x98);for(i=0;i<16;i++){write_data(tab2[i]);delayms(5);}TMOD = 0x01;TH0 = (65536-5000)/256;TL0 = (65536-5000)%256;EA = 1;ET0 = 1;TR0 = 1;write_com(0x0c);}//------------毫秒延时--------------- void delayms(uint x){uchar i;while(x--){for(i=0;i<120;i++);}}/*//--------------判忙程序--------------- void check_busy(){// LCDdata = 0xff;RS = 0;RW = 1;// E = 0;E = 1;LCDdata = 0xff;while(LCDdata&0x80);E = 0;}*///------------写命令----------------- void write_com(uchar com){// check_busy();RS = 0;RW = 0;E = 0;LCDdata = com;// delayms(5);E = 1;delayms(5);E = 0;}//-------------写数据------------------ void write_data(uchar date){// check_busy();RS = 1;RW = 0;E = 0;LCDdata = date;// delayms(5);E = 1;delayms(5);E = 0;}//-----------定时中断0------------- void timer0() interrupt 1{TH0 = (65536-5000)/256;TL0 = (65536-5000)%256;count++;}void t_bcd(){time[0] = sec%10;time[1] = sec/10;time[2] = min%10;time[3] = min/10;time[4] = hour%10;time[5] = hour/10;}//--------------时钟时间显示----------------- void disp_time(){write_com(0x85);write_data(0x30+time[1]);write_data(0x30+time[0]);write_com(0x83);write_data(0x30+time[3]);write_data(0x30+time[2]);write_com(0x81);write_data(0x30+time[5]);write_data(0x30+time[4]);}//------------调整时间程序--------------- void t_time(){static uchar num;if(key1 == 0){delayms(5);while(!key1);TR0 = 0;num++;}//-----------------调时-----------------if(num == 1){write_com(0x81);write_com(0x0f);if(key2 == 0){delayms(5);if(key2 == 0){while(!key2);hour++;if(hour == 24){hour = 0;}t_bcd();write_data(0x30+time[5]);write_data(0x30+time[4]);}}if(key3 == 0){delayms(5);if(key3 == 0){while(!key3);hour--;if(hour == -1){hour = 23;}t_bcd();write_data(0x30+time[5]);write_data(0x30+time[4]);}}}//-----------------调分----------------------if(num == 2){write_com(0x83);if(key2 == 0){delayms(5);if(key2 == 0){while(!key2);min++;if(min == 60){min = 0;}t_bcd();write_data(0x30+time[3]);write_data(0x30+time[2]);}}if(key3 == 0){delayms(5);if(key3 == 0){while(!key3);min--;if(min == -1){min = 59;}t_bcd();write_data(0x30+time[3]);write_data(0x30+time[2]);}}}//---------------调秒------------------if(num == 3){write_com(0x85);if(key2 == 0){delayms(5);if(key2 == 0){while(!key2);sec++;if(sec == 60){sec = 0;}t_bcd();write_data(0x30+time[1]);write_data(0x30+time[0]);}}if(key3 == 0){delayms(5);if(key3 == 0){while(!key3);sec--;if(sec == -1){sec = 59;}t_bcd();write_data(0x30+time[1]);write_data(0x30+time[0]);}}}//---------------退出调整时间----------------- if(num == 4){num = 0;write_com(0x0c);TR0 = 1;}}。
12864各种画图程序(带字库修改)
12864各种画图程序(带字库修改)/************************************************************** *********************************************************************************** ************ *********///程序说明:本程序为12864(st7920)驱动程序,只实现了最简单的显示功能//端口设置:RS、RW、EN分别为P0口的0、1、2,数据口为P2口//注意:1.要想在液晶屏上同时显示自定义字库和绘图,必须先显示自定义字库// 2.本程序所有函数均有用且正确,由于我的keil未破解不能编译,所以将其注释了// 3.用取模软件取的图形或汉字必须是逐行取的,因为本函数是在液晶上逐行打点的/****************************************************************** ******************************************************************************* **********/ #include#include //内含-NOP-函数#include //内含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;elseif(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轴为基准< bdsfid="385" p=""></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;{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;}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轴为基准{< bdsfid="500" p=""></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++){。
LCD12864驱动程序(带字库的)
{
while(buf--);
}*/
/***********忙检测********************/
void Busy()
{
DataPort=0xFF;
RS=0;
RW=1;
while (1)
{
E =1;
if (P0^7==0) break;
}
E=0;
}
void main(void)
{
TMOD=0x01; ///选择定时器模式
TR0=1; //开中断,并允许T0中断
ET0=1;
EA=1; //总开关
Init_LCቤተ መጻሕፍቲ ባይዱ();
Clear_LCD();
while(1);
}
void t0(void) interrupt 1 using 0
{
//delay(100);
/*void Line_Num(uchar k)
{
//uint l;
if(k>=128&&k<=135)l=1;
if(k>135&&k<=143) l=3;
if(k>143&&k<=151) l=2;
if(k>151&&k<=159) l=4;
}*/
/*******************逐行显示***************************************/
void Write_Data(uchar Data)
{
Busy();
RS=1;
RW=0;
LCD12864显示屏 带中文字库
蓝屏LCD12864显示屏带中文字库带背光12864-5V ST7920需要用串口,请把R9上的0欧电阻改到R10带中文字库的,兰屏,白字以下是在液晶模块的第二行第一个字符的位置显示字母“A”的程序: ORG 0000HRS EQU P3.7;确定具体硬件的连接方式RW EQU P3.6 ;确定具体硬件的连接方式E EQU P3.5 ;确定具体硬件的连接方式MOV P1,#00000001B ;清屏并光标复位ACALL ENABLE;调用写入命令子程序MOV P1,#00111000B ;设置显示模式:8位2行5x7点阵ACALL ENABLE ;调用写入命令子程序MOV P1,#00001111B ;显示器开、光标开、光标允许闪烁ACALL ENABLE ;调用写入命令子程序MOV P1,#00000110B ;文字不动,光标自动右移ACALL ENABLE ;调用写入命令子程序MOV P1,#0C0H ;写入显示起始地址(第二行第一个位置)ACALL ENABLE ;调用写入命令子程序MOV P1,#01000001B ;字母A的代码SETB RS ;RS=1CLR RW ;RW=0 ;准备写入数据CLR E ;E=0 ;执行显示命令ACALL DELAY ;判断液晶模块是否忙?SETB E ;E=1 ;显示完成,程序停车AJMP $ENABLE:CLR RS ;写入控制命令的子程序CLR RWCLR EACALL DELAYSETB ERETDELAY:MOV P1,#0FFH ;判断液晶显示器是否忙的子程序CLR RSSETB RWCLR ENOPSETB EJB P1.7,DELAY ;如果P1.7为高电平表示忙就循环等待RETEND程序在开始时对液晶模块功能进行了初始化设置,约定了显示格式。
注意显示字符时光标是自动右移的,无需人工干预,每次输入指令都先调用判断液晶模块是否忙的子程序DELAY,然后输入显示位置的地址0C0H,最后输入要显示的字符A的代码41H。
12864中文字库C语言
12864中文字库C语言#include <reg52.h>#include <intrins.h>#define LcmXPixel 128 //横像素#define LcmYPixel 64 //纵像素//#define BUS_MODE //总线模式#define IO_MODE //IO模式//总线模式程序接口#ifdef BUS_MODEchar xdata LcmWCmdPort _at_ 0x0000; //写命令char xdata LcmWDatPort _at_ 0x0100; //写数据char xdata LcmRStaPort _at_ 0x0200; //读状态char xdata LcmRDatPort _at_ 0x0300; //读数据#endifvoid int_zhongduan();void delay(unsigned int t);//IO模式程序接口#ifdef IO_MODEsbit RSP = P2^0; //RSP表示RS Port,P=Port,下同sbit RWP = P2^1;sbit EP = P2^2; //E信号在本程序中是通过单片机的WR和RD与非出来的,是为了不改动总线模式的连线方式sbit RES =P2^3;#define LcmDataBus P0 //用户可以不用这样操作,直接用一个IO 口来操作,替换本程序中_E1_()和_E0_()两个函数#endifsbit Key=P3^2;sbit P33=P3^3;sbit p0_dr=P3^4; //坚鸿测试架增加指令,控制P0口的输入输出。
(用户不用理会这里)unsigned char code AC_TABLE[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,};unsigned char code str1[]="黄河远上白云间,一片孤城万仞山。
带字库12864超详细扩展操作,写自定义字符,画图,画直线,画圆,读取数据等操作
在此指出,这一篇文章出至网络上zhaoshan413之手,感谢他的无私贡献,让大家轻松玩转带字库12864!~~[p=30, 2, left]之前说学完12864字库液晶后和大家交流一下心得,一直没有时间,今天整理一下发上来,希望对想学习的朋友能有点帮助…首先说明一点,本人也是初学者,自感水平不高,若有不足及不对之处,望情指正…以下以并行口传输为例,别的还不会,呵呵![/p][p=30, 2, left]先传一下ST7920的芯片说明书:[/p][p=30, 2, left]/bbs/redirect.php?tid=7676&goto=lastpo st#lastpost[/p][p=30, 2, left]ST7920(字库)12864.pdf(2010-12-01 10:46:58, Size: 1.65 MB, Downloads: 1689)[/p][p=30, 2, left]一、首先说一下关于驱动函数的书写,这些是液晶显示的基础一般包括四个函数:1、写命令函数;2、写数据函数;3、读状态函数;4、读数据函数;这四个函数并不是必须全部写的,具体要看你实现的功能,如果只是单纯的显示汉字和字符,写命令、写数据、读状态这三个函数就够了,如过你还需要进行一些绘图的操作,那读数据函数也必须书写。
另外关于读状态函数,其实也就是用于判忙操作,我看郭天祥的书里面是这样说的:原则上每次对控制器进行读写操作之前,都必须进行读写检测,由于单片机的操作速度慢于液晶控制器的反应速度,因此可不进行读写检测,或者只进行简短的延时即可。
因此,读状态函数也可以不写,只用简短的延时函数替换即可。
1、写操作的编写:首先看一下时序图[/p][p=30, 2, left]时序.JPG[/p][p=30, 2, left]由图可见操作很简单:1>RS=1(写数据操作);或者RS=0(写命令操作);2>RW=0;//指明为写操作3>E=1;4>DB=data;//data为你要写入的命令或数据值5>E=0;[/p][p=30, 2, left]以下是我的驱动函数,仅供参考:[/p][p=30, 2, left]CODE:/********************************液晶端口定义**************************/#define lcd_data P0 //数据口sbit RS = P2^4; //选择寄存器(并行) 0:指令寄存器1:数据寄存器;sbit RW = P2^5; //读写控制脚(并行) 0:写入 1:读出sbit E = P2^6; //读写数据启始脚(并行)sbit PSB = P2^1; //串并方式选择引脚,0为串行模式,1为8/4位数据口模式sbit RST = P2^3; //复位引脚//******************************************************* *//延时函数//******************************************************* *void delay(unsigned int k){unsigned int i;unsigned char j;for(i=0;i<k;i++){for(j=0;j<10;j++);}}//******************************************************* *//延时1ms函数//******************************************************* *void delay_ms(unsigned int k)//延时0.994us,晶振12M{unsigned int x,y;for(x=k;x>0;x--)for(y=121;y>0;y--);}//******************************************************* *//写命令函数//******************************************************* *void LcdWcom(unsigned char WCom){delay(1);RS=0; //指明操作对象为指令寄存器RW=0; //指明为写操作E=1;lcd_data=WCom; //将命令写入总线E=0;}//******************************************************* *//写数据函数//******************************************************* *void LcdWdata(unsigned char WData){delay(1);RS=1; //指明操作对象为数据寄存器RW=0; //指明为写操作E=1;lcd_data=WData; //将数据写入总线E=0;}[/p][p=30, 2, left]二、初始化操作[/p][p=30, 2, left]以8位并行操作为例,操作流程图如下:[/p][p=30, 2, left]初始化.JPG[/p][p=30, 2, left]初始化操作如下:[/p][p=30, 2, left]1>芯片上电;[/p][p=30, 2, left]2>延时40ms以上;[/p][p=30, 2, left]3>复位操作:RST出现一个上升沿(RST=1;RST=0;RST=1;);[/p][p=30, 2, left]4>功能设定;[/p][p=30, 2, left]5>延时100us以上;[/p][p=30, 2, left]6>再次进行功能设定;[/p][p=30, 2, left]7>延时37us;[/p][p=30, 2, left]8>显示开关控制;[/p][p=30, 2, left]9>延时100us 以上;[/p][p=30, 2, left]10>清除显示;[/p][p=30, 2, left]11>延时10ms以上;[/p][p=30, 2, left]12>进入点设置;[/p][p=30, 2, left]13>初始化结束;[/p][p=30, 2, left]这里我遇到了一个小问题,我的液晶按照这个顺序进行初始化结果不正确,无法显示,最后我把调整了一下就可以了,调整后的顺序为:清除显示进入点设置显示开关控制,不知道是什么原因,知道的告诉我一声…[/p][p=30, 2, left]CODE://******************************************************* *//显示初始化函数//******************************************************* *void Display_Init(void){delay_ms(45); //延时45msPSB=1; //8位并行口//复位操作RST=1;delay(1);RST=0;delay(1);RST=1;delay(1);//功能设定LcdWcom(0x30); //设置为8位并行口,基本指令集delay(10);LcdWcom(0x30); //再次设置为8位并行口,基本指令集delay(5);// //显示开关控制// LcdWcom(0x0c); //游标显示关,正常显示,整体显示开// delay(10);//清除显示LcdWcom(0x01);delay_ms(12); //延时12ms//进入点设置LcdWcom(0x06); //设置为游标右移,DDRAM位地址加1,画面不移动delay(5);LcdWcom(0x0C); //开显示}[/p][p=30, 2, left]三、显示基本的字符和汉字[/p][p=30, 2, left]1、要想显示汉字或字符,首先要确定显示的位置,看看芯片说明书上关于屏幕地址的分配:[/p][p=30, 2, left]DDRAM位址.JPG[/p][p=30, 2, left]由于此液晶为128*64,即是横向128个点,竖向64个点,由于该液晶控制器支持的字符为8*16,汉字为16*16,因此只能显示四行,如果是汉字,为每行显示8个,如果是字符,每行显示16个。
12864点阵LCD液晶屏带中文字库
功能
令 RS R/W D7 D6 D5 D4 D3 D2 D1 D0
待命
进入待命模式,执行其他指令都棵终止
0 0 0 0000001
模式
待命模式
卷动地 SR=1:允许输入垂直卷动地址
址开关 0 0 0 0 0 0 0 0 1 SR SR=0:允许输入 IRAM 和 CGRAM 地址
开启
反白
选择 2 行中的任一行作反白显示,并可决定反白与否。初始值 R1R
0 0 0 0 0 0 0 1 R1 R0
选择
0=00,第一次设定为反白显示,再次设定变回正常
睡眠
SL=0:进入睡眠模式
0 0 0 0 0 0 1 SL X X
模式
SL=1:脱离睡眠模式
CL=0/1:4/8 位数据 扩充
RE=1: 扩充指令操作 功能 0 0 0 0 1 CL X RE G 0
RE=0: 基本指令操作 设定
示移位控 0 0 0 0 0 1 S/C R/L X X RAM 的内容
制
DL=0/1:4/8 位数据 功能
0 0 0 0 1 DL X RE X X RE=1: 扩充指令操作 设定
RE=0: 基本指令操作
设定 CG
RAM
0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0 设定 CGRAM 地址
G=1/0:绘图开关
设定
设定绘图 RAM
绘图 RA
0 0 0 AC3 AC2 AC1 AC0 先设定垂直(列)地址 AC6AC5…AC0
001
M
AC6 AC5 AC4 AC3 AC2 AC1 AC0 再设定水平(行)地址 AC3AC2AC1AC0
地址
将以上 16 位地址连续写入即可
带中文字库的12864lcd显示程序
for(j = 100; j > 0; j--); }
// 检测 LCD是否处于忙状态 , 若忙返回 1, 空闲返回 0 bit checkBusy() { bit busy;
RS = 0; RW = 1; E = 1; delayUs(); busy = (bit)(LCD_DATA&0x80); E = 0; return busy; }
1
文档来源为 :从网络收集整理 .word 版本可编辑 .欢迎下载支持 .
// 等待 LCD到空闲 void wait() {
while(checkBusy()); }
// 写命令 void writeCmd(uchar cmd) {
wait(); RS = 0; RW = 0; E = 0; delayUs(); LCD_DATA = cmd; delayUs(); E = 1; delayUs(); E = 0; }3ຫໍສະໝຸດ delayMs(10); }
void setPosition(uchar x, uchar y) { uchar p;
switch(x%4) {
case 0: p = 0x80; break; // case 1: p = 0x90; break; // case 2: p = 0x88; break; // case 3: p = 0x98; break; // } p += y; writeCmd(p); }
PSB = 1; // 并口方式 writeCmd(0x30); // 基本指令 , 扩充指令为 34H delayMs(10); writeCmd(0x0c); // 显示开 , 关光标 delayMs(10); writeCmd(0x01); // 清屏
12864点阵液晶显示测试程序(带字库)
12864点阵液晶显示测试程序(带字库)接口说明1 12864-1测试程序:#include <reg52.h>#define uint unsigned int#define uchar unsigned char#define x1 0x80#define x2 0x88#define y 0x80#define comm 0#define dat 1sbit rs = P1^1; //H=data; L=command;sbit rw = P1^2; //H=read; L=write;sbit e = P1^3; //input enable;sbit psb= P1^4; //H=并口; L=串口;sbit rst= P1^5; //Reset Signal 低电平有效sbit busy=P2^7; //lcd busy bitvoid wr_lcd (uchar dat_comm,uchar content);void chk_busy (void);void delay (uint us);uchar code tab1[]={" 床前明月光, "" 疑是地上霜, ""举头望明月, ""低头思故乡。
"};uchar code tab31[]={"你的选择""没有错"};uchar code tab32[]={/*-- 调入了一幅图像:D:\Backup\桌面\未命名1.bmp --*//*-- 宽度x高度=128x32 --*/0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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 init_lcd (void){rst=1;psb=1;wr_lcd (comm,0x30); /*30---基本指令动作*/wr_lcd (comm,0x01); /*清屏,地址指针指向00H*/wr_lcd (comm,0x06); /*光标的移动方向*/wr_lcd (comm,0x0c); /*开显示,关游标*/}/*---------------显示汉字或字符----------------*/ void chn_disp (uchar code *chn){uchar i,j;wr_lcd (comm,0x30);wr_lcd (comm,0x80);for (j=0;j<4;j++){for (i=0;i<16;i++)wr_lcd (dat,chn[j*16+i]);}}/*-----------上半屏显示汉字或字符------------*/ void chn_disp1 (uchar code *chn){uchar i,j;wr_lcd (comm,0x30);wr_lcd (comm,0x80);j=0;for (i=0;i<16;i++)wr_lcd (dat,chn[j*16+i]);wr_lcd (comm,0x90);j=1;for (i=0;i<16;i++)wr_lcd (dat,chn[j*16+i]);}/*----------------显示图形-----------------*/void img_disp (uchar code *img){uchar i,j;for(j=0;j<32;j++){for(i=0;i<8;i++){wr_lcd (comm,0x34);wr_lcd (comm,y+j);wr_lcd (comm,x1+i);wr_lcd (comm,0x30);wr_lcd (dat,img[j*16+i*2]);wr_lcd (dat,img[j*16+i*2+1]);}}for(j=32;j<64;j++){for(i=0;i<8;i++){wr_lcd (comm,0x34);wr_lcd (comm,y+j-32);wr_lcd (comm,x2+i);wr_lcd (comm,0x30);wr_lcd (dat,img[j*16+i*2]);wr_lcd (dat,img[j*16+i*2+1]);}}wr_lcd (comm,0x36);}/*-------------下半屏显示图形--------------*/ void img_disp1 (uchar code *img){uchar i,j;for(j=0;j<32;j++){for(i=0;i<8;i++){wr_lcd (comm,0x34);wr_lcd (comm,y+j);wr_lcd (comm,x2+i);wr_lcd (comm,0x30);wr_lcd (dat,img[j*16+i*2]);wr_lcd (dat,img[j*16+i*2+1]);}}wr_lcd (comm,0x36);}/*--------------显示点阵----------------*/void lat_disp (uchar data1,uchar data2) {uchar i,j,k,x;x=x1;for(k=0;k<2;k++){for(j=0;j<16;j++){for(i=0;i<8;i++){wr_lcd (comm,0x34);wr_lcd (comm,y+j*2);wr_lcd (comm,x+i);wr_lcd (comm,0x30);wr_lcd (dat,data1);wr_lcd (dat,data1);}for(i=0;i<8;i++){wr_lcd (comm,0x34);wr_lcd (comm,y+j*2+1);wr_lcd (comm,x+i);wr_lcd (comm,0x30);wr_lcd (dat,data2);wr_lcd (dat,data2);}}x=x2;}wr_lcd (comm,0x36);}/*-----------------------------------------------*///当data1=0xff,data2=0xff时,在x0,y0处反白显示16xl*yl.void con_disp (uchar data1,uchar data2,uchar x0,uchar y0,uchar xl,uchar yl) {uchar i,j;for(j=0;j<yl;j++){for(i=0;i<xl;i++){wr_lcd (comm,0x34);wr_lcd (comm,y0+j);wr_lcd (comm,x0+i);wr_lcd (comm,0x30);wr_lcd (dat,data1);wr_lcd (dat,data2);}}wr_lcd (comm,0x36);}/*--------------清DDRAM------------------*/void clrram (void){wr_lcd (comm,0x30);wr_lcd (comm,0x01);}/*---------------------------------------*/void wr_lcd (uchar dat_comm,uchar content) {chk_busy ();if(dat_comm){rs=1; //datarw=0; //write}else{rs=0; //commandrw=0; //write}P2=content; //output data or comme=1;;e=0;}void chk_busy (void){P2=0xff;rs=0;rw=1;e =1;while(busy==1);e =0;}void delay (uint us) //delay time{while(us--);}void delay1 (uint ms){uint i,j;for(i=0;i<ms;i++)for(j=0;j<15;j++)delay(1);}/*------------------主程序--------------------*/void main (){SP=0x5f;init_lcd ();while (1){lat_disp (0x00,0x00);chn_disp (tab1);con_disp (0xff,0xff,0x8c,0x80,2,16);delay1 (28000);clrram();lat_disp (0xcc,0xcc);delay1 (28000);lat_disp (0x00,0x00);chn_disp1 (tab31);img_disp1 (tab32);delay1 (28000);clrram();lat_disp (0xff,0x00);delay1 (28000);img_disp (tab5);delay1 (28000);}}。
12864带字库c语言源码
#include <stdio.h>#include <math.h>#include <reg52.h>#include <string.h>unsigned char code IC_DAT[];unsigned char code pic1[];unsigned char code pic2[];unsigned char code pic3[];sbit RS =P2^4;sbit WRD=P2^5;sbit E= P2^6;sbit PSB=P2^1;sbit RES=P2^3;void TransferData(char data1,bit DI);void display(void);void display_grapic(void);void delayms(unsigned int n);void DisplayLine(unsigned char line1,unsigned char line2); void DisplayGraphic(unsigned char code *adder);void delay(unsigned int m);void lcd_mesg(unsigned char code *adder1);unsigned char code IC_DAT[]={"上海浩豚电子科技""单片机开发板系列""中文字库测试程序""恭喜发财身体健康"};unsigned char code IC_DAT2[]={"海纳百川宽容为先""欲成大业诚信为先""游弋商海济世为先""人立于世守法为先"};void initinal(void) //LCD字库初始化程序delay(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delay(1); //延时RES=0; //复位delay(1); //延时RES=1; //复位置高delay(10);TransferData(0x30,0); //Extended Function Set :8BIT设置,RE=0: basic instruction set, G=0 :graphic display OFFdelay(100); //大于100uS的延时程序TransferData(0x30,0); //Function Setdelay(37); ////大于37uS的延时程序TransferData(0x08,0); //Display on Controldelay(100); //大于100uS的延时程序TransferData(0x10,0); //Cursor Display Control光标设置delay(100); //大于100uS的延时程序TransferData(0x0C,0); //Display Control,D=1,显示开delay(100); //大于100uS的延时程序TransferData(0x01,0); //Display Cleardelay(10); //大于10mS的延时程序TransferData(0x06,0); //Enry Mode Set,光标从右向左加1位移动delay(100); //大于100uS的延时程序}void initina2(void) //LCD显示图片(扩展)初始化程序{delay(40); //大于40MS的延时程序PSB=1; //设置为8BIT并口工作模式delay(1); //延时RES=0; //复位delay(1); //延时RES=1; //复位置高delay(10);TransferData(0x36,0); //Extended Function Set RE=1: extended instructiondelay(100); //大于100uS的延时程序TransferData(0x36,0); //Extended Function Set:RE=1: extended instruction setdelay(37); ////大于37uS的延时程序TransferData(0x3E,0); //EXFUNCTION(DL=8BITS,RE=1,G=1)delay(100); //大于100uS的延时程序TransferData(0x01,0); //CLEAR SCREENdelay(100); //大于100uS的延时程序void main(void){while(1){initina2(); //调用LCD显示图片(扩展)初始化程序DisplayGraphic(pic2); //显示图片2delayms(200);DisplayGraphic(pic3); //显示图片3delayms(200);initinal(); //调用LCD字库初始化程序delay(100); //大于100uS的延时程序lcd_mesg(IC_DAT); //显示中文汉字1delayms(240);delayms(240);initinal(); //调用LCD字库初始化程序delay(100); //大于100uS的延时程序lcd_mesg(IC_DAT2); //显示中文汉字2delayms(240);delayms(240);}}void lcd_mesg(unsigned char code *adder1){unsigned char i;TransferData(0x80,0); //Set Graphic Display RAM Addressdelay(100);for(i=0;i<32;i++){TransferData(*adder1,1);adder1++;}TransferData(0x90,0); //Set Graphic Display RAM Addressdelay(100);for(i=32;i<64;i++){TransferData(*adder1,1);adder1++;}}void TransferData(char data1,bit DI) //传送数据或者命令,当DI=0是,传送命令,当DI=1,传送数据.{WRD=0;RS=DI;delay(1);P0=data1;E=1;delay(1);E=0;}void delayms(unsigned int n) //延时10×n毫秒程序{unsigned int i,j;for(i=0;i<n;i++)for(j=0;j<2000;j++);}void delay(unsigned int m) //延时程序{unsigned int i,j;for(i=0;i<m;i++)for(j=0;j<10;j++);}void DisplayGraphic(unsigned char code *adder){int i,j;//*******显示上半屏内容设置for(i=0;i<32;i++) //{TransferData((0x80 + i),0); //SET 垂直地址VERTICAL ADDTransferData(0x80,0); //SET 水平地址HORIZONTAL ADDfor(j=0;j<16;j++){TransferData(*adder,1);adder++;}}//*******显示下半屏内容设置for(i=0;i<32;i++) //{TransferData((0x80 + i),0); //SET 垂直地址VERTICAL ADDTransferData(0x88,0); //SET 水平地址HORIZONTAL ADDfor(j=0;j<16;j++){TransferData(*adder,1);adder++;}}}unsigned char code pic2[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x1F,0xFF,0x81,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x18,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x08,0x00,0x00,0x00,0x03, 0xC0,0x1F,0xFF,0x80,0x00,0x00,0x04,0x07,0x81,0xE0,0x10,0x10,0x03,0xC0,0x30,0x03, 0xC0,0x1F,0xFF,0x80,0x00,0x00,0x0C,0x0C,0xC3,0x30,0x08,0x20,0x0C,0xE0,0x70,0x03, 0xC0,0x18,0x01,0x87,0xFF,0xFE,0x3C,0x18,0x66,0x18,0x04,0x40,0x0C,0x60,0x70,0x03, 0xC0,0x1F,0xFF,0x87,0xFF,0xFE,0x0C,0x18,0x66,0x18,0x02,0x80,0x18,0x00,0xB0,0x03, 0xC0,0x1F,0xFF,0x80,0x06,0x00,0x0C,0x18,0x66,0x18,0x01,0x00,0x1B,0x81,0x30,0x03, 0xC0,0x01,0x98,0x00,0x06,0x00,0x0C,0x00,0xE3,0x30,0x02,0x80,0x1C,0xC1,0x30,0x03, 0xC0,0x19,0x99,0x80,0x66,0x60,0x0C,0x00,0xC1,0xE0,0x04,0x40,0x18,0x62,0x30,0x03, 0xC0,0x19,0x99,0x80,0x66,0x30,0x0C,0x01,0x83,0x30,0x08,0x20,0x18,0x66,0x30,0x03, 0xC0,0x0D,0x9B,0x00,0xC6,0x38,0x0C,0x03,0x06,0x18,0x10,0x10,0x18,0x67,0xFC,0x03,0xC0,0x0D,0x9B,0x01,0xC6,0x1C,0x0C,0x06,0x06,0x18,0x20,0x08,0x18,0x60,0x30,0x03, 0xC0,0x01,0x98,0x03,0x86,0x0C,0x0C,0x0C,0x06,0x18,0x00,0x00,0x08,0x60,0x30,0x03, 0xC0,0x7F,0xFF,0xE3,0x06,0x00,0x0C,0x18,0x03,0x30,0x00,0x00,0x0C,0xC0,0x30,0x03, 0xC0,0x7F,0xFF,0xE0,0x1E,0x00,0x0C,0x1F,0xE1,0xE0,0x00,0x00,0x07,0x80,0x30,0x03, 0xC0,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00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,0x18,0xC1,0x81,0xB1,0x8C,0x30,0xFF,0xE1,0x8F,0x86,0x06,0x03,0x03, 0xC3,0x03,0x0C,0x30,0xC7,0x01,0xB1,0x8C,0x30,0x06,0x01,0x81,0x86,0x0C,0x03,0x03, 0xC3,0xFF,0xFC,0x70,0xDE,0x03,0x18,0xC6,0x30,0x06,0x01,0xFF,0xFE,0x0C,0x03,0x03, 0xC3,0xFF,0xFC,0x20,0x18,0x03,0x18,0xC6,0x30,0x06,0x01,0xFF,0xFE,0x18,0x03,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};unsigned char code pic3[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC3,0x02,0x0E,0x1C,0x08,0xF8,0x67,0xE3,0x87,0x0C,0x08,0x38,0x70,0x23,0xE1,0x83, 0xC4,0x8E,0x11,0x22,0x18,0x80,0x90,0x24,0x48,0x92,0x38,0x44,0x88,0x62,0x02,0x43, 0xC8,0x42,0x11,0x22,0x28,0x81,0x00,0x24,0x48,0xA1,0x08,0x44,0x88,0xA2,0x04,0x03, 0xC8,0x42,0x01,0x02,0x28,0xF1,0xE0,0x44,0x48,0xA1,0x08,0x04,0x08,0xA3,0xC7,0x83, 0xC8,0x42,0x02,0x0C,0x48,0x89,0x10,0x43,0x88,0xA1,0x08,0x08,0x31,0x22,0x24,0x43, 0xC8,0x42,0x04,0x02,0x88,0x09,0x10,0x44,0x47,0xA1,0x08,0x10,0x0A,0x20,0x24,0x43, 0xC8,0x42,0x08,0x22,0xFC,0x89,0x10,0x44,0x40,0xA1,0x08,0x20,0x8B,0xF2,0x24,0x43, 0xC4,0x82,0x10,0x22,0x08,0x89,0x10,0x84,0x49,0x12,0x08,0x40,0x88,0x22,0x24,0x43, 0xC3,0x02,0x1F,0x1C,0x08,0x70,0xE0,0x83,0x86,0x0C,0x08,0x7C,0x70,0x21,0xC3,0x83, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xCF,0xC7,0x0E,0x18,0x10,0x70,0xE0,0x47,0xC3,0x3F,0x1C,0x38,0x60,0x41,0xC3,0x83, 0xC0,0x48,0x91,0x24,0x70,0x89,0x10,0xC4,0x04,0x81,0x22,0x44,0x91,0xC2,0x24,0x43, 0xC0,0x48,0x91,0x42,0x10,0x89,0x11,0x44,0x08,0x01,0x22,0x45,0x08,0x42,0x24,0x43, 0xC0,0x88,0x91,0x42,0x10,0x08,0x11,0x47,0x8F,0x02,0x22,0x45,0x08,0x40,0x20,0x43, 0xC0,0x87,0x11,0x42,0x10,0x10,0x62,0x44,0x48,0x82,0x1C,0x45,0x08,0x40,0x41,0x83, 0xC0,0x88,0x8F,0x42,0x10,0x20,0x14,0x40,0x48,0x82,0x22,0x3D,0x08,0x40,0x80,0x43, 0xC0,0x88,0x81,0x42,0x10,0x41,0x17,0xE4,0x48,0x82,0x22,0x05,0x08,0x41,0x04,0x43, 0xC1,0x08,0x92,0x24,0x10,0x81,0x10,0x44,0x48,0x84,0x22,0x48,0x90,0x42,0x04,0x43, 0xC1,0x07,0x0C,0x18,0x10,0xF8,0xE0,0x43,0x87,0x04,0x1C,0x30,0x60,0x43,0xE3,0x83, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x8F,0x86,0x7E,0x38,0x70,0xC0,0x83,0x87,0x02,0x3E,0x19,0xF8,0xE1,0xC3,0x03, 0xC1,0x88,0x09,0x02,0x44,0x89,0x23,0x84,0x48,0x86,0x20,0x24,0x09,0x12,0x24,0x83, 0xC2,0x88,0x10,0x02,0x44,0x8A,0x10,0x84,0x48,0x8A,0x20,0x40,0x09,0x12,0x28,0x43, 0xC2,0x8F,0x1E,0x04,0x44,0x8A,0x10,0x80,0x40,0x8A,0x3C,0x78,0x11,0x12,0x28,0x43, 0xC4,0x88,0x91,0x04,0x38,0x8A,0x10,0x80,0x83,0x12,0x22,0x44,0x10,0xE2,0x28,0x43, 0xC8,0x80,0x91,0x04,0x44,0x7A,0x10,0x81,0x00,0xA2,0x02,0x44,0x11,0x11,0xE8,0x43, 0xCF,0xC8,0x91,0x04,0x44,0x0A,0x10,0x82,0x08,0xBF,0x22,0x44,0x11,0x10,0x28,0x43,0xC0,0x88,0x91,0x08,0x44,0x91,0x20,0x84,0x08,0x82,0x22,0x44,0x21,0x12,0x44,0x83, 0xC0,0x87,0x0E,0x08,0x38,0x60,0xC0,0x87,0xC7,0x02,0x1C,0x38,0x20,0xE1,0x83,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC1,0x07,0x0E,0x04,0x7C,0x33,0xF1,0xC3,0x86,0x04,0x1C,0x38,0x11,0xF0,0xCF,0xC3, 0xC7,0x08,0x91,0x0C,0x40,0x48,0x12,0x24,0x49,0x1C,0x22,0x44,0x31,0x01,0x20,0x43, 0xC1,0x08,0x91,0x14,0x40,0x80,0x12,0x24,0x50,0x84,0x22,0x44,0x51,0x02,0x00,0x43, 0xC1,0x00,0x81,0x14,0x78,0xF0,0x22,0x24,0x50,0x84,0x02,0x04,0x51,0xE3,0xC0,0x83, 0xC1,0x01,0x06,0x24,0x44,0x88,0x21,0xC4,0x50,0x84,0x04,0x18,0x91,0x12,0x20,0x83, 0xC1,0x02,0x01,0x44,0x04,0x88,0x22,0x23,0xD0,0x84,0x08,0x05,0x10,0x12,0x20,0x83, 0xC1,0x04,0x11,0x7E,0x44,0x88,0x22,0x20,0x50,0x84,0x10,0x45,0xF9,0x12,0x20,0x83, 0xC1,0x08,0x11,0x04,0x44,0x88,0x42,0x24,0x89,0x04,0x20,0x44,0x11,0x12,0x21,0x03, 0xC1,0x0F,0x8E,0x04,0x38,0x70,0x41,0xC3,0x06,0x04,0x3E,0x38,0x10,0xE1,0xC1,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,};#include <reg52.h>#include <intrins.h>#include <stdio.h>#define uchar unsigned char#define Fisrt_Addr 0 //定义字符/汉字显示起始位置typedef unsigned char uint8;sbit LCD_RS=P2^2;sbit LCD_RW=P2^3;sbit LCD_E=P2^4;sbit PCB=P2^5;uchar i,j;uint8 AC_TABLE[]={0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87, //第一行汉字位置0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97, //第二行汉字位置0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, //第三行汉字位置0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, //第四行汉字位置};void delay(int ms){while(ms--){for(j=0;j<120;j++);}}bit lcd_busy(){ bit result;LCD_RS=0;LCD_RW=1;LCD_E= 1;result=(bit)(P0&0x80);LCD_E=0;return result;}void lcd_wcmd(uchar cmd){while(lcd_busy());LCD_RS=0;LCD_RW=0;LCD_E=0;P0=cmd;LCD_E=1;LCD_E=0;}void lcd_wdata(uchar dat){while(lcd_busy());LCD_RS=1;LCD_RW=0;LCD_E=0;P0=dat ;LCD_E=1;LCD_E=0;}void lcd_initial(){lcd_wcmd(0x30);delay(1);lcd_wcmd(0x0C); //开显示,关光标,不闪烁delay(1);lcd_wcmd(0x06);//指定在资料写入或读取时,光标的移动方向delay(1);lcd_wcmd(0x01);delay(10); //这里要延时长一点,否侧会影响下面的操作}/*------------------清屏命令--------------------------*/void Clr_Screen(){lcd_wcmd(0x30);//考虑到前面出现0x34lcd_wcmd(0x01);delay(10);}/*------------------整屏写入数据:全亮,或者竖条-----------------------------*///先写0x34关绘图,写地址数据,0x360x绘图void Lcd_Fill(uchar disdata){ uchar x,y; //参考PDF写GDRAM的步骤,显示坐标for(y=0;y<32;y++)for(x=0;x<16;x++){ lcd_wcmd(0x34);lcd_wcmd(y+0x80); //行地址lcd_wcmd(x+0x80); //列地址lcd_wdata(disdata);lcd_wdata(disdata);lcd_wcmd(0x36);}lcd_wcmd(0x30);//考虑到前面出现0x34}/*------------------显示字符串--------------------------*/void Zi_FU(uchar code *s){while(*s!=0){ lcd_wdata(*s);s++;delay(10);}}//注意:中文显示时空格符或数字ASCII码必需两个一起用,标点符号注意中英文void intruction(){Clr_Screen() ;lcd_wcmd(0x80);//第一行(如果是地址是:80H,即LCD的第一行的第一个位置显示)Zi_FU("erwatgeawgaseg");lcd_wcmd(0x90);//第二行(如果是地址是:90H,即LCD的第二行的第一个位置显示)Zi_FU("wetwetw");lcd_wcmd(0x88);//第三行(如果是地址是:88H,即LCD的第二行的第一个位置显示)Zi_FU("yhwerqytqw");lcd_wcmd(0x98);//第四行(如果是地址是:98H,即LCD的第二行的第一个位置显示)Zi_FU("weagfawgaw?);delay(1000);}void feeling1(){lcd_wcmd(0x30);Zi_FU("fasgfwqf");delay(300);lcd_wcmd(0x90+Fisrt_Addr);Zi_FU("gwagawga");delay(300);lcd_wcmd(0x88+Fisrt_Addr);Zi_FU("nfaishdgfioa");delay(300);lcd_wcmd(0x98+Fisrt_Addr);delay(500);Zi_FU("6456464");}/*------------------显示图片---------------------------*/void Disp_Img(uchar code *bmp){uchar count=2,X=0x80;lcd_wcmd(0x34); //扩展指令lcd_wcmd(0x36); //打开绘图for(;count>0;count--){for(i=0;i<32;i++){ lcd_wcmd(0x80|i);lcd_wcmd(X); //X地址坐标,自动加1.for(j=0;j<16;j++) //16*8=128lcd_wdata(*bmp++);}X=0x88;//下半屏}}/********************************************* 函数名称:去字摸函数,取模方式是横向,顺序函数功能:**********************************************/ void ZK(uchar *zk){uchar i, j;for(j=0;j<16;j++){lcd_wcmd(0x34); //扩展指令lcd_wcmd(0x36); //打开绘图lcd_wcmd(0x80|j);lcd_wcmd(0x80) ;//X地址坐标,自动加1.for(i=0;i<2;i++){lcd_wdata(*zk++);}}}/********************************************* 函数名称: 向某一行写字符函数功能:**********************************************/ void Lcd_Write_Poss(uchar x,uchar y,uchar *ZiFu){uchar addr,i=0;if(x==1)addr=0x80;if(x==2)addr=0x90;if(x==3)addr=0x88;if(x==4)addr=0x98;addr=addr+y;lcd_wcmd(0x30);lcd_wcmd(addr);while(*ZiFu!='\0'){lcd_wdata(*ZiFu++);}}void main(){PCB=1;while(1){lcd_initial();delay(1000);Clr_Screen();feeling1();delay(3000);for(i=8;i>0;i--){lcd_wcmd(0x18); //一二行与三四行调换了,液晶分为上下两个半屏,delay(1000); //有时会乱,与上面程序有关,要加lcd_wcmd(0x30),clrscreen();}Clr_Screen(); //清屏feeling1();lcd_wcmd(0x34);lcd_wcmd(0x04); //0X04第一行和第三行反白显示,delay(3000); //0X05第二行和第四行反白显示,与PDF不符lcd_wcmd(0x04); //恢复正常delay(3000);lcd_wcmd(0x34);lcd_wcmd(0x03); //允许输入滚动地址for(i=0x40;i<0x7f;i++){lcd_wcmd(i); //垂直滚动屏幕的内容delay(500);}}}。
12864程序,字库与自定义字符的显示
uchar code user1[]={
/*--文字:你--*/
/*--楷体_GB231212;此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x08,0x80,0x08,0x80,0x08,0x80,0x11,0x38,0x11,0xC8,0x32,0x10,0x50,0x40,
delay(1);
RES=1;
delay(10);
w_cmd(0x30);//功能设置,选着8位元模式
delay(1);
w_cmd(0x30);//选择基本指令集,因为DL与RE不能同时改变需要两个指令
delay(1);
w_cmd(0x0c);//开显示(无游标、不反白)
delay(1);
w_cmd(0x01);//clear print
12864并口输入在输入输出数据是注意时序之前由于忙检测时序写错而无法显示字库文字自定义字符注意地址与编码方式对应不然会显示乱码includesbitrsp24
/*------------------------------------
12864并口输入,在输入输出数据是注意时序
之前由于忙检测时序写错,而无法显示字库文字
{
RW=1;
RS=0;
E=1;
data_port=0xff;
while((data_port&&0x80)==0x80);//data_port&&0x80必须加上括号
E=0;
}
void w_cmd(uint dat)
{check_busy();
RS=0;
RW=0;
E=1;
data_port=dat;
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);}。
lcd12864带字库经典程序
X++;
Delay5Ms();
}
}
}
/***********短延时********************************************************/
voidDelay5Ms(void)
{
unsignedintTempCyc= 5552;
while(TempCyc--);
WriteDataLCD(DData);
}
/***********按指定位置显示一串字符*****************************************/
voidDisplayListChar(unsignedcharX,unsignedcharY,unsignedcharcode*DData)
voidWriteDataLCD(unsignedcharWDLCD)
{
ReadStatusLCD();//检测忙
LCD_RS= 1;
LCD_RW= 0;
LCD_Data=WDLCD;
LCD_E= 1;
LCD_E= 1;
LCD_E= 0;
}
/***********写指令********************************************************/
sbitLCD_RS=P1^0;
sbitLCD_RW=P1^1;
sbitLCD_E=P1^2;
sbitPSB=P1^6;//PSB脚为-12系列的串、并通讯功能切换,使用位并行接口,PSB=1
/********宏定义***********************************************************/
LCD 12864液晶显示汉字程序
/*--文字: --*/
/*--宋体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,0x00,0x00,0x00,0x00,
/*--文字: --*/
/*--宋体12;此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x05,0x04,0x04,0x04,0x04,0x04,0x04,0x00,
/*--文字: --*/
/*--宋体12;此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x40,0x20,0x10,0x0E,0x10,0x20,0x3F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,
/*--文字:地--*/
/*--宋体12;此字体下对应的点阵为:宽x高=16x16 --*/
LCD12864显示屏 带中文字库
蓝屏LCD12864显示屏带中文字库带背光12864-5V ST7920需要用串口,请把R9上的0欧电阻改到R10带中文字库的,兰屏,白字以下是在液晶模块的第二行第一个字符的位置显示字母“A”的程序: ORG 0000HRS EQU P3.7;确定具体硬件的连接方式RW EQU P3.6 ;确定具体硬件的连接方式E EQU P3.5 ;确定具体硬件的连接方式MOV P1,#00000001B ;清屏并光标复位ACALL ENABLE;调用写入命令子程序MOV P1,#00111000B ;设置显示模式:8位2行5x7点阵ACALL ENABLE ;调用写入命令子程序MOV P1,#00001111B ;显示器开、光标开、光标允许闪烁ACALL ENABLE ;调用写入命令子程序MOV P1,#00000110B ;文字不动,光标自动右移ACALL ENABLE ;调用写入命令子程序MOV P1,#0C0H ;写入显示起始地址(第二行第一个位置)ACALL ENABLE ;调用写入命令子程序MOV P1,#01000001B ;字母A的代码SETB RS ;RS=1CLR RW ;RW=0 ;准备写入数据CLR E ;E=0 ;执行显示命令ACALL DELAY ;判断液晶模块是否忙?SETB E ;E=1 ;显示完成,程序停车AJMP $ENABLE:CLR RS ;写入控制命令的子程序CLR RWCLR EACALL DELAYSETB ERETDELAY:MOV P1,#0FFH ;判断液晶显示器是否忙的子程序CLR RSSETB RWCLR ENOPSETB EJB P1.7,DELAY ;如果P1.7为高电平表示忙就循环等待RETEND程序在开始时对液晶模块功能进行了初始化设置,约定了显示格式。
注意显示字符时光标是自动右移的,无需人工干预,每次输入指令都先调用判断液晶模块是否忙的子程序DELAY,然后输入显示位置的地址0C0H,最后输入要显示的字符A的代码41H。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
/*TS12864A-3 端口定义*/
#define LCD_data P0 //数据口
sbit LCD_RS = P1^0; //寄存器选择输入
sbit LCD_RW = P1^1; //液晶读/写控制
sbit LCD_EN = P2^5; //液晶使能控制
sbit LCD_PSB = P1^2; //串/并方式控制
sbit wela = P2^6;
sbit dula = P2^7;
uchar code dis1[] = {"欢迎指导工作"};
uchar code dis2[] = {"淮南师范学院"};
uchar code dis3[] = {"罗雷雷"};
uchar code dis4[] = {"胡伟伟"};
#define delayNOP(); {_nop_();_nop_();_nop_();_nop_();};
uchar IRDIS[2];
uchar IRCOM[4];
void delay0(uchar x); //x*0.14MS
void beep();
void dataconv();
void lcd_pos(uchar X,uchar Y); //确定显示位置
/*******************************************************************/ /* */ /* 延时函数*/ /* */ /*******************************************************************/ void delay(int ms)
{
while(ms--)
{
uchar i;
for(i=0;i<250;i++)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}
/*******************************************************************/
/* */
/*检查LCD忙状态*/ /*lcd_busy为1时,忙,等待。
lcd-busy为0时,闲,可写指令与数据。
*/
/* */
/*******************************************************************/
bit lcd_busy()
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delayNOP();
result = (bit)(P0&0x80);
LCD_EN = 0;
return(result);
}
/*******************************************************************/
/* */
/*写指令数据到LCD */ /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。
*/ /* */
/*******************************************************************/ void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
_nop_();
_nop_();
P0 = cmd;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*******************************************************************/
/* */
/*写显示数据到LCD */ /*RS=H,RW=L,E=高脉冲,D0-D7=数据。
*/ /* */
/*******************************************************************/
void lcd_wdat(uchar dat)
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P0 = dat;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*******************************************************************/ /* */ /* LCD初始化设定*/ /* */ /*******************************************************************/ void lcd_init()
{
LCD_PSB = 1; //并口方式
lcd_wcmd(0x34); //扩充指令操作
delay(5);
lcd_wcmd(0x30); //基本指令操作
delay(5);
lcd_wcmd(0x0C); //显示开,关光标
delay(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delay(5);
}
/*********************************************************/
/* */
/* 主程序*/
/* */
/*********************************************************/
main()
{
uchar i;
delay(10); //延时
wela=0;
dula=0;
lcd_init(); //初始化LCD
lcd_pos(0,0); //设置显示位置为第一行的第1个字符
i = 0;
while(dis1[i] != '\0')
{ //显示字符
lcd_wdat(dis1[i]);
i++;
}
lcd_pos(1,0); //设置显示位置为第二行的第1个字符
i = 0;
while(dis2[i] != '\0')
{
lcd_wdat(dis2[i]); //显示字符
i++;
}
lcd_pos(2,0); //设置显示位置为第三行的第1个字符
i = 0;
while(dis3[i] != '\0')
{
lcd_wdat(dis3[i]); //显示字符
i++;
}
lcd_pos(3,0); //设置显示位置为第四行的第1个字符
i = 0;
while(dis4[i] != '\0')
{
lcd_wdat(dis4[i]); //显示字符
i++;
}
while(1);
}
/*********************************************************/
/* */
/* 延时x*0.14ms子程序*/
/* */
/*********************************************************/
void delay0(uchar x) //x*0.14MS
{
uchar i;
while(x--)
{
for (i = 0; i<13; i++) {}
}
}
/*********************************************************/ /* */ /* 设定显示位置*/ /* */ /*********************************************************/ 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 ;
lcd_wcmd(pos); //显示地址
}。