12864显示汉字程序

合集下载

12864 汉字显示演示程序

12864 汉字显示演示程序

;12864(带字库汉字显示演示程序);*************************************************************************** ;* sxj1974@ (51c51 test web) *;* Create by :石学军 更多例程请登陆网站 *;***************************************************************************RS EQU P2.0RW EQU P2.1E EQU P2.2PSB EQU P2.3RST EQU P2.5;-----------------------------------------------LCD_X EQU 30HLCD_Y EQU 31HCOUNT EQU 32HCOUNT1 EQU 33HCOUNT2 EQU 34HCOUNT3 EQU 35H;-----------------------------------------------LCD_DATA EQU 36HLCD_DATA1 EQU 37HLCD_DATA2 EQU 38HSTORE EQU 39H;-----------------------------------------------ORG 0000HLJMP MAINORG 0100H;-----------------------------------------------MAIN:MOV SP,#5FHCLR RST ;复位LCALL DELAY4SETB RSTNOPSETB PSB ;通讯方式为8位数据并口;********************初始化**********************LGS0: MOV A,#34H ;34H--扩充指令操作LCALL SEND_IMOV A,#30H ;30H--基本指令操作LCALL SEND_IMOV A,#01H ;清除显示LCALL SEND_IMOV A,#06H ;指定在资料写入或读取时,光标的移动方向LCALL SEND_I ;DDRAM 的地址计数器(AC)加1MOV A,#0CH ;开显示,关光标,不闪烁LCALL SEND_I;=============================================== TU_PLAY1:MOV DPTR,#TU_TAB1 ;显示图形LCALL PHO_DISPLCALL DELAY3;================================================= ;;显示汉字和字符;加入80ms的延时,使你能够看清楚显示的过程;根据汉字显示坐标分段写入(顺序写入);================================================= HAN_WR2:LCALL CLEAR_PHAN_WR2A:MOV DPTR,#TAB1A ;显示汉字和字符MOV COUNT,#10H ;地址计数器设为16。

protues中无字库12864汉字显示程序

