📄 lcd.c
字号:
/*
*************************************************************************
* Copyright (c) 2003, The Lab of Embedded System and Net Security,WHUT..
* All rights reserved.
*
* Filename: lcd.c
* Discription: This file drives lcd
*
* version: 1.0
* Author: Qiu Yanfei <qyfhm@tom.com>
* Accomplished Date: 2004/7/28 19:55:00
*************************************************************************
*/
#include <stdarg.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include "..\cpu\44breg.h"
#define LCD_GLOBALS
#include "lcd.h"
/*
****************************************************************
* function name: void Lcd_Init(void)
* input: Null
* output: Null
* description: initialize lcd controller
* global variant:NULL
* ******************************************************************
*/
void Lcd_Init (void)
{
rLCDCON1=(0x0)|(DISMODE<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL<<12);
// disable,8B_SNGL_SCAN,WDLY=8clk,WLH=8clk,
rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);
//LINEBLANK=10 (without any calculation)
rLCDSADDR1= (MODESEL<<27) | ( ((unsigned int)aLcdActiveBuffer>>22)<<21 ) | M5D((unsigned int)aLcdActiveBuffer>>1);
// 256-color, LCDBANK, LCDBASEU
#ifdef COLOR_LCD
rLCDSADDR2= M5D((((unsigned int)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE))>>1)) | (MVAL<<21);
rLCDSADDR3= (LCD_XSIZE/2) | ( ((SCR_XSIZE-LCD_XSIZE)/2)<<9 );
//The following value has to be changed for better display.
rREDLUT =0xfdb96420;
rGREENLUT=0xfdb96420;
rBLUELUT =0xfb40;
rDITHMODE=0x0;
rDP1_2 =0xa5a5;
rDP4_7 =0xba5da65;
rDP3_5 =0xa5a5f;
rDP2_3 =0xd6b;
rDP5_7 =0xeb7b5ed;
rDP3_4 =0x7dbe;
rDP4_5 =0x7ebdf;
rDP6_7 =0x7fdfbfe;
rLCDCON1=(0x1)|(2<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL<<12);
rPDATE=0xfe;
#else
rLCDSADDR2 = M5D( (((U32)aLcdActiveBuffer+(SCR_XSIZE*LCD_YSIZE/8))>>1) ) | (MVAL<<21);
rLCDSADDR3 = (LCD_XSIZE/16) | ( ((SCR_XSIZE-LCD_XSIZE)/16)<<9 );
#endif /*COLOR_LCD*/
rLCDCON1=(0x1)|(DISMODE<<5)|(MVAL_USED<<7)|(0x3<<8)|(0x3<<10)|(CLKVAL<<12);
rPDATE=0xfe;
Lcd_Clr();
}
/*
******************************************************************
* function name: void Lcd_Clr(void)
* input: Null
* output: Null
* description: clear lcd screen* global variant:Null
******************************************************************
*/
void Lcd_Clr(void)
{
U32 i;
U32 *pDisp = (U32*)aLcdActiveBuffer;
#ifdef COLOR_LCD
for (i = 0; i < (SCR_XSIZE * SCR_YSIZE / 4); i++)
{
*pDisp++ = ALLBLUE;//ALLWHITE;//ALLBLACK;
}
#else
for (i = 0; i < (SCR_XSIZE * SCR_YSIZE / 32); i++)
{
*pDisp++ = WHITE; //ALLBLUE;//ALLWHITE;//ALLBLACK;
}
#endif /* COLOR_LCD */
}
/*
*****************************************************************
* function name:void Lcd_Draw_Box(INT16U usLeft,INT16U usTop,INT16U usRight,INT16U usBottom,INT8U ucColor)
* input: INT16U usLeft,usTop,usRight,usBottom: corner coordinate of the rectangle
* INT8U ucColor: line color
* output: Null
* description: draw a rectangle in specified color
* global variant:Null
*****************************************************************
*/
void Lcd_Draw_Box (U16 usLeft, U16 usTop, U16 usRight, U16 usBottom, U8 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);
}
/*
*******************************************************************************************************
* function name:void Lcd_Draw_Line(INT16U usX0,INT16U usY0,INT16U usX1,INT16U usY1,INT8U ucColor, INT16U usWidth)
* input: INT16U usX0,usX1,usY0,usY1: start and end point coordinate.
* INT8U ucColor: line color
* INT16U usWidth: line width
* output: Null
* description: draw a line in specified color
* global variant:Null
*********************************************************************************************************
*/
void Lcd_Draw_Line (U16 usX0, U16 usY0, U16 usX1, U16 usY1, U8 ucColor, U16 usWidth)
{
U16 usDx;
U16 usDy;
U16 y_sign;
U16 x_sign;
U16 decision;
U16 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);
}
}
}
}
/*
********************************************************************************************************
* function name: void Lcd_Draw_HLine(INT16U usX0,INT16U usY0,INT16U usX1,INT16U usY1,INT8U ucColor, INT16U usWidth)
* input: INT16U usX0,usX1,usY0,usY1: start and end point coordinate.
* INT8U ucColor: line color
* INT16U usWidth: line width
* output: Null
* description: draw a horizontal line with a specified color.
* global variant:Null
*********************************************************************************************************
*/
void Lcd_Draw_HLine (U16 usX0, U16 usX1, U16 usY0, U8 ucColor, U16 usWidth)
{
U16 usLen;
if (usX1 < usX0)
{
GUISWAP (usX1, usX0);
}
while(usWidth-- > 0)
{
usLen = usX1 - usX0 + 1;
while(usLen-- > 0)
{
LCD_PutPixel(usX0 + usLen, usY0, ucColor);
}
usY0++;
}
}
/********************************************************************************************************
* function name:void Lcd_Draw_VLine(INT16U usX0,INT16U usY0,INT16U usX1,INT16U usY1,INT8U ucColor, INT16U usWidth)
* input: INT16U usX0,usX1,usY0,usY1:start and end point coordinate.
* INT8U ucColor: line color
* INT16U usWidth: line width
* output: Null
* description:draw a vertical line with a specified color.
* global variant:Null
*********************************************************************************************************
*/
void Lcd_Draw_VLine (U16 usY0, U16 usY1, U16 usX0, U8 ucColor, U16 usWidth)
{
U16 usLen;
if (usY1 < usY0)
{
GUISWAP (usY1, usY0);
}
while(usWidth-- > 0)
{
usLen = usY1 - usY0 + 1;
while(usLen-- > 0)
{
LCD_PutPixel(usX0, usY0 + usLen, ucColor);
}
usX0++;
}
}
/*
***************************************************************
* function name: void Lcd_Fill_Box(INT16U usX0,INT16U usY0,INT16U usX1,INT16U usY1,INT8U ucColor)
* input: INT16U usX0,usX1,usY0,usY1: corner coordinate of the rectangle
* INT8U ucColor: filled color
* output: Null
* description: fill a area with specified color used for part screen clear.
* LcdClrRect() is recommended with high efficiency.
* global variant:Null
*****************************************************************
*/
void Lcd_Fill_Box (U16 usX0, U16 usY0, U16 usX1, U16 usY1, U8 ucColor)
{
U16 i;
U16 j;
if (usX0 > usX1)
{
GUISWAP(usX0, usX1);
GUISWAP(usY0, usY1);
}
for (i = usX0; i <= usX1; i++)
{
if (usY0 <= usY1)
{
for (j = usY0; j <= usY1; j++)
{
LCD_PutPixel(i, j, ucColor);
}
}
else
{
for (j = usY0; j >= usY1; j--)
{
LCD_PutPixel(i, j, ucColor);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -