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

📄 disp.c

📁 lcm显示功能
💻 C
字号:
// --------------------------------------------------------------------------------------
// - Suported library for LCD graphic display EL12864A. This is fast way to paint image -
// - and write our text to graphic display. Use application Image Converter for convert -
// - image in *.BMP format to three code compress array type (None, Zero, Full).	-
// - 											-
// -           You can download Image Converter V1.1 from www.imfsoft.com		-
// - 											-
// --------------------------------------------------------------------------------------

#include <stdio.h>
#include <reg51.h>
#include "DefHW.h"

// --------------------------------------
// - Table ASCII			-
// --------------------------------------
code unsigned char TabASCII[]=
{
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,
	0x00,0x00,0x14,0x7F,0x14,0x7F,0x14,0x00,0x26,0x49,0x7F,0x49,0x32,0x00,0x43,0x33,
	0x08,0x66,0x61,0x00,0x36,0x49,0x55,0x22,0x50,0x00,0x00,0x05,0x03,0x00,0x00,0x00,
	0x00,0x3E,0x41,0x00,0x00,0x00,0x00,0x41,0x3E,0x00,0x00,0x00,0x14,0x08,0x3E,0x08,
	0x14,0x00,0x08,0x08,0x3E,0x08,0x08,0x00,0x00,0xA0,0x60,0x00,0x00,0x00,0x10,0x10,
	0x10,0x10,0x10,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x60,0x1C,0x03,0x00,0x00,
	0x3E,0x41,0x41,0x41,0x3E,0x00,0x00,0x41,0x7F,0x40,0x00,0x00,0x42,0x61,0x51,0x49,
	0x66,0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x46,0x45,
	0x45,0x49,0x31,0x00,0x3C,0x4A,0x49,0x49,0x31,0x00,0x02,0x01,0x61,0x19,0x07,0x00,
	0x36,0x49,0x49,0x49,0x36,0x00,0x46,0x49,0x49,0x29,0x1E,0x00,0x00,0x36,0x36,0x00,
	0x00,0x00,0x00,0x56,0x36,0x00,0x00,0x00,0x08,0x14,0x14,0x14,0x22,0x00,0x14,0x14,
	0x14,0x14,0x14,0x00,0x22,0x14,0x14,0x14,0x08,0x00,0x02,0x51,0x09,0x06,0x00,0x00,
	0x34,0x52,0x52,0x42,0x3C,0x00,0x60,0x1C,0x13,0x1C,0x60,0x00,0x7F,0x49,0x49,0x49,
	0x36,0x00,0x3E,0x41,0x41,0x41,0x22,0x00,0x7F,0x41,0x41,0x22,0x1C,0x00,0x7F,0x49,
	0x49,0x49,0x41,0x00,0x7F,0x09,0x09,0x09,0x01,0x00,0x3E,0x41,0x49,0x49,0x3A,0x00,
	0x7F,0x08,0x08,0x08,0x7F,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x30,0x40,0x40,0x3F,
	0x00,0x00,0x7F,0x18,0x14,0x22,0x41,0x00,0x7F,0x40,0x40,0x40,0x00,0x00,0x7F,0x0C,
	0x18,0x0C,0x7F,0x00,0x7F,0x06,0x08,0x30,0x7F,0x00,0x3E,0x41,0x41,0x41,0x3E,0x00,
	0x7F,0x09,0x09,0x09,0x06,0x00,0x3E,0x41,0x51,0x21,0x5E,0x00,0x7F,0x09,0x09,0x09,
	0x76,0x00,0x26,0x49,0x49,0x49,0x32,0x00,0x01,0x01,0x7F,0x01,0x01,0x00,0x3F,0x40,
	0x40,0x40,0x3F,0x00,0x0F,0x10,0x60,0x10,0x0F,0x00,0x1F,0x60,0x18,0x60,0x1F,0x00,
	0x63,0x14,0x08,0x14,0x63,0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x61,0x51,0x49,0x45,
	0x43,0x00,0x00,0x7F,0x41,0x00,0x00,0x00,0x15,0x16,0x7C,0x16,0x15,0x00,0x00,0x41,
	0x7F,0x00,0x00,0x00,0x04,0x02,0x01,0x02,0x04,0x00,0x40,0x40,0x40,0x40,0x40,0x00,
	0x00,0x01,0x02,0x04,0x00,0x00,0x20,0x54,0x54,0x54,0x78,0x00,0x7F,0x44,0x44,0x44,
	0x38,0x00,0x38,0x44,0x44,0x44,0x28,0x00,0x38,0x44,0x44,0x44,0x7F,0x00,0x38,0x54,
	0x54,0x54,0x18,0x00,0x7E,0x05,0x05,0x01,0x00,0x00,0x98,0xA4,0xA4,0xA4,0x7C,0x00,
	0x7F,0x08,0x08,0x08,0x70,0x00,0x00,0x7D,0x00,0x00,0x00,0x00,0x40,0x3F,0x00,0x00,
	0x00,0x00,0x00,0x7F,0x08,0x14,0x22,0x40,0x00,0x00,0x3F,0x40,0x00,0x00,0x7C,0x04,
	0x78,0x04,0x78,0x00,0x7C,0x08,0x04,0x04,0x78,0x00,0x38,0x44,0x44,0x44,0x38,0x00,
	0xFE,0x12,0x12,0x12,0x0C,0x00,0x0C,0x12,0x12,0x12,0xFE,0x00,0x7E,0x04,0x02,0x02,
	0x00,0x00,0x24,0x4A,0x52,0x24,0x00,0x00,0x04,0x3F,0x44,0x40,0x00,0x00,0x3C,0x40,
	0x40,0x20,0x7C,0x00,0x0C,0x10,0x60,0x10,0x0C,0x00,0x1C,0x60,0x1C,0x60,0x1C,0x00,
	0x6C,0x10,0x10,0x6C,0x00,0x00,0x5C,0x50,0x70,0x1C,0x00,0x00,0x64,0x54,0x54,0x4C,
	0x00,0x00,0x00,0x08,0x36,0x41,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x41,
	0x36,0x08,0x00,0x00,0x08,0x08,0x2A,0x1C,0x08,0x00,0x08,0x1C,0x2A,0x08,0x08,0x00
};

// --------------------------------------
// - Write Byte to Display		-
// --------------------------------------
void DISP_WRITE(uchar wByte)
{
  uchar x;	
 
  PORT = wByte;
  E = TRUE; 
  E = FALSE;

  for(x=0;x<Time_Delay;x++);	
 }   	

// --------------------------------------
// - Set Adr X	(0..Disp_Height) 	-
// --------------------------------------
void DISP_ADR_X(uchar Adr)
{
  RS = FALSE;

  DISP_WRITE((0xB8|(Adr&0x07)));

  RS = TRUE;
 }

// --------------------------------------
// - Set Adr Y	(0..Disp_Width) 	-
// --------------------------------------
void DISP_ADR_Y(uchar Adr)
{
  RS = FALSE;

  DISP_WRITE((0x40|(Adr&0x3F)));

  RS = TRUE;
 }

// --------------------------------------
// - Set Adr Z				-
// --------------------------------------
void DISP_ADR_Z(uchar Adr)
{
  RS = FALSE;

  DISP_WRITE((0xC0|(Adr&0x3F)));

  RS = TRUE;
 }

// --------------------------------------
// - Display ON				-
// --------------------------------------
void DISP_ON(void)
{
  CS1 = TRUE;
  CS2 = TRUE;
  RS  = FALSE;

  DISP_WRITE(0x3F);

  RS  = TRUE;
  CS1 = FALSE;
  CS2 = FALSE;
 }

// --------------------------------------
// - Display OFF			-
// --------------------------------------
void DISP_OFF(void)
{	
  CS1 = TRUE;
  CS2 = TRUE;
  RS  = FALSE;

  DISP_WRITE(0x3E);

  RS  = TRUE;
  CS1 = FALSE;
  CS2 = FALSE;
 }

// --------------------------------------
// - Display Clear			-
// --------------------------------------
void DISP_CLEAR(void)
{
  uchar x,y;

  CS1 = TRUE;
  CS2 = TRUE;

  for(x=0;x<Disp_Height;x++)
  {
    DISP_ADR_X(x);
    DISP_ADR_Y(0);		
    for(y=0;y<Disp_Width;y++) DISP_WRITE(0);
   }
	
  CS1 = FALSE; 
  CS2 = FALSE;
 }

// --------------------------------------
// - Inicialization routine		-
// --------------------------------------
void DISP_INIT(void)
{
  RESET = FALSE;
  CS1	= FALSE;
  CS2	= FALSE;
  RS	= FALSE;
  RESET = TRUE; 				
  DISP_OFF();
  DISP_ON();
  DISP_CLEAR();
 }

// --------------------------------------
// - Convert Low Nibble to Byte		-
// --------------------------------------
void DISP_ZOOM(uchar *cByte)
{ 
  uchar M;
  M = (*cByte);
  (*cByte) = 0;
  if((M&0x08)==0x08) (*cByte)|=0xC0; 
  if((M&0x04)==0x04) (*cByte)|=0x30;
  if((M&0x02)==0x02) (*cByte)|=0x0C;
  if((M&0x01)==0x01) (*cByte)|=0x03;
 }

// --------------------------------------
// - Select direct control and send Byte to display 
// - wByte ... Byte to write
// - DISP_ROW .. Position in ROW <0..7>
// - DISP_COL .. Position in COLUMN <0..63>
// - DISP_ACT .. Actual Position in COLUMN <0..127>
// --------------------------------------
void DISP_DATA(uchar wByte, uchar DISP_ROW, uchar DISP_COL, uchar *DISP_ACT)
{
  if((*DISP_ACT)<Disp_Width)
  {
    CS1 = TRUE;			// Select control 1
    CS2	= FALSE;
   }
  else
  {
    CS1 = FALSE;
    CS2 = TRUE;
   }
  if(((*DISP_ACT)==DISP_COL)||((*DISP_ACT)==Disp_Width))
  {
    DISP_ADR_Y((*DISP_ACT)&0x3F);
    DISP_ADR_X(DISP_ROW);
   }
  DISP_WRITE(wByte);
  (*DISP_ACT)++;
  CS1 = FALSE;
  CS2 = FALSE;
 }

// --------------------------------------
// - Routine for writing text in ASCII code
// - *TextArray ... Pointer to Array with text
// -  TextLen ..... Length text 
// -  Size  ....... Size text <0..1> 	
// -  PosRow ...... Position in ROW <0..7>
// -  PosCol ...... Position in COLUMN <0..63>
// --------------------------------------
void DISP_TEXT(uchar *TextArray, uchar TextLen, uchar Size, uchar PosRow, uchar PosCol)
{
  uchar i,x,y,Large,TmpChar,TmpData,ActPos;	

  Size &= 0x01;			// Reduce size at 0 and 1
  Large = (Size == 0x01); 
  
  for(i=0;i<=Size;i++)
  { 
    ActPos = PosCol;
    for (x=0;x<TextLen;x++)
    {
      TmpChar = TextArray[x];		// Get Char and test Range
      if((TmpChar<32)||(TmpChar>128)) TmpChar = 32; 
      for (y=0;y<6;y++)
      { 
        TmpData = TabASCII[6*(TmpChar-32)+y];
        if(Large)
        {
          if(i == 0x01) TmpData = TmpData>>4;
          DISP_ZOOM(&TmpData);
          DISP_DATA(TmpData,PosRow,PosCol,&ActPos);
         }
        DISP_DATA(TmpData,PosRow,PosCol,&ActPos);
       }
     }
    PosRow++;
   } 
 }

// --------------------------------------
// - Decode IMAGE in Compress 0 (NONE) 	-
// --------------------------------------
void DISP_RY0(uchar *ImageArray, uchar PosRow, uchar PosCol)
{
  uchar x,y,Width,Height,ActPos;
  uint u;
  
  u = 3;
  Height = ImageArray[0]; 
  Width = ImageArray[1];

  for(x=0;x<Height;x++)
  {
    ActPos = PosCol;
    for(y=0;y<Width;y++)
    {
      DISP_DATA(ImageArray[u],PosRow,PosCol,&ActPos);
      u++;
     }
    PosRow++;
   }
 }


// --------------------------------------
// - Decode IMAGE in Compress 1 (ZERO) 	-
// --------------------------------------
void DISP_RY1(uchar *ImageArray, uchar PosRow, uchar PosCol)
{
  uchar x,y,Width,Height,TmpData,Count,ActPos;
  uint u;
  
  u = 3;
  Count = 0;
  TmpData = 0;
  Height = ImageArray[0]; 
  Width = ImageArray[1];

  for(x=0;x<Height;x++)
  {
    ActPos = PosCol;
    for(y=0;y<Width;y++)
    {
      if(Count == 0)
      {
        TmpData = ImageArray[u];
        u++;
        if(TmpData == 0)
        {
          Count = ImageArray[u];
          u++;
          Count--;
         }
       }
      else Count--; 
      DISP_DATA(TmpData,PosRow,PosCol,&ActPos);
     }
    PosRow++;
   }
 }


// --------------------------------------
// - Decode IMAGE in Compress 2 (FULL) 	-
// --------------------------------------
void DISP_RY2(uchar *ImageArray, uchar PosRow, uchar PosCol)
{
  uchar x,y,Width,Height,TmpData,Count,ActPos;
  uint u;
  
  u = 3;
  Count = 0;
  TmpData = 0;
  Height = ImageArray[0]; 
  Width = ImageArray[1];

  for(x=0;x<Height;x++)
  {
    ActPos = PosCol;
    for(y=0;y<Width;y++)
    {
      if(Count == 0)
      {
        TmpData = ImageArray[u];
        u++;
        Count = ImageArray[u];
        u++; 
      }      
      Count--; 
      DISP_DATA(TmpData,PosRow,PosCol,&ActPos);
     }
    PosRow++;
   }
 }

// --------------------------------------
// - Routine for paint commpress Image
// - ImageArray ... Pointer to Image table  
// - PosRow ....... Position in ROW <0..7>
// - PosColL ...... Position in COLUMN <0..63>
// --------------------------------------
void DISP_ICON(uchar *ImageArray,uchar PosRow,uchar PosCol)
{
  switch (ImageArray[2])
  {
    case 0: DISP_RY0(ImageArray,PosRow,PosCol); break; 
    case 1: DISP_RY1(ImageArray,PosRow,PosCol); break; 
    case 2: DISP_RY2(ImageArray,PosRow,PosCol); break; 
   }
 }

// --------------------------------------
// - Time PAUSE	(WAIT x 0.1s)		-
// --------------------------------------
void PAUSE(uchar WAIT)
{	
  uchar x,y;

  for(;WAIT;WAIT--)
  {
    for(x=0;x<0xFF;x++)
    {
      for(y=0;y<0xFF;y++) {;}
     }
   } 
 }

⌨️ 快捷键说明

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