⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcdwin.c

📁 使用coderwarrior打开 内含中文字库
💻 C
📖 第 1 页 / 共 3 页
字号:


#include "config.h"

#include <stddef.h>           /* needed for definition of NULL */
#include "LCD_Private.h"      /* private modul definitions & config */
#include "GUI_Private.h"
#include "GUIDebug.h"
#include "LCD_0.h"            /* Defines for first display */

#if (LCD_CONTROLLER == 8822)

#ifndef LCD_DISPLAY_INDEX
  #define LCD_DISPLAY_INDEX 0
#endif

/*
        *********************************************************
        *                                                       *
        *       Macros for internal use                         *
        *                                                       *
        *********************************************************
*/

void delay(unsigned int num);
void LCD_CmdWrite(unsigned char cmdReg,unsigned char cmdData);
unsigned char LCD_CmdRead(unsigned char cmdReg);
void LCD_DataWrite(unsigned char WrData);
void LCD_ChkBusy(void);
void GotoXY(unsigned char x1,unsigned char y1);
void LCD8822_SetPixelIndex(int x,int y,unsigned char data);
unsigned char  LCDSIM_GetPixelIndex(int x,int y);
unsigned LCD_L0_GetPixelIndex(int x, int y);
void delay(unsigned int num);
void LCD_Reset(void);
void LCD_Initial(void);
void LCD_Clear_1(void);
void LCD_Clear_2(void);



/*
        *********************************************************
        *                                                       *
        * Standard variables for driver                         *
        *                                                       *
        *********************************************************
*/

static U8 Cache[((LCD_XSIZE_PHYS+7)>>3)*LCD_YSIZE_PHYS];

static const LCD_PIXELINDEX LCD_ConversionTable[2] = {0, 1};



/*
        *********************************************************
        *                                                       *
        *          Support for Segment/COMLUTs                  *
        *                                                       *
        *********************************************************
*/

/* For compatibility with older configs, define defaults */
#ifndef LCD_SUPPORT_COMTRANS
  #define LCD_SUPPORT_COMTRANS 0
#endif
#ifndef LCD_SUPPORT_SEGTRANS
  #define LCD_SUPPORT_SEGTRANS 0
#endif

#if LCD_SUPPORT_COMTRANS
  extern LCD_TYPE_COMTRANS LCD__aLine2Com0[LCD_LASTCOM0-LCD_FIRSTCOM0+1];
#endif

#if LCD_SUPPORT_SEGTRANS
  extern LCD_TYPE_SEGTRANS LCD__aRow2Seg0[LCD_LASTSEG0-LCD_FIRSTSEG0+1];
#endif

/*
        *********************************************************
        *                                                       *
        *       Macros for internal use                         *
        *                                                       *
        *********************************************************
*/

#if (LCD_SUPPORT_COMTRANS)
  #if (LCD_MIRROR_Y)
    #error LCD_MIRROR_Y not supported with COMTrans !
  #endif
  #if (LCD_MIRROR_X)
    #error LCD_MIRROR_X not supported with COMTrans !
  #endif
#endif


#define SETPIXEL  LCD8822_SetPixelIndex
#define XORPIXEL  LCD_L0_XorPixel
#define GETPIXEL  LCDSIM_GetPixelIndex



#define XY2OFF(x,y) ((x>>3)+y*((LCD_XSIZE_PHYS+7)>>3))
#define BKCOLOR LCD_BKCOLORINDEX
#define   COLOR LCD_COLORINDEX


//PINSEL6     D0--D7脚
//PINSEL8     A0--A15脚
//OE:P4.24   WE:P4.25   CS0:P4.30    RS:P4.8   BUSY:P4.9   DATA:P3.0-P3.7   RST:P4.10

#define SET_LCD_CS()  FIO4SET = (1<<30)
#define CLR_LCD_CS()  FIO4CLR = (1<<30)

#define SET_LCD_RD()  FIO4SET = (1<<24)
#define CLR_LCD_RD()  FIO4CLR = (1<<24)

#define SET_LCD_WR()  FIO4SET = (1<<25)
#define CLR_LCD_WR()  FIO4CLR = (1<<25)

#define SET_LCD_RS()  FIO4SET = (1<<8)
#define CLR_LCD_RS()  FIO4CLR = (1<<8)


/*
        *********************************************************
        *                                                       *
        *       ID translation table                            *
        *                                                       *
        *********************************************************

This table contains 0, 1, 2, ... and serves as translation table for DDBs

*/

static const U8 TransId[] = { 0,1 };


//Driver
#define LCDCmd  (*(volatile unsigned char *)(0x80000000))
#define LCDData  (*(volatile unsigned char *)(0x80000100))
 
void delay(unsigned int num)
{
    unsigned int i;
	for(i=0;i<num;i++);
}



void LCD_CmdWrite(unsigned char cmdReg,unsigned char cmdData)
{
    LCD_ChkBusy();
    LCDCmd = cmdReg;
    delay(10);
    LCD_ChkBusy();
    LCDCmd = cmdData;
    delay(10);
}

unsigned char LCD_CmdRead(unsigned char cmdReg)
{
  unsigned char REG_Read;
    LCD_ChkBusy();
    LCDCmd = cmdReg;
    
    LCD_ChkBusy();
    REG_Read = LCDCmd;
    LCD_ChkBusy();
    delay(10);
    return REG_Read;
}

