lcdchar.c

来自「三星2410的一些DEMO小例程」· C语言 代码 · 共 256 行

C
256
字号
/*
 *************************************************************************
 * Copyright (c) 2005, The Lab of Embedded System and Net Security,WHUT..
 * All rights reserved. 
 *
 * Filename:    lcdchar.c
 * Discription: This file deals with lcd text output,for s3c2410
 * 
 
 *************************************************************************
*/
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>


#include	"2410addr.h"
#include    "2410lib.h"
#include    "def.h"

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


static U16 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  = LCD_XSIZE_TFT_240320 - 1;
static S32	 g_windowBottom = LCD_YSIZE_TFT_240320 - 1; 
*/
static S32	 g_windowRight  = LCD_XSIZE_TFT_640480 - 1;
static S32	 g_windowBottom = LCD_YSIZE_TFT_640480 - 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, U16 bkColor, U16 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)
	{
		Glib_FilledRectangle(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;
						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(U16 color)
{
	g_frontColor=color;
}

U8 getcolor(void)
{
	return g_frontColor;
}

U8 getbkcolor(void)
{
  return g_backColor;
}

void setbkcolor(U16 color)
{
	U32 i;
	U16 *pDisp =(U16*)frameBuffer16BitTft640480;
	g_backColor=color;
	for (i = 0; i < (SCR_XSIZE_TFT_640480 * SCR_YSIZE_TFT_640480); i++)
	{
		*pDisp++ = g_backColor;
	}
/*	
	for (i = 0; i < (SCR_XSIZE_TFT_240320 * SCR_YSIZE_TFT_240320  / 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)
	{
		Glib_FilledRectangle(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;
		      	  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 + =
减小字号Ctrl + -
显示快捷键?