"); //-->
/*
*********************************************************************************************************
* 礐/GUI
* Universal graphic software for embedded applications
*
* (c) Copyright 2002, Micrium Inc., Weston, FL
* (c) Copyright 2000, SEGGER Microcontroller Systeme GmbH
*
* 礐/GUI is protected by international copyright laws. Knowledge of the
* source code may not be used to write a similar product. This file may
* only be used in accordance with a license and should not be redistributed
* in any way. We appreciate your understanding and fairness.
*
* File : LCD_X_8080.c
* Purpose : Port routines
*
* Hardware configuration
* Needs to be adopted to your target hardware.
*********************************************************************************************************
*/
/*
**********************************************************************
----------------------------------------------------------------------
File : LCDConf.h
Purpose : SSD1289 LCD控制器的头文件,以8080并行连接方式
Data : 2010-1-7 21:21
----------------------------------------------------------------------
**********************************************************************
*/
#include <stddef.h> /* needed for definition of NULL */
#include "LCD_Private.H" /* private modul definitions & config */
#include "GUI_Private.H"
#include "GUIDebug.h"
#include "LCDConf.h"
//#include "LCD_0.h" /* Defines for first display */
/**********************************include*****************************************************/
//******************************************************************************/
#include"system.h"
#include"string.h"
#include "alt_types.h"
#include "altera_avalon_pio_regs.h"
#if (LCD_CONTROLLER == 1289 ) \
&& (!defined(WIN32) | defined(LCD_SIMCONTROLLER))
/***************************************The start *******************************************/
//LCD数据读写端口定义
//与硬件相关(都为模拟时序)
// FPGA平台
//*********************************PIO define****************************************************
static volatile alt_u16 DQ_DIR =0 ;// IORD_ALTERA_AVALON_PIO_DIRECTION( RGB_DQ16_BASE ) ;
#define DAT16_DIR_OUT IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,DQ_DIR = 0xffff) //端口数据方向 --定义为输出
#define DAT16_DIR_IN IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,DQ_DIR = 0x0000 ) //端口数据方向 --定义为输入
#define DAT16_WRITE(data16) IOWR_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE,data16);
#define DAT16_READ IORD_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE)
#define CS 0x01 // BIT0
#define RS 0x02 // BIT1
#define WR 0x04 // BIT2
#define RD 0x08 // BIT3
#define RESET 1//BIT4
#define EN 1//BIT5 //
static volatile alt_u8 CONTROL4 = 0 ;
#define CS_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|CS)
#define RS_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|RS)
#define WR_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|WR)
#define RD_SET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4|RD)
#define CS_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~CS))
#define RS_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~RS))
#define WR_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~WR))
#define RD_RSET IOWR_ALTERA_AVALON_PIO_DATA(CONTROL4_BASE,CONTROL4=CONTROL4&(~RD))
#define LCD_RESET_H IOWR_ALTERA_AVALON_PIO_DATA(LCD_RESET_BASE,1)
#define LCD_RESET_L IOWR_ALTERA_AVALON_PIO_DATA(LCD_RESET_BASE,0)
#define LCD_backlight_on IOWR_ALTERA_AVALON_PIO_DATA( LIGH_EN_BASE,1)
#define LCD_backlight_off IOWR_ALTERA_AVALON_PIO_DATA( LIGH_EN_BASE,0)
//***************************************************************************************/
//底层数据读写时序
/**********************端口相关*********************************************************/
//端口读取16位数据
//***************************begin***************************************************/
alt_u16 READ_DATA16( )
{
if(DQ_DIR != 0x0000) //DQ_DIR == 0x0000 时为输入状态
{
DAT16_DIR_IN ; //端口数据方向 --定义为输入
}
return DAT16_READ ;
}
/*******************************************************************************/
//端口写16位数据
//******************************************************************************/
void WRITE_DATA16( alt_u16 data16 )
{
if(DQ_DIR != 0xffff) //DQ_DIR == 0x0000 时为输入状态
{
DAT16_DIR_OUT ; //端口数据方向 --定义为输入
}
//IOWR_ALTERA_AVALON_PIO_DIRECTION(RGB_DQ16_BASE,0xffff); //端口数据方向 --定义为输出
//IOWR_ALTERA_AVALON_PIO_DATA(RGB_DQ16_BASE,data16); //写16位数据
DAT16_WRITE(data16);
}
#define COLOR LCD_COLORINDEX
#define LCD_DELAY(ms) ; //OSTimeDlyHMSM(0, 0, 0, ms)//GUI_Delay(ms)
//向LCD写数据
//********************************begin*************************************************/
void wr_dat (unsigned int c)
{
CS_SET;
RD_SET;
RS_SET;
WR_SET;
WRITE_DATA16( c);
CS_RSET;
WR_RSET;
}
/*******************************************************************************
* 向LCD 写命令 *
* Parameter: c: command to be written *
* Return: *
*******************************************************************************/
void wr_cmd (unsigned int c)
{
CS_SET;
RD_SET;
WR_SET;
RS_RSET;
WRITE_DATA16( c);
CS_RSET;
WR_RSET;
CS_SET;
}
/*******************************************************************************
* Read data from LCD controller *
* Parameter: *
* Return: read data *
*******************************************************************************/
unsigned int rd_dat (void)
{
unsigned int val = 0;
RS_SET;
WR_SET;
RD_RSET;
val = READ_DATA16() ;
val = READ_DATA16() ;
return val;
}
/*******************************************************************************
* Write to LCD register *
* Parameter: reg: register to be read *
* val: value to write to register *
*******************************************************************************/
void wr_reg (unsigned int reg, unsigned int val)
{
/*
RD_SET;
WR_SET;
CS_SET;
RS_RSET;
*/
wr_cmd(reg);
CS_RSET;
WR_RSET;
WR_SET;
RS_SET;
wr_dat(val);
WR_RSET;
CS_SET;
RD_SET;
WR_SET;
RS_SET;
}
/*******************************************************************************
* Read from LCD register *
* Parameter: reg: register to be read *
* Return: value read from register *
*******************************************************************************/
unsigned int rd_reg (unsigned int reg)
{
CS_RSET;
wr_cmd(reg);
reg = rd_dat();
CS_SET;
return reg;
}
//*****************************the end***********************************************/
/********************************************************
* *
* LCD_L0_SetOrg *
* *
*********************************************************
Purpose: Sets the original position of the virtual display.
Has no function at this point with the PC-driver.
*/
//int OrgX, OrgY;
void LCD_L0_SetOrg(int x, int y)
{
//OrgX = x;
//OrgY = y;
wr_reg(0x4E,x);
wr_reg(0x4F,y);
}
/*
void LCD_L0_SetOrg(int x, int y)
{
GUI_USE_PARA(x);
GUI_USE_PARA(y);
}
*/
/*
*********************************************************
* *
* LCD_On *
* LCD_Off *
* *
*********************************************************
*/
void LCD_L0_On(void)
{
LCD_DELAY(100);
wr_reg(0x07,0x0233);
LCD_DELAY(100);
LCD_backlight_on;
}
void LCD_L0_Off(void)
{
LCD_DELAY(100);
wr_reg(0x07,0x0000);//wr_reg(0x07,0x0173);
LCD_DELAY(100);
LCD_backlight_off;
}
/*
*********************************************************
* *
* LCD_L0_SetLUTEntry *
* *
*********************************************************
*/
void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR color)
{
GUI_USE_PARA(Pos);
GUI_USE_PARA(color);
}
/********************************/
/*液晶屏清屏函数 */
/********************************/
void LCD_Clear(void)
{
unsigned int num = 240*320;
wr_cmd(0x22);
while(num)
{
wr_dat(0);
//LCD_Write_Data(0);
num--;
}
//LCD_Write_End();
}
/*
*********************************************************
* *
* LCD_Init_Controler: Init the display *
* *
*********************************************************
*/
void LCD_Init_Controler()
{
//复位LCD
LCD_RESET_L;
//delay 100ms
LCD_DELAY(100);
LCD_RESET_H;
//delay 10ms
LCD_DELAY(10);
wr_reg(0x0000,0x0001); //打开晶振
wr_reg(0x0003,0xA8A8); //0xA8A4
wr_reg(0x000C,0x0000); //power control
wr_reg(0x000D,0x080C); //power control
wr_reg(0x000E,0x2B00);
wr_reg(0x001E,0x00B0);
wr_reg(0x0001,0x2B3F); //驱动输出控制320*240 0x6B3F
wr_reg(0x0002,0x0600); //LCD Driving Waveform control
wr_reg(0x0010,0x0000);
wr_reg(0x0011,0x6070); //0x4030 //定义数据格式 16位色 横屏 0x6058
wr_reg(0x0005,0x0000);
wr_reg(0x0006,0x0000);
wr_reg(0x0016,0xEF1C);
wr_reg(0x0017,0x0003);
wr_reg(0x0007,0x0233); //0x0233
wr_reg(0x000B,0x0000);
wr_reg(0x000F,0x0000); //扫描开始地址
wr_reg(0x0041,0x0000);
wr_reg(0x0042,0x0000);
wr_reg(0x0048,0x0000);
wr_reg(0x0049,0x013F);
wr_reg(0x004A,0x0000);
wr_reg(0x004B,0x0000);
wr_reg(0x0044,0xEF00);
wr_reg(0x0045,0x0000);
wr_reg(0x0046,0x013F);
wr_reg(0x0030,0x0707);
wr_reg(0x0031,0x0204);
wr_reg(0x0032,0x0204);
wr_reg(0x0033,0x0502);
wr_reg(0x0034,0x0507);
wr_reg(0x0035,0x0204);
wr_reg(0x0036,0x0204);
wr_reg(0x0037,0x0502);
wr_reg(0x003A,0x0302);
wr_reg(0x003B,0x0302);
wr_reg(0x0023,0x0000);
wr_reg(0x0024,0x0000);
wr_reg(0x0025,0xE000);
//LCD_On(); //
//LCD_Clear();//
}
/*
*********************************************************
* *
* LCD_L0_ReInit : Re-Init the display *
* *
*********************************************************
ReInit contains all of the code that can be re-executed at any point without
changing or even disturbing what can be seen on the LCD.
Note that it is also used as a subroutine by LCD_Init().
*/
void LCD_L0_ReInit(void)
{
LCD_Init_Controler(); /* macro defined in config */
}
/*
*********************************************************
* *
* LCD_Init : Init the display *
* *
*********************************************************
*/
int LCD_L0_Init(void)
{
GUI_DEBUG_LOG("\nLCD_Init()");
/* Init controllers (except lookup table) */
// LCD_L0_ReInit();
LCD_Init_Controler();
LCD_On();
return 0; /* Init successfull ! */
}
/*
*********************************************************
* *
* LCD_L0_CheckInit *
* *
* Check if display controller(s) is/are still *
* properly initialized *
* *
*********************************************************
Return value: 0 => No error, init is O.K.
*/
int LCD_L0_CheckInit(void)
{
return 0;
}
/*
*********************************************************
* *
* Internal set pixel routines *
* *
*********************************************************
*/
static void SetPixel(int x, int y, LCD_PIXELINDEX c)
{
wr_reg(0x4E,x);
wr_reg(0x4F,y);
wr_reg(0x22,c);
}
void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex)
{
SetPixel(x, y, ColorIndex);
}
static U32 GetPixelIndex(int x, int y)
{
LCD_PIXELINDEX col;
wr_reg(0x4E,x);
wr_reg(0x4F,y);
col = rd_reg(0x22);
return col;
}
unsigned int LCD_L0_GetPixelIndex(int x, int y)
{
return GetPixelIndex(x,y);
}
/*
* ******************************************************
*/
/*
*********************************************************
* *
* LCD_L0_XorPixel *
* *
*********************************************************
Purpose: This routine is called by emWin. It writes 1 pixel into the
display.
*/
static void XorPixel(int x, int y)
{
LCD_PIXELINDEX Index = GetPixelIndex(x,y);
SetPixel(x,y,LCD_NUM_COLORS-1-Index);
}
void LCD_L0_XorPixel(int x, int y)
{
XorPixel(x, y);
}
/*
*********************************************************
* *
* LCD_L0_DrawHLine optimized *
* *
* 16 bit bus, Using BITBLT *
* *
*********************************************************
*/
void LCD_L0_DrawHLine (int x0, int y, int x1)
{
//wr_reg(0x4E,x0);
//wr_reg(0x4F,y);
LCD_L0_SetOrg(x0 , y);// wr_reg(0x22,c);
wr_cmd(0x0022);
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
while (x0 <= x1)
{
LCD_L0_XorPixel(x0, y);
x0++;
}
}
else
{
while (x0 <= x1)
{
//SetPixel(x0, y, COLOR);
wr_dat( COLOR);
x0++;
}
}
}
/*
*********************************************************
* *
* LCD_L0_DrawVLine optimized *
* *
* 16 bit bus, using BITBLT *
* *
*********************************************************
*/
void LCD_L0_DrawVLine (int x, int y0, int y1)
{
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
while (y0 <= y1)
{
LCD_L0_XorPixel(x, y0);
y0++;
}
}
else
{
while (y0 <= y1)
{
LCD_L0_SetPixelIndex(x, y0, COLOR);
y0++;
}
}
}
/*
*********************************************************
* *
* LCD_FillRect *
* *
*********************************************************
*/
void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
#if !LCD_SWAP_XY
for (; y0 <= y1; y0++)
{
LCD_L0_DrawHLine(x0,y0, x1);
}
#else
for (; x0 <= x1; x0++)
{
LCD_L0_DrawVLine(x0,y0, y1);
}
#endif
}
/*
**********************************************************
* *
* Draw Bitmap 1 BPP *
* *
**********************************************************
*/
static void DrawBitLine1BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
{
// LCD_PIXELINDEX aColor[2];
U16 Pixels = ((*p) << 8) | (*(p + 1));
U8 RemPixels;
p++;
// aColor[0] = *pTrans;
// aColor[1] = *(pTrans + 1);
x += Diff;
RemPixels = 16 - Diff;
Pixels <<= Diff;
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
{
do {
if (RemPixels==0)
{
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000)
{
XorPixel(x, y);
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
else
{
do {
if (RemPixels==0)
{
Pixels = ((*(p + 1)) << 8) | (*(p + 2));
p += 2;
RemPixels = 16;
}
if (Pixels & 0x8000)
{
SetPixel(x, y, *(pTrans+1));
}
RemPixels--;
Pixels <<=1;
x++;
} while (--xsize);
}
}
/*
*********************************************
* *
* Draw Bitmap 2 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 2)
static void DrawBitLine2BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
{
LCD_PIXELINDEX pixels;
/*
// Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)
switch (Diff&3)
{
case 0:
goto WriteTBit0;
case 1:
goto WriteTBit1;
case 2:
goto WriteTBit2;
default:
goto WriteTBit3;
}
else switch (Diff&3)
{
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
default:
goto WriteBit3;
}
/*
Write without transparency
*/
WriteBit0:
SetPixel(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteBit1:
SetPixel(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteBit2:
SetPixel(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteBit3:
SetPixel(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
if (pixels&(3<<6))
SetPixel(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteTBit1:
if (pixels&(3<<4))
SetPixel(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteTBit2:
if (pixels&(3<<2))
SetPixel(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteTBit3:
if (pixels&(3<<0))
SetPixel(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteTBit0;
}
#endif
/*
*********************************************
* *
* Draw Bitmap 4 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 4)
static void DrawBitLine4BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
{
U8 pixels;
/*
// Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)
{
if ((Diff&1) ==0)
goto WriteTBit0;
goto WriteTBit1;
}
else
{
if ((Diff&1) ==0)
goto WriteBit0;
goto WriteBit1;
}
/*
Write without transparency
*/
WriteBit0:
SetPixel(x+0, y, *(pTrans+(pixels>>4)));
if (!--xsize)
return;
WriteBit1:
SetPixel(x+1, y, *(pTrans+(pixels&0xf)));
if (!--xsize)
return;
x+=2;
pixels = *(++p);
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
if (pixels>>4)
SetPixel(x+0, y, *(pTrans+(pixels>>4)));
if (!--xsize)
return;
WriteTBit1:
if (pixels&0xf)
SetPixel(x+1, y, *(pTrans+(pixels&0xf)));
if (!--xsize)
return;
x+=2;
pixels = *(++p);
goto WriteTBit0;
}
#endif
/*
*********************************************
* *
* Draw Bitmap 8 BPP (256 colors) *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 16)
static void DrawBitLine8BPP(int x, int y, U8 const*p, int xsize, const LCD_PIXELINDEX*pTrans)
{
LCD_PIXELINDEX pixel;
if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS)==0)
{
if (pTrans)
{
for (;xsize > 0; xsize--,x++,p++)
{
pixel = *p;
SetPixel(x, y, *(pTrans+pixel));
}
}
else
{
for (;xsize > 0; xsize--,x++,p++)
{
SetPixel(x, y, *p);
}
}
}
else/* Handle transparent bitmap */
{
if (pTrans)
{
for (; xsize > 0; xsize--, x++, p++)
{
pixel = *p;
if (pixel)
{
SetPixel(x+0, y, *(pTrans+pixel));
}
}
}
else
{
for (; xsize > 0; xsize--, x++, p++)
{
pixel = *p;
if (pixel)
{
SetPixel(x+0, y, pixel);
}
}
}
}
}
#endif
/*
*********************************************************
* *
* Universal draw Bitmap routine *
* *
*********************************************************
*/
void LCD_L0_DrawBitmap (int x0, int y0,
int xsize, int ysize,
int BitsPerPixel,
int BytesPerLine,
const U8* pData, int Diff,
const LCD_PIXELINDEX* pTrans)
{
int i;
for (i=0; i<ysize; i++)
{
switch (BitsPerPixel)
{
case 1:
DrawBitLine1BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#if (LCD_MAX_LOG_COLORS > 2)
case 2:
DrawBitLine2BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#endif
#if (LCD_MAX_LOG_COLORS > 4)
case 4:
DrawBitLine4BPP(x0, i+y0, pData, Diff, xsize, pTrans);
break;
#endif
#if (LCD_MAX_LOG_COLORS > 16)
case 8:
DrawBitLine8BPP(x0, i+y0, pData, xsize, pTrans);
break;
#endif
}
pData += BytesPerLine;
}
}
#else
void LCD13XX(void) { } /* avoid empty object files */
#endif /* (LCD_CONTROLLER == 0) */
专栏文章内容及配图由作者撰写发布,仅供工程师学习之用,如有侵权或者其他违规问题,请联系本站处理。 联系我们
相关推荐
MPLAB® X IDE 编译调试(上)
基于PIC32的蜂窝网机器到机器(M2M)通信解决方案
最新版单片机反编译软件
我和一个现代女性的聊天记录
美股大涨转大跌,苹果特斯拉跌近5%
(第三章)《深入浅出LPC9401 Flash单片机》
是德科技:AI高速运算 不受关税影响
请教:Arm7(S3C4510B)的vxWorks跳转问题
基于PIC32的低成本图形解决方案
(最新)智能卡水表模块解决方案
板子ping通以后,能直接运行ftp传输文件吗?
照片冲洗 再受冲击
谁控制了电解质,谁就为电动汽车铺平了道路
光纤发送器布线图 IGBT
COMPUTEX 2025:AI 驱动型智能移动出行的未来正在形成
德州仪器推出新款电源管理芯片,可提高现代数据中心的保护级别、功率密度和效率水平
半导体设备竞赛升级:国际巨头加码AI芯片技术,中国厂商集体加速“突围”
(第一二章)《深入浅出LPC9401 Flash单片机》
MPLAB® X IDE 编译调试(下)
美分析师:关税战将让美国科技行业倒退十年
北京堵车真相2-专家你要有基本良心! (转帖)
windriver发布的正式补丁里的源代码-TFFS
TX—KA959 IGBT驱动器的应用连接图
ZX7—315型弧焊电源工作原理图
三种放电阻止型缓冲电路 IGBT
UALink规范推出打响撼动英伟达AI统治的第一枪
文远知行 + QNX,为全球汽车业注入智能驾驶变革新动能
如何使用dsPIC® DSC 实现两路电机控制?
TX—KD201的原理框图
模拟芯视界 | 使用第二级滤波器来减少电压纹波