?? st7529.c
字號:
/*
注意:
1 我是用16灰度的例子修改而成的,而在實際應用中只用到了5個灰度,故在用前景色畫圖時,
我是把0~15的索引值轉換為我要用到的5個灰度.
2 我是用一個16位數畫3個點的模式的,如果用其他模式的需要修改部分代碼.
3 在畫位圖的4個函數中,我只優化了畫8位那個,1,2,4位的還未優化
*/
#include <string.h> /* for memset */
#include <stddef.h> /* needed for definition of NULL */
#include "LCD_Private.h" /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "config.h"
#include "LCDConf_7529.h"
#ifndef LCDCONF_H
#define LCDCONF_H
#endif
#define UART_BPS 115200 // 定義通訊波特率
#define TRUE 1
#define FALSE 0
#define WIN32 1
#define LCD_OPTIMIZE 0
#define PixelIndex uint8
#define LOG2PHYS(x,y) x,y
#define SETPIXEL(x, y, c) _SetPixel(x, y, c)
#define GETPIXEL(x, y) _GetPixel(x,y)
#define XORPIXEL(x, y) XorPixel(x,y)
#define LCD_ON() LCD_WRITE_A1(0xAF)
#define LCD_OFF() LCD_WRITE_A1(0xAE)
uint16 ScanBuff[LCD_YSIZE][LCD_XSIZE/3+1]; //用作顯示緩存,使得不用從液晶控制器讀回數據
void UART0_Init(void)
{
uint16 Fdiv;
U0LCR = 0x83; // DLAB = 1,可設置波特率
Fdiv = (Fpclk / 16) / UART_BPS; // 設置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03;
}
void UART0_SendByte(uint8 data)
{
U0THR = data; // 發送數據
while( (U0LSR&0x40)==0 ); // 等待數據發送完畢
}
void UART0_SendStr(INT8U const *str)
{
while(1)
{
if( *str == '\0' ) break;
UART0_SendByte(*str++); // 發送數據
}
}
void OutPutOneByte(INT8U i)
{
if(i/16>9)UART0_SendByte(i/16+55);
else UART0_SendByte(i/16+48);
if(i%16>9)UART0_SendByte(i%16+55);
else UART0_SendByte(i%16+48);
}
/*********************************************************************
*
* Initialisation macro
*
**********************************************************************
*/
void LCD_WRITE_A0(uint16 dat)
{
LCDDAT = dat;
}
void LCD_WRITE_A1(uint16 dat)
{
LCDCOM = dat;
}
int LCD_READ_A0(void)
{
uint16 dat;
dat = LCDDAT;
return dat;
}
/*******************************************************
* 名稱: DelaymS
* 功能: 軟件延時(1mS,與系統時鐘有關)。
* 入口參數: no 延時控制(uint32),值越大延時越長
* 出口參數: 無
*******************************************************/
void DelaymS(uint32 no)
{ uint32 i;
for(; no>0; no--)
{
for(i=0; i<500; i++);
}
}
/*******************************************************
* 名稱: LcdSetAddr
* 功能: 設置數據地址指針(坐標值)。
* 入口參數: x1 起始橫坐標的值 (0-158)
* y1 起始縱坐標的值 (0-158)
* x2 結束橫坐標的值 (1-159)
* y2 結束縱坐標的值 (1-159)
* 出口參數: 設置正確返回TRUE,參數超出范圍返回FALSE
*******************************************************/
uint8 LcdSetAddr(uint16 x1, uint16 y1, uint16 x2, uint16 y2)
{
LCD_WRITE_A1(LASET); // 設置地址高8位
LCD_WRITE_A0(y1);
LCD_WRITE_A0(y2);
LCD_WRITE_A1(CASET); // 設置地址低8位
LCD_WRITE_A0(x1/3);
LCD_WRITE_A0(x2/3);
if((x2<160) && (y2<160)) return(TRUE);
else return(FALSE);
}
/*******************************************************
* 名稱: LcdSetWrite
* 功能: 設置數據地址指針(坐標值),并發送寫數據命令。
* 接著不斷的寫入數據即可,GRAM地址會自動增加。
* 入口參數: x 橫坐標的值 (0-159)
* y 縱坐標的值 (0-159)
* 出口參數: 設置正確返回TRUE,參數超出范圍返回FALSE
*******************************************************/
uint8 LcdSetWrite(uint16 x1, uint16 y1, uint16 x2, uint16 y2)
{
uint8 ret;
ret = LcdSetAddr(x1, y1, x2, y2);
LCD_WRITE_A1(RAMWR); // 寫數據
return(ret);
}
/*******************************************************
* 名稱: ReadEEPROM
* 功能: 讀取EEPROM數據。
* 入口參數: 無
* 出口參數: 無
*******************************************************/
void ReadEEPROM(void)
{
LCDCOM = ExtIn;
LCDCOM = EPINT;
LCDDAT = 0x0019;
LCDCOM = ExtOut;
LCDCOM = EPCTIN;
LCDDAT = 0x0000;
DelaymS(100);//100ms
LCDCOM = EPMRD;
DelaymS(100);//100ms
LCDCOM = EPCOUT;
LCDCOM = ExtIn;
}
/*******************************************************
* 名稱: LCD_INIT_CONTROLLER
* 功能: 初始化液晶模塊。
* 入口參數: 無
* 出口參數: 無
*******************************************************/
void LCD_INIT_CONTROLLER()
{
U8 i, j;
UART0_Init();
LCDCOM = ExtIn;
LCDCOM = SLPOUT; //SLEEP OUT
LCDCOM = OSCON; //OSC ON
LCDCOM = PWRCTRL; //POWER CONTROL SET
LCDDAT = 0x0008;
DelaymS(1); //1MS
LCDCOM = PWRCTRL;
LCDDAT = 0x000B;
LCDCOM = VOLCTRL; //ELECTRONIC CONTROL
LCDDAT = 0x0000;
LCDDAT = 0x0005;
LCDCOM = DISCTRL; //DISPALY CONTROL
LCDDAT = 0x0000;
LCDDAT = 0x0027;
LCDDAT = 0x0000;
LCDCOM = DISNOR; //NORMAL DISPALY
LCDCOM = COMSCN; //COM SCAN DIRECTION
LCDDAT = 0x0001;
LCDCOM = DATSDR; //DATA SCAN DIRECTION
LCDDAT = 0x0001;
LCDDAT = 0x0000;
LCDDAT = 0x0001;
LCDCOM = LASET; //LINE ADDRESS SET
LCDDAT = 0x0000;
LCDDAT = 0x009F;
LCDCOM = CASET; //COLUMN ADDRESS SET
LCDDAT = 0x0000;
LCDDAT = 0x0036;
LCDCOM = ExtOut;
LCDCOM = ANASET; //ANALOG CIRCUIT SET
LCDDAT = 0x0000;
LCDDAT = 0x0002;
LCDDAT = 0x0001;
LCDCOM = SWINT; //SOFTWARE INITIAL
ReadEEPROM(); //READ EEPROM FLOW
LCDCOM = ExtIn;
LCDCOM = DISON; //DISPLAY ON
for(i=0;i<LCD_YSIZE;i++) //初始化顯示緩沖區,0xffff為全白色
{
for(j=0;j<LCD_XSIZE/3+1;j++)
ScanBuff[i][j] = 0xffff;
}
}
/***************************************************************************************/
void _SetPixel(int x, int y, LCD_PIXELINDEX c) //畫點函數
{
uint8 colour;
uint16 temp = ScanBuff[y][x/3]; //根據上層傳過來的灰度索引參數C轉換為液晶相應的灰度
if(c == 0)colour = 0; //索引值轉換
else if((c > 0) && (c <= 5))colour = 0x08;
else if((c > 5) && (c <= 10))colour = 0x10;
else if((c > 10) && (c < 15))colour = 0x18;
else colour = 0x1f;
switch(x%3)
{
case 0:ScanBuff[y][x/3] = (temp & 0x07ff) | (uint16)(colour << 11);break;
case 1:ScanBuff[y][x/3] = (temp & 0xf83f) | (uint16)(colour << 6);break;
case 2:ScanBuff[y][x/3] = (temp & 0xffc0) | (colour);break;
default:break;
}
LcdSetWrite( x, y, x+3, y+1);
LCD_WRITE_A0(ScanBuff[y][x/3]);
}
/***************************************************************************************/
unsigned int _GetPixel(int x, int y) //取點函數
{
int temp = ScanBuff[y][x/3];
switch(x%3)
{
case 0:temp = ((temp & 0xf800) >> 11);break;
case 1:temp = ((temp & 0x07c0) >> 6);break;
case 2:temp = (temp & 0x001f);break;
default:break;
}
return (uint8)temp;
}
/***************************************************************************************/
void XorPixel(int x, int y) //異或函數
{
uint16 temp1, temp = ScanBuff[y][x/3];
switch(x%3)
{
case 0:temp1 = ((temp & 0xf800) >> 11);break;
case 1:temp1 = ((temp & 0x07c0) >> 6);break;
case 2:temp1 = (temp & 0x001f);break;
default:break;
}
temp1 = 0x1f - temp1;
switch(x%3)
{
case 0:temp = ((temp & 0x07ff) | (temp1 << 11));break;
case 1:temp = ((temp & 0xf83f) | (temp1 << 6));break;
case 2:temp = ((temp & 0xffe0) | temp1);break;
default:break;
}
ScanBuff[y][x/3] = temp;
LcdSetWrite( x, y, x+3, y+1);
LCD_WRITE_A0(temp);
}
/***************************************************************************************/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex) //上層調用的畫點函數
{
SETPIXEL(x, y, PixelIndex);
}
/***************************************************************************************/
unsigned int LCD_L0_GetPixelIndex(int x, int y) //上層調用的取點函數
{
unsigned int temp;
temp = GETPIXEL(x, y);
return (temp);
}
/***************************************************************************************/
void LCD_L0_XorPixel(int x, int y) //上層調用的異或函數
{
XORPIXEL(x, y);
}
/***************************************************************************************/
uint16 Xor_Pixel(uint16 Pixel) //異或三個點(16位)的子函數
{
uint8 P0,P1,P2;
P0 = 0x1f - ((Pixel & 0xf800) >> 11);
P1 = 0x1f - ((Pixel & 0x07c0) >> 6);
P2 = 0x1f - (Pixel & 0x001f);
return ((P0 << 11) | (P1 << 6) | P2);
}
/***************************************************************************************/
void LCD_L0_DrawHLine (int x0, int y, int x1) //上層調用的畫橫線函數
{
uint8 remainder_x0 = x0%3;
uint8 remainder_x1 = x1%3;
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) //反轉模式
{
uint16 temp;
uint8 i, P1, P2;
if((remainder_x0 == 0) && (remainder_x1 == 2)) //開始和結束的像素都是3的倍數
{
while (x0 <= x1)
{
ScanBuff[y][x0/3] = Xor_Pixel(ScanBuff[y][x0/3]);
x0+=3;
}
LCDCOM = ExtIn;
LcdSetWrite( x0, y, x1, y+1);
for(i = x0; i < x1; i+=3)
LCD_WRITE_A0(ScanBuff[y][i/3]);
}
else if((remainder_x0 != 0) && (remainder_x1 == 2)) //開始的像素不是3的倍數
{
temp = ScanBuff[y][x0/3];
switch(remainder_x0)
{
case 1:P1 = 0x1f - ((temp & 0x07c0) >> 6);
P2 = 0x1f - (temp & 0x001f);
ScanBuff[y][x0/3] = (temp & 0xf800) | (P1 << 6) | P2;
break;
case 2:P2 = 0x1f - (temp & 0x001f);
ScanBuff[y][x0/3] = (temp & 0xffc0) | P2;
break;
default:break;
}
while ((x0 + 3) <= x1)
{
ScanBuff[y][x0/3 + 1] = Xor_Pixel(ScanBuff[y][x0/3]);
x0+=3;
}
LCDCOM = ExtIn;
LcdSetWrite( x0, y, x1, y+1);
for(i = x0; i < x1; i+=3)
LCD_WRITE_A0(ScanBuff[y][i/3]);
}
else if((remainder_x0 == 0) && (remainder_x1 != 2)) //結束的像素不是3的倍數
{
temp = ScanBuff[y][x1/3];
switch(remainder_x1)
{
case 0:P1 = 0x1f - ((temp & 0xf800) >> 11);
ScanBuff[y][x1/3] = (temp &0x07ff) | (P1 << 11);
break;
case 1:P1 = 0x1f - ((temp & 0xf800) >> 11);
P2 = 0x1f - (temp & 0x07c0 >> 6);
ScanBuff[y][x1/3] = (temp & 0x001f) | (P1 << 11) | (P2 << 6);
break;
default:break;
}
while (x0 <= (x1 - 3))
{
ScanBuff[y][x0/3] = Xor_Pixel(ScanBuff[y][x0/3 - 1]);
x0+=3;
}
LCDCOM = ExtIn;
LcdSetWrite( x0, y, x1, y+1);
for(i = x0; i < x1; i+=3)
LCD_WRITE_A0(ScanBuff[y][i/3]);
}
else //開始和結束的像素不都是3的倍數
{
temp = ScanBuff[y][x0/3];
switch(remainder_x0)
{
case 1:P1 = 0x1f - ((temp & 0x07c0) >> 6);
P2 = 0x1f - (temp & 0x001f);
ScanBuff[y][x0/3] = (temp & 0xf800) | (P1 << 6) | P2;
break;
case 2:P2 = 0x1f - (temp & 0x001f);
ScanBuff[y][x0/3] = (temp & 0xffc0) | P2;
break;
default:break;
}
temp = ScanBuff[y][x1/3];
switch(remainder_x1)
{
case 0:P1 = 0x1f - ((temp & 0xf800) >> 11);
ScanBuff[y][x1/3] = (temp &0x07ff) | (P1 << 11);
break;
case 1:P1 = 0x1f - ((temp & 0xf800) >> 11);
P2 = 0x1f - (temp & 0x07c0 >> 6);
ScanBuff[y][x1/3] = (temp & 0x001f) | (P1 << 11) | (P2 << 6);
break;
default:break;
}
while ((x0 + 3) <= (x1 - 3))
{
ScanBuff[y][x0/3 + 1] = Xor_Pixel(ScanBuff[y][x0/3 - 1]);
x0+=3;
}
LCDCOM = ExtIn;
LcdSetWrite( x0, y, x1, y+1);
for(i = x0; i < x1; i+=3)
LCD_WRITE_A0(ScanBuff[y][i/3]);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -