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

📄 lcd_disphz.c

📁 s3c2410开发板的测试代码,包括lcd
💻 C
字号:
/*
*********************************************************
* Copyright (c)
* All rights reserved.				            
*
* 文件名称:LCD_DispHZ.c
* 文件标识:
* 摘    要:本文件是用与在液晶屏上显示汉字。
* 当前版本:1.0
* 作    者:刘征
* 完成日期:2005.4.3
*
* 取代版本:
* 作    者:
* 完成日期:
*********************************************************
*/

/*
*********************************************************
*   					 头文件
*********************************************************
*/
#include <stdio.h>
#include <stdarg.h>
#include "2410addr.h"
#include "2410lib.h"
#include "def.h"
#include "lcdlib.h"
#include "glib.h"
#include "LCD_DispHZ.h"
#include "VGA_ASCII8_16.h"
#include "CHS16_16.h"

/*
*********************************************************
*  				    函数原型
*********************************************************
*/


/*
*********************************************************
*  					  常量
*********************************************************
*/
#define LCD_YSIZE LCD_YSIZE_TFT_800600//根据不同屏调整
#define LCD_XSIZE LCD_XSIZE_TFT_800600

/*
*********************************************************
*  					  变量
*********************************************************
*/
//显示字符时的行数和列数
static unsigned int VGA_X = 0; // 0 ~ 39
static unsigned int VGA_Y = 0; // 0 ~ 14

/*
*********************************************************
* 函数介绍:本函数是确定字符显示的坐标位置				
* 输入参数:x---x坐标
*           y---y坐标
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_GotoXY(unsigned char x,unsigned char y)
{
    if(x >= VGA_X_MAX) 
         x = VGA_X_MAX - 1;
    if(y >= VGA_Y_MAX) 
         y = VGA_Y_MAX - 1;

    VGA_X = x;
    VGA_Y = y;
}

/*
*********************************************************
* 函数介绍:本函数是上移Up 行				
* 输入参数:Up---行数
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_LineUp(unsigned int Up)
{
	unsigned int i,j;

    if(Up && Up < LCD_YSIZE)//是否所传入的行数在指定的范围内
    {
    	for(i = Up; i < LCD_YSIZE; i++)//从当前行到LCD_YSIZE最大行
    	{
    		for(j = 0; j < LCD_XSIZE; j++)//每行都填背景色,上移一行
    		{
    			PutPixel(j, i, 0);//填每个像素
    		}
    	}
    }
}

/*
*********************************************************
* 函数介绍:本函数是送一个字节到LCD上显示,颜色由colorIndex确定				
* 输入参数:x---x坐标
*           y---y坐标
*           Fill---待显示的字节
*           colorIndex---颜色索引值
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_Fill(unsigned int x,unsigned int y,unsigned char Fill,unsigned long colorIndex)
{
	unsigned int k;
	
	if (x<LCD_XSIZE && y<LCD_YSIZE)
	{
		for(k=0; k<8; k++)
		{
			if(((Fill>>(7-k))&0x1) != NULL)
			{
				PutPixel(x+k,y,colorIndex);
			}
		}
	}
}

/*
*********************************************************
* 函数介绍:本函数显示一个汉字				
* 输入参数:x---x坐标
*           y---y坐标
*           QW---待显示的汉字
*           colorIndex---颜色索引值
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_PutHZ(unsigned int x,unsigned int y,unsigned short int QW,unsigned long colorIndex)
{
	unsigned int i,j;
	unsigned char *pZK;

    //根据汉字的区位码,计算该汉字在字库中偏移量 
	pZK = _pSYSFont1616 + (((QW >> 8)-1)*94 + (QW & 0x00FF)- 1)*32;
	for(i=0; i<16; i++) //将32位字节的点阵按位在屏幕上打印出来,显示汉字
	{
		for(j=0; j<2; j++)//16*16点阵,一行占2个字节
		{
			Lcd_Fill(x+8*j,y+i,*pZK,colorIndex);
			pZK++;
		}
	}
}

/*
*********************************************************
* 函数介绍:本函数显示一个ASCII字符				
* 输入参数:x---x坐标
*           y---y坐标
*           Fill---待显示的ASCII字符
*           colorIndex---颜色索引值
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_PutASCII(unsigned int x,unsigned int y,unsigned char Fill,unsigned long colorIndex)
{
	unsigned int i;
	unsigned char *pZK;

    //计算该ASCII字符在字库中偏移量
	pZK = _pSYSFont0816 + Fill*16;
	for( i = 0 ; i < 16 ; i++ )
	{
		Lcd_Fill(x,y+i,*pZK,colorIndex);
		pZK++;
	}
}

/*
*********************************************************
* 函数介绍:本函数是LCD屏幕上打印出一串字符串			
* 输入参数:fmt--指向被显示的字符串
*           colorIndex---颜色索引值
* 输出参数:无
* 返回值  :无
*********************************************************
*/ 
void Lcd_printf(unsigned long colorIndex,char *fmt,...)
{
    va_list ap;
    char string[256];
	unsigned char *pStr = (unsigned char *)string;
    unsigned int i = 0;

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    va_end(ap);
	 
    while(*pStr != 0 )
	{
		switch(*pStr)
		{
			case '\n' :
				{
                    VGA_X = 0;
                    VGA_Y++;
                    if( VGA_Y >= VGA_Y_MAX)
                    {
                        VGA_Y = VGA_Y_MAX - 1;
                        Lcd_LineUp(16);
                    }                    
		            pStr++;
                    i++;                    					
                    break;
				}

			default:
				{
                    if( VGA_X >= VGA_X_MAX )
                    { 
                        VGA_X = 0;
                        VGA_Y++;
                    }

                    if( VGA_Y >= VGA_Y_MAX)
                    {
                        VGA_Y = VGA_Y_MAX - 1;
                        Lcd_LineUp(16);
                    }

					if( *pStr > 0xA0 & *(pStr+1) > 0xA0 )  //中文输出
                    {
                        if( VGA_X >= (VGA_X_MAX - 1) )
                        { 
                            VGA_X = 0;
                            VGA_Y++;
                        }

                        if( VGA_Y >= VGA_Y_MAX)
                        {
                            VGA_Y = VGA_Y_MAX - 1;
                            Lcd_LineUp(16);
                        }

                        Lcd_PutHZ(VGA_X*8 , VGA_Y*16 , (*pStr - 0xA0)*0x0100 + *(pStr+1) - 0xA0,colorIndex);

                        VGA_X++;
                        pStr++;
                        i++;

                        VGA_X++;
		                pStr++;
                        i++;
                    }
                    else               //英文输出
                    {
                        Lcd_PutASCII(VGA_X*8, VGA_Y*16,*pStr,colorIndex);
                        VGA_X++;
		                pStr++;
                        i++;

                    }
                    break;
				}
		}

        if( i > 255 ) break;//最大显示255个字符
	}
   
}

⌨️ 快捷键说明

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