protues中无字库12864汉字显示程序
if(lie1>63)
lie1=0;
}
page=5;
lie1=0;
for(i=0;i<8;i++)
{
if(i<4)
screen(0);
else
screen(1);
show1616(page,lie1,address);
lie1+=16;
if(lie1>63)
lie1=0;
address+=32;
}
screen(2);
{
uchar i;
page(pa);
lie(li);
for(i=0;i<16;i++)
dat(*(add++));
page(pa+1);
lie(li);
for(i=0;i<16;i++)
dat(*(add++));
}
void main()
{
uchar i,page,lie1;
uchar *address;
}
void line(uchar line)
{
line=line&0x3f;
line=line|0xc0;
com(line);
}
void onoff(uchar onoff)
{
if(onoff==1)
com(0x3f);
else
com(0x3e);
}
void reset()
{
reset1=0;
delay(2);
0x80,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x80,0x00,

12864汉字液晶显示驱动程序

12864汉字液晶显示驱动程序

12864汉字液晶显示驱动程序模块主要硬件构成说明接口说明*注释1:如在实际应用中仅使用串口通讯模式,可将PSB接固定低电平,也可以将模块上的J8和“GND”用焊锡短接。

*注释2:模块内部接有上电复位电路,因此在不需要经常复位的场合可将该端悬空。

*注释3:如背光和模块共用一个电源,可以将模块上的JA、JK用焊锡短接。

2.2并行接口管脚号管脚名称电平管脚功能描述1 VSS 0V 电源地2 VCC 3.0+5V 电源正3 V0 - 对比度(亮度)调整RS=“H”,表示DB7——DB0为显示数据4RS(CS)H/LRS=“L”,表示DB7——DB0为显示指令数据R/W=“H”,E=“H”,数据被读到DB7——DB0 5R/W(SID) H/LR/W=“L”,E=“H→L”, DB7——DB0的数据被写到IR或DR6 E(SCLK) H/L 使能信号7 DB0 H/L 三态数据线8 DB1 H/L 三态数据线9 DB2 H/L 三态数据线10 DB3 H/L 三态数据线11 DB4 H/L 三态数据线12 DB5 H/L 三态数据线13 DB6 H/L 三态数据线14 DB7 H/L 三态数据线15 PSB H/L H:8位或4位并口方式,L:串口方式(见注释1)16 NC - 空脚17 /RESET H/L 复位端,低电平有效(见注释2)18 VOUT - LCD驱动电压输出端19 A VDD 背光源正端(+5V)(见注释3)20 K VSS 背光源负端(见注释3)*注释1:如在实际应用中仅使用并口通讯模式,可将PSB接固定高电平,也可以将模块上的J8和“VCC”用焊锡短接。

*注释2:模块内部接有上电复位电路,因此在不需要经常复位的场合可将该端悬空。

*注释3:如背光和模块共用一个电源,可以将模块上的JA、JK用焊锡短接。

控制器接口信号说明:1、RS,R/W的配合选择决定控制界面的4种模式:2、E信号● 忙标志:BF BF标志提供内部工作情况.BF=1表示模块在进行内部操作,此时模块不接受外部指令和数据.BF=0时,模块为准备状态,随时可接受外部指令和数据. 利用STATUS RD 指令,可以将BF读到DB7总线,从而检验模块之工作状态.● 字型产生ROM(CGROM)字型产生ROM(CGROM)提供8192个此触发器是用于模块屏幕显示开和关的控制。

LCD12864显示中文及图片C程序

LCD12864显示中文及图片C程序

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

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

12864字符和汉字显示程序

12864字符和汉字显示程序

#include<reg52.h>#define uchar unsigned char#define uint unsigned intsbit lcdrs=P2^4;sbit lcdrw=P2^5;sbit lcden=P2^6;/****************************** 函数名:delayus()功能:延时k微秒参数:k返回值:无*******************************/ void delayus(uint k){while(k--);}/****************************** 函数名:lcd_wrcom()功能:12864写命令参数:lcd_com返回值:无*******************************/ void lcd_wrcom(char lcd_com){uchar temp;lcdrs=0;lcdrw=1;do //12864判忙{lcden=1;temp=P0;delayus(6);lcden=0;}while(temp & 0x80);//不忙则退出循环lcdrw=0;P0=lcd_com; //写命令lcden=1;delayus(6);lcden=0;}/****************************** 函数名:lcd_wrdata()功能:12864写数据参数:lcd_dat返回值:无*******************************/ void lcd_wrdata(char lcd_dat){uchar temp;lcdrs=0;lcdrw=1;do //12864判忙{lcden=1;temp=P0;delayus(6);lcden=0;}while(temp & 0x80);lcdrs=1;lcdrw=0;P0=lcd_dat; //写数据lcden=1;delayus(6);lcden=0;}/****************************** 函数名:init_12864()功能:12864初始化参数:无返回值:无*******************************/ void init_12864(){delayus(100); //延时100微秒lcd_wrcom(0x30);//功能设定delayus(5000);lcd_wrcom(0x02);//地址归位delayus(100);lcd_wrcom(0x0e);//显示状态delayus(100);lcd_wrcom(0x1c);//游标和显示的移位delayus(100);lcd_wrcom(0x01);//清屏delayus(5000); //延时5毫秒}/******************************************* 函数名称:disp_HZ功能:控制液晶显示汉字参数:addr--显示位置的首地址pt--指向显示数据的指针num--显示汉字个数返回值:无********************************************/ void disp_HZ(uchar addr,const uchar * pt,uchar num) {uchar i;lcd_wrcom(addr);for(i = 0;i < (num*2);i++)lcd_wrdata(*(pt++));}/******************************函数名:main()功能:调用子程序/12864显示程序参数:无返回值:无*******************************/void main() //显示字符{uchar i;const uchar hang1[]={"一路江南"};//汉字显示init_12864();lcd_wrcom(0x80);//设定显示起始地址for(i=0;i<16;i++)lcd_wrdata(0x00+i);lcd_wrcom(0x90);//设定显示起始地址for(i=0;i<16;i++)lcd_wrdata(0x10+i);lcd_wrcom(0x88);//设定显示起始地址for(i=0;i<16;i++)lcd_wrdata(0x20+i);lcd_wrcom(0x98);//设定显示起始地址for(i=0;i<16;i++)lcd_wrdata(0x30+i);disp_HZ(0x80,hang1,4);//调用显示汉字while(1);}。

12864并行显示中文

12864并行显示中文

以下是我写的12864LCD并行口显示程序,矩阵键盘接的是P1口,P0口接LCD上DB0~ DB7。

/***************头文件******************************/#define _12864_h/*****包含头文件**************/#include<reg51.h>/********定义I/0口**********/#define LCD12864_DATA P0#define GPIO_KEY P1sbit LCD12864_E = P2^7;sbit LCD12864_RW = P2^5;sbit LCD12864_RS = P2^6;sbit LCD12864_RET= P2^0;sbit LCD12864_PSB =P2^2;/*声明全局变量*/extern unsigned char keyvalue;/******声明全局函数*********/void Delay1ms(unsigned int); //声明延时函数unsigned char KeyDown(void);void BusyChk_12864(void); //声明忙检测函数void WrCom(unsigned char); //声明写入命令函数//unsigned char ReDat(void); //声明读数据函数void WrDat(unsigned char); //声明写数据函数void LcdInit(void); //12864初始化函数void SetAddress(unsigned char ,unsigned char); //设置地址转换void DisplayString(unsigned char ,unsigned char,unsigned char *p);//行显示字符#endif//***************************12864.c文件*****************************//#include"12864.h"#include<reg51.h>#include"string.h"#define LCM_ST7920_FIRST_LINE_ADDRESS 0x80#define LCM_ST7920_SECOND_LINE_ADDRESS 0x90#define LCM_ST7920_THIRD_LINE_ADDRESS 0x88#define LCM_ST7920_FOURTH_LINE_ADDRESS 0x98/*定义全局变量*/unsigned char keyvalue=0;/****************************************************************************** ** 函数名: Delay1ms* 函数功能: 延时函数,延时1ms* 输入: c* 输出 e : 无* 说名: 该函数是在12MHZ晶振下,12分频单片机的延时。

12864汉字液晶显示--按键电子时钟程序(具有闪烁,移位,加一,减一功能)

12864汉字液晶显示--按键电子时钟程序(具有闪烁,移位,加一,减一功能)

//12864汉字液晶显示--按键电子时钟程序(具有闪烁,移位,加一,减一功能)#include &lt;reg52.h&gt;#include &lt;intrins.h&gt;#define uchar unsigned charvoid lcd_ini();void ascii_change(void);void delay();void wri_add(uchar com);void wri_dat(uchar com1);void shan(void);void disp();void tkey(void);sbit cs=P1^7;sbit sid=P1^6;sbit sclk=P1^5;bit flag=1;uchar dat,count,f=1;//f测试哪个单元为当前闪烁状态uchar data clock[3]={23,45,12};uchar code clockname[10]={&quot;北京时间:&quot;};uchar data num[6];/*******主程序*************/void main(){lcd_ini();count=10;//机器周期为1us,每次定时50ms,此变量用来控制循环次数,在下面赋值为20,共定时1秒TMOD=0x01;TL0=0XB0;TH0=0X3C;EA=1;ET0=1;IT0=1;EX0=1;TR0=1;while(1){back:ascii_change();disp();delay();if(flag==1)goto back;tkey();shan();delay();}}/****lcd初始化*******/void lcd_ini(){wri_add(0x30);delay();wri_add(0x0c);delay();wri_add(0x01);delay();wri_add(0x06);delay();}/********定时程序*************/ void timer1() interrupt 1 using 2 {TL0=0XB0;TH0=0X3C;count--;if(count==0){count=10;clock[2]++;//秒//}elsegoto out;if(clock[2]==60){clock[2]=0;clock[1]++;//分//}if(clock[1]==60){clock[1]=0;clock[0]++;}if(clock[0]==24)//时//clock[0]=0;out:_nop_();}/*******十位个位转换成ASCII码************/ void ascii_change(void){num[5]=clock[2]-(clock[2]/10)*10+0x30;num[4]=clock[2]/10+0x30;num[3]=clock[1]-(clock[1]/10)*10+0x30;num[2]=clock[1]/10+0x30;num[1]=clock[0]-(clock[0]/10)*10+0x30;num[0]=clock[0]/10+0x30;}/********廷时程序*************/void delay(){uchar i,j;for (i=250;i&gt;0;i--)for (j=250;j&gt;0;j--);}/*****Write address*********/void wri_add(uchar com){uchar i,j,k;cs=0;cs=1;dat=0xf8;for(i=1;i&lt;=8;i++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}dat=com;dat=dat&amp;0xf0;for(j=1;j&lt;=8;j++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}dat=com;dat=_cror_(dat,4);// 此为高低四位交换dat=dat&amp;0xf0;for(k=1;k&lt;=8;k++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}}/*********Write data*************/ void wri_dat(uchar com1){uchar i,j,k;cs=0;cs=1;dat=0xfa;for(i=1;i&lt;=8;i++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}dat=com1;dat=dat&amp;0xf0;for(j=1;j&lt;=8;j++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}dat=com1;dat=_cror_(dat,4);// 此为高低四位交换dat=dat&amp;0xf0;for(k=1;k&lt;=8;k++){sid=(bit)(dat&amp;0x80);sclk=0;sclk=1;sclk=0;dat=dat&lt;&lt;1;}}/******display program***********/ void disp(){uchar i,k=0;wri_add(0x80);for (i=1;i&lt;=9;i++)wri_dat(clockname[i-1]);wri_add(0x90);for (i=1;i&lt;=6;i++) {k++;if(k==3||k==5)wri_dat(clockname[8]);//时间之间的冒号。

12864显示汉字

12864显示汉字

#include<reg52.h>#include<intrins.h>//声明_nop_();#define uchar unsigned char#define uint unsigned int//sbit ce=P2^3;//#define LCD_databus P0sbit rs=P2^2;sbit en=P2^0;sbit rw=P2^1;sbit cs1=P2^4;sbit cs2=P2^3;uchar num;/*void delay(uint z){uint x,y;for(x=z;x>0;x--)for(y=110;y>0;y--);}*/void write_LCD_command(uchar value)//指令函数{rs=0;//RS=1为数据操作,RS=0为写指令或读状态rw=0;// LCD_databus=value;P0=value;en=1;_nop_();//延时一个机器周期12M晶振的话就是1us 只是为了更精确的延时_nop_();en=0;}void write_LCD_data(uchar value)//数据函数{rs=1;//RS=1为数据操作,RS=0为写指令或读状态rw=0;// LCD_databus=value;P0=value;en=1;_nop_();_nop_();//延时一个机器周期12M晶振的话就是1us 只是为了更精确的延时en=0;}void Set_page(uchar page)//设置页,12864LCD共有8页,每页有8行点阵点。

{page=0xb8|page;//首页地址为0XB8write_LCD_command(page);}void Set_line(uchar startline)//设置显示的起始行,共有0--63行,一般从0行开始显示{startline=0xc0|startline;//起始行地址0XC0write_LCD_command(startline);}void Set_column(uchar column)//设置显示的列{column=column&0x3f; //列的最大值为0X3F,即64column=0x40|column; //列的首地址为0X40,write_LCD_command(column);}void Set0n0ff(uchar onoff)//设置显示开关,onoff取值为0或{onoff=0x3e|onoff;//0X3E是关显示,0X3F是开显示write_LCD_command(onoff);//所以若onoff为0,则表示关显示,onoff为1,则表示开显示}void SelectScreen(uchar screen)//选屏幕{switch(screen){case 0:cs1=0;cs2=0;break;case 1:cs1=0;cs2=1;break;case 2:cs1=1;cs2=0;break;default:break;}}void ClearScreen(uchar screen)//青萍{uchar i,j;SelectScreen(screen);for(i=0;i<8;i++){Set_page(i);Set_column(0);for(j=0;j<64;j++){write_LCD_data(0x00);}}}void InitLCD()//初始化{SelectScreen(0);Set0n0ff(0);SelectScreen(0);Set0n0ff(1);SelectScreen(0);ClearScreen(0);Set_line(0);}void show(uchar screen,uchar page,uchar column,uchar *p)//screen表示选择屏幕,page表示页,column表示列,*p表示汉字的数组{uchar i;SelectScreen(screen); //选屏Set_page(page); //设置页,写上半页Set_column(column);//设置列for(i=0;i<16;i++) //控制16列的数据输出{write_LCD_data(p[i]);} //汉字的上半部分Set_page(page+1); //写下半页Set_column(column); //控制列for(i=0;i<16;i++) //控制16列的数据输出{write_LCD_data(p[i+16]);} //汉字的下半部分}/*void Display(uchar ss,uchar page,uchar column,uchar *p){uchar i;SelectScreen(ss);Set_page(page);Set_column(column);for(i=0;i<16;i++){write_LCD_data(p[i]);}}*unsigned char code huan[]= // 欢{0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00};*/unsigned char code pu[]={0x04,0x04,0x24,0x24,0x64,0xAF,0x24,0x34,0x24,0xAF,0x64,0x34,0x24,0x86,0x04,0x00, 0x01,0x01,0x01,0xFD,0x45,0x45,0x45,0x45,0x45,0x45,0x45,0xFF,0x05,0x01,0x01,0x00,};unsigned char code ti[]={ 0x10,0x10,0x10,0xFF,0x90,0x50,0x00,0xFE,0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x02,0x42,0x81,0x7F,0x00,0x82,0x42,0x3A,0x42,0x82,0xFE,0x92,0x9A,0xD2,0x42,0x00,};unsigned char code ben[]={ 0x00,0x10,0x10,0x10,0x10,0xF0,0x10,0xFF,0x10,0xF0,0x10,0x10,0x18,0x10,0x00,0x00, 0x10,0x10,0x08,0x04,0x0B,0x08,0x08,0xFF,0x08,0x08,0x0B,0x04,0x08,0x18,0x08,0x00,};unsigned char code wushu[]={0x00,0x40,0x42,0x42,0x42,0x42,0xFE,0x42,0xC2,0x42,0x43,0x42,0x60,0x40,0x00,0x00, 0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x70,0x00,unsigned char code shu[]={0x10,0x10,0xD0,0xFF,0x90,0x38,0xC8,0x08,0xC8,0x38,0x90,0x10,0xFF,0x10,0x10,0x00,0x04,0x03,0x00,0xFF,0x20,0x10,0x0C,0x03,0x04,0x18,0x40,0x81,0x7F,0x00,0x00,0x00,};unsigned char code ming[]={0x00,0xFC,0x44,0x44,0x44,0xFE,0x04,0x00,0xFE,0x22,0x22,0x22,0x22,0xFF,0x02,0x00, 0x00,0x0F,0x04,0x04,0x04,0x8F,0x40,0x30,0x0F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00, };unsigned char code jing[]={ 0x20,0x58,0xCF,0x48,0x48,0x24,0xA4,0xAC,0xB5,0xA6,0xB4,0xAC,0xE6,0xB4,0x20,0 x00,0x02,0x02,0x7F,0x22,0x92,0x80,0x4F,0x3A,0x0A,0x0A,0x7A,0x8A,0x8F,0x80,0xE0,0x00, };unsigned char code yy[]={0x08,0x08,0x08,0x88,0x08,0xF8,0x09,0x0E,0x08,0xF8,0x08,0x88,0x08,0x0C,0x08,0x00, 0x00,0x04,0x02,0x41,0x30,0x0F,0x00,0x40,0x80,0x7F,0x00,0x00,0x01,0x06,0x00,0x00, };unsigned char code fei[]={ 0x08,0x88,0x88,0x88,0x88,0xFF,0x00,0x00,0x00,0xFF,0x88,0x88,0xC8,0x8C,0x08,0x00, 0x10,0x10,0x10,0x10,0x10,0xFF,0x00,0x00,0x00,0xFF,0x10,0x10,0x10,0x18,0x10,0x00,};unsigned char code tai[]={0x00,0x40,0x60,0x50,0x48,0x44,0x43,0x40,0x40,0x40,0x48,0x50,0x60,0xC0,0x00,0x00, 0x00,0x00,0x00,0xFE,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFF,0x02,0x00,0x00,0x00, };unsigned char code douhao[]={ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x46,0x2F,0x1F,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };unsigned char code lai[]={0x00,0x08,0x28,0x48,0xC8,0x08,0x08,0xFF,0x08,0x88,0x48,0x68,0x0C,0x88,0x00,0x00, 0x21,0x21,0x11,0x11,0x09,0x05,0x03,0xFF,0x03,0x05,0x09,0x19,0x11,0x31,0x11,0x00,unsigned char code yi[]={ 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};unsigned char code wuti[]={0x40,0x3C,0x10,0xFF,0x90,0xA0,0x10,0x1F,0xF0,0x10,0xF0,0x10,0x10,0xF8,0x10,0x00, 0x02,0x02,0x01,0xFF,0x00,0x10,0x0C,0x43,0x30,0x0E,0x41,0x80,0x40,0x3F,0x00,0x00, };unsigned char code he[]={0x80,0x40,0x20,0xF8,0x07,0x04,0xE4,0x24,0x24,0xF4,0x24,0x04,0xFC,0x06,0x04,0x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x0F,0x04,0x04,0x0F,0x40,0x80,0x7F,0x00,0x00,0x00, };unsigned char code chu[]={0x00,0x00,0xE0,0x1E,0x10,0x10,0xF0,0x00,0x00,0xFF,0x20,0x40,0x80,0x80,0x00,0x00, 0x82,0x41,0x20,0x1B,0x04,0x1B,0x20,0x40,0x40,0x5F,0x40,0x40,0x40,0x61,0x20,0x00, };unsigned char code re[]={ 0x20,0x24,0x24,0x24,0xAF,0xE4,0xBC,0xA4,0xA4,0xA4,0xAF,0xE4,0xA6,0x34,0x20,0 x00,0x04,0x44,0x32,0x01,0x77,0x84,0x8C,0x94,0xB4,0x84,0x84,0xC7,0x10,0x60,0x00,0x00, };unsigned char code chen[]={0x00,0x40,0x20,0x10,0x08,0x0C,0x00,0x7F,0x00,0x04,0x08,0x10,0x30,0x60,0x00,0x00, 0x40,0x44,0x44,0x44,0x44,0x44,0x44,0x7F,0x44,0x44,0x44,0x44,0x46,0x64,0x40,0x00, };unsigned char code ai[]={0x20,0x20,0x20,0xFF,0x20,0x20,0x10,0xD8,0x94,0x93,0x90,0xD4,0x98,0x30,0x00,0x00, 0x10,0x30,0x10,0x1F,0x08,0x8C,0x85,0x44,0x34,0x0F,0x14,0x24,0x44,0xC6,0x44,0x00, };unsigned char code juhao[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x38,0x7C,0x44,0x44,0x7C,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };void main()InitLCD();ClearScreen(0);Set_line(0);show(1,0,1*16,pu);////1表示左屏显示,0表示从0页开始显示。

12864显示汉字程序.c

12864显示汉字程序.c

#include <string.h>#include <stdio.h>#define F_CPU 7372800 /* 单片机主频为7.3728MHz,用于延时子程序*/ #include <util/delay.h>#include <avr/io.h>#include <avr/iom128.h>#define BIT(x) (1<<x)#define uchar unsigned char#define uint unsigned int#define delay_us(x) _delay_us(x)#define delay_ms(x) _delay_ms(x)void system_init(){PORTA = 0xFF; //电平设置DDRA = 0xFF; //方向输出PORTF = 0xFF; //电平设置DDRF = 0xFF; //方向输出PORTD=0xFF;DDRD=0xFF;PORTE=0xFF; //PSB对应于PE2DDRE=0xFF;PORTD |= BIT(4); //关掉数码管,以免显示乱码PORTD |= BIT(5);PORTA=0xFF; //关数码管PORTD&=~BIT(5);PORTF |=BIT(2);}//*********************************************************************** // 显示屏命令写入函数//***********************************************************************void LCD_write_com(unsigned char com){PORTF &= ~BIT(1);PORTF &= ~BIT(2);PORTF |= BIT(3);PORTA = com;delay_ms(5);PORTF &= ~BIT(3);}//*********************************************************************** // 显示屏数据写入函数//***********************************************************************void LCD_write_data(unsigned char data){PORTF|= BIT(1);PORTF &= ~BIT(2);PORTF |= BIT(3);PORTA= data;delay_ms(5);PORTF &= ~BIT(3);}//*********************************************************************** // 显示屏清空显示//***********************************************************************void LCD_clear(void){LCD_write_com(0x01);delay_ms(5);}//*********************************************************************** //函数名称:DisplayCgrom(uchar hz)显示CGROM里的汉字//入口参数:无//返回参数:无//*********************************************************************** void DisplayCgrom(uchar addr,uchar *hz){LCD_write_com(addr);delay_ms(5);while(*hz != '\0'){LCD_write_data(*hz);hz++;delay_ms(5);}}//****************************************************************//函数名称:Display()显示测试结果//入口参数:无//返回参数:无//****************************************************************void Display(void){DisplayCgrom(0x80,"李白乘舟将欲行,");DisplayCgrom(0x88,"桃花潭水深千尺,");DisplayCgrom(0x90,"忽闻岸上踏歌声。

12864翻页显示汉字源程序

12864翻页显示汉字源程序

12864翻页显示汉字源程序#include#include#define GDM12864ADataPort P1 //LCD数据线sbit DI=P2^2; // 数据\指令选择sbit RW=P2^1; // 读\写选择sbit EN=P2^0; // 读\写使能sbit cs1=P2^4; // 片选1sbit cs2=P2^3; // 片选2sbit UP=P0^0;//定义UPsbit DOWN=P0^1;//定义DOWNsbit TEST=P3^0;//定义DOWNunsigned char i,j,t;static int nxx;int t0,t1,t2,t3,tx,k,k0,k1,k2,k3;//*--------函数列表-------//状态检查void CheckState(){unsigned char dat;DI=0;RW=1;do{GDM12864ADataPort=0x00;EN=1;dat=GDM12864ADataPort;EN=0;dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号) }while(!(dat==0x00));}/*-----------------------------------------------------------------------------------------------------*///向LCD发送命令//command :命令SendCommandToLCD(unsigned char command){CheckState();RW=0;GDM12864ADataPort=command;EN=1; EN=0;}/*----------------------------------------------------------------------------------------------------*///写显示数据//dat:显示数据void WriteByte(unsigned char dat){CheckState();DI=1; RW=0;GDM12864ADataPort=dat;EN=1; EN=0;}/*----------------------------------------------------------------------------------------------------*///读显示数据unsigned char ReadByte(){unsigned char dat;CheckState();DI=1; RW=1;GDM12864ADataPort=0xff;EN=1; dat=GDM12864ADataPort; EN=0;return(dat);}/*----------------------------------------------------------------------------------------------------*///设定行地址(页)--X 0-7void SetLine(unsigned char line){line=line & 0x07; // 0<=line<=7line=line|0xb8; //1011 1xxxSendCommandToLCD(line);}/*----------------------------------------------------------------------------------------------------*///设定列地址--Y 0-63void SetColumn(unsigned char column){column=column &0x3f; // 0=<column<=63column=column | 0x40; //01xx xxxxSendCommandToLCD(column);}/*----------------------------------------------------------------------------------------------------*///设定显示开始行--XXvoid SetStartLine(unsigned char startline) //0--63{startline=startline & 0x07;startline=startline|0xc0; //1100 0000SendCommandToLCD(startline);}/*----------------------------------------------------------------------------------------------------*///开关显示void SetOnOff(unsigned char onoff){onoff=0x3e | onoff; //0011 111xSendCommandToLCD(onoff);}/*---------------------------------------------------------------------------------------------------*///选择屏幕//screen: 0-全屏,1-左屏,2-右屏void SelectScreen(unsigned char screen){ //cs1: 1--左; cs2: 1--右switch(screen){ case 0: cs1=0;//全屏_nop_(); _nop_(); _nop_();cs2=0;_nop</column<=63_(); _nop_(); _nop_();break;case 1: cs1=0;//左屏_nop_(); _nop_(); _nop_();cs2=1;_nop_(); _nop_(); _nop_();break;case 2: cs1=1;//右屏_nop_(); _nop_(); _nop_();cs2=0;_nop_(); _nop_(); _nop_();break;}}/*---------------------------------------------------------------------------------------------------*///延时GDM12864delay(){unsigned int i=500;while(i--) {;}}/*---------------------------------------------------------------------------------------------------*///清屏//screen: 0-全屏,1-左屏,2-右void ClearScreen(unsigned char screen){ unsigned char i,j;SelectScreen(screen);for(i=0;i<8;i++){SetLine(i);for(j=0;j<128;j++){WriteByte(0x00);}}}/*---------------------------------------------------------------------------------------------------*///初始化LCDvoid InitLCD(){ unsigned char i=250; //延时while(i--);SelectScreen(0);SetOnOff(0); //关显示//ClearScreen(0);//清屏SelectScreen(0);SetOnOff(1); //开显示SelectScreen(0);SetStartLine(0); //开始行:0}/*----------------------------------------------------------------------------------------------------*//*----------------------------------------------------------------------------------------------*/unsigned char code ASC[]={/*.--0x2E */0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x0C,0x0C,0x00,0x00,0x00,/*'/'--0x2F */0x00,0x00,0x00,0x80,0xC0,0x60,0x30,0x00, 0x0C,0x06,0x03,0x01,0x00,0x00,0x00,0x00,/*0--0x30 */0xF8,0xFC,0x04,0xC4,0x24,0xFC,0xF8,0x00, 0x07,0x0F,0x09,0x08,0x08,0x0F,0x07,0x00,/*1--0x31 */0x00,0x10,0x18,0xFC,0xFC,0x00,0x00,0x00, 0x00,0x08,0x08,0x0F,0x0F,0x08,0x08,0x00,/*2--0x32 */0x08,0x0C,0x84,0xC4,0x64,0x3C,0x18,0x00, 0x0E,0x0F,0x09,0x08,0x08,0x0C,0x0C,0x00,/*3--0x33 */0x08,0x0C,0x44,0x44,0x44,0xFC,0xB8,0x00, 0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,/*4--0x34 */0xC0,0xE0,0xB0,0x98,0xFC,0xFC,0x80,0x00, 0x00,0x00,0x00,0x08,0x0F,0x0F,0x08,0x00,/*5--0x35 */0x7C,0x7C,0x44,0x44,0xC4,0xC4,0x84,0x00, 0x04,0x0C,0x08,0x08,0x08,0x0F,0x07,0x00,/*6--0x36 */0xF0,0xF8,0x4C,0x44,0x44,0xC0,0x80,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,/*7--0x37 */0x0C,0x0C,0x04,0x84,0xC4,0x7C,0x3C,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,0x00,0x00,/*8--0x38 */0xB8,0xFC,0x44,0x44,0x44,0xFC,0xB8,0x00,0x07,0x0F,0x08,0x08,0x08,0x0F,0x07,0x00,/*9--0x39 */0x38,0x7C,0x44,0x44,0x44,0xFC,0xF8,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00};/*----------------------------------------------------------------------------------------------*/#define CB6AB0x0000 /*东 */#define CC4CF CB6AB+32 /*南 *///从左到右从上到下,纵向8点下高位分粗细体unsigned char code Hztable[]={//" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //"唐"0x00,0x00,0x00,0xFE,0xFC,0x84,0xA4,0xA4, 0xA5,0xFF,0xFE,0xA4,0xE4,0xF6,0xA4,0x80, 0x00,0x80,0x40,0x3F,0x1F,0xFC,0xFA,0x4A, 0x4A,0x4F,0x4F,0x4A,0xFB,0xFF,0x10,0x00, //0x00,0x00,0xFC,0x44,0x54,0x54,0x54,0x55, //0xFE,0x54,0x54,0x54,0xF6,0x44,0x40,0x00, //0x40,0x30,0x0F,0x00,0xFD,0x45,0x45,0x45, //0x47,0x45,0x45,0x45,0xFD,0x00,0x00,0x00,//"山",0x00,0x00,0xC0,0x80,0x00,0x00,0x00,0x00, 0xFE,0xFC,0x00,0x00,0x00,0x00,0xC0,0x80, 0x00,0x00,0xFF,0x7F,0x20,0x20,0x20,0x20, 0x3F,0x3F,0x20,0x20,0x20,0x20,0xFF,0x7F,//"华",0x00,0x40,0x20,0x30,0xFC,0xF7,0x02,0x80, 0x60,0xFF,0xFE,0x18,0x0E,0xC4,0x00,0x00, 0x00,0x08,0x08,0x08,0x0B,0x09,0x08,0xFE, 0xFE,0x09,0x0B,0x0B,0x0B,0x0B,0x0D,0x08,//"光",0x00,0x00,0x80,0x82,0xBC,0x98,0x80,0xFF, 0xFE,0x80,0xE0,0xB8,0x9E,0xC4,0x80,0x00,0x00,0x80,0x80,0x40,0x60,0x38,0x1F,0x07, 0x00,0x7F,0xFF,0xC0,0xC0,0xC0,0xF0,0x40, //" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"自",0x00,0x00,0x00,0xFC,0xF8,0x88,0x8C,0x8F, 0x8A,0x88,0x88,0x88,0xF8,0xFC,0x08,0x00, 0x00,0x00,0x00,0xFF,0x7F,0x44,0x44,0x44, 0x44,0x44,0x44,0x44,0xFF,0x7F,0x00,0x00,//"力",0x00,0x00,0x10,0x10,0x10,0x10,0xFF,0xFE, 0x10,0x10,0x10,0x10,0xF0,0xF8,0x10,0x00, 0x00,0x80,0x40,0x60,0x38,0x1F,0x07,0x00, 0x00,0x40,0x40,0xE0,0x7F,0x1F,0x00,0x00,//"更",0x00,0x02,0x02,0xFE,0xFA,0xAA,0xAA,0xAA, 0xFE,0xFE,0xAA,0xAA,0xFA,0xFE,0x0B,0x02, 0x00,0x80,0x80,0x41,0x41,0x22,0x34,0x1C, 0x0F,0x1B,0x30,0x60,0x61,0xC1,0xC0,0x40,//"生",0x00,0x80,0x60,0x38,0x1E,0x14,0x10,0x10, 0xFF,0xFE,0x10,0x10,0x90,0x18,0x10,0x00, 0x00,0x40,0x40,0x40,0x41,0x41,0x41,0x41, 0x7F,0x7F,0x41,0x41,0x41,0x41,0x60,0x40,//"艰",0x00,0x04,0x34,0xC4,0xE4,0x7E,0x1C,0xFF, 0xFE,0x92,0x92,0x92,0xFE,0xFF,0x02,0x00, 0x00,0x20,0x18,0x0E,0x03,0x1E,0x4C,0xFF, 0x7F,0x61,0x36,0x1C,0x39,0x6E,0xE4,0x40,//"苦",0x00,0x84,0x84,0x84,0x84,0x9F,0x9F,0xE4, 0xE4,0x9F,0x9F,0x84,0x84,0xC6,0x84,0x00, 0x00,0x00,0x00,0xFE,0x7C,0x44,0x44,0x47, 0x47,0x44,0x44,0xFC,0x7E,0x04,0x00,0x00,//"奋",0x00,0x00,0x88,0x88,0xC8,0x68,0x38,0x1F, 0x0E,0x18,0x38,0x68,0x4C,0xC8,0x80,0x80, 0x00,0x01,0x00,0xFF,0xFF,0x49,0x49,0x7F, 0x7F,0x49,0x49,0xFF,0xFF,0x00,0x01,0x00,//"斗",0x00,0x00,0x00,0x20,0xE0,0xC6,0x9C,0x08, 0x00,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x04,0x04,0x04,0x05,0x04,0x04,0x04,0xFF,0x7F,0x02,0x02,0x02,0x03,0x02, //"科",0x00,0x24,0xA4,0xFE,0xFE,0xA3,0x22,0xC0, 0x8C,0x38,0x10,0xFF,0xFE,0x00,0x00,0x00, 0x00,0x0C,0x03,0xFF,0x7F,0x01,0x0B,0x08, 0x0B,0x05,0x04,0xFF,0x7F,0x02,0x03,0x02,//"技",0x00,0x10,0x10,0xFF,0xFE,0x10,0x98,0x48, 0xC8,0x48,0x7F,0x7E,0xC8,0xE8,0x4C,0x08, 0x00,0x0C,0x46,0xFF,0x7F,0x01,0x80,0x40, 0x61,0x37,0x1C,0x1E,0x37,0x61,0xE0,0x40,//"创",0x00,0x80,0x40,0xE0,0xB8,0x9E,0x8F,0x9A, 0xF0,0xA0,0x00,0xF0,0xF0,0x00,0xFF,0xFE, 0x00,0x00,0x00,0x7F,0xFF,0xC0,0xC4,0xCF, 0xE7,0x40,0x00,0x03,0x23,0x40,0xFF,0x7F,//"新",0x00,0x44,0x4C,0x7C,0xD7,0xE6,0x7C,0x5C, 0x44,0xFE,0xFC,0x46,0xC2,0xC3,0x62,0x40, 0x00,0x22,0x1A,0x4E,0xFF,0x7F,0x0E,0x9A, 0x60,0x3F,0x1F,0x00,0xFF,0xFF,0x00,0x00,//"精",0x00,0x26,0xA8,0xFF,0xFE,0xA8,0x66,0x44, 0xD4,0x54,0x7F,0x7E,0x54,0xD6,0x64,0x40, 0x00,0x0C,0x03,0xFF,0x7F,0x01,0x06,0x00, 0xFF,0x7F,0x15,0x55,0xFF,0x7F,0x01,0x00,//"益",0x00,0x08,0x08,0x88,0xC9,0x6E,0x3C,0x18, 0x08,0x1C,0x3E,0x6B,0xCA,0x88,0x8C,0x08, 0x00,0x82,0x81,0xFF,0xFE,0x82,0xFE,0xFE, 0x82,0xFE,0xFE,0x82,0xFE,0xFF,0x83,0x81,//"求",0x00,0x00,0x08,0x68,0xC8,0x88,0x08,0xFF, 0xFE,0x88,0xCB,0x7E,0x2C,0x08,0x00,0x00, 0x00,0x10,0x70,0x38,0x0D,0x26,0x41,0xFF, 0x7F,0x03,0x06,0x1C,0x38,0x70,0x20,0x00,//"精",0x00,0x26,0xA8,0xFF,0xFE,0xA8,0x66,0x44, 0xD4,0x54,0x7F,0x7E,0x54,0xD6,0x64,0x40, 0x00,0x0C,0x03,0xFF,0x7F,0x01,0x06,0x00, 0xFF,0x7F,0x15,0x55,0xFF,0x7F,0x01,0x00, //" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"华",0x10,0xFF,0x08,0x04,0x06,0xC0,0x00,0x00, 0x04,0x04,0x04,0x04,0x05,0x04,0x04,0xFF, 0x04,0x04,0x05,0x05,0x05,0x05,0x04,0x00,//"光",0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F, 0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00, 0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,//"研",0x82,0x42,0xF2,0x4E,0x43,0xC2,0x80,0x82, 0xFE,0x82,0x82,0x82,0xFF,0x82,0x80,0x00, 0x00,0x00,0x3F,0x10,0x10,0x5F,0x20,0x18, 0x07,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//"发",0x00,0x10,0x18,0x16,0x10,0x90,0xF0,0x9F, 0x90,0x90,0x92,0x94,0x10,0x18,0x10,0x00, 0x40,0x20,0x90,0x88,0x46,0x41,0x23,0x14, 0x08,0x14,0x22,0x21,0x40,0xC0,0x40,0x00,//"所",0x00,0x00,0xFC,0x24,0x24,0x22,0xE3,0x02, 0xFC,0x44,0x44,0x42,0xC3,0x62,0x40,0x00, 0x40,0x20,0x1F,0x02,0x02,0x42,0x27,0x10, 0x0F,0x00,0x00,0x00,0xFF,0x00,0x00,0x00, //" "0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*--------------------------------------------------------------------------------------------------*///显示8*8点阵//旋转90度:字模被竖着切分//lin:行(0-7), column: 列(0-15)//address : 字模区首地址void Show88(unsigned char lin,unsigned char column,unsigned int address){ unsigned char i;if(column>16) {return;}if(column<8) SelectScreen(1); //如果列数<8(0,1,2,3,4,5,6,7)则写在第一屏上else {SelectScreen(2); //否则 (8,9,10,11,12,13,14,15)写在第二屏上column=column & 0x07; //防止越界}SetLine(lin);SetColumn(column<<3);for(i=0;i<8;i++) WriteByte(ASC[address+i]);}void Show88hz(unsigned char lin,unsigned char column,unsigned int address){ unsigned char i;if(column>16) {return;}if(column<8) SelectScreen(1); //如果列数<8(0,1,2,3,4,5,6,7)则写在第一屏上else {SelectScreen(2); //否则 (8,9,10,11,12,13,14,15)写在第二屏上column=column & 0x07; //防止越界}SetLine(lin);SetColumn(column<<3);for(i=0;i<8;i++) WriteByte(Hztable[address+i]);}/*------------------------------------------------------------------------------------------------*///显示8*16字符//旋转90度:字模被竖着切分//lin:行(0-3), column: 列(0-15)//character:字符代码(标准ASCII码)void ShowChar(unsigned char lin,unsigned char column,unsigned char character){ lin=lin<<1;//一个字符占两页Show88(lin ,column, character*16 );Show88(lin+1,column,character*16+8 );}/*----------------------------------------------------------------------------------------------*///显示一个汉字//旋转90度:字模被竖着切分//lin:行(0-3), column: 列(0-7)//hzcode: 汉字代码(自定义的)//uchar code HZtablevoid ShowHZ(unsigned char lin,unsigned char column,unsigned int hzcode){lin=lin<<1; //lin*2,一个汉字占两页Show88hz(lin,column,hzcode*32);Show88hz(lin,column+1,hzcode*32+8);Show88hz(lin+1,column,hzcode*32+16);Show88hz(lin+1,column+1,hzcode*32+24);}/*----------------------------------------------------------------------------------------------*///演示主程序void main(){int a;a=1;k0=0;k1=1;k2=2;k3=3;GDM12864delay();//等待设备准备调用延时InitLCD();//初始化LCDSetLine(0);SetColumn(0);SetStartLine(0);ClearScreen(0);//清屏while(a){for(t0=0;t0<8;t0++){ShowHZ(k0,t0<<1,t0); //显示}for(t1=8;t1<16;t1++){ShowHZ(k1,(t1-8)<<1,t1);//显示}for(t2=16;t2<24;t2++){ShowHZ(k2,(t2-16)<<1,t2);//显示}for(t3=24;t3<32;t3++){ShowHZ(k3,(t3-24)<<1,t3);//显示}if (UP==0){TEST=0;k=k0;k0=k1;k1=k2;k2=k3;k3=k;TEST=1;}if (DOWN==0) {TEST=0;k=k3;k3=k2;k2=k1;k1=k0;k0=k;TEST=1;}}}。

多种12864液晶屏显示程序

多种12864液晶屏显示程序

多种12864液晶屏显示程序(1)#include#define uchar unsigned char#define uint unsigned int#define lcddata P0sbit RS=P2^0;sbit RW=P2^1;sbit E=P2^2;sbit PSB=P2^3;void delayms(uint n)//1T单片机毫秒延时函数{ unsigned int x;while(n--){x=627;while(x--);}}void delayus(uint t)//1T单片机微秒延时函数{ unsigned int a,b;for(b=t;b>0;b--)for(a=3;a>0;a--);}bit lcdbusy() //忙检查{bit result;RS=0;RW=1;E=1;delayus(5);result=(bit)(P0&0x80);E=0;return(result) ;}void writecmd(uchar cmd) //写命令{while(lcdbusy()) ;RS=0;RW=0;E=0;delayus(5);P0=cmd;delayus(10);E=1;delayus(5);E=0;}void writedat(uchar dat) //写数据{while(lcdbusy()) ;RS=1;RW=0;E=0;delayus(5);P0=dat;delayus(10);E=1;delayus(5);E=0;}void print(uchar place,uchar num,uchar *point)//液晶屏显示数组{uchar i,progdata;writecmd(place);for(i=0;i<="">{progdata=*(point+i);writedat(progdata);}}void lcdclear(){unsigned char i;writecmd(0x30);writecmd(0x80);writecmd(0x01);delayus(20);for(i=0;i<64;i++)writedat(' ');}void lcdinit()//液晶屏初始化{PSB=1;//并口方式writecmd(0x30);//基本指令操作delayms(5);writecmd(0x06);//写一个字符后地址指针自动加1 delayms(5);writecmd(0x0c);//开显示,关光标delayms(5);writecmd(0x01);//清屏指令delayms(5);}void main(){lcdinit();print(0x80,3,"战斗机");//起始位,显示汉字数print(0x85,3,"巡洋舰");print(0x8a,4,"航空母舰");while(1);}(2)#include#define uchar unsigned char#define uint unsigned int#define lcddata P0sbit RS=P2^0;sbit RW=P2^1;sbit E=P2^2;sbit PSB=P2^3;void delayms(uint n)//1T单片机毫秒延时函数{ unsigned int x;while(n--){x=627;while(x--);}}void delayus(uint t)//1T单片机微秒延时函数{ unsigned int a,b;for(b=t;b>0;b--)for(a=3;a>0;a--);}bit lcdbusy() //忙检查{bit result;RS=0;RW=1;E=1;delayus(5);result=(bit)(P0&0x80);E=0;return(result) ;}void writecmd(uchar cmd) //写命令{while(lcdbusy()) ;RS=0;RW=0;E=0;delayus(5);P0=cmd;delayus(10);E=1;delayus(5);E=0;}void writedat(uchar dat) //写数据{while(lcdbusy()) ;RS=1;RW=0;E=0;delayus(5);P0=dat;delayus(10);E=1;delayus(5);E=0;}void lcdpos(uchar x,uchar y)//液晶屏显示位置,x轴0~7,y轴0~7 {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;writecmd(pos);}void print(uchar *str) //液晶屏显示数组{while(*str!='\0'){writedat(*str);str++;}}void lcdclear()//液晶屏清屏函数{unsigned char i;writecmd(0x30);writecmd(0x80);writecmd(0x01);delayus(20);for(i=0;i<64;i++)writedat(' ');}void lcdinit()//液晶屏初始化{PSB=1;//并口方式writecmd(0x30);//基本指令操作delayms(5);writecmd(0x06);//写一个字符后地址指针自动加1 delayms(5); writecmd(0x0c);//开显示,关光标delayms(5);writecmd(0x01);//清屏指令delayms(5);}void main(){lcdinit();lcdpos(0,0);//起始位(行数,列数)print("战斗机");lcdpos(0,5);print("巡洋舰");lcdpos(2,2);print("航空母舰");while(1);}(3)#include#define uchar unsigned char#define uint unsigned int#define lcddata P0sbit RS=P2^0;sbit RW=P2^1;sbit E=P2^2;sbit PSB=P2^3;uchar code dis1[]="战斗机"; //液晶屏一行显示8个汉字,16个字节(i=0;i<16;i++)uchar code dis2[]="巡洋舰";uchar code dis3[]="航空母舰";void delayms(uint n)//1T单片机毫秒延时函数{unsigned int x;while(n--){x=627;while(x--);}}void delayus(uint t)//1T单片机微秒延时函数{unsigned int a,b;for(b=t;b>0;b--)for(a=3;a>0;a--);}bit lcdbusy() //忙检查{bit result;RW=1;E=1;delayus(5);result=(bit)(P0&0x80);E=0;return(result) ;}void writecmd(uchar cmd) //写命令{while(lcdbusy()) ;RS=0;RW=0;E=0;delayus(5);P0=cmd;delayus(10);E=1;delayus(5);E=0;}void writedat(uchar dat) //写数据{while(lcdbusy()) ;RS=1;RW=0;E=0;delayus(5);P0=dat;delayus(10);delayus(5);E=0;}void lcdpos(uchar x,uchar y)//液晶屏显示位置,x轴0~7,y轴0~7 {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;writecmd(pos);}void lcdclear()//液晶屏清屏函数{unsigned char i;writecmd(0x30);writecmd(0x80);writecmd(0x01);delayus(20);for(i=0;i<64;i++)writedat(' ');}void lcdinit()//液晶屏初始化{PSB=1;//并口方式writecmd(0x30);//基本指令操作delayms(5);writecmd(0x06);//写一个字符后地址指针自动加1delayms(5);writecmd(0x0c);//开显示,关光标delayms(5);writecmd(0x01);//清屏指令delayms(5);}void main(){uint i;lcdinit();lcdpos(0,0);//起始位(行数,列数)for(i=0;i<6;i++)//占用字节数(一个汉字占两个字节,一个字母、数字、符号占一个字节)writedat(dis1[i]);lcdpos(0,5);for(i=0;i<6;i++)writedat(dis2[i]);lcdpos(2,2);for(i=0;i<8;i++)writedat(dis3[i]);while(1);}(4)#include#define uchar unsigned char#define uint unsigned int#define lcddata P0sbit RS=P2^0;sbit RW=P2^1;sbit E=P2^2;sbit PSB=P2^3;uchar code dis1[]="战斗机"; //液晶屏一行显示8个汉字,16个字节(i=0;i<16;i++)uchar code dis2[]="巡洋舰";uchar code dis3[]="航空母舰";void delayms(uint n)//1T单片机毫秒延时函数{unsigned int x;while(n--){x=627;while(x--);}}void delayus(uint t)//1T单片机微秒延时函数{unsigned int a,b;for(b=t;b>0;b--)for(a=3;a>0;a--);}bit lcdbusy() //忙检查{bit result;RS=0;RW=1;E=1;delayus(5);result=(bit)(P0&0x80);E=0;return(result) ;}void writecmd(uchar cmd) //写命令{while(lcdbusy()) ;RS=0;RW=0;E=0;delayus(5);P0=cmd;delayus(10);E=1;delayus(5);E=0;}void writedat(uchar dat) //写数据{while(lcdbusy()) ;RS=1;RW=0;E=0;delayus(5);P0=dat;delayus(10);E=1;delayus(5);E=0;}void lcdpos(uchar x,uchar y)//液晶屏显示位置,x轴0~7,y轴0~7 {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;writecmd(pos);}void lcdclear()//液晶屏清屏函数{unsigned char i;writecmd(0x30);writecmd(0x80);writecmd(0x01);delayus(20);for(i=0;i<64;i++)writedat(' ');}void lcdinit()//液晶屏初始化{PSB=1;//并口方式writecmd(0x30);//基本指令操作delayms(5);writecmd(0x06);//写一个字符后地址指针自动加1 delayms(5); writecmd(0x0c);//开显示,关光标delayms(5);writecmd(0x01);//清屏指令delayms(5);}void main(){uint i;lcdinit();lcdpos(0,0);//起始位(行数,列数)i=0;while(dis1[i]!='\0'){writedat(dis1[i]);//显示字符i++;}lcdpos(0,5);i=0;while(dis2[i]!='\0'){writedat(dis2[i]);i++;}lcdpos(2,2);i=0;while(dis3[i]!='\0'){writedat(dis3[i]);i++;}while(1); }(5)#include#define uchar unsigned char#define uint unsigned intsbit CS=P2^0; //片选信号sbit SID=P2^1; //数据信号sbit SCLK=P2^2; //时钟信号sbit PSB=P2^3; //串并行选择,H并行,L串行sbit key=P3^0;unsigned char code temp1[]={"战斗机"}; unsigned char code temp2[]={"航空母舰"};void delayms(uint n)//毫秒延时{unsigned int x;while(n--){x=627;while(x--);}}void delay(uint m)//100us延时{unsigned int da,db;for(da=0;da<m;da++)< bdsfid="537" p=""></m;da++)<> for(db=0;db<100;db++);}void sendbyte(uchar bbyte) //发送一个字节{unsigned char i;for(i=0;i<8;i++){SID=bbyte&0x80;SCLK=1;SCLK=0;bbyte<<=1;}}void writechar(bit start,uchar ddata) //写指令或数据{unsigned char start_data,Hdata,Ldata;if(start==0)start_data=0xf8;elsestart_data=0xfa;Hdata=ddata&0xf0;Ldata=(ddata<<4)&0xf0;sendbyte(start_data);delay(5);sendbyte(Hdata);delay(1);sendbyte(Ldata);delay(1);}void lcdsetxy(uchar x,uchar y)//设置LCD显示的起始位置,X 为行,Y为列{uchar address;switch(x){case 0: address = 0x80 + y; break;case 1: address = 0x80 + y; break;case 2: address = 0x90 + y; break;case 3: address = 0x88 + y; break;case 4: address = 0x98 + y; break;default:address = 0x80 + y; break;}writechar(0, address);}void print(uchar X,uchar Y,uchar *s)//中英文字符串显示函数{lcdsetxy( X, Y );while (*s){writechar( 1, *s );s ++;delay(1);}}void lcdclear() //清屏函数{writechar(0,0x01);}void lcdinit(){delay(10);PSB=0;CS=1;writechar(0,0x30); writechar(0,0x0c); writechar(0,0x01); } void main(){lcdinit();print(1,2,temp1);print(3,2,temp2);while(1);}。

12864串行显示中文

12864串行显示中文
LCD12864_RET=1;
LCD12864_PSB=0; //串行
WrCom(0x01);//清屏
WrCom(0x30);//基本指令用0x30,扩展指令用0x34
Delay1ms(20);
WrCom(0x0C);//显示开,光标关
WrCom(0x06);//进入模式指针加1,屏幕不移动
}
/****************************************************************************
#endif
/********************************12864.C*************************************/
#include"12864.h"
#include<reg51.h>
#include"string.h"
//#define LCM_ST7920_FIRST_LINE_ADDRESS0x80
void LcdInit(void);
//void Print(unsigned char);
void SetAddress( unsigned char,unsigned char );
void DisplayString(unsigned char x ,unsigned char y,unsigned char *add);
sbit LCD12864_SID = P2^5; //RW
sbit LCD12864_CS = P2^6; //RS
sbit LCD12864_RET= P2^0;
sbit LCD12864_PSB =P2^2;

12864液晶显示汉字程序

12864液晶显示汉字程序

/*=============================程序说明=============================== 项目名称: 显示汉字作者:创建日期:修改说明:程序说明:(1)CPU 型号:(2)时钟频率:(3)实现功能:(4)程序概述:===================================================================*/ //==========================头文件加载=============================== #include <mega16.h>#include <delay.h>#include "music.h"//===========================端口声明================================ #define LcdRS PORTB.0 //#define LcdRSDDR DDRB.0 //#define LcdRW PORTB.1 //#define LcdRWDDR DDRB.1 //#define LcdEN PORTB.4 //#define LcdENDDR DDRB.4 //#define LcdRST PORTB.6 //#define LcdRSTDDR DDRB.6 //#define LcdIoIn PORTA //#define LcdIoOut PINA //#define LcdIoDDR DDRA //#define LcdIn() LcdIoDDR = 0xff //调整输入输出#define LcdOut() LcdIoDDR = 0x00//=========================全局常量声明============================== //=========================全局变量声明==============================//===========================函数声明================================ void Lcd_init(void);void Lcd_CheckBusy(void);void Lcd_WriteCommand(uint8 com);void Lcd_WriteDat(uint8 Dat);void Lcd_writeStringRom(uint8 Add, uint8 flash String[]);//============================主函数================================= void main()//主函数{//---------------------------系统初始化--------------------------Lcd_init();music_init();Lcd_writeStringRom(0x80, "梁成颂");while(1){}}//===========================功能子函数================================ void Lcd_init(void){LcdRS = 1;LcdRSDDR = 1;LcdRW = 1;LcdRWDDR = 1;LcdEN = 1;LcdENDDR = 1;LcdRST = 1; //LcdRSTDDR = 1;LcdIoIn = 1; //LcdIoDDR = 1;LcdIoIn = 0xff; //LcdIn(); //LcdRST = 0;delay_ms(20);LcdRST = 1;delay_ms(50);Lcd_WriteCommand(0x38); //系统设置delay_ms(1);Lcd_WriteCommand(0x38); //系统设置Lcd_WriteCommand(0x08); //开显示Lcd_WriteCommand(0x01); //清屏Lcd_WriteCommand(0x06); //光标设置Lcd_WriteCommand(0x0c); //开显示Lcd_WriteCommand(0x01); //清屏}void Lcd_CheckBusy(void) //怕忙检测{LcdOut();LcdRS = 0;LcdRW = 1;LcdEN = 1;while((LcdIoOut & 0x80) == 0x80);LcdEN = 0;}void Lcd_WriteCommand(uint8 com) //写指令{Lcd_CheckBusy();LcdIn();LcdRS = 0;LcdRW = 0;LcdEN = 1;LcdIoIn = com;LcdEN = 0;}void Lcd_WriteDat(uint8 Dat) //写指令{Lcd_CheckBusy();LcdIn();LcdRS = 1;LcdRW = 0;LcdEN = 1;LcdIoIn = Dat;LcdEN = 0;}void Lcd_writeStringRom(uint8 Add, uint8 flash String[]) {uint16 i = 0;Lcd_WriteCommand(Add);while(String[i] != '\0'){Lcd_WriteDat(String[i]);i++;}}。

12864显示汉字程序

12864显示汉字程序

液晶TS12864-3驱动程序,可流水显示汉字#include<reg52.h>#define uchar unsigned char#define uint unsigned int#define DataPort P3#define N 800sbit E=P2^0;sbit RW=P2^1;sbit RS=P2^2;sbit PSB=P2^3;int num;uint i=0;uint l=0;uint b;uchar a[]="我爱我家09abcdefg,今天是2007年8月8日星期三,太热了!~_~"; uchar d[]={0x98,0x90,0x88,0x80};/**************延时1ms*count*****************/void delay(int count){int x,y;for(x=0;x<count;x++)for(y=0;y<120;y++);}/**************延时1us***********************//*void delayuS(uchar buf){while(buf--);}*//***********忙检测********************/void Busy(){DataPort=0xFF;RS=0;RW=1;while (1){E =1;if (P0^7==0) break;}E=0;}/***********写指令子程序****************/void Write_Com(uchar command){Busy(); //检测忙标志位RS=0;RW=0;DataPort=command; //写入指令E=1;delay(1);E=0;}/***********写数据子程序***************/void Write_Data(uchar Data){Busy();RS=1;RW=0;DataPort=Data;E=1;delay(1);E=0;}/***********LCD初始化*******************/void Init_LCD(void){PSB=0;delay(1);PSB=1; //将PSB置1,通信方式为8位数据并口delay(1);Write_Com(0x30);//30H--基本指令操作Write_Com(0x0c);//开显示,关光标,不闪烁。

PG12864F汉字显示程序

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);//。

