?? display.c
字號:
char_data=*p++;
WriteData(char_data);
row+=1;
}
}
else
{
for(j=0;j<16;j++)
{
char_addr_point_set(row,col); //設置Vram地址
WriteCommand(0x0042);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
row+=1;
}
}
}
//***************************************************************************/
void showchar16(unsigned int row,unsigned int col,unsigned int chp,unsigned int attribute)
{// row:顯示行 col:顯示列 chp:顯示第幾個字. attribute:反色。1:顯示字黑,0顯示字白
unsigned int j,char_data;
const unsigned int *p;
p=&HZ16_DOT_LIB[0];
chp=chp*32;
p=p+chp;
col/=8;
//-----------------------------------------
// 顯示中文
//-----------------------------------------
if(attribute)
{
for(j=0;j<16;j++)
{
char_addr_point_set(row,col); //設置Vram地址
//顯示光標右移,設置光標地址
WriteCommand(0x0042); // 寫顯示數據
char_data=*p++; //左8位
WriteData(char_data);
char_data=*p++; //右8位
WriteData(char_data);
row+=1;
}
}
else
{
for(j=0;j<16;j++)
{
char_addr_point_set(row,col); //設置Vram地址
WriteCommand(0x0042);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
row+=1;
}
}
}
//***************************************************************************/
void showchar24(unsigned int row,unsigned int col,unsigned int chp,unsigned int attribute)
{// row:顯示行 col:顯示列 chp:顯示第幾個字. attribute:反色。1:顯示字黑,0顯示字白
unsigned int j,char_data;
const unsigned char *p;
p=&Cdot24lib[0];
chp=chp*72;
p=p+chp;
col/=8;
//-----------------------------------------
// 顯示中文
//-----------------------------------------
if(attribute)
{
for(j=0;j<24;j++)
{
char_addr_point_set(row,col); //設置Vram地址
WriteCommand(0x0042);
char_data=*p++;
WriteData(char_data); //左8位
char_data=*p++;
WriteData(char_data); //中8位
char_data=*p++;
WriteData(char_data); //右8位
row+=1;
}
}
else
{
for(j=0;j<24;j++)
{
char_addr_point_set(row,col); //設置Vram地址
WriteCommand(0x0042);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
char_data=*p++;
char_data^=0x00ff;
WriteData(char_data);
row+=1;
}
}
}
//***************************************************************************/
// 畫水平線(Y1=Y2) X=8*i
//***************************************************************************/
void lineH(unsigned int y1,unsigned int x1,unsigned int y2,unsigned int x2)
{
unsigned int i,ipos,length1,length2;
ipos=y1*40+x1/8+1200;
length1=y2*40+x2/8+1200;
length2=length1-ipos;
wr_cmd_0(0x4c);
wr_cmd_2(0x46,ipos);
wr_cmd_0(0x42);
for(i=0;i<length2;i++)
{
WriteData(0xff);
}
}
//==================================================
// 畫點
//==================================================
void pixel(unsigned int PointY,unsigned int PointX) // PointY 行 PointX 列
{
unsigned int i, StartAddr;
unsigned int dat,dat2,dat3;
StartAddr=PointY*40 + PointX/8 +1200;
dat=(unsigned int)(7-PointX%8); //產生點的數據
dat2=0x0001;
for(i=0;i<dat;i++)
{
dat2<<=1;
}
wr_cmd_0(0x004c);
wr_cmd_2(0x0046,StartAddr); //讀該點所在單元地址內容
wr_cmd_0(0x0043);
dat3=ReadDataLcm();
dat2|=dat3;
wr_cmd_0(0x004c);
wr_cmd_2(0x0046,StartAddr); //設置該點所在單元地址
wr_cmd_1(0x0042,dat2); // 畫點位數據
}
//==================================================
// 畫點--點
//==================================================
void line(unsigned int y1,unsigned int x1,unsigned int y2,unsigned int x2)
{
unsigned int x,y;
float k,b;
if(x1==x2) // x1=x2,畫垂直線
{
if(y1<=y2)
{
for(y=y1;y<=y2;y++)
{
pixel(y, x1);
}
}
else
{
for(y=y2;y<=y1;y++)
{
pixel(y, x1);
}
}
}
else
{
if( fabs(y1-y2) <= fabs(x1-x2)) // |k|<=1 // y行數 <= x列數
{
k=((float)y2-y1) / ((float)x2-x1) ;
b=y1-k*x1;
if( x1 < x2 )
{
for(x=x1;x<=x2;x++)
{
y=(unsigned int)(k*x+b);
pixel(y, x);
}
}
else
{
for(x=x2;x<=x1;x++)
{
y=(unsigned int)(k*x+b);
pixel(y,x);
}
}
}
else // 行數>列數
{
k=((float)x2-x1) / ((float)y2-y1) ;
b=x1-k*y1;
if( y1 <= y2 )
{
for(y=y1;y<=y2;y++)
{
x=(unsigned int)(k*y+b);
pixel(y,x);
}
}
else
{
for(y=y2;y<=y1;y++)
{
x=(unsigned int)(k*y+b);
pixel(y , x);
}
}
}
}
}
//==================================================
// 畫圓
//==================================================
void circle(unsigned char OY,unsigned char OX,unsigned char R)//
{
unsigned int dx,dy,xx,rr,rs;
dy = R;
rr = R*R;
rs = R*71/100; //0.71R
for(dx=0;dx<=rs;)
{
dx++;
xx = dx*dx;
while((rr-xx)<(dy*dy))
{
dy--;
}
pixel(OY-dy,OX+dx); //第一象限
pixel(OY-dy,OX-dx); //第二象限
pixel(OY+dy,OX-dx); //第三象限
pixel(OY+dy,OX+dx); //第四象限
pixel(OY-dx,OX+dy); //第一象限
pixel(OY-dx,OX-dy); //第二象限
pixel(OY+dx,OX-dy); //第三象限
pixel(OY+dx,OX+dy); //第四象限
}
}
/***************顯示一幅全屏圖像******************/
void Displayonebmp (Uchar Area,Uchar const *puts) //參數Area為第幾圖層
{
Uint X;
Uchar i,j;
X=0;
WriteCommand(0x4c ); //設置光標為右移
WriteCommand( 0x46 ); //設置光標的地址
switch(Area)
{
case 1:WriteData( BasePart1 );break; //BasePart1
case 2:WriteData( BasePart2 );break;
case 3:WriteData( BasePart3 );break;
}
WriteCommand( 0x42 ); //允許MCU把數據寫入到顯示緩沖區去
for(i=0;i<240;i++)
{
for(j=0;j<40;j++)
{
WriteData(puts[X]);
X++;
}
}
}
void dispbmp(void)
{
Displayonebmp (1,bmp2);
}
//============================== 西文顯示演示程序 ==============================
// 僅僅用于文本方式下的西文字符串顯示,本函數只寫入第3顯示區
void TextDisp( Uchar Ox,Uchar Oy, Uchar const *ptr ) {
Uchar TexLength=0,ii;
Uint iTemp;
while(ptr[TexLength]>0x1f) {TexLength++;}; // 獲取字串長度
iTemp = Oy*paraP9+Ox;
WriteCommand( 0x5d ); // 光標形狀設置,代碼0x5d
WriteData( 0x07 ); // 設置光標水平點為CSX=8
WriteData( 0x07 ); // 光標為塊狀形式,垂直點為CSY=8
WriteCommand( 0x5b ); // 顯示合成方式設置.代碼0x5b
WriteData( 0x01 ); // 設置參數:顯示3區為文本屬性,二重xor合成
WriteCommand( 0x59 ); // 寫入指令DISP ON/OFF代碼,后續參數:
WriteData( 0x56 ); // 01 01 01 10顯示1~4區開顯示,光標閃爍顯示
iTemp = (Uint)Oy * paraP9 + Ox; // 光標位置到實際ram地址換算
WriteCommand( 0x4c ); // 自動右移光標指向
WriteCommand( 0x46 ); // 制定光標位置
WriteData( (Uchar)(iTemp &0xff) ); // 設置光標地址CSR
WriteData( (Uchar)(iTemp /256 + BasePart3) ); // 加入顯示三區起始地址SAD2H
WriteCommand( 0x42 ); // 當前位置寫入數據指令
for(ii=0;ii < TexLength;ii++) {
WriteData( ptr[ii] ); // 寫入顯示字符代碼
}
DelayMs(350);
}
void text_1(void)
{
TextDisp( 0,13, StrForSample1 ); // 英文字符串的顯示,演示光標自動移位
}
/*==============================================================================
; 漢字寫入子程序(圖形方式)。每次調用輸出一個漢字
; 支持圖形方式使用,完成漢字點陣碼的輸出。
; 攜入參數: Ox,Oy....寫入顯示的左上角坐標,Ox是以字節單位,Oy以行掃描線單位
Ptr......漢字碼,庫內的排列編碼,大型程序時請改用unsigned int類型
; 無返回數據。
==============================================================================*/
void PPutCdotInGraph( Uint Ox, Uchar Oy, Uchar Cnumber, Uchar DotWidth ) //漢字寫入子程序(圖形方式)
{
Uint tempPtr,Optr;
Uchar tempCount1,tempCount2,nByte;
Optr = (Uint)Oy * paraP9 + Ox+0x04b0;
nByte = DotWidth/8;
WriteCommand( CsrDirD ); // 自動右移。
tempPtr = (Uint)Cnumber * DotWidth*nByte;
for (tempCount1=0;tempCount1<nByte;tempCount1++) {
WriteCommand( CsrW ); // 光標定位指令
WriteData( (Uchar)(Optr &0xff) ); // 設置光標地址CSR
WriteData( (Uchar)(Optr /256 ) );
WriteCommand( mWrite ); // ram寫指令
switch(DotWidth){
case 8: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
WriteData( HZ8_DOT_LIB[tempPtr] ); // 寫入數據
tempPtr += nByte;
}
break;
case 24: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
WriteData( Cdot24lib[tempPtr] ); // 寫入數據
tempPtr += nByte;
}
break;
case 32: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
WriteData( Cdot32lib[tempPtr] ); // 寫入數據
tempPtr += nByte;
}
break;
case 48: for(tempCount2=0;tempCount2<DotWidth;tempCount2++) {
WriteData( Cdot48lib[tempPtr] ); // 寫入數據
tempPtr += nByte;
}
break;
}
tempPtr = Cnumber * DotWidth*nByte + tempCount1 + 1;
Optr++;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -