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

📄 lcd.c

📁 基于ARM7的直流电机的驱动,还有FLASH驱动,LCD驱动等
💻 C
📖 第 1 页 / 共 3 页
字号:
//
void
ShowLedDigit(UINT x, UINT y, UINT n) {
	UCHAR	bits = DTbl[n];
	
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);
	
	if(bits & 0x1) {
		DrawVertLine(x, y + 11, y + 19, LED_COLOR);
		DrawVertLine(x + 1, y + 12, y + 18, LED_COLOR);
		DrawVertLine(x + 2, y + 13, y + 17, LED_COLOR);
	}
	if(bits & 0x2) {
		DrawHorzLine(x + 4, x + 5, y + 18, LED_COLOR);
		DrawHorzLine(x + 3, x + 6, y + 19, LED_COLOR);
		DrawHorzLine(x + 2, x + 7, y + 20, LED_COLOR);
	}
	if(bits & 0x4) {
		DrawVertLine(x + 7, y + 13, y + 17, LED_COLOR);
		DrawVertLine(x + 8, y + 12, y + 18, LED_COLOR);
		DrawVertLine(x + 9, y + 11, y + 19, LED_COLOR);
	}
	if(bits & 0x10) {
		DrawVertLine(x + 7, y + 3, y + 7, LED_COLOR);
		DrawVertLine(x + 8, y + 2, y + 8, LED_COLOR);
		DrawVertLine(x + 9, y + 1, y + 9, LED_COLOR);
	}
	if(bits & 0x20) {
		DrawHorzLine(x + 2, x + 7, y + 0, LED_COLOR);
		DrawHorzLine(x + 3, x + 6, y + 1, LED_COLOR);
		DrawHorzLine(x + 4, x + 5, y + 2, LED_COLOR);
	}
	if(bits & 0x40) {
		DrawVertLine(x + 0, y + 1, y + 9, LED_COLOR);
		DrawVertLine(x + 1, y + 2, y + 8, LED_COLOR);
		DrawVertLine(x + 2, y + 3, y + 7, LED_COLOR);
	}
	if(bits & 0x80) {
		DrawHorzLine(x + 2, x + 7, y + 9, LED_COLOR);
		DrawHorzLine(x + 1, x + 8, y + 10, LED_COLOR);
		DrawHorzLine(x + 2, x + 7, y + 11, LED_COLOR);
	}
}

// 用七段码数显示一个整数
// x: 横坐标
// y: 纵坐标
// val: 待显示整数
// w: 数据位数
//
void
ShowLedNumber(UINT x, UINT y, UINT val, UINT w) {
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);

	x += w * 13 - 13;//13每位,-13表示和最后面的空格13
	do {

		ASSERT(x < LCD_XSIZEp);

		ShowLedDigit(x, y, val % 10);
		val /= 10;
		x -= 13;
	} while(--w != 0 && val != 0);
}


#define	NM(x)	((UCHAR)(x) - 0xA1)
static const unsigned short bit_mask[16]={
	0x0080,0x0040,0x0020,0x0010,0x0008,0x0004,0x0002,0x0001,
	0x8000,0x4000,0x2000,0x1000,0x0800,0x0400,0x0200,0x0100};

// 显示汉字
//
// x: 横坐标
// y: 纵坐标
// hz: 汉字
//
void
OutHz(UINT x, UINT y, const char *hz)
{
	UCHAR	*pdc;
	USHORT	*hzDot;
	int		i, j;
	
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);
	CHECK_PTR(hz);
	
	pdc = (UCHAR*)DC + x + y * LCD_XSIZE;
	hzDot = (USHORT *)CHS_FONT + (94L*NM(hz[0]) + NM(hz[1])) * 16L;
	for(i = 0; i < 16; i++) {//汉字大小16x16
		UINT	bits = *hzDot++;
		for(j = 0; j < 16; j++)
		if(bits & bit_mask[j])
			pdc[j] = attr;
		//else
		//	pdc[j] = bgcr;
		pdc += LCD_XSIZE;
	}
}

// 显示ASCII字符
//
// x: 横坐标
// y: 纵坐标
// ch: ASCII字符
//
void
OutAscii(UINT x, UINT y, char ch)
{
	int		i, j;
	UCHAR	*pzk, *pdc;
	
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);
	
	pdc = (UCHAR*)DC + x + y * LCD_XSIZE;
	pzk = (UCHAR*)ASCII_FONT + (UCHAR)ch * 16;
	for(i = 0; i < 16; i++) {//16x8	大小
		UCHAR bits = *pzk++;
		for(j = 0; j < 8; j++)
		if(bits & bit_mask[j])
			pdc[j] = attr;
		//else
		//	pdc[j] = bgcr;
		pdc += LCD_XSIZE;
	}
}

// 显示汉字符串
//
// x: 横坐标
// y: 纵坐标
// str: 字符串
//
void
OutString(UINT x, UINT y, const char *str)
{
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);
	CHECK_PTR(str);

	while(*str) {
		
		ASSERT(x < LCD_XSIZEp);
		
		if((UCHAR)*str > 0xa0 && (UCHAR)str[1] > 0xa0) {
			OutHz(x, y, str);
			str += 2;
			x += 16;
		}
		else {
			OutAscii(x, y, *str);
			str++;
			x += 8;
		}
	}
}

// 显示汉字符串(显示在一行内)
//
// x: 横坐标
// y: 纵坐标
// str: 字符串
//
void
OutString2(UINT x, UINT y, const char *str)
{
	ASSERT(x < LCD_XSIZEp);
	ASSERT(y < LCD_YSIZEp);
	CHECK_PTR(str);
	
	while(*str && x + 8 < 640) {
		if((UCHAR)*str > 0xa0 && (UCHAR)str[1] > 0xa0) {
			OutHz(x, y, str);
			str += 2;
			x += 16;
		}
		else {
			OutAscii(x, y, *str);
			str++;
			x += 8;
		}
	}
}

/*定义与菜单相关的全局变量************************/

uchar Language;              //菜单语言切换

#define MenuMaxNum 19        //菜单最大条数

uint Board_P[130][200];

uint Data[MenuMaxNum]={1,2,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};   //菜单调整保存后数据(选中的项目)

uchar select_num[MenuMaxNum]={2,3,0,3,4,0,4,3,4,3,0,4,0,3,2,0,0,2,0};   //菜单下项目个数

uint menu_x=75,menu_y=104;

uint help_x=300,help_y=315;

uint scroll_x=223,scroll_y=100;

uint set_x=298,set_y=106;

uint Board_x=220,Board_y=160;

// LcdMain移出内容
uint L_Tab=1;
uint i=1;                           //i标志选中的位置
uint local=1;                       //选择条位置
uint local_i=1;                     //设置块位置
uint Layle=1;                       //菜单层位置
uint Data_Temp[MenuMaxNum];         //保存临时数据  最后保存退出时用这些数据

// 状态定义
#define SETSTATE		1

UCHAR CurState;


/* 屏幕保护**************************************************/

static UCHAR	Greening;// 屏幕保护状态

void GreenMain(void *args)
{
	void SelectState(UCHAR);
	// 是否运行
	UCHAR running = FALSE;
	static UINT ScreenX,ScreenY;
	
	while(1)
	{
		// 执行进入与退出屏幕保护的相关处理
		if(Greening && !running)
		{	
			// 进入屏幕保护	
			// ...
			
			Lcd_Clr(); //LCD 清屏
			ScreenX = 100;
			ScreenY = 100;
			running = TRUE;
		}
		else if(!Greening && running)
		{
			// 恢复屏幕显示
			// ... 
			
			Lcd_Clr(); //LCD 清屏
			SelectState(CurState);
			running = FALSE;
		}
		
		// 屏幕保护代码
		if(running == TRUE)
		{
			// 屏幕保护代码
			// ...
			
			Lcd_Clr();
			drawbmp(ScreenX,ScreenY,logo,sizeof(logo));//公司标志
		}
		
		tm_delay(30);
	}
}

