?? lcd_driver.c
字號:
/*****************************************************************************
Filename: native.c
Version: 0.01
Description: calculate measure value
Returns: result
Revision History:
EQH-01, 屈宵軍 09/25/04, - Original release
*****************************************************************************/
/*寫漢字液晶子程 液晶屏分為4行*12列漢字,全部使用模擬接口方式。*/
#include<math.h>
#include<tms320.h>
#include "LCD.h"
/********************************/
/* 演示主程序 */
/********************************/
void Lcd_Driver(void)
{
uint x;
unsigned char temp, byteH,byteL; //word split as byte
for(x=0;x<100;x++)
{
byteH=(Hzk[x]&0x0FF00)>>8;
byteL=(Hzk[x]&0x000FF);
temp=byteH;
temp=byteH;
temp=byteH;
temp=byteH;
temp=byteL;
temp=byteL;
temp=byteL;
temp=byteL;
byteL=temp;
}
col=0;
row=0;
Delay(40); /*延時大約40Ms,等待外設準備好 */
Lcminit(); /*液晶模塊初始化,包括全屏幕清屏*/
Putstr(STR2,24); /*第一行字符輸出,24字節 */
col=0;
row=2;
Putstr(STR1,12); /*第二行字符輸出,12字節 */
col=0;
row=4;
Putstr(STR3,25); /*第三行字符輸出,24字節 */
col=0;
row=6;
Putstr(STR4,24); /*第四行字符輸出,12字節 */
x=0;
col=0;
row=0;
xy = 1; /*方向標志。定為水平方向 */
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; /*方向標志。定為垂直方向 */
Linehv(31); /*畫一條豎線(0,1)-(0,31) */
col=191;
row=1;
xy = 0;
Linehv(31); /*畫一條豎線(191,1)-(191,31) */
//col=0; /*設定斜線的起點坐標 */
//row=63;
//Linexy(44,31); /*畫一段斜線(0,63)-(44,31) */
//col=44;
//row=31;
//Linexy(190,62); /*繼續畫斜線(44,31)-(191,63) */
while(0){
Rollscreen(x); /*定位新的顯示起始行 */
x++;
Delay(100); /*延時,控制滾動速度 */
};
}
/************************************************/
/*畫線。任意方向的斜線,不支持垂直的或水平線 */
/************************************************/
void Linexy(uint endx,uint endy)
{
register uint t;
int xerr=0,yerr=0,delta_x,delta_y,distance;
int incx,incy;
/* compute the distance in both directions */
delta_x=endx-col;
delta_y=endy-row;
/* compute the direction of the increment ,
an increment of "0" means either a vertical or horizontal lines */
if(delta_x>0) incx=1;
else if( delta_x==0 ) incx=0;
else incx=-1;
if(delta_y>0) incy=1;
else if( delta_y==0 ) incy=0;
else incy=-1;
/* determine which distance is greater */
delta_x = fabs( delta_x );
delta_y = fabs( delta_y );
if( delta_x > delta_y ) distance=delta_x;
else distance=delta_y;
/* draw the line */
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方向的,不支持斜線 */
/****************************************/
void Linehv(uint length)
{
uint xs,ys;
if (xy)
{ ys = col;
for (xs=0;xs<length;xs++)
{
col = ys + xs;
point();
}
}
else
{ xs = row;
for (ys=0;ys<length;ys++)
{
row = xs + ys;
point();
}
}
}
/****************************************/
/* 畫點 */
/****************************************/
void point(void)
{
uint x1,y1,x,y;
x1=col;
y1=row;
row=y1>>3; /*取Y方向分頁地址 */
Rddata();
y=y1&0x07; /*字節內位置計算 */
x=0x01;
x=x<<y; /*移入所畫點 */
Wrdata(cbyte|x); /*畫上屏幕 */
col=x1; /*恢復xy坐標 */
row=y1;
}
/****************************************/
/* 屏幕滾動定位 */
/****************************************/
void Rollscreen(uint x)
{
cbyte = DISPFIRST|x; /*定義顯示起始行為x?*/
WrcmdL(cbyte);
WrcmdM(cbyte);
WrcmdR(cbyte);
}
/****************************************/
/* 一個字串的輸出 */
/****************************************/
void Putstr(char *puts,uint i)
{
uint j,X;
for (j=0;j<i;j++)
{
X = puts[j];
if (X&0x80)
{
Putcdot(X&0x7f); /*只保留低7位*/
}
else Putedot(X-0x20); /*ascii碼表從0x20開始*/
}
}
/****************************************/
/* 半角字符點陣碼數據輸出 */
/****************************************/
void Putedot(uint Order)
{
uint i,bakerx,bakery; /*共定義4個局部變量 */
int x; /*偏移量,字符量少的可以定義為uint */
bakerx = col; /*暫存x,y坐標,已備下半個字符使用 */
bakery = row;
x=Order * 0x10; /*半角字符,每個字符16字節 */
/*上半個字符輸出,8列 */
for(i=0;i<8;i++)
{
cbyte = Ezk[x]; /*取點陣碼,rom數組 */
Wrdata(cbyte); /*寫輸出一字節 */
x++;
col++;
if (col==LCMLIMIT){col=0;row++;row++;}; /*下一列,如果列越界換行*/
if (row>7) row=0; /*如果行越界,返回首行 */
} /*上半個字符輸出結束 */
col = bakerx; /*列對齊 */
row = bakery+1; /*指向下半個字符行 */
/*下半個字符輸出,8列 */
for(i=0;i<8;i++)
{
cbyte = Ezk[x]; /*取點陣碼 */
Wrdata(cbyte); /*寫輸出一字節 */
x++;
col++;
if (col==LCMLIMIT){col=0;row=row+2;}; /*下一列,如果列越界換行*/
if (row>7) row=1; /*如果行越界,返回首行 */
} /*下半個字符輸出結束 */
row=bakery;
} /*整個字符輸出結束 */
/****************************************/
/* 全角字符點陣碼數據輸出 */
/****************************************/
void Putcdot(uint Order)
{
uint i,bakerx,bakery; /*共定義3個局部變量 */
int x; /*偏移量,字符量少的可以定義為uint */
bakerx = col; /*暫存x,y坐標,已備下半個字符使用 */
bakery = row;
x=Order * 0x20; /*每個字符32字?*/
/*上半個字符輸出,16列 */
for(i=0;i<16;i++)
{
Wrdata(Hzk[x]); /*寫輸出一字節 */
x++;
col++;
if (col==LCMLIMIT){ col=0;row++;row++;} /*下一列,如果列越界換行*/
if (row>6) row=0; /*如果行越界,返回首行 */
} /*上半個字符輸出結束 */
/*下半個字符輸出,16列 */
col = bakerx;
row = bakery+1;
for(i=0;i<16;i++) /*下半部分*/
{
Wrdata(Hzk[x]);
x++;
col++;
if (col==LCMLIMIT){col=0;row++;row++;} /*下一列,如果列越界換行*/
if (row>7) row=1; /*如果行越界,返回首行 */
} /*下半個字符輸出結束 */
row = bakery;
} /*整個字符輸出結束 */
/****************************************/
/* 清屏,全屏幕清零 */
/****************************************/
void Lcmcls( void )
{
for(row=0;row<8;row++)
for(col=0;col<LCMLIMIT;col++) Wrdata(0);
}
/****************************************/
/* 從液晶片上讀數據,保留在全局變量中 */
/****************************************/
void Rddata(void)
{
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
*Datalcm_pointer=0xFF;
*Dilcm_pointer = 1; /*數據*/
*Rwlcm_pointer = 1; /*讀數據*/
*Elcm_pointer = 1; /*讀入到LCM*/
// _nop_();
cbyte = *Datalcm_pointer; /*虛讀一次 */
*Elcm_pointer = 0;
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
*Datalcm_pointer=0xFF;
// _nop_();
*Dilcm_pointer = 1; /*數據*/
*Rwlcm_pointer = 1; /*讀數據*/
*Elcm_pointer = 1; /*讀入到LCM*/
// _nop_();
cbyte = *Datalcm_pointer; /*從數據口讀數據,真讀 */
*Elcm_pointer = 0;
}
/****************************************/
/* 數據寫輸出 */
/****************************************/
void Wrdata(uint X)
{
Locatexy(); /*坐標定位,返回時保留分區狀態不變 */
// wtcom();
*Dilcm_pointer = 1; /*數據輸出*/
*Rwlcm_pointer = 0; /*寫輸出 */
*Datalcm_pointer = X; /*數據輸出到數據口 */
*Elcm_pointer = 1; /*讀入到LCM*/
// _nop_();
*Elcm_pointer = 0;
}
/****************************************/
/* 命令輸出,每次輸出一個分區控制口 */
/****************************************/
/*
*void Wrcmd(uint X)
{
Locatexy(); 確定分區,返回時保留分區狀態不變
wtcom(); 等待LCM操作允許
*Dilcm_pointer = 0; 數據操作
*Rwlcm_pointer = 0; 寫輸出
*Datalcm_pointer = X; 數據輸出到數據口
*Elcm_pointer = 1;_nop_();*Elcm_pointer = 0; 讀入到LCM
}
*/
/********************************/
/* 命令輸出到左區控制口 */
/********************************/
void WrcmdL(uint X)
{
lcdbusyL(); /*確定分區,返回時保留分區狀態不變*/
*Dilcm_pointer = 0; /*命令操作 */
*Rwlcm_pointer = 0; /*寫輸出 */
*Datalcm_pointer = X; /*數據輸出到數據口 */
*Elcm_pointer = 1;
*Elcm_pointer = 0; /*讀入到LCM*/
}
/********************************/
/* 命令輸出到中區控制口 */
/********************************/
void WrcmdM(uint X)
{
lcdbusyM(); /*確定分區,返回時保留分區狀態不變*/
*Dilcm_pointer = 0; /*命令操作 */
*Rwlcm_pointer = 0; /*寫輸出 */
*Datalcm_pointer = X; /*命令輸出到數據口 */
*Elcm_pointer = 1;//_nop_();
*Elcm_pointer = 0; /*讀入到LCM*/
}
/********************************/
/* 命令輸出到右區控制口 */
/********************************/
void WrcmdR(uint X)
{
lcdbusyR(); /*確定分區,返回時保留分區狀態不變 */
*Dilcm_pointer = 0; /*命令操作 */
*Rwlcm_pointer = 0; /*寫輸出 */
*Datalcm_pointer = X; /*命令輸出到數據口 */
*Elcm_pointer = 1;//_nop_();
*Elcm_pointer = 0; /*讀入到LCM*/
}
/********************************************************/
/* 分區操作允許等待,返回時保留分區選擇狀態 */
/********************************************************/
void lcdbusyL(void)
{
*CS1LCM_pointer = 0; /*CLR CS1 */
*CS2LCM_pointer = 0; /*SETB CS2 */
//CS3LCM = 1; /*SETB CS3 */
wtcom(); /* waitting for enable */
}
void lcdbusyM(void)
{
*CS1LCM_pointer = 0; /*SETB CS1 */
*CS2LCM_pointer = 1; /*CLR CS2 */
//CS3LCM = 1; /*SETB CS3 */
wtcom(); /* waitting for enable */
}
void lcdbusyR(void)
{
*CS1LCM_pointer = 1; /*SETB CS1 */
*CS2LCM_pointer = 0; /*SETB CS2 */
//CS3LCM = 0; /*CLR CS3 */
wtcom(); /* waitting for enable */
}
void wtcom(void)
{
*Dilcm_pointer = 0; /*CLR DI */
*Rwlcm_pointer = 1; /*SETB RW */
*Datalcm_pointer = 0xFF; /*MOV DATA_LCM,#0FFH */
*Elcm_pointer = 1;//_nop_();
// while(*Datalcm_pointer & Lcdbusy);
*Elcm_pointer = 0;
}
/********************************************************/
/*根據設定的坐標數據,定位LCM上的下一個操作單元位置 */
/********************************************************/
void Locatexy(void)
{
unsigned char x,y;
switch (col&0xc0) /* col.and.0xC0 */
{ /*條件分支執行 */
case 0: {lcdbusyL();break;} /*左區 */
case 0x40: {lcdbusyM();break;} /*中區 */
case 0x80: {lcdbusyR();break;} /*右區 */
}
x = col&0x3F|SETX; /* col.and.0x3f.or.setx=0x40 */
y = row&0x07|SETY; /* row.and.0x07.or.sety=b8 */
wtcom(); /* waitting for enable */
*Dilcm_pointer = 0; /*CLR DI */
*Rwlcm_pointer = 0; /*CLR RW */
*Datalcm_pointer = y; /*MOV P0,Y */
*Elcm_pointer = 1;//_nop_();
*Elcm_pointer = 0;
wtcom(); /* waitting for enable */
*Dilcm_pointer = 0; /*CLR DI */
*Rwlcm_pointer = 0; /*CLR RW */
*Datalcm_pointer = x; /*MOV P0,X */
*Elcm_pointer = 1;//_nop_();
*Elcm_pointer = 0;
}
/********************************/
/*液晶屏初始化 */
/********************************/
void Lcminit(void)
{
cbyte = DISPOFF; /*關閉顯示屏 */
WrcmdL(cbyte); /*左區*/
WrcmdM(cbyte); /*中區*/
WrcmdR(cbyte); /*右區*/
cbyte = DISPON; /*打開顯示屏 */
WrcmdL(cbyte); /*左區*/
WrcmdM(cbyte); /*中區*/
WrcmdR(cbyte); /*右區*/
cbyte = DISPFIRST; /*定義顯示起始行為零 */
WrcmdL(cbyte);
WrcmdM(cbyte);
WrcmdR(cbyte);
Lcmcls();
col=0; /*清屏 */
row=0;
Locatexy();
}
/********************************/
/* 延時 */
/********************************/
void Delay(uint MS)
{
// uint us,usn;
while(MS!=0)
{ /*usn = 4;
while(usn!=0)
{
us=0xf0;
while (us!=0){us--;};
usn--;
}*/
MS--;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -