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

📄 display._c

📁 已经上传的YF-320240-3.5寸彩屏(可由单片机控制)的测试程序。主CPU为MEGA128
💻 _C
📖 第 1 页 / 共 3 页
字号:
#include <iom128v.h>
#include <macros.h>
#include <math.h>
#include "lcd.h"
#include "touch.h"
#include "display.h"
#include "stdio.h"

/*
     功能:轮换一个有符号的整数
	 输入,目标数组,需要显示的数,小数点位数,
	 输出:无
	 编者:赫树开
	 日期:二○○六年二月二十四日
*/
/*void Convert_SignedInt(unsigned char *str,int temp, unsigned char point)
{
    unsigned char tt[8];
    unsigned char i;
	sprintf(tt,"%6d",temp);//右-左,遇见" "证明字符串结束
	for(i = 0;i< point;i++)
	{
	    tt[6-i] = tt[5-i];
		if(tt[6-i] == ' ')
		{
		    tt[6-i] = '0';
		}
	}
	if(point)
	{
	   tt[6-point] = '.';
	   if(tt[6-point-1] == ' ')//如果前面为空格,证明没有只有小数,而没有整数
	   {
	       tt[5-point] = '0';
	   }
	}  
	if(tt[6-point-1] == ' ')//如果不是小数,又全部为空格,所以该数只能是0
	{
	    tt[5-point] = '0';
	} 
	else if(tt[5 - point] =='-')
	{
	    tt[4-point] = '-';
		tt[5-point] = '0';
	}
	tt[7] = 0;
	StringCat(str,tt,6);
}*/
/*
     功能:显示一个无符号的整数
	 输入,显示坐标,需要显示的数,小数点位数,字和背景色
	 输出:无
	 编者:赫树开
	 日期:二○○六年二月二十四日
*/
void Dis_Int(unsigned int x,unsigned char y,unsigned int temp, unsigned char point,unsigned char front,unsigned char back)
{
    unsigned char tt;
    unsigned char flag=0;
	
    if(point>4) point=4;
    tt=temp/10000;
    temp%=10000;
    if((tt==0)&(flag==0)&(point!=4))
    {
       tt=' ';
    }
    else
    {
       flag=1;
       tt+=0x30;
    }
    Dis_Ascii(x,y,tt,front,back);
    if(point==4)
    {
       x+=8;
       Dis_Ascii(x,y,'.',front,back);
    }
    tt=temp/1000;
    temp%=1000;
    if((tt==0)&(flag==0)&(point!=3))
    {
        tt=' ';
    }
    else
    {
       flag=1;
       tt+=0x30;
    }
    x+=8;
    Dis_Ascii(x,y,tt,front,back);
    if(point==3)
    {
       x+=8;
       Dis_Ascii(x,y,'.',front,back);
    }
    tt = temp/100;
    temp %= 100;
    if((tt==0)&(flag==0)&(point!=2))
    {
        tt=' ';
    }
    else
    {
        flag=1;
        tt+=0x30;
    }
    x+=8;
    Dis_Ascii(x,y,tt,front,back);
    if(point==2)
    {
       x+=8;
       Dis_Ascii(x,y,'.',front,back);
    }
    tt=temp/10;
    temp%=10;
    if((tt==0)&(flag==0)&(point!=1))
    {
       tt=' ';
    }
    else
    {
       flag=1;
       tt+=0x30;
    }
    x+=8;
    Dis_Ascii(x,y,tt,front,back);
    if(point==1)
    {
       x+=8;
       Dis_Ascii(x,y,'.',front,back);
    }
    x+=8;
    Dis_Ascii(x,y,temp+0x30,front,back);
}
/*
    功能:画直线
  参数:(x1,y1) 为起点坐标
     (x2,y2) 为终点坐标
     color 为线的颜色
     编写者:赫树开
     日期:2005.12.1
*/
void DrawLine(unsigned int x1,unsigned char y1,unsigned int x2,unsigned char y2,unsigned char color)
{
     float sx,sy,ex,ey;
	 unsigned int x;
	 unsigned char y;
	 sx = x1;
	 sy = y1;
	 ex = x2;
	 ey = y2;
	 if(fabs(sx-ex)>=fabs(sy-ey))
	 {   
	     if(x1>x2)//交换两者数据,保证x1<x2
		 {
		     x = x1;
			 x1 = x2;
			 x2 = x;
		 }
	     for(x=x1;x<x2;x++)
	     { 
		     y = (ey-sy)*(x-sx)/(ex-sx)+sy;
		     Y_ADDR = y;
             X_ADDR = x;
             CMD = ( x/256)<<2;//TFT板为CMD = ( x/256)<<2;,CSTN板为CMD = (( x/256)<<6)|0x04;
		     DAT = color;
		     Y_ADDR = y+1;
             X_ADDR = x;
             CMD = ( x/256)<<2;//TFT板为CMD = ( x/256)<<2;,CSTN板为CMD = (( x/256)<<6)|0x04;
		     DAT = color;
         }
     }
	 else
	 {
	     if(y1>y2)//交换两者数据,保证y1<y2
		 {
		     y = y1;
			 y1 = y2;
			 y2 = y;
		 }
	     for(y=y1;y<y2;y++)
	     { 
		     x = (ex-sx)*(y-sy)/(ey-sy)+sx;
		     Y_ADDR = y;
             X_ADDR = x;
             CMD = ( x/256)<<2;//TFT板为CMD = ( x/256)<<2;,CSTN板为CMD = (( x/256)<<6)|0x04;
		     DAT = color;
			 _NOP();
			 _NOP();
			 DAT = color;
		     //Y_ADDR = y;
             //X_ADDR = x+1;
             //CMD = ( x/256)<<2;//TFT板为CMD = ( x/256)<<2;,CSTN板为CMD = (( x/256)<<6)|0x04;
		     //DAT = color; 
         }
	 }		 
}

