附录B.3 LGM12864的应用程序
程序1.显示汉字
功能说明:LCD循环显示汉字字符串首先在第一行显示“陕西理工学院”,第二行显示“电气工程系”,第三行显示“☆明德博学励志笃行☆”,第四行显示“◤有志者事竟成◥”
主程序如下:
/**16 *16字符点阵,宋体,逐行,阴码,逆向取字模,16进制输出***/
/***显示“陕西理工学院” **/
/*** “电气工程系”**/
/** “☆明德博学励志笃行☆”**/
/** “◤有志者事竟成◥”**/
#include <REG51.H>
#define uchar unsigned char
#define uint unsigned int
sbit RS=P3^7;
sbit RW=P3^6;
sbit EN=P3^5;
sbit CS1=P3^4;
sbit CS2=P3^3;
sbit RST=P3^2;
/************************函数列表**************************/
void delay(unsigned long v);
void wcode(uchar c,uchar csl,uchar csr);
void wdata(uchar c,uchar csl,uchar csr);
void set_startline(uchar i);
void set_xy(uchar x,uchar y);
void dison_off(uchar o);
void reset();
void lcd_init(void);
void lw(uchar x, uchar y, uchar dd);
void display_hz(uchar x, uchar y, uchar n, uchar fb);
uchar code hz[];
void lcd_busy(void);
void clear_lcd();
void rollscreen(uchar z);
/*******************************************************/
void main(void)
{
uchar loop;
delay(10);
reset();
lcd_init();
delay(10);
while(1)
{
/************显示第一行(8个字)***********/
for(loop=0;loop<8;loop++)
{display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);
display_hz(2*loop,0,loop,0);}
/*************显示第二行(8个字)**********/
for(loop=0;loop<8;loop++)
{display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);
display_hz(2*loop,2,loop+8,0);}
/**************显示第三行(8个字)*************/
for(loop=0;loop<8;loop++)
{display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);
display_hz(2*loop,4,loop+16,0);}
/*************显示第四行(8个字)*************/
for(loop=0;loop<8;loop++)
{display_hz(2*loop,6,loop+24,0);
display_hz(2*loop,6,loop+24,0);
www.751com.cn
rollscreen(0);
}
}
/***滚动子程序*/
void rollscreen(uchar z)
{uchar zc;
while(z<64)
{zc=z+0xc0;
wcode(zc,1,1);
delay(5000);
delay(5000);
z++;}
}
/*-------------延时子程序-------------------------------*/
void delay(unsigned long v)
{
while(v!=0)v--;
}
/*----------写指令子程序---------------------------------*/
void wcode(uchar c,uchar csl,uchar csr)
{
CS1=csl;
CS2=csr;
lcd_busy();
RS=0;
RW=0;
P2=c;
EN=0;
delay(10);
EN=1;
delay(10);
EN=0;
}
/*-------------写数据子程序---------------------------*/
void wdata(uchar c,uchar csl,uchar csr)
{
CS1=csl;
<< 上一页 [11] [12] [13] [14] [15] 下一页