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

📄 lcdchar.c

📁 ES44b0开发板的LCD驱动程序
💻 C
字号:
/*
 *************************************************************************
 * Copyright (c) 2003, The Lab of Embedded System and Net Security,WHUT..
 * All rights reserved. 
 *
 * Filename:    lcdchar.c
 * Discription: This file deals with lcd text output
 * 
 * version:            1.0
 * Author:             Qiu Yanfei <qyfhm@tom.com>
 * Accomplished Date:  2004/7/28 19:55:00
 *************************************************************************
*/
#include <stdarg.h>
#include <stdio.h>
#include <string.h>


#include	"..\cpu\44breg.h"
#include    "..\cpu\44blib.h"
#include    "..\cpu\def.h"

#include "lcd.h"
#include "hzk16.h"
#include "LCDchar.h"

static U8 g_frontColor=BLACK, g_backColor=WHITE;

static S32   cursor_x=0, cursor_y=0;
static S32   g_windowLeft   = 0;
static S32	 g_windowTop    = 0;
static S32	 g_windowRight  = SCR_XSIZE - 1;
static S32	 g_windowBottom = SCR_YSIZE - 1; 

static void LCD_SendCharacter( char *temp_ptr);  // fzg add it 
static U32  get_hz( char *temp_ptr);    //fzg add it                          
static void LCD_SendChar( char temp_char);
void LCD_SendString( char *pt);

/*
***********************************************************************
*Make sure that the width and height is not less than what a char needs.
*the first pixel is (g_windowLeft, g_windowTop)
*the last pixel is (g_windowLeft + g_windowWidth - 1, g_windowTop + g_windowHeight - 1)
***********************************************************************
*/

void LCD_SetOutWindow(S32 x0, S32 y0, S32 x1, S32 y1, U8 bkColor, U8 frntColor)
{
	g_windowLeft   = x0;
	g_windowTop    = y0;
	g_windowRight  = x1;
	g_windowBottom = y1;
	g_backColor    = bkColor;
	g_frontColor   = frntColor;

	gotoxy(x0, y0);
}


static void LCD_SendChar( char temp_char)
{
    U32 ascii_w,i;
	U8 temp_num=0x80;
	S32 x, y; 
    
    if (cursor_x > g_windowRight + 1 - CHAR_WIDTH)
	{
		gotoxy(g_windowLeft, cursor_y + CHAR_HEIGHT + 1);
	}

	if (cursor_y > g_windowBottom + 1 - CHAR_HEIGHT)
	{
		Lcd_Fill_Box(g_windowLeft, g_windowTop, g_windowRight, g_windowBottom, g_backColor);
		gotoxy(g_windowLeft, g_windowTop);
	}   
	
	if ((cursor_x <= g_windowRight + 1 - CHAR_WIDTH) && (cursor_y <= g_windowBottom + 1 - CHAR_HEIGHT)
		&& (cursor_x >= g_windowLeft) && (cursor_y >= g_windowTop))
	{
		if(temp_char=='\n')     
		{ 
			gotoxy(g_windowLeft, cursor_y+CHAR_HEIGHT+1);
		}	    
		else
	    {
			x=cursor_x;
			y=cursor_y;
			for(ascii_w=0;ascii_w<CHAR_HEIGHT ;ascii_w++)
			{
				for(i=0;i<CHAR_WIDTH;i++)
				{
					if((Ascii[temp_char*CHAR_HEIGHT +ascii_w]&(temp_num>>i))!=0)
				    {
						x=cursor_x+i;
						y=cursor_y+ascii_w;
						LCD_PutPixel(x, y, g_frontColor);
					
				    }				   
				 } 
			 }
			 
			 gotoxy(cursor_x + CHAR_WIDTH , cursor_y);				
		 }		
	}
}

void LCD_SendString(char *pt)
{       
	while(*pt)
	{      
		 if(((*pt)>>7) & 0x01)
		 {
		 	LCD_SendCharacter(pt);   //display character 
		 	pt += 2;		  
		 }
		 else
		 {
		 	LCD_SendChar(*pt++);        //display ascii 
		 }
	}		 	
					                     
}

void LCD_Printf(char *fmt,...)
{
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    LCD_SendString(string);
    va_end(ap);
}

void gotoxy(unsigned int x,unsigned int y)
{
	
	cursor_x=x;
	cursor_y=y;
}

void setcolor(unsigned char color)
{
	g_frontColor=color;
}

U8 getcolor(void)
{
	return g_frontColor;
}

U8 getbkcolor(void)
{
  return g_backColor;
}

void setbkcolor(U8 color)
{
	U32 i;
	U32 *pDisp = (unsigned long *)aLcdActiveBuffer;
	g_backColor=color;
	
	for (i = 0; i < (SCR_XSIZE * SCR_YSIZE  / 4); i++)
	{
		*pDisp++ = ((g_backColor << 24) | (g_backColor << 16) | (g_backColor << 8) | g_backColor);
	}
}

/*
***************************************************************************************************
*
*	     THIS FUNCTIONG AIM TO DISPLAY CHINESE IN LCD
*
*	          ADDED  BY FAN ZUGUANG  2004-03-30 12:08PM					
*
***************************************************************************************************
*/

static void LCD_SendCharacter( char *temp_ptr)
{   
	U32 offset;
    U32 i,j,k;
    U8 temp_num=0x80;
    S32 x, y; 
    
    if (cursor_x > g_windowRight + 1 - CHINESE_WIDTH)
	{   
		gotoxy(g_windowLeft, cursor_y + CHAR_HEIGHT + 1);
	}

	if (cursor_y > g_windowBottom + 1 - CHAR_HEIGHT)
	{
		Lcd_Fill_Box(g_windowLeft, g_windowTop, g_windowRight, g_windowBottom, g_backColor);
		gotoxy(g_windowLeft, g_windowTop);
	}	
	
	offset=get_hz(temp_ptr);

	if ((cursor_x <= g_windowRight + 1 - CHINESE_WIDTH) && (cursor_y <= g_windowBottom + 1 - CHAR_HEIGHT)
		&& (cursor_x >= g_windowLeft) && (cursor_y >= g_windowTop))
	{	

	    for (i=0;i<16;i++)     
		   for(j=0;j<2;j++)
		      for(k=0;k<8;k++)
		      { 
		      	if((character[offset +i*2+j]&(temp_num>>k))!=0)	
		      	{
		           x=cursor_x+j*8+k;
		           y=cursor_y+i;
		      	   LCD_PutPixel(x, y, g_frontColor);	      	
		        }

		      }             
    }	
    	    
    gotoxy(cursor_x + CHINESE_WIDTH , cursor_y);	
}

/*
***************************************************************************************************
*
*	THIS FUNCTIONG AIM TO GET THE OFFSET OF THE CHINESE CHARACTER IN THE STORAGE
*
*	          ADDED  BY FAN ZUGUANG  2004-03-30 12:08PM					
*
***************************************************************************************************
*/

static U32 get_hz( char *temp_ptr)
{    
	U8  qh,wh;
    U32 offset;
    
    qh=(*temp_ptr)-0xa0;
    
    temp_ptr++;

    wh=*temp_ptr-0xa0;
    
    offset=(94*(qh-1)+(wh-1))*32;

    return offset;	
}

⌨️ 快捷键说明

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