/*********************界面初始化********************/

void LCD_Menu_Iint()               //初始化菜单 
{
    
	DrawRect(10,10,630,470,44);    //画外边框
	DrawRect(45,80,250,380,44);    //显示选择框
    Lcd_FillRect(61,72,48,16,0);
	DrawRect(280,80,600,280,44);   //显示设置框
	Lcd_FillRect(296,72,48,16,0);
    DrawRect(280,300,600,380,44);  //显示帮助框
	Lcd_FillRect(296,292,48,16,0);
	if(Language==1)
	{
	OutString(270,30,"用户设置选项");
	OutString(296,72," 设置 ");
	OutString(61,72," 选择 ");
	OutString(296,292," 帮助 ");
	}
	else
	{
	OutString(270,30,"USER SETTING");
	OutString(296,72," SET ");
	OutString(61,72,"SELECT ");
	OutString(296,292," HELP ");
	}  	
}

void LCD_Scroll_Iint()
{
   	DrawRect(223,100,237,344,44);          //画滚动条
	OutAscii(227,102,30);
	OutAscii(227,329,31);
	Lcd_FillRect(scroll_x+2,scroll_y+18,10,30,44);
}

void LCD_Data_Iint(uint *Data_Temp)
{
  int i;
  for(i=0;i<MenuMaxNum;i++)
    Data_Temp[i]=Data[i];
}

/*清菜单区域*/
void CLR_Menu()
{
	Lcd_FillRect(menu_x,menu_y,112,240,0);
}
/*清帮助区域*/
void CLR_Help()
{
	Lcd_FillRect(help_x,help_y,224,37,0);
}
/*清设置区域*/
void CLR_Setting()
{
	Lcd_FillRect(set_x,set_y,300,170,0);
}

/***********************各种效果**************************/

//设置项目

void Change_Set_Iint(uint i,uint *Data_Temp)
{
    int x,y;
    x=set_x+16;
    y=set_y+16;
    if(select_num[i-1]!=0)                      //选择模式
    {
    if(Data_Temp[i-1]==0) return;                    //无选项错误
    if(Data_Temp[i-1]<=3)
      Lcd_FillRect(x+10,y+32*Data_Temp[i-1]+2,6,6,44); 
    if(Data_Temp[i-1]>3)
      Lcd_FillRect(x+154,y+32*Data_Temp[i-1],6,6,44);
    }
    else
    {
      //直接在规定位置显示存储数据
    }  

}

// 上移设置项目

void Change_Set_Up(uint *j)
{
  uint a,x,y;
  x=set_x+16;
  y=set_y+16;
  a=*j;
  if(a==1) return;
  if(a==4)
  {
    Lcd_FillRect(x+154,y+34,6,6,0);
    Lcd_FillRect(x+10,y+98,6,6,44);
  }
  if(a>4)
  {
    Lcd_FillRect(x+154,y+32*(a-3)+2,6,6,0);
    Lcd_FillRect(x+154,y+32*(a-4)+2,6,6,44);
  }
  if(a<4)
  {
    Lcd_FillRect(x+10,y+32*a+2,6,6,0);
    Lcd_FillRect(x+10,y+32*(a-1)+2,6,6,44);
  }
  a--;
  *j=a;
}

// 下移设置项目

void Change_Set_Down(uint i,uint *j)
{
  uint a,x,y;
  a=*j;
  x=set_x+16;
  y=set_y+16;
  if(a==select_num[i-1]) return;
  if(a==3)
  {
    Lcd_FillRect(x+10,y+98,6,6,0);
    Lcd_FillRect(x+154,y+34,6,6,44);
  }
  if(a>3)
  {
    Lcd_FillRect(x+154,y+32*(a-3)+2,6,6,0);
    Lcd_FillRect(x+154,y+32*(a-2)+2,6,6,44);
  }
  if(a<3)
  {
    Lcd_FillRect(x+10,y+32*a+2,6,6,0);
    Lcd_FillRect(x+10,y+32*(a+1)+2,6,6,44);
  }
  a++;
  *j=a;
}

// 绘制按键

void Draw_Button()                        
{
   uint i;
   for(i=0;i<5;i++)
	FillRect(40+i*120,400,126+i*120,450,44);
}

// 按键按下效果 i  按键位置

void Button_Press(uint i)                 
{
   Lcd_NotRect(40+(i-1)*120,400,86,50);
   tm_delay(10);
   Lcd_NotRect(40+(i-1)*120,400,86,50); 
}

// 绘制弹出提示面板

void Draw_Board()                
{
  DrawRect(Board_x,Board_y,Board_x+198,Board_y+128,44);
  Lcd_FillRect(Board_x+4,Board_y+4,190,120,255);
}

// 保存弹出板下的内容

void LCD_Board_P()               
{
  uint w=198,h=128;
  int i,j;
  for(i=Board_y;i<=Board_y+h;i++)
    for(j=Board_x;j<=Board_x+w;j++)
      Board_P[i-Board_y][j-Board_x]=*((UCHAR*)DC + j + i * LCD_XSIZE);
      
}

// 还原弹出板下的内容

void LCD_Board_V()               
{
  uint w=198,h=128;
  int i,j;
  Lcd_FillRect(Board_x,Board_y,w,h,0);
  for(i=Board_y;i<=Board_y+h;i++)
    for(j=Board_x;j<=Board_x+w;j++)
      *((UCHAR*)DC + j + i * LCD_XSIZE)=Board_P[i-Board_y][j-Board_x];
}

// Enter按键进入效果

void SET_Enter()     
{
  int i;
  for(i=0;i<=5;i++)
  {   
  	DrawRect(288+i*2,96+i*2,598-i*2,272-i*2,44);
  	tm_delay(5);
  	DrawRect(288+i*2,96+i*2,598-i*2,272-i*2,0); 
  }
  DrawRect(288+5*2,96+5*2,598-5*2,272-5*2,44);
}

// 滚动条效果   与 i,local 相关  与maxnum 相关

void LCD_Scroll_DOWN(uint i)
{
   if(i!=1)
     Lcd_FillRect(scroll_x+2,scroll_y+18,10,30,0);
     Lcd_FillRect(scroll_x+2,scroll_y+20+9*(i-1),10,30,0);
   if(i<=18)
     Lcd_FillRect(scroll_x+2,scroll_y+20+9*i,10,30,44);
}

void LCD_Scroll_UP(uint i)
{
     Lcd_FillRect(scroll_x+2,scroll_y+20+9*(i+1),10,30,0);
     Lcd_FillRect(scroll_x+2,scroll_y+20+9*i,10,30,44);
}

/*选中效果*/
void LCD_Select(int i)
{
   Lcd_NotRect(menu_x,menu_y+32*(i-1),112,16); 
}   

/**********************定义键面文字*******************/

// 按键效果切换

void Button_Change(uint Tab)                 
{
	uint i;
	char str[5][10]={"向上","向下","进入","保存","退出",};
	char str1[5][10]={"调整+","调整-","","保存","返回",};
	char str2[5][10]={"UP","DOWN","ENTER","SAVE","QUIT",};
	char str3[5][10]={"ADD+","SUB-","","SAVE","RETURN",};
    char str4[2][10]={"确认","取消"};
    char str5[2][10]={"保存","返回"};
    char str6[2][10]={"CENTER","CANCLE"};
    char str7[2][10]={"SAVE","RETURN"};
    
    Draw_Button();
	if(Language==1)
	{ 
	  if(Tab==0)
	    for(i=0;i<2;i++)
	      OutString(190+i*240,417,str4[i]);
	  if(Tab==1)
	    for(i=0;i<5;i++)
	      OutString(70+i*120,417,str[i]);
      if(Tab==2)
        for(i=0;i<5;i++)

⌨️ 快捷键说明

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