/****************************************************************************************
文件名:LEDDRIVE.C
功能:LED显示模块驱动。
****************************************************************************************/
#include "config.h"
/* ========== Hardware define ========== */
#define S ( ( uint32 )1 << 29 )
#define CP1 ( ( uint32 )1 << 30 )
#define CP2 ( ( uint32 )1 << 31 )
#define D3 ( ( uint32 )1 << 24 )
#define D2 ( ( uint32 )1 << 23 )
#define D1 ( ( uint32 )1 << 22 )
#define D0 ( ( uint32 )1 << 21 )
#define A0 ( ( uint32 )1 << 13 )
#define A1 ( ( uint32 )1 << 14 )
#define A2 ( ( uint32 )1 << 15 )
#define A3 ( ( uint32 )1 << 16 )
#define A4 ( ( uint32 )1 << 17 )
#define A5 ( ( uint32 )1 << 18 )
#define A6 ( ( uint32 )1 << 19 )
#define A7 ( ( uint32 )1 << 20 )
#define A8 ( ( uint32 )1 << 21 )
#define A9 ( ( uint32 )1 << 22 )
#define A10 ( ( uint32 )1 << 23 )
#define A11 ( ( uint32 )1 << 24 )
#define A12 ( ( uint32 )1 << 25 )
#define A13 ( ( uint32 )1 << 26 )
#define A14 ( ( uint32 )1 << 27 )
#define A15 ( ( uint32 )1 << 28 )
#define ALE ( ( uint32 )1 << 4 )
#define WR ( ( uint32 )1 << 5 )
#define RD ( ( uint32 )1 << 6 )
//=================== 硬件接口函数 =====================
void ClearScreen ( TCOLOR dat )
{
uint8 tmpX , tmpY ;
uint16 ramAddr ;
FIODIR = ( FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ) | ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
ramAddr = 0x0000 ;
for ( tmpY = 0 ; tmpY < 240 ; tmpY++ )
{
for ( tmpX = 0 ; tmpX < 40 ; tmpX++ )
{
FIOSET = ( ramAddr << 13 ) & 0x1fffe000 ;
FIOCLR = ( ( ~ramAddr ) << 13 ) & 0x1fffe000 ;
FIOSET = RD | WR ;
FIOSET = ALE ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = RD | WR ;
FIOCLR = 0x001fe000 ;
FIOSET = RD ;
FIOCLR = WR ;
FIOSET = RD ;
FIOSET = RD ;
FIOSET = RD ;
FIOSET = RD ;
FIOSET = RD ;
FIOSET = RD ;
FIOSET = WR ;
FIOSET = RD ;
ramAddr++ ;
}
}
return ;
}
void GUI_ReDisp ( void )
{
uint8 dispData ;
uint16 ramAddr ;
uint32 tmp ;
uint8 CP1cnt = 0 , CP2cnt = 0 ;
uint8 delayCount = 0 ;
FIODIR = ( FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ) | ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
ramAddr = 0x0000 ;
for ( CP1cnt = 0 ; CP1cnt < 240 ; CP1cnt++ )
{
for ( CP2cnt = 0 ; CP2cnt < 40 ; CP2cnt++ )
{
FIODIR = ( FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ) | ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ;
FIOSET = ( ramAddr << 13 ) & 0x1fffe000 ;
FIOCLR = ( ( ~ramAddr ) << 13 ) & 0x1fffe000 ;
FIOSET = RD | WR ;
FIOSET = ALE ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = RD | WR ;
FIODIR = FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ;
FIOSET = WR ;
FIOCLR = RD ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
tmp = FIOPIN ;
dispData = ( uint8 )( ( tmp >> 13 ) & 0x000000ff ) ;
dispData = ~dispData ;
FIOSET = RD ;
FIOSET = WR ;
ramAddr++ ;
FIOPIN = ( FIOPIN & 0xfe1fffff ) | ( ( dispData << 17 ) & 0x01e00000 ) ;
FIOSET = CP2 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOCLR = CP2 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOPIN = ( FIOPIN & 0xfe1fffff ) | ( ( dispData << 21 ) & 0x01e00000 ) ;
FIOSET = CP2 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOCLR = CP2 ;
}
if ( CP1cnt == 239 ) break ;
FIOSET = CP1 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOCLR = CP1 ;
}
FIOSET = S | CP1 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOCLR = CP1 ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
delayCount++ ;
FIOCLR = S ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
return ;
}
//======================================================
/****************************************************************************
* 名称:GUI_Initialize()
* 功能:初始化GUI,包括初始化显示缓冲区,初始化LCM并清屏。
* 入口参数:无
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void GUI_Initialize(void)
{
GPIOInit ( S | CP1 | CP2 | D3 | D2 | D1 | D0 , 1 ) ;
GPIOInit ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 , 1 ) ;
GPIOInit ( A8 | A9 | A10 | A11 | A12 | A13 | ALE | RD | WR , 1 ) ;
ClearScreen ( WHITE ) ;
return;
}
/****************************************************************************
* 名称:GUI_FillSCR()
* 功能:全屏填充。直接使用数据填充显示缓冲区。
* 入口参数:dat 填充的数据
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void GUI_FillSCR(TCOLOR dat)
{
ClearScreen ( dat ) ;
return;
}
/****************************************************************************
* 名称:GUI_ClearSCR()
* 功能:清屏。
* 入口参数:无
* 出口参数:无
* 说明:用户根据LCM的实际情况编写此函数。
****************************************************************************/
void GUI_ClearSCR(void)
{
ClearScreen ( WHITE ) ;
return;
}
/****************************************************************************
* 名称:GUI_Point()
* 功能:在指定位置上画点。
* 入口参数:x 指定点所在列的位置
* y 指定点所在行的位置
* color 显示颜色
* 出口参数:返回值为1时表示操作成功,为0时表示操作失败。
****************************************************************************/
uint8 GUI_Point ( uint32 x , uint32 y , TCOLOR color , uint8 type )
{
uint8 dispData ;
uint16 ramAddr ;
uint32 readTmp ;
unsigned char BitData = 0 ;
/* 参数过滤 */
if ( x >= GUI_LCM_XMAX ) return 0 ;
if ( y >= GUI_LCM_YMAX ) return 0 ;
/* 刷新显示*/
ramAddr = ( uint16 )( ( y * 40 ) + ( x / 8 ) ) ;
FIODIR = ( FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ) | ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = ( ramAddr << 13 ) & 0x1fffe000 ;
FIOCLR = ( ( ~ramAddr ) << 13 ) & 0x1fffe000 ;
FIOSET = RD | WR ;
FIOSET = ALE ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = RD | WR ;
FIODIR = FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ;
FIOSET = WR ;
FIOCLR = RD ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
FIOSET = WR ;
readTmp = FIOPIN ;
dispData = ( uint8 )( ( readTmp >> 13 ) & 0x000000ff ) ;
FIOSET = RD ;
FIOSET = WR ;
BitData = 0x80 >> ( x - ( unsigned char )( ( x / 8 ) * 8 ) ) ;
if ( color )
{
BitData = BitData | dispData ;
}
else if ( type )
{
BitData = ( ~BitData ) & dispData ;
}
else if ( !type )
{
BitData = dispData ;
}
FIODIR = ( FIODIR & ( ~( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ) ) | ( A0 | A1 | A2 | A3 | A4 | A5 | A6 | A7 ) ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = ( ramAddr << 13 ) & 0x1fffe000 ;
FIOCLR = ( ( ~ramAddr ) << 13 ) & 0x1fffe000 ;
FIOSET = RD | WR ;
FIOSET = ALE ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOSET = RD | WR ;
FIOCLR = ALE ;
FIOSET = RD | WR ;
FIOSET = ( BitData << 13 ) & 0x001fe000 ;
FIOCLR = ( ( ~BitData ) << 13 ) &