51單片機(jī)漢字液晶子程序 液晶屏分為4行*12列漢字
/*寫漢字液晶子程液晶屏分為4行*12列漢字,全部使用模擬接口方式。
/* TGLCMLIMIT64A接口程序(模擬方式)
;***************************************************************************
;連線圖:
;*LCM---89C52**LCM---89C52**LCM-------89C52**LCM----------89C52**
;*DB0---P0.0**DB4---P0.4**D/I-------P2.6**CS1----------P2.4**
;*DB1---P0.1**DB5---P0.5**R/W-------P2.7**CS2----------P2.5**
;*DB2---P0.2**DB6---P0.6**RST--------VCC**CS3----------P3.2**
;*DB3---P0.3**DB7---P0.7**E---------P2.3**
;注:89C52的晶振頻率為12MHz*
;***************************************************************************/
//畫線部分請(qǐng)參照avr的c程序。
/*#pragmaSRC/*生成ASM文件開關(guān),必要時(shí)打開 */
#i nclude
#i nclude
#i nclude
#define Ucharunsignedchar
/***********液晶顯示器接口引腳定義***************/
sbit Elcm= P2^3; //
sbit CS1LCM= P2^4; //
sbit CS2LCM= P2^5; //
sbit CS3LCM= P3^2; /*這個(gè)連接只是做實(shí)驗(yàn)的臨時(shí)接法。*/
sbitDILcm= P2^6; //
sbit Rwlcm= P2^7; //
sfrDatalcm= 0x80; //數(shù)據(jù)口
unsignedchartesti[]={"浸渠叁繩漱塔烴威犧曉玄瑤"};
/***********常用操作命令和參數(shù)定義***************/
#define DISPON 0x3f /*顯示on */
#define DISPOFF 0x3e /*顯示off */
#define DISPFIRST 0xc0 /*顯示起始行定義 */
#define SETX 0x40 /*X定位設(shè)定指令(頁(yè)) */
#define SETY 0xb8 /*Y定位設(shè)定指令(列) */
#define LCDbusy 0x80 /*LCM忙判斷位 */
/**************顯示分區(qū)邊界位置*****************/
#define MODL 0x00 /*左區(qū) */
#define MODM 0x40 /*左區(qū)和中區(qū)分界 */
#define MODR 0x80 /*中區(qū)和右區(qū)分界 */
#define LCMLIMIT 0xC0 /*顯示區(qū)的右邊界 */
/****************全局變量定義*******************/
Ucharcol,row,cbyte; /*列x,行(頁(yè))y,輸出數(shù)據(jù) */
bitxy; /*畫線方向標(biāo)志:1水平 */
/*****************函數(shù)列表**********************/
voidLcminit(void); /*液晶模塊初始化 */
voidDelay(Uchar); /*延時(shí),入口數(shù)為Ms */
voidlcdbusyL(void); /*busy判斷、等待(左區(qū)) */
voidlcdbusyM(void); /*busy判斷、等待(中區(qū)) */
voidlcdbusyR(void); /*busy判斷、等待(右區(qū)) */
voidPutedot(Uchar); /*半角字符輸出 */
voidPutcdot(Uchar); /*全角(漢字)輸出 */
voidWrdata(Uchar); /*數(shù)據(jù)輸出給LCM */
voidLcmcls(void); /*LCM全屏幕清零(填充0) */
voidwtcom(void); /*公用busy等待 */
voidLOCatexy(void); /*光標(biāo)定位 */
voidWrcmdL(Uchar); /*左區(qū)命令輸出 */
voidWrcmdM(Uchar); /*中區(qū)命令輸出 */
voidWrcmdR(Uchar); /*右區(qū)命令輸出 */
voidPutstr(Uchar*puts,Uchari); /*中英文字符串輸出 */
voidRollscreen(Ucharx); /*屏幕向上滾動(dòng)演示 */
voidRddata(void); /*從液晶片上讀數(shù)據(jù) */
voidLinehv(Ucharlength); /*橫(豎)方向畫線 */
voidpoint(void); /*打點(diǎn) */
voidLinexy(Ucharendx,Ucharendy);
/******************數(shù)組列表*********************/
UcharcodeEzk[]; /*ASCII常規(guī)字符點(diǎn)陣碼表 */
UcharcodeHzk[]; /*自用漢字點(diǎn)陣碼表 */
UcharcodeSTR1[]; /*自定義字符串 */
UcharcodeSTR2[]; //
UcharcodeSTR3[]; //
UcharcodeSTR4[]; //
/********************************/
/*演示主程序 */
/********************************/
voidmain(void)
{
Ucharx,y;
col=0;
row=0;
Delay(40); /*延時(shí)大約40Ms,等待外設(shè)準(zhǔn)備好 */
Lcminit(); /*液晶模塊初始化,包括全屏幕清屏*/
Putstr(STR2,24); /*第一行字符輸出,24字節(jié) */
col=0;
row=2;
Putstr(STR1,12); /*第二行字符輸出,12字節(jié) */
col=0;
row=4;
Putstr(STR3,24); /*第三行字符輸出,24字節(jié) */
col=0;
row=6;
Putstr(STR4,24); /*第四行字符輸出,12字節(jié) */
x=0;
col=0;
row=0;
xy=1; /*方向標(biāo)志。定為水平方向 */
Linehv(192); /*畫一條橫線(0,0)-(191,0) */
col=0;
row=15;
xy=1;
Linehv(192); /*畫一條橫線(0,15)-(191,15) */
col=0;
row=32;
xy=1;
Linehv(192); /*畫一條橫線(0,32)-(191,32) */
col=0;
row=1;
xy=0; /*方向標(biāo)志。定為垂直方向 */
Linehv(31); /*畫一條豎線(0,1)-(0,31) */
col=191;
row=1;
xy=0;
Linehv(31); /*畫一條豎線(191,1)-(191,31) */
col=0; /*設(shè)定斜線的起點(diǎn)坐標(biāo) */
row=63;
Linexy(44,31); /*畫一段斜線(0,63)-(44,31) */
col=44;
row=31;
Linexy(190,62); /*繼續(xù)畫斜線(44,31)-(191,63) */
while(1){
Rollscreen(y); /*定位新的顯示起*/
y++;
y%=8;
x=testi[y];
Delay(100); /*延時(shí),控制滾動(dòng)速度 */
};
}
/************************************************/
/*畫線。任意方向的斜線,不支持垂直的或水平線 */
/************************************************/
voidLinexy(Ucharendx,Ucharendy)
{
registerUchart;
intxerr=0,yerr=0,delta_x,delta_y,distance;
Ucharincx,incy;
/* computethedistanceinbothdirections*/
delta_x=endx-col;
delta_y=endy-row;
/*computethedirectionoftheincrement,
anincrementof"0"meanseitheraverticalorhorizontallines*/
if(delta_x>0)incx=1;
elseif(delta_x==0)incx=0;
elseincx=-1;
if(delta_y>0)incy=1;
elseif(delta_y==0)incy=0;
elseincy=-1;
/*determinewhichdistanceisgreater*/
delta_x=cabs(delta_x);
delta_y=cabs(delta_y);
if(delta_x>delta_y)distance=delta_x;
elsedistance=delta_y;
/*drawtheline*/
for(t=0;t<=distance+1;t++){
point();
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance){
xerr-=distance;
col+=incx;
}
if(yerr>distance){
yerr-=distance;
row+=incy;
}
}
}
/****************************************/
/*畫線。只提供X或Y方向的,不支持斜線 */
/****************************************/
voidLinehv(Ucharlength)
{
Ucharxs,ys;
if(xy){ys=col;
for(xs=0;xs