/*
    功能:显示命令按键
	参数:struct Command
	
*/
void Dis_Command(struct Command cmd)
{
    if((cursor.x >cmd.x)&&(cursor.y >cmd.y)&&((cursor.x-cmd.x)<cmd.width)&&((cursor.y - cmd.y) < cmd.lenth))
	{
	    if((cmd.width >0)&&(cmd.lenth>0))
	    {
	        Dis_Rect(cmd.x,cmd.y,cmd.width,cmd.lenth,cmd.cursor_color);
	    } 
		if(cmd.font == FLAG)
		{
		   Dis_Flag(cmd.x+5,cmd.y+5,*cmd.str - 0x30,cmd.string_color,cmd.color);
		}
		else
		{
	      Display(cmd.x+5,cmd.y+5,cmd.str,cmd.font,cmd.string_color,cmd.cursor_color);
		}  
	} 
	else
	{
        if((cmd.width >0)&&(cmd.lenth>0))
	    {
	        Dis_Rect(cmd.x,cmd.y,cmd.width,cmd.lenth,cmd.color);
	    } 
		if(cmd.font == FLAG)
		{
		   Dis_Flag(cmd.x+5,cmd.y+5,*cmd.str - 0x30,cmd.string_color,cmd.color);
		}
		else
		{
	       Display(cmd.x+5,cmd.y+5,cmd.str,cmd.font,cmd.string_color,cmd.color);
		}
	}
  
}
/*显示光标*/
unsigned char const DotCursor[][32]=
{
   0xFF,0xC0,0x80,0x80,0x81,0x00,0x82,0x00,//光标 0
   0x81,0x00,0x80,0x80,0x90,0x40,0xA8,0x20,
   0xC4,0x10,0x82,0x08,0x01,0x04,0x00,0x88,
   0x00,0x50,0x00,0x20,0x00,0x00,0x00,0x00,
   /*--  宽度x高度=16x16  --*/
   0x01,0x80,0x03,0xC0,0x06,0x60,0x0C,0x30,//上键头 1
   0x18,0x18,0x30,0x0C,0x3F,0xFC,0x01,0x80,
   0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
   0x01,0x80,0x01,0x80,0x01,0x80,0x01,0x80,
   /*--  调入了一幅图像:这是向右的箭头的图像  --*/
   /*--  宽度x高度=16x16  --*/
   0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x70,//右键头 2
   0x00,0x58,0x00,0x4C,0x00,0x46,0xFF,0xC3,
   0xFF,0xC3,0x00,0x46,0x00,0x4C,0x00,0x58,
   0x00,0x70,0x00,0x60,0x00,0x00,0x00,0x00,
   
   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,//√ 3
   0x00,0x06,0x00,0x0C,0x00,0x18,0x00,0x30,
   0x00,0x60,0x40,0xC0,0x61,0x80,0xF3,0x00,
   0xB6,0x00,0x1E,0x00,0x0C,0x00,0x00,0x00,
   /*--  调入了一幅图像:这是各向左的粗箭头的图像  --*/
/*--  宽度x高度=16x16  --*/
   0x03,0x00,0x07,0x00,0x0F,0x00,0x1B,0x00,//4
   0x33,0xFF,0x63,0xFF,0x40,0x03,0x80,0x03,
   0x80,0x03,0x40,0x03,0x63,0xFF,0x33,0xFF,
   0x1B,0x00,0x0F,0x00,0x07,0x00,0x03,0x00,
   
/*--  调入了一幅图像:这是向右的粗箭头的图像  --*/
/*--  宽度x高度=16x16  --*/
   0x00,0xC0,0x00,0xE0,0x00,0xF0,0x00,0xD8,//5
   0xFF,0xCC,0xFF,0xC6,0xC0,0x02,0xC0,0x01,
   0xC0,0x01,0xC0,0x02,0xFF,0xC6,0xFF,0xCC,
   0x00,0xD8,0x00,0xF0,0x00,0xE0,0x00,0xC0,
   /*--  调入了一幅图像:这是向上的粗箭头的图像  --*/
/*--  宽度x高度=16x16  --*/
   0x01,0x80,0x03,0xC0,0x06,0x60,0x0C,0x30,//6
   0x18,0x18,0x30,0x0C,0x7E,0x7E,0x7E,0x7E,
   0x06,0x60,0x06,0x60,0x06,0x60,0x06,0x60,
   0x06,0x60,0x06,0x60,0x07,0xE0,0x07,0xE0,
/*--  调入了一幅图像:这是向下的粗箭头的图像  --*/
/*--  宽度x高度=16x16  --*/

⌨️ 快捷键说明

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