带字库12864液晶显示程序

带字库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显示程序,51单片机,C语言

12864显示程序,51单片机,C语言

12864显示程序,51单片机,C语言可显示固定中文,字符,数字;可实时动态刷新显示数字,字符;#include<reg52.h>sbit rs=P1^2;sbit rw=P1^1;sbit cs=P1^0;sbit psb=P1^3;unsigned char code table[]={" X0: Y0: "}; unsigned char code table1[]={"现在X1: Y1: "}; unsigned char code table2[]={"划线模式:"}; unsigned char code table3[]={"开始暂停"};void delay(unsigned char z) //延时{unsigned i,j;for(i=0;i<z;i++)for(j=0;j<110;j++);}void write_com(unsigned int com) //写命令{rs=0;rw=0;cs=0;P2=com;delay(5);cs=1;delay(5);cs=0;}void write_date(unsigned char dat) //写数据{rs=1;rw=0;cs=0;P2=dat;delay(5);cs=1;delay(5);cs=0;}void pos(unsigned char x,unsigned char y) //起点函数{unsigned char 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/2;write_com(pos);}void init(){unsigned char i;psb=1; //1并行,0串行write_com(0x30); //基本指令操作delay(5);write_com(0x0c); //显示开,关光标delay(5);write_com(0x01); //清除led的显示内容delay(5);pos(0,0);i=0;while(table[i]!='\0') //第一行固定显示{write_date(table[i]);i++;}pos(1,0);i=0;while(table1[i]!='\0'){write_date(table1[i]); //第二行固定显示i++;}pos(2,0);i=0;while(table2[i]!='\0'){write_date(table2[i]); //第三行固定显示i++;}pos(3,0);i=0;while(table3[i]!='\0'){write_date(table3[i]); //第四行固定显示i++;}}void write_dianya(unsigned char add_x,unsigned char add_y,int date){//12864刷新char bai,shi,ge;bai=date/100;shi=date%100/10;ge=date%10;pos(add_x,add_y);write_date(0x30+bai);write_date(0x30+shi);write_date(0x30+ge);}void main(){init();while(1){write_dianya(0,3,134);}}。

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