void LCD_DataWrite(unsigned char WrData)
{
    LCD_ChkBusy();
    LCDData = WrData;
    delay(25);          //最少22个delay
}


unsigned char LCD_DataRead(void)
{
    unsigned char temp;
    LCD_ChkBusy();
    temp = LCDData;
    delay(10);
    return temp;
}



void LCD_ChkBusy(void)
{
	do
	{
	}
	while((FIO4PIN & (1<<9)) != 0);
}


void GotoXY(unsigned char x1,unsigned char y1)
{
    LCD_CmdWrite(0x60,x1);           //设定水平坐标
	LCD_CmdWrite(0x70,y1);           //设定垂直坐标
}

void LCD8822_SetPixelIndex(int x,int y,unsigned char data)
{
 unsigned char temp;
    LCD_CmdWrite(0x00,0xC5);
    GotoXY(x/8,y);
    temp = LCD_DataRead();
    if(data !=0)
    {
        temp = temp| (1<<(7-(x & 0x07)));
    }
    else 
    {
        temp = temp& (~(1<<(7-(x & 0x07))));
    }
    LCD_DataWrite(temp);
}

unsigned char  LCDSIM_GetPixelIndex(int x,int y)
{
     unsigned char temp;
     GotoXY(x/8,y);
     temp = LCD_DataRead();
     temp = (temp >> (7-(x&0x07))) & 0x01;
     return temp;
}

/****************************************************************************************/




void LCD_L0_SetPixelIndex(int x, int y, int ColorIndex) {
  LCD8822_SetPixelIndex(x, y, ColorIndex);
}



void LCD_L0_XorPixel(int x, int y) {
char temp;
temp = LCDSIM_GetPixelIndex(x,y);

LCD8822_SetPixelIndex(x, y, 1-temp);
}





/*
        *********************************************************
        *                                                       *
        *          LCD_L0_DrawHLine unoptimized                 *
        *                                                       *
        *********************************************************
*/

void LCD_L0_DrawHLine  (int x0, int y,  int x1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (x0 <= x1) {
      XORPIXEL(x0, y);
      x0++;
    }
  } else {
    while (x0 <= x1) {
      SETPIXEL(x0, y, COLOR);
      x0++;
    }
  }
}

//#endif


/*
        *********************************************************
        *                                                       *
        *          LCD_L0_DrawVLine                             *
        *                                                       *
        *********************************************************
*/

void LCD_L0_DrawVLine  (int x, int y0,  int y1) {
  if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
    while (y0 <= y1) {
      XORPIXEL(x, y0);
      y0++;
    }
  } else {
    while (y0 <= y1) {
      SETPIXEL(x, y0, COLOR);
      y0++;
    }
  }
}


/*
        *********************************************************
        *                                                       *
        *          LCD_FillRect, unoptimized                    *
        *                                                       *
        *********************************************************
*/

void LCD_L0_FillRect(int x0, int y0, int x1, int y1) {
  for (; y0 <= y1; y0++) {
    LCD_L0_DrawHLine(x0,y0, x1);
  }
}


/*
        *********************************************************
        *                                                       *
        *    Support for dynamic inversion of entire LCD        *
        *                                                       *
        *********************************************************

*/

#if LCD_REVERSEMODE_SUPPORT

void LCD_SetNormalDispMode    (void) {
}
void LCD_SetReverseDispMode   (void) {
}

#endif


/*
        *********************************************************
        *                                                       *
        *          Draw Bitmap 1 BPP, optimized                 *
        *                                                       *
        *********************************************************
*/

#if (LCD_OPTIMIZE)               \
      && (!LCD_SWAP_XY)          \
      && (!LCD_MIRROR_X)         \
      && (!LCD_MIRROR_Y)         \
      && (!LCD_SUPPORT_COMTRANS) \
      && (!LCD_SUPPORT_SEGTRANS)

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;
  if ((Index0==Index1) & (!(GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)))) {
    LCD_PIXELINDEX ColorIndexOld= COLOR;
    COLOR = Index0;
    LCD_L0_DrawHLine(x,y,x+xsize-1);
    COLOR = ColorIndexOld;
    return;
  }
  {
    int Adr=XY2OFF(x,y);
    int x1 = x+xsize-1;
    U8 Mask    = 0xff   >> (x &7);
    U8 EndMask = 0xff80 >> (x1&7);
    U8 CacheByte;
    U16 PixelData;
    int NumBytes = (x1>>3) - (x>>3);
    if (NumBytes) {
      CacheByte=Cache[Adr];
      PixelData   = (*(p+1) | ((*p)<<8));
      PixelData >>= (8+(x&7)-(Diff&7));
      switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR)) {
      case 0:
        if (!COLOR)
          PixelData ^= 255;
        CacheByte = (CacheByte&~Mask)|(PixelData&Mask);
        break;
      case LCD_DRAWMODE_TRANS:
        if (COLOR)
          CacheByte |= (PixelData&Mask);
        else
          CacheByte &= ~(PixelData&Mask);
        break;
      case LCD_DRAWMODE_XOR:
        CacheByte ^= (PixelData&Mask);
        break;
      }
      LCD_WRITE(Adr++,CacheByte);
      { 
        int DiffOld = Diff;
        Diff+= 8-(x&7); 
        if ((DiffOld&~7) != (Diff&~7))
          p++;
      }
      x=0;
      NumBytes--;
      for (; NumBytes; NumBytes--) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -