M128128.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:13k
- /****************************************************************************************
- * 文件名:LCDDRIVE.C
- * 功能:图形液晶240*128驱动(型号为SMG240128A)。32K显示存,0000H-7FFFH地址。显示是横向字节,高位
- * 在前。
- * 说明:图形液晶采用T6963C为LCD控制芯片,内带负压产生器,单5伏供电,并行接口(使用LPC2210驱动)。
- * 硬件连接: D0--D7 <===> D0--D7
- * /WR <===> nWE
- * /RD <===> nOE
- * /CE <===> nCS3_1
- * C/D <===> A1
- *
- * /RST <===> VCC
- ****************************************************************************************/
- /*********************************************************************
- * INCLUDES
- */
- #include "includes.h"
- /*********************************************************************
- * CONSTANTS
- */
- #define LOW 0
- #define HIGH 1
- //#define ESC_KEY 0x1b
- #define LCD_DISP_ON 0x3f // Controls the display onor off. Internal status and
- #define LCD_DISP_OFF 0x3e // display RAM data is not affected.L:OFF, H:ON
- #define LCD_SET_X( X ) ( 0x40 + X )
- #define LCD_SET_Y( Y ) ( 0xb8 + Y )
- #define LCD_DISP_START_L( L ) ( 0xc0 + L )
- #define LCD_STATUS_BUSY 0x80
- #define LCD_STATUS_READ() ( 0x80 & LCD_DATA_BUS )
- /*********************************************************************
- * MACROS
- */
- #define LCD_DATA_BUS 0
- #define LCD_CONTROL_BUS 0
- #define LCD_DATA_BUS_CON 0
- #define LCD_CONTROL_BUS_CON 0
- #define PAGE_ALL_S ( ( LCD_CONTROL_BUS & 0xff ) | 0x0f )
- #define PAGE_ALL_DS ( LCD_CONTROL_BUS & 0xf0 )
- #define PAGE_1 ( ( LCD_CONTROL_BUS & 0xf0 ) | 0x01 )
- #define PAGE_2 ( ( LCD_CONTROL_BUS & 0xf0 ) | 0x02 )
- #define PAGE_3 ( ( LCD_CONTROL_BUS & 0xf0 ) | 0x04 )
- #define PAGE_4 ( ( LCD_CONTROL_BUS & 0xf0 ) | 0x08 )
- #define LCD_DATA_BUS_INIT() ( LCD_DATA_BUS_CON = ( ( LCD_DATA_BUS_CON & 0xffff0000 ) | 0x5555 ) )
- #define LCD_CONTROL_BUS_INIT() ( LCD_CONTROL_BUS_CON = 0x5555 )
-
- #define CMD ( LCD_CONTROL_BUS & ~0x10 )
- #define DAT ( LCD_CONTROL_BUS | 0x10 )
- #define WRITE ( LCD_CONTROL_BUS & ~0x20 )
- #define READ ( LCD_CONTROL_BUS | 0x20 )
- #define ENABLE ( LCD_CONTROL_BUS & ~0x40 )
- #define DISNABLE ( LCD_CONTROL_BUS | 0x40 )
- #define RESET ( LCD_CONTROL_BUS & ~0x80 )
- #define WORK ( LCD_CONTROL_BUS | 0x80 )
- #define LCD_PAGE_CS( PAGE_x ) ( LCD_CONTROL_BUS = PAGE_x )//( LCD_CONTROL_BUS & 0xf0 ) | ( 0x01 << PAGE_x ) )
- #define RS( x ) ( LCD_CONTROL_BUS = x )
- #define RW( x ) ( LCD_CONTROL_BUS = x )
- #define CE( x ) ( LCD_CONTROL_BUS = x )
- #define LCD_RESET( rst ) ( LCD_CONTROL_BUS = rst )
- /*********************************************************************
- * TYPEDEFS
- */
- #define WRITE_IN_BUFFER 1
- /*********************************************************************
- * GLOBAL VARIABLES
- */
- /*********************************************************************
- * LOCAL VARIABLES
- */
- /*********************************************************************
- * GLOBAL FUNCTIONS
- */
-
- /*********************************************************************
- * LOCAL FUNCTIONS
- */
- INT8U lcdWriteData( INT8U page, INT8U dat);
- void LCD_WriteCommand(unsigned char page,unsigned char command);
- void LCD_WriteData(unsigned char mode,unsigned char page,unsigned char data_in);
- void set128128Addr(unsigned char mode,unsigned char x,unsigned char y);
- void writeLcd128128Data(unsigned char mode,unsigned char x,unsigned char y,unsigned char data_in);
- void LCD_Init(void);
- /*********************************************************************
- *********************************************************************/
- /***********************************************************************
- * 名称:LCD_Init()
- * 功能:LCM初始化,将LCM初始化为纯图形模式,显示起始地址为0x0000,。
- * 入口参数:无
- * 出口参数:无
- * 说明:函数会设置LCM数据总线为输出方式
- ***********************************************************************/
- LcdDispArea_s DispArea;
- LcdDispCursor_s LcdCursor;
- void LCD_Init(void)
- {
-
- }
- /***********************************************************************
- * 名称:LCD_WriteData()
- * 功能:写1字节数据子程序。会先判断状态字。
- * 入口参数:dat 要写入LCM的数据
- * 出口参数:操作出错返回0,否则返回1
- ***********************************************************************/
- INT8U lcdWriteData( INT8U page, INT8U dat)
- {
-
- return(1);
- }
- /***********************************************************************
- * 原型:void wr_12864_data(unsigned char mode,unsigned char i,unsigned char data_in)
- * 功能:给12864写一个数据
- * 入口参数:mode:写入方式:1直接写入,0取反后写入
- * i:选择:1左半屏,2右半屏
- * data_in:要写入的数据
- * 出口参数:无
- ***********************************************************************/
- void LCD_WriteData(unsigned char mode,unsigned char page,unsigned char data_in)
- {
- if(mode)
- lcdWriteData( page, data_in );
- else
- lcdWriteData( page, ~data_in);
- }
- /***********************************************************************
- * 原型:void wr_12864_order(unsigned char i,unsigned char order)
- * 功能:给12864写一个指令
- * 入口参数:i:选择 1左半屏,2右半屏,3同时左右屏
- * order:指令
- * 出口参数:无
- ***********************************************************************/
- void LCD_WriteCommand(unsigned char page,unsigned char command)
- {
- }
- /***********************************************************************
- * 原型:void set_12864_addr(unsigned char mode,unsigned char x,unsigned char y)
- * 功能:设置lcd12864显示座标
- * 入口参数:mode:地址写入方式:1只设置x地址,2只设置y地址,3同时设置x和y地址
- * x:液晶x轴座标(0到127)
- * y:液晶y轴座标(0到15)
- * 出口参数:无
- ***********************************************************************/
- void set128128Addr(unsigned char addr_mode,unsigned char x,unsigned char y)
- {
- INT8U page;
- switch(addr_mode)
- {
- case SET_X: // 只写X坐标
- if ( x > 63 )
- {
- if( y > 7 )
- page = PAGE_4;
- else
- page = PAGE_2;
- LCD_WriteCommand( page, LCD_SET_X( x-64 ) );
- break;
- }
- else
- {
- if( y > 7 )
- page = PAGE_3;
- else
- page = PAGE_1;
- LCD_WriteCommand( page, LCD_SET_X( x ) );
- }
- break;
-
- case SET_Y: // 只写Y坐标
- if( y > 7 )
- {
- LCD_WriteCommand( PAGE_3, LCD_SET_Y( y-8 ) );
- LCD_WriteCommand( PAGE_4, LCD_SET_Y( y-8 ) );
- break;
- }
- else
- {
- LCD_WriteCommand( PAGE_1, LCD_SET_Y( y ) );
- LCD_WriteCommand( PAGE_2, LCD_SET_Y( y ) );
- }
- break;
-
- case SET_X_Y: // 同时写X和Y坐标
- if( y > 7 )
- {
- LCD_WriteCommand( PAGE_3, LCD_SET_Y( y-8 ) );
- LCD_WriteCommand( PAGE_4, LCD_SET_Y( y-8 ) );
- }
- else
- {
- LCD_WriteCommand( PAGE_1, LCD_SET_Y( y ) );
- LCD_WriteCommand( PAGE_2, LCD_SET_Y( y ) );
- }
- if ( x > 63 )
- {
- if( y > 7 )
- page = PAGE_4;
- else
- page = PAGE_2;
- LCD_WriteCommand( page, LCD_SET_X( x-64 ) );
- break;
- }
- else
- {
- if( y > 7 )
- page = PAGE_3;
- else
- page = PAGE_1;
- LCD_WriteCommand( page, LCD_SET_X( x ) );
- }
- break;
- default: break;
- }
- }
- /***********************************************************************
- * 原型:void open_12864(unsigned char mode)
- * 功能:12864开显示
- * 入口参数:page:选择:1左半屏,2右半屏,3左右屏
- * 出口参数:无
- ***********************************************************************/
- void LCD_On (void) { LCD_WriteCommand( PAGE_ALL_S,LCD_DISP_ON); }
- /***********************************************************************
- * 原型:void shut_12864(unsigned char mode)
- * 功能:12864关显示
- * 入口参数:page:选择:1左半屏,2右半屏,3左右屏
- * 出口参数:无
- ***********************************************************************/
- void LCD_Off (void) { LCD_WriteCommand(PAGE_ALL_S,LCD_DISP_OFF); }
- /***********************************************************************
- * 原型:void write_lcd12864_data( unsigned char mode,unsigned char x,
- * unsigned char y,unsigned char data_in)
- * 功能:给12864指定座标写数据
- * 入口参数:mode 写入方式:1直接写入,0取反后写入
- * x 屏幕x轴座标(0到127)
- * y 屏幕y轴座标(0到7)
- * data_in 要写入的数据
- * 出口参数:无
- ***********************************************************************/
- void writeLcd128128Data(unsigned char mode,unsigned char x,unsigned char y,unsigned char data_in)
- {
- INT8U page;
- if( y > 7 )
- {
- if( x > 63 )
- {
- page = PAGE_4;
- x -= 64;
- }
- else
- {
- page = PAGE_3;
- }
- y -= 8;
- }
- else
- {
- if( x > 63 )
- {
- page = PAGE_2;
- x -= 64;
- }
- else
- {
- page = PAGE_1;
- }
- }
- LCD_WriteCommand( page, LCD_SET_Y( y ) );
- LCD_WriteCommand( page, LCD_SET_X( x ) );
- LCD_WriteData( mode, page, data_in );
- }
- /*------------------ esay GUI ---------------------*/
- INT8U lcd_buffer[ 16 ][ 128 ];
- INT8U Xy_Map=0;
- /******************************************************************************************************************
- * 函数名称:LCM12864_ReadByte()
- * 功 能:从显示缓冲区读取指定点上的数据。
- * 入口参数:x x坐标值(0-127)
- * y y坐标值(0-63)
- * 出口参数:返回该点上的字节数据。
- *******************************************************************************************************************/
- INT8U LCM128128_ReadByte(INT32U x, INT32U y)//修改:把INT8U改成int
- {
- /* 参数过滤 */ //修改:去掉参数过滤
- //x = x&0x7f;
- //y = y&0x3f;
- y = y>>3;
- return (lcd_buffer[y][x]); // 返回显示缓冲区指定点上的数据
- }
- /***********************************************************************
- * 函数名称:GUI_FillSCR()
- * 功 能:全屏填充。填充显示缓冲区及LCM12864。
- * 入口参数:data 填充的数据
- * 出口参数:无
- ***********************************************************************/
- void GUI_FillSCR(INT8U data)
- {
- INT32U x;
- INT32U y;
-
- /* 填充显示缓冲区 */
- for( y = 0; y<(GUI_LCM_YMAX>>2); y++)
- {
- for(x=0; x<GUI_LCM_XMAX; x++)
- gui_disp_buf[y][x] = data;
- }
- }
- INT8U const DEC_HEX_TAB[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- /***********************************************************************
- * 函数名称:GUI_Point()
- * 功 能:在指定位置上画点。
- * 入口参数:x 指定点所在列的位置
- * y 指定点所在行的位置
- * color 对于黑白色或蓝白色LCM12864,为0时灭,为1时显示
- * 出口参数:返回值为1时表示操作成功,为0时表示操作失败。
- ***********************************************************************/
- INT8U GUI_Point( INT32U x, INT32U y, INT16U color )
- {
- INT32U bak;
- /* 参数过滤 */
- if( x >= GUI_LCM_XMAX ) return(0);
- if( y >= GUI_LCM_YMAX ) return(0);
- switch( Xy_Map )
- {
- //case 0:break;
- case 1:
- bak=x;
- x=y;
- y=GUI_LCM_XMAX-bak-1;
- break;
- case 2:
- x=GUI_LCM_XMAX-x-1;
- y=GUI_LCM_YMAX-y-1;
- break;
- case 3:break;
- }
- /* 设置相应的点为1或0 */
- bak = LCM128128_ReadByte( x, y );
- if( 0 == color )
- {
- bak &= (~DEC_HEX_TAB[y&0x07]);
- }
- else
- {
- bak |= DEC_HEX_TAB[y&0x07];
- }
- y=y>>3;
-
- lcd_buffer[y][x] = bak;
-
- return (1);
- }
- /***********************************************************************
- * 函数名称:GUI_ReadPoint()
- * 功 能:读取指定点的颜色。
- * 入口参数:x 指定点所在列的位置
- * y 指定点所在行的位置
- * ret 保存颜色值的指针
- * 出口参数:返回0表示指定地址超出缓冲区范围。
- * 说 明:对于单色,设置ret的d0位为1或0
- ***********************************************************************/
- INT8U GUI_ReadPoint( int x, int y, int *ret )
- {
- INT32U bak;
- /* 参数过滤 */
- if( x >= GUI_LCM_XMAX ) return(0);
- if( y >= GUI_LCM_YMAX ) return(0);
- switch(Xy_Map)
- {
- case 0:break;
- case 1:
- bak=x;
- x=y;
- y=GUI_LCM_XMAX-bak-1;
- break;
- case 2:
- x=GUI_LCM_XMAX-x-1;
- y=GUI_LCM_YMAX-y-1;
- break;
- case 3:break;
- }
- bak = LCM128128_ReadByte(x,y);
- if( (bak & ( DEC_HEX_TAB[ y & 0x07 ] ) ) == 0 )
- *ret = 0x00;
- else
- *ret = 0x01;
-
- return(1);
- }
- /***********************************************************************
- * 函数名称:Refresh_FrameBuffer()
- * 功 能:刷新屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- INT8U RefreshFrameBuffer(INT8U disp_mode )
- {
- INT8U x = 0;
- INT8U y = 0;
- INT8U page;
- for( y = 0; y <= 15; y++ )
- {
- set128128Addr( SET_X_Y, 0, y );
- for( x = 0; x <= 127; x++ )
- {
- if( x == 0 )
- set128128Addr( SET_X_Y, 0, y );
- if(x<64)
- {
- if( y > 7 )
- page = PAGE_3;
- else
- page = PAGE_1;
- LCD_WriteData( disp_mode, page, lcd_buffer[y][x] );
- }
- if(x==64)
- set128128Addr(SET_X_Y,x,y);
- if(x>63)
- {
- if( y > 7 )
- page = PAGE_4;
- else
- page = PAGE_2;
- LCD_WriteData( disp_mode, page, lcd_buffer[y][x] );
- }
- }
- }
- }