?? lcd.c
字號:
/* LCD控制和顯示函數*/
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "lcd.h"
#include "bmp.h"
/*宏定義*/
#define DMA_Byte (0)
#define DMA_HW (1)
#define DMA_Word (2)
#define DW DMA_Byte //set ZDMA0 as half-word
/*外部變量*/
extern INT8U g_auc_Ascii6x8[];
extern INT8U g_auc_Ascii8x16[];
extern STRU_BITMAP Stru_Bitmap_gbMouse;
/*--- 開始函數代碼 ---*/
/*初始化LCD控制器*/
void Lcd_Init(void)
{
rDITHMODE=0x1223a; /*抖動模式設定*/
rDP1_2 =0x5a5a; /*以下為抖動時間設置*/
rDP4_7 =0x366cd9b;
rDP3_5 =0xda5a7;
rDP2_3 =0xad7;
rDP5_7 =0xfeda5b7;
rDP3_4 =0xebd7;
rDP4_5 =0xebfd7;
rDP6_7 =0x7efdfbf;
/*以下參考P199內容*/
/*LCDCON1控制字清0*/
rLCDCON1=(0)|(1<<5)|(MVAL_USED<<7)|(0x0<<8)|(0x0<<10)|(CLKVAL_GREY16<<12);
/*設置LCD的垂直尺寸為240,水平尺寸為320,水平線掃描空間時間為10MCLK*/
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
/*rLCDSADDR1~3為幀緩沖區起始地址*/
rLCDSADDR1= (0x2<<27) | ( ((LCD_ACTIVE_BUFFER>>22)<<21 ) | M5D(LCD_ACTIVE_BUFFER>>1));
/*設置:16級灰度,LCDBANK,LCDBASEU*/
rLCDSADDR2= M5D(((LCD_ACTIVE_BUFFER+(SCR_XSIZE*LCD_YSIZE/2))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/4) | ( ((SCR_XSIZE-LCD_XSIZE)/4)<<9 );
// enable,4B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON1=(1)|(1<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL_GREY16<<12);
rBLUELUT=0xfa40;
//Enable LCD Logic and EL back-light.
rPDATE=rPDATE&0x0e;
}
/*清屏(清顯示存儲區)函數*/
void Lcd_Active_Clr(void)
{
INT32U i;
INT32U *pDisp = (INT32U *)LCD_ACTIVE_BUFFER;
for( i = 0; i < (SCR_XSIZE*SCR_YSIZE/2/4); i++ )
{
*pDisp++ = WHITE;
}
}
/*捕獲指定點的顏色*/
INT8U LCD_GetPixel(INT16U usX, INT16U usY)
{
INT8U ucColor;
ucColor = *((INT8U*)(LCD_VIRTUAL_BUFFER + usY*SCR_XSIZE/2 + usX/8*4 + 3 - (usX%8)/2));
ucColor = (ucColor >> ((1-(usX%2))*4)) & 0x0f;
return ucColor;
}
/*清顯示屏(的顯示緩沖區內容)函數*/
void Lcd_Clr(void)
{
INT32U i;
INT32U *pDisp = (INT32U *)LCD_VIRTUAL_BUFFER;
for( i = 0; i < (SCR_XSIZE*SCR_YSIZE/2/4); i++ )
{
*pDisp++ = WHITE;
}
}
/*用指定顏色填充指定的區域(usLeft,usTop,usRight,usBottom :矩形的頂點坐標;ucColor:指定顏色*/
void LcdClrRect(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
{
INT16 i,k,l,m;
INT32U ulColor = (ucColor << 28) | (ucColor << 24) | (ucColor << 20) | (ucColor << 16) |
(ucColor << 12) | (ucColor << 8) | (ucColor << 4) | ucColor;
i = k = l = m = 0;
if( (usRight-usLeft) <= 8 )
{
for( i=usTop; i<=usBottom; i++)
{
for( m=usLeft; m<=usRight; m++)
{
LCD_PutPixel(m, i, ucColor);
}
}
return;
}
/* 檢查邊界線 */
if( 0 == (usLeft%8) )
k=usLeft;
else
{
k=(usLeft/8)*8+8;
}
if( 0 == (usRight%8) )
l= usRight;
else
{
l=(usRight/8)*8;
}
for( i=usTop; i<=usBottom; i++ )
{
for( m=usLeft; m<=(k-1); m++ )
{
LCD_PutPixel(m, i, ucColor);
}
for( m=k; m<l; m+=8 )
{
(*(INT32U*)(LCD_VIRTUAL_BUFFER + i * SCR_XSIZE / 2 + m / 2)) = ulColor;
}
for( m=l; m<=usRight; m++ )
{
LCD_PutPixel(m, i, ucColor);
}
}
}
/*用指定顏色畫矩形(usLeft,usTop,usRight,usBottom :矩形的頂點坐標;ucColor:指定顏色*/
void Lcd_Draw_Box(INT16 usLeft, INT16 usTop, INT16 usRight, INT16 usBottom, INT8U ucColor)
{
Lcd_Draw_HLine(usLeft, usRight, usTop, ucColor, 1);
Lcd_Draw_HLine(usLeft, usRight, usBottom, ucColor, 1);
Lcd_Draw_VLine(usTop, usBottom, usLeft, ucColor, 1);
Lcd_Draw_VLine(usTop, usBottom, usRight, ucColor, 1);
}
/*用指定顏色畫直線(usX0,usY0 :線起點坐標;usX1,usY1: 線終點坐標;*/
/*ucColor:指定顏色, usWidth:線的寬度*/
void Lcd_Draw_Line(INT16 usX0, INT16 usY0, INT16 usX1, INT16 usY1, INT8U ucColor, INT16U usWidth)
{
INT16 usDx;
INT16 usDy;
INT16 y_sign;
INT16 x_sign;
INT16 decision;
INT16 wCurx, wCury, wNextx, wNexty, wpy, wpx;
if( usY0 == usY1 )
{
Lcd_Draw_HLine (usX0, usX1, usY0, ucColor, usWidth);
return;
}
if( usX0 == usX1 )
{
Lcd_Draw_VLine (usY0, usY1, usX0, ucColor, usWidth);
return;
}
usDx = abs(usX0 - usX1);
usDy = abs(usY0 - usY1);
if( ((usDx >= usDy && (usX0 > usX1)) ||
((usDy > usDx) && (usY0 > usY1))) )
{
GUISWAP(usX1, usX0);
GUISWAP(usY1, usY0);
}
y_sign = (usY1 - usY0) / usDy;
x_sign = (usX1 - usX0) / usDx;
if( usDx >= usDy )
{
for( wCurx = usX0, wCury = usY0, wNextx = usX1,
wNexty = usY1, decision = (usDx >> 1);
wCurx <= wNextx; wCurx++, wNextx--, decision += usDy )
{
if( decision >= usDx )
{
decision -= usDx;
wCury += y_sign;
wNexty -= y_sign;
}
for( wpy = wCury - usWidth / 2;
wpy <= wCury + usWidth / 2; wpy++ )
{
LCD_PutPixel(wCurx, wpy, ucColor);
}
for( wpy = wNexty - usWidth / 2;
wpy <= wNexty + usWidth / 2; wpy++ )
{
LCD_PutPixel(wNextx, wpy, ucColor);
}
}
}
else
{
for( wCurx = usX0, wCury = usY0, wNextx = usX1,
wNexty = usY1, decision = (usDy >> 1);
wCury <= wNexty; wCury++, wNexty--, decision += usDx )
{
if( decision >= usDy )
{
decision -= usDy;
wCurx += x_sign;
wNextx -= x_sign;
}
for( wpx = wCurx - usWidth / 2;
wpx <= wCurx + usWidth / 2; wpx++ )
{
LCD_PutPixel(wpx, wCury, ucColor);
}
for( wpx = wNextx - usWidth / 2;
wpx <= wNextx + usWidth / 2; wpx++ )
{
LCD_PutPixel(wpx, wNexty, ucColor);
}
}
}
}
/*畫線函數反復調用像素控制函數得到水平線或垂直線.
/*畫水平線*/
void Lcd_Draw_HLine(INT16 usX0, INT16 usX1, INT16 usY0, INT8U ucColor, INT16U usWidth)
{
INT16 usLen;
if( usX1 < usX0 )
{
GUISWAP (usX1, usX0);
}
while( (usWidth--) > 0 )
{
usLen = usX1 - usX0 + 1;
while( (usLen--) > 0 )
{
LCD_PutPixel(usX0 + usLen, usY0, ucColor);
}
usY0++;
}
}
/*畫垂直線*/
void Lcd_Draw_VLine (INT16 usY0, INT16 usY1, INT16 usX0, INT8U ucColor, INT16U usWidth)
{
INT16 usLen;
if( usY1 < usY0 )
{
GUISWAP (usY1, usY0);
}
while( (usWidth--) > 0 )
{
usLen = usY1 - usY0 + 1;
while( (usLen--) > 0 )
{
LCD_PutPixel(usX0, usY0 + usLen, ucColor);
}
usX0++;
}
}
/*顯示8x16 ASCII字符串*/
void Lcd_DspAscII8x16(INT16U x0, INT16U y0, INT8U ForeColor, INT8U * s)
{
INT16 i,j,k,x,y,xx;
INT8U qm;
INT32U ulOffset;
INT8 ywbuf[16],temp[2];
for( i = 0; i < strlen((const char*)s); i++ )
{
if( (INT8U)*(s+i) >= 161 )
{
temp[0] = *(s + i);
temp[1] = '\0';
return;
}
else
{
qm = *(s+i);
ulOffset = (INT32U)(qm) * 16; //Here to be changed tomorrow
for( j = 0; j < 16; j ++ )
{
ywbuf[j] = g_auc_Ascii8x16[ulOffset + j];
}
for( y = 0; y < 16; y++ )
{
for( x = 0; x < 8; x++ )
{
k = x % 8;
if( ywbuf[y] & (0x80 >> k) )
{
xx = x0 + x + i*8;
LCD_PutPixel(xx, y + y0, (INT8U)ForeColor);
}
}
}
}
}
}
/*顯示6x8 ASCII字符串*/
void Lcd_DspAscII6x8(INT16U usX0, INT16U usY0,INT8U ForeColor, INT8U* pucChar)
{
INT32U i,j;
INT8U ucTemp;
while( *pucChar != 0 )
{
for( i=0; i < 8; i++ )
{
ucTemp = g_auc_Ascii6x8[(*pucChar) * 8 + i];
for( j = 0; j < 8; j++ )
{
if( (ucTemp & (0x80 >> j)) != 0 )
{
LCD_PutPixel(usX0 + i, usY0 + 8 - j, (INT8U)ForeColor);
}
}
}
usX0 += XWIDTH;
pucChar++;
}
}
#ifndef Eng_v
/*顯示漢字字符串*/
extern const INT8U g_auc_HZK16[];
void Lcd_DspHz16(INT16U x0, INT16U y0, INT8U ForeColor, INT8U *s)
{
INT16 i,j,k,x,y,xx;
INT8U qm,wm;
INT32U ulOffset;
INT8 hzbuf[32],temp[2];
for( i = 0; i < strlen((const char*)s); i++ )
{
if( ((INT8U)(*(s+i))) < 161 )
{
temp[0] = *(s+i);
temp[1] = '\0';
break;
}
else
{
qm = *(s+i) - 161;
wm = *(s + i + 1) - 161;
ulOffset = (INT32U)(qm * 94 + wm) * 32;
for( j = 0; j < 32; j ++ )
{
hzbuf[j] = g_auc_HZK16[ulOffset + j];
}
for( y = 0; y < 16; y++ )
{
for( x = 0; x < 16; x++ )
{
k = x % 8;
if( hzbuf[y * 2 + x / 8] & (0x80 >> k) )
{
xx = x0 + x + i * 8;
LCD_PutPixel( xx, y + y0, (INT8U)ForeColor);
}
}
}
i++;
}
}
}
#endif
/*********************************************************************************************
* name: ReverseLine()
* func: Reverse display some lines
* para: ulHeight -- line's height
* ulY -- line's Y-coordinate
* ret: none
* modify:
* comment:
*********************************************************************************************/
void ReverseLine(INT32U ulHeight, INT32U ulY)
{
INT32U i, j, temp;
for( i = 0; i < ulHeight; i++ )
{
for( j = 0; j < (SCR_XSIZE/4/2) ; j++ )
{
temp = *(INT32U*)(LCD_VIRTUAL_BUFFER + (ulY+i)*SCR_XSIZE/2 + j*4);
temp ^= 0xFFFFFFFF;
*(INT32U*)(LCD_VIRTUAL_BUFFER + (ulY+i)*SCR_XSIZE/2 + j*4) = temp;
}
}
}
/*dma中斷句柄函數*/
static INT8U ucZdma0Done=1; //當DMA傳送完成,ucZdma0Done被清零
void Zdma0Done(void)
{
rI_ISPC=BIT_ZDMA0; //清
ucZdma0Done=0;
}
/*使用dma傳送顯示緩沖區內容到顯示存儲區*/
void Lcd_Dma_Trans(void)
{
INT8U err;
ucZdma0Done=1;
//#define LCD_VIRTUAL_BUFFER (0xc400000)
//#define LCD_ACTIVE_BUFFER (LCD_VIRTUAL_BUFFER+(SCR_XSIZE*SCR_YSIZE/2)) //DMA ON
//#define LCD_ACTIVE_BUFFER LCD_VIRTUAL_BUFFER //DMA OFF
//#define LCD_BUF_SIZE (SCR_XSIZE*SCR_YSIZE/2)
//So the Lcd Buffer Low area is from LCD_VIRTUAL_BUFFER to (LCD_ACTIVE_BUFFER+(SCR_XSIZE*SCR_YSIZE/2))
rNCACHBE1=(((unsigned)(LCD_ACTIVE_BUFFER)>>12) <<16 )|((unsigned)(LCD_VIRTUAL_BUFFER)>>12);
rZDISRC0=(DW<<30)|(1<<28)|LCD_VIRTUAL_BUFFER; // inc
rZDIDES0=( 2<<30) |(1<<28)|LCD_ACTIVE_BUFFER; // inc
rZDICNT0=( 2<<28)|(1<<26)|(3<<22)|(0<<20)|(LCD_BUF_SIZE);
// | | | | |------->0 = Disable DMA
// | | | |---------------->Int. whenever transferred
// | | |------------------------->Write time on the fly
// | |--------------------------------->Block(4-word) transfer mode
// |----------------------------------------->whole service
//reEnable ZDMA transfer
rZDICNT0 |= (1<<20); //after ES3
rZDCON0=0x1; // start!!!
Delay(500);
//while(ucZdma0Done); //wait for DMA finish
}
/*LCD測試函數*/
void Lcd_Test(void)
{
Lcd_Init(); /* 初始化LCD控制器*/
Lcd_Clr(); /* 清顯示緩沖區*/
Lcd_Active_Clr(); /* 清顯示存儲區*/
#ifdef Eng_v // 如果是英文版
Lcd_DspAscII8x16(10,0,DARKGRAY,"This is BinBin.Jin's graduation design");
#else
Lcd_DspHz16(10,0,DARKGRAY,"這是姚家興畢業設計");
#endif
Lcd_DspAscII8x16(10,20,BLACK,"Hangzhou [gongshang] university");
Lcd_Draw_Box(10,40,310,230,14); /* 畫矩形,共12個 */
Lcd_Draw_Box(20,45,300,225,13);
Lcd_Draw_Box(30,50,290,220,12);
Lcd_Draw_Box(40,55,280,215,11);
Lcd_Draw_Box(50,60,270,210,10);
Lcd_Draw_Box(60,65,260,205,9);
Lcd_Draw_Box(70,70,250,200,8);
Lcd_Draw_Box(80,75,240,195,7);
Lcd_Draw_Box(90,80,230,190,6);
Lcd_Draw_Box(100,85,220,185,5);
Lcd_Draw_Box(110,90,210,180,4);
Lcd_Draw_Box(120,95,200,175,3);
BitmapView(125,135,Stru_Bitmap_gbMouse); /*畫位圖,在BMP.C中,為一個光標指針的位圖 */
Lcd_Dma_Trans(); /*用DMA傳送顯示緩沖區內容到顯示存儲區 */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -