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

📄 lcd.c

📁 HY-12896A-T01 LCD的驱动
💻 C
📖 第 1 页 / 共 2 页
字号:
	      }
	}
   }

   gCurCol++;
}



/********************************************************************/
//功能:    在屏幕上显示一个汉字
//         str指向这个汉字的显示矩阵
//         reverse为是否要反显 reverse = 0 为正显, reverse = 1 为反显.
//
/********************************************************************/
void print_chinese(unsigned char * str,int reverse)
{
    unsigned char j,k;

    if(gCurCol >= 15)//一共有十六列, 每个汉字占用两列
    {
	 gCurCol = 0;
         gCurRow++;
    }

    if(gCurRow >= 6)	//一共有六行(编号从零开始).
    {
     gCurRow = 0;
    }

   set_cursor(gCurRow,gCurCol);

   for(j = 0; j < 2; j++)
   {
      set_pos(gCurRow * 2 + j, gCurCol * 8);
		
      if(reverse == 0)//正显
      {
         for(k = 0; k < 16; k++)	//汉字的宽度是十六个点阵
	 {
	     wdata(str[j*16 +k]);
	     wdata(str[j*16 +k]);
	 }
      }
      else if(reverse == 1)//反显
      {
          for(k=0;k<16;k++)	
	  {
	     wdata(~str[j*16 +k]);
	     wdata(~str[j*16 +k]);
	  }
      }
  }

   gCurCol+=2;
}


/**********************************************************************/
//将一个字符的编码转换成符合HY-12896A-T01显示器编码
//
//ASCII 字符的矩阵为 8*16  以下是字库中字符的的编码模式
//       0       (7,6,5,4,3,2,1,0)
//       2       (7,6,5,4,3,2,1,0)
//       :        ...............
//       :        ...............
//      14       (7,6,5,4,3,2,1,0)
//      15       (7,6,5,4,3,2,1,0)
//
//
//而且字符字库中的编码是反面显示的.
/**********************************************************************/
void disp_character( char * str, int reverse)
{
	unsigned char j,k;
	unsigned char ldata,result;
	unsigned char printf_buffer[16];
	
	for(j = 0; j < 8; j++)//
	{
		result = 0;
		
		//for(k = 0; k < 8; k++) //closed by ChengDong Lu at 03/27/2006
                for(k = 2; k < 8; k++)//added by ChengDong Lu at 03/27/2006
		{
			//ldata = str[k]; //closed by ChengDong Lu at 03/27/2006
                        ldata = str[ k - 2 ];//added by ChengDong Lu at 03/27/2006
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}

		printf_buffer[ 7 - j ] = result;
	}
	
	
	for(j = 0; j < 8; j++)//显示字符的下半部位
	{
		result = 0;
		
		//for(k = 0; k < 4; k++)//closed by ChengDong Lu at 03/27/2006
                for(k = 0; k < 6; k++) //added by ChengDong Lu at 03/27/2006
		{
			//ldata = str[8 + k];//closed by ChengDong Lu at 03/27/2006
                        ldata = str[8 + k - 2 ];//added by ChengDong Lu at 03/27/2006
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}

		//result = result >> 4;//closed by ChengDong Lu at 03/27/2006
                result = result >> 2;//added by ChengDong Lu at 03/27/2006
		printf_buffer[ 15 - j] = result;
	}

	print_character(printf_buffer,reverse);
}



/*********************************************************************/
//将字库中的汉字编码转换成符合  HY-12896A-T01 显示的编码.
//                  字库中的汉字的编码
//0(15,14,13,12,11,10,9,8)  1 (7,6,5,4,3,2,1,0)
//2(15,14,13,12,11,10,9,8)  3 (7,6,5,4,3,2,1,0)
//4(15,14,13,12,11,10,9,8)  5 (7,6,5,4,3,2,1,0)
//                        :
//                        :
//30(15,14,13,12,11,10,9,8) 31 (7,6,5,4,3,2,1,0)
//
//
/*********************************************************************/
void disp_chinese(unsigned char * str, int reverse)
{
	unsigned char j,k;
	unsigned char ldata,result;
	unsigned char printf_buffer[32];
	
	for(j = 0; j < 8; j++)//换算汉字的上半部分的左部分
	{
		result = 0;

		for(k = 0; k < 8; k++)
		{
			ldata = str[2 * k ];
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}
		
		printf_buffer[ j ] = result;
	}
	
	
	for(j = 0; j < 8; j++)//换算汉字的上半部分的右部分
	{
		result = 0;
		
		for(k = 0; k < 8; k++)
		{
			ldata = str[2 * k + 1];
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}
		
		printf_buffer[ 8 + j] = result;
	}
	
	for(j = 0; j < 8; j++)//换算汉字的下半部分的左部分
	{
		result = 0;
		
		for(k = 0; k < 8; k++)
		{
			ldata = str[16 + 2 * k ];
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}
		
		printf_buffer[16 + j] = result;
	}
	
	for(j = 0; j < 8; j++)//换算汉字的下半部分的右部分
	{
        result = 0;

		for(k = 0; k < 8; k++)
		{
			ldata = str[16 + 2 * k + 1];
			ldata = ldata << j;
			ldata = ldata & 0x80;
			result = result >> 1;
			result = result | ldata;
		}
		
		printf_buffer[ 24 + j] = result;
	}

	print_chinese(printf_buffer,reverse);//将转换好的编码写入到相应的显存中去.
}


/*****************************************************/
//从汉字库中找出当前该汉字的编码
//返回值: i = -1 没有找到
//        i >= 0 当前该汉字在字库character_dots[]中的位置
/******************************************************/
int get_hzk_dots(unsigned char hightbyte,unsigned char lowbyte)
 {
    int i;
    int j;

   j = get_charactor_dots_size();

    for(i = 0; i < j; i++)
    {
        if(hightbyte == charactor_dots[i].index[0] && lowbyte == charactor_dots[i].index[1])
        {
          return i;
        }
    }

    return ( -1);

 }






/*************************************************************/
//应用层调用这个函数在显示屏上显示字符
//row      :   为要显示的行号(一共有六行,行号从零开始编号)
//col      :   为要显示的列号(一共有十六列,每个汉字占用两列,字符占用一列)
//pstr     :   为要显示的字符串
//reverse  :   为是否是么显 reverse = 0时为正显 ,reverse = 1时为反显
//flash    :   为是否闪烁    flash = 0 时为不闪烁 flash = 1 时闪烁
/**************************************************************/

int  lcd_print(int row, int col, char *pStr, int reverse, int flash)
{
    unsigned char c1,c2;//cData;
    //unsigned char tmpBuf[64];
    unsigned char tmpBuf[96];//changed by ChengDong Lu at 04/03/2006
    unsigned char i,uLen;
    unsigned char uRow,uCol;
    unsigned char *pDots;
    int location;
	
    if(row <6 && row >=0 && col < 16 && col >=0 )
    {
	set_cursor(row,col);
    }
	
    strcpy(tmpBuf,pStr);
    uLen=strlen(tmpBuf);

    i=0;

    while(i<uLen)
    {
        c1 = tmpBuf[i];
        c2 = tmpBuf[i+1];

        uRow = fnGetRow();
        uCol = fnGetCol();

        if( c1<0x80)  // ASCII
        {
            if(c1 < 0x20)
            {
                switch(c1)
                {
                case CR:
                case LF: // ??3μ?ò??DD
                    i++;
                    if(uRow < 5)
                    {
                       set_cursor(uRow + 1,0);
                    }
                    else
                    {
                         set_cursor(0,0);
                    }
                    continue;
                case BS: // í???
                    if(uCol > 0)
                    {
		      uCol--;
		    }
						
		    set_cursor(uRow,uCol);
                   // cData = 0x00;
                    break;

                default: // ????
                    c1 = 0x1f;
                    break;
                }
            }
	
	         //pDots=get_asc_dots(c1)£? //é????a??oˉêyμ?1|?üê???μ?μ±?°×?·?μ?±à???ú×??a?Dμ?ê×μ??·
	         // disp_character(pDots);
             disp_character(ASC_MSK + (c1-0x1f) * 12, reverse);

            if(c1 != BS) // ·?í???
            {
                uCol++;
            }

        }
        else
        { // ?D??
		
          //  pDots=get_hzk_dots(c1,c2); //closed by ChengDong Lu at 03/12/2006
          // é????a??oˉêyμ?1|?üê???μ?μ±?°oo×?μ?±à???ú×??a?Dμ?ê×μ??·
          // μ?ê??ò??×?oóòa?¨×??oμ?×??a£?μ??ù?Yêμ?ê?é??è¥D′3ìDò
            location = get_hzk_dots(c1, c2);
            if(location >= 0)
            {
                pDots = &charactor_dots[location].dots[0];
                print_chinese(pDots, reverse);
            }

            uCol += 2;
            i++;
        }

        i++;
    }
    return uLen;
}




/******************************************************************************/
	//PB2 		RST 		    重启		
	//PB3 		CS		    片选			
	//PB4 		SCK		    时钟
	//PB1 		SDA 		    Serial data		
	//PB0 		A0 		    Register selection
/*****************************************************************************/
void lcd_main(void)
{

        lcd_init();
        lcd_EnLight( );

/*
        set_cursor(2,4);
	disp_chinese(GB_16, 1);
	lcd_delay(50);//??ê??°2a?±
	
	disp_chinese(GB_16 + 32, 1);
	lcd_delay(50);//??ê??°ê??±
	
	disp_chinese(GB_16 + 64, 0);
	lcd_delay(50);//??ê??°?D?±
	
	disp_chinese(GB_16 + 96, 0);
	lcd_delay(50);//??ê??°???±
	
	// lcd_print(0,1,"WELLCOME !",1,0);
	// lcd_print(1,1,"GOOD FRIEND !",1,0);

*/
        lcd_DisLight( );
	
}

⌨️ 快捷键说明

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