LCD_M128128.c
上传用户:zbk8730
上传日期:2017-08-10
资源大小:12168k
文件大小:18k
- /*
- *********************************************************************************************************
- * 礐/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 : LCDWin.C
- * Purpose : Driver for Simulator under Windows
- *
- * Version-Date---Author-Explanation
- *
- * 2.00 010402 RS a) LCD_GetDevCaps removed from driver
- * (now LCD.c)
- * 1.30c 000529 JE a) Interface changed
- * 1.30b 000428 RS a) DIB class eliminated
- * b) Internal cleanups, support for high color
- * 1.30a 000417 RS a) Major cleanup in DIB class
- * 1.30 000309 RS a) Interface change for emWIn V1.30
- * (LCD_L0_SetLUTEntry, LCD_GetDevCap)
- * 1.10a 000121 RS a) RECTHEIGHT, RECTWIDTH modified in order to
- * fix bug which would at some time prevent
- * displaying the first line of the display.
- * 1.10.00 000110 RS a) Modifications in order to make it easy to
- * implement driver in any windows program
- * 1.04.02 991118 RS a) additional assertion added
- * LCD_MAX_LOG_COLORS
- * 1.04.01 991018 RS a) Support for LCD_FIXEDPALETTE added
- * with Anitaliasing enabled
- * 1.04.00 991013 JE/RS a) Support for LCD_FIXEDPALETTE added
- * b) Driver now accepts the same LCDConf.h as
- * the embedded system
- * c) Bugfix for ..
- * 1.02.02 990831 RS a) Small optimization added for 16-color bitmaps
- * 1.02.01 990726 RS a) Transparency support for 16-color bitmpas
- * added
- * 1.02.00 990212 RS a) New interface version 1.02 supported
- * 1.00 990118 RS First release
- *
- * Known problems or limitations with current version
- *
- *********************************************************************************************************
- */
- #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 "M128128.h"
- #include "LCD_0.h" /* Defines for first display */
- U8 lcd_buffer [ LCD_YSIZE>>3 ] [ LCD_XSIZE ];
- INT8U const DEC_HEX_TAB[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- /*********************************************************************
- * 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 GUI_FillSCR(INT8U data);
- /***********************************************************************
- * 名称:LCD_WriteData()
- * 功能:写1字节数据子程序。会先判断状态字。
- * 入口参数:dat 要写入LCM的数据
- * 出口参数:操作出错返回0,否则返回1
- ***********************************************************************/
- INT8U lcdWriteData( INT8U page, INT8U dat)
- {
- INT8U i = 0;
-
- return(1);
- }
- /***********************************************************************
- * 原型: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)
- {
- INT8U i = 0;
-
- }
- /***********************************************************************
- * 原型: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);
- }
- /***********************************************************************
- * 名称:Full_FillScreem()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void Full_FillLcd( INT8U page, INT8U dat )
- {
- INT8U x,y;
- LCD_WriteCommand( page, LCD_DISP_ON );
- Delay(10);
- for(y=0;y<8;y++)
- {
- LCD_WriteCommand( page, LCD_SET_Y( y ) );
- LCD_WriteCommand( page, LCD_SET_X( 0 ) );
-
- for(x=0;x<64;x++)
- {
- LCD_WriteData( NORMAL_DISP, page, dat );
- }
- }
- }
- /***********************************************************************
- * 名称:Full_FillScreem()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- LcdDispArea_s DispArea;
- LcdDispCursor_s LcdCursor;
- int LCD_L0_Init(void)
- {
- DispArea.mode = NORMAL_DISP;
-
- return 0;
- }
- /***********************************************************************
- * 名称:Full_FillScreem()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_ReInit(void)
- {
- LCD_INIT_CONTROLLER(); /* macro defined in config */
- }
- /***********************************************************************
- * 原型: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 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 );
- }
- /**********************************************************************
- * 函数名称:LCM12864_ReadByte()
- * 功 能:从显示缓冲区读取指定点上的数据。
- * 入口参数:x x坐标值(0-127)
- * y y坐标值(0-63)
- * 出口参数:返回该点上的字节数据。
- ***********************************************************************/
- int LCM128128_ReadByte(int x, int y)//修改:把INT8U改成int
- {
- if(x>LCD_XSIZE) return 0;
- if(y>LCD_YSIZE) return 0;
- y = y>>3;
- return lcd_buffer[y][x]; // 返回显示缓冲区指定点上的数据
- }
- /***********************************************************************
- * 函数名称:GUI_FillSCR()
- * 功 能:全屏填充。填充显示缓冲区及LCM12864。
- * 入口参数:data 填充的数据
- * 出口参数:无
- ***********************************************************************/
- void GUI_FillSCR(INT8U data)
- {
- int x;
- int y;
-
- /* 填充显示缓冲区 */
- for( y = 0; y<(LCD_YSIZE>>3); y++)
- {
- for(x=0; x<LCD_XSIZE; x++)
- lcd_buffer[y][x] = data;
- }
- }
- /***********************************************************************
- * 函数名称:LCD_L0_SetPixelIndex()
- * 功 能:在指定位置上画点。
- * 入口参数:x 指定点所在列的位置
- * y 指定点所在行的位置
- * color 对于黑白色或蓝白色LCM12864,为0时灭,为1时显示
- * 出口参数:返回值为1时表示操作成功,为0时表示操作失败。
- ***********************************************************************/
- void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex)
- {
- int bak;
-
- bak = LCM128128_ReadByte( x, y );
- if( 0 == PixelIndex )
- {
- bak &= (~DEC_HEX_TAB[y&0x07]);
- }
- else
- {
- bak |= DEC_HEX_TAB[y&0x07];
- }
- y=y>>3;
-
- lcd_buffer[y][x] = bak;
- }
- /***********************************************************************
- * 函数名称:LCD_L0_GetPixelIndex()
- * 功 能:读取指定点的颜色。
- * 入口参数:x 指定点所在列的位置
- * y 指定点所在行的位置
- * ret 保存颜色值的指针
- * 出口参数:返回0表示指定地址超出缓冲区范围。
- * 说 明:对于单色,设置ret的d0位为1或0
- ***********************************************************************/
- unsigned int LCD_L0_GetPixelIndex( int x, int y )
- {
- int bak;
-
- bak = LCM128128_ReadByte(x,y);
- if( (bak & ( DEC_HEX_TAB[ y & 0x07 ] ) ) == 0 )
- return 0;
- else
- return 1;
- }
- /***********************************************************************
- * 函数名称:RefreshFrameBuffer()
- * 功 能:刷新屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void RefreshFrameBuffer(INT8U disp_mode )
- {
- int x = 0;
- int 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] );
- }
- }
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_DrawPixel()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_DrawPixel(int x, int y)
- {
- if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
- {
- LCD_L0_XorPixel(x, y);
- }
- else
- {
- LCD_L0_SetPixelIndex(x, y, LCD_COLORINDEX);
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_DrawHLine()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_DrawHLine (int x0, int y, int x1)
- {
- if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
- {
- for (; x0 <= x1; x0++)
- {
- LCD_L0_XorPixel(x0, y);
- }
- }
- else
- {
- for (; x0 <= x1; x0++)
- {
- LCD_L0_SetPixelIndex(x0, y, LCD_COLORINDEX);
- }
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_DrawVLine()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_DrawVLine (int x, int y0, int y1)
- {
- if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
- {
- for (; y0 <= y1; y0++)
- {
- LCD_L0_XorPixel(x, y0);
- }
- }
- else
- {
- for (; y0 <= y1; y0++)
- {
- LCD_L0_SetPixelIndex(x, y0, LCD_COLORINDEX);
- }
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_FillRect()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
- {
- for (; y0 <= y1; y0++)
- {
- LCD_L0_DrawHLine(x0, y0, x1);
- }
- }
- /***********************************************************************
- * 名称:DrawBitLine1BPP()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- static void DrawBitLine1BPP( int x,
- int y,
- U8 const*p,
- int Diff,
- int xsize,
- const LCD_PIXELINDEX*pTrans)
- {
- LCD_PIXELINDEX Index0 = *(pTrans+0);
- LCD_PIXELINDEX Index1 = *(pTrans+1);
- x+=Diff;
- switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
- case 0: /* Write mode */
- do {
- LCD_L0_SetPixelIndex(x++,y, (*p & (0x80>>Diff)) ? Index1 : Index0);
- if (++Diff==8) {
- Diff=0;
- p++;
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_TRANS:
- do {
- if (*p & (0x80>>Diff))
- LCD_L0_SetPixelIndex(x,y, Index1);
- x++;
- if (++Diff==8) {
- Diff=0;
- p++;
- }
- } while (--xsize);
- break;
- case LCD_DRAWMODE_XOR:;
- do {
- if (*p & (0x80>>Diff)) {
- int Pixel = LCD_L0_GetPixelIndex(x,y);
- LCD_L0_SetPixelIndex(x,y, LCD_NUM_COLORS-1-Pixel);
- }
- x++;
- if (++Diff==8) {
- Diff=0;
- p++;
- }
- } while (--xsize);
- break;
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_DrawBitmap()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- 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;
- /*
- Use DrawBitLineXBPP
- */
- 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
- #if (LCD_BITSPERPIXEL > 8)
- case 16:
- DrawBitLine16BPP(x0, i+y0, (const U16 *)pData, xsize, pTrans);
- break;
- #endif
- }
- pData += BytesPerLine;
- }
- }
- /***********************************************************************
- * 名称:LCD_L0_SetOrg()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- int OrgX, OrgY;
- void LCD_L0_SetOrg(int x, int y)
- {
- OrgX = x;
- OrgY = y;
- }
- /***********************************************************************
- * 名称:LCD_On()/LCD_Off()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_On (void) { LCD_WriteCommand( PAGE_ALL_S,LCD_DISP_ON); }
- void LCD_Off (void) { LCD_WriteCommand(PAGE_ALL_S,LCD_DISP_OFF); }
- /***********************************************************************
- * 名称:LCD_L0_SetLUTEntry()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color)
- {
- GUI_USE_PARA(Pos);
- GUI_USE_PARA(Color);
- }
- /***********************************************************************
- * 名称:LCD_L0_CheckInit()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- int LCD_L0_CheckInit(void)
- {
- return 0;
- }
- /***********************************************************************
- * 名称:LCD_L0_XorPixel()
- * 功能:清除屏幕。
- * 入口参数:无
- * 出口参数:无
- ***********************************************************************/
- void LCD_L0_XorPixel(int x, int y)
- {
- LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
- LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
- }
- /***********************************************************************
- * END
- ***********************************************************************/