液晶TS12864-3驱动程序,可流水显示汉字
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define DataPort P3
#define N 800
sbit E=P2^0;
sbit RW=P2^1;
sbit RS=P2^2;
sbit PSB=P2^3;
int num;
uint i=0;
uint l=0;
uint b;
uchar a[]="我爱我家09abcdefg,今天是2007年8月8日星期三,太热了!~_~"; uchar d[]={0x98,0x90,0x88,0x80};
/**************延时1ms*count*****************/
void delay(int count)
{int x,y;
for(x=0;x<count;x++)
for(y=0;y<120;y++);
}
/**************延时1us***********************/
/*void delayuS(uchar buf)
{
while(buf--);
}*/
/***********忙检测********************/
void Busy()
{
DataPort=0xFF;
RS=0;
RW=1;
while (1)
{
E =1;
if (P0^7==0) break;
}
E=0;
}
/***********写指令子程序****************/
void Write_Com(uchar command)
{
Busy(); //检测忙标志位
RS=0;
RW=0;
DataPort=command; //写入指令
E=1;
delay(1);
E=0;
}
/***********写数据子程序***************/
void Write_Data(uchar Data)
{
Busy();
RS=1;
RW=0;
DataPort=Data;
E=1;
delay(1);
E=0;
}
/***********LCD初始化*******************/
void Init_LCD(void)
{
PSB=0;
delay(1);
PSB=1; //将PSB置1,通信方式为8位数据并口
delay(1);
Write_Com(0x30);//30H--基本指令操作
Write_Com(0x0c);//开显示,关光标,不闪烁。

Write_Com(0x01);//清除显示
Write_Com(0x02);
Write_Com(0x06);//指定在资料写入或读取时,光标的移动方向,DDRAM的
地址计数器(AC)加1。

Write_Com(0x04);//显示状态全关
}
/*****************清屏***********************/
void Clear_LCD(void)
{
Write_Com(0x01);
Write_Com(0x34);
Write_Com(0x30);
}
/******************读地址*************************************/
/*void Read_Add(void)
{
//uchar add=0;
DataPort=0xFF;
RS=0;
RW=1;
Busy();
add=(DataPort|0x10)&0xbf;
//return(add);
}*/ //读地址失败
/*****************判断行*******************/
/*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 Display_Line(uchar x)
{
uchar c=0;
c=x-0x1; //本函数说明,函数内部的计算公式一定要处在函数的首行if(i==0) Write_Com(x);
if(i==2*(0x87-c)) Write_Com(0x90);
if(i==2*(0x97-c)) Write_Com(0x98);
if(i==2*(0x8f-c)) Write_Com(0x88);
}
/*void Scan_Line(void)
{
if(i==14) Write_Com(0x90);
if(i==30) Write_Com(0x88);
if(i==45) Write_Com(0x98);
}*/
void Show_Chiese()
{
EA=0;
b=sizeof(a);
num=b;
for(l=0;l<4;l++)
{
for(i=0;i<num;i++)
{
Display_Line(d[l]);
Write_Data(a[i]);
}
delay(N);
//EA=1;
}
EA=1;
TH0=0x06;
TL0=0x06;
Clear_LCD();
delay(500);
}
void main(void)
{
TMOD=0x01; ///选择定时器模式
TR0=1; //开中断,并允许T0中断ET0=1;
EA=1; //总开关
Init_LCD();
Clear_LCD();
while(1);
{
};
}
void t0(void) interrupt 1 using 0
{
//delay(100);
Show_Chiese();
//EA=0;
}。

相关文档
最新文档