进阶——十六届蓝桥杯嵌入式熟练度练习(按键+LCD)

高亮(一)

声明

 char buf[21];
 unsigned char upled=0x04;
 uint8_t key_val;
 uint8_t key_down,key_up,key_old;
 uint32_t key_time;
 uint8_t key_temp,key_flag;
 uint8_t line_flag;

按键代码

void key_proc(void)
{
key_val=key_scan();
	key_down=key_val&(key_val^key_old);
	key_up=~key_val&(key_val^key_old);
	key_old=key_val;
if(key_down==4)
{
     line_flag++;
	if(line_flag==4)
	{line_flag=1;}
}
}

lcd高亮显示代码

注意:此段代码if-else的括号范围

void lcd_proc(void)
{  	
	
	if(line_flag==1)
	{LCD_SetTextColor(Green);}
	else
	{LCD_SetTextColor(Black);}
LCD_DisplayStringLine(Line1,(uint8_t*)("11111111111"));
	if(line_flag==2)
	{LCD_SetTextColor(Green);}
	else
	{LCD_SetTextColor(Black);}	
LCD_DisplayStringLine(Line2,(uint8_t*)("22222222222"));	
	if(line_flag==3)
	{LCD_SetTextColor(Green);}
	else
	{LCD_SetTextColor(Black);}
LCD_DisplayStringLine(Line3,(uint8_t*)("33333333333"));
	
}

高亮(二)

 LCD_Clear(White);
  LCD_SetBackColor(White);
  LCD_SetTextColor(Black);

lcd

void lcd_proc(void)
{  	
	
	if(line_flag==1)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}
LCD_DisplayStringLine(Line1,(uint8_t*)("11111111111"));
	if(line_flag==2)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}	
LCD_DisplayStringLine(Line2,(uint8_t*)("22222222222"));	
	if(line_flag==3)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}
LCD_DisplayStringLine(Line3,(uint8_t*)("33333333333"));
	
}

 多页码

声明

  LCD_Clear(White);
  LCD_SetBackColor(White);
  LCD_SetTextColor(Black);
LCD_DisplayStringLine(Line3,(uint8_t*)("w  e  l  c  o  m  e"));

lcd代码

void lcd_proc(void)
{  	if(lcd_page==1)
	{
		LCD_DisplayStringLine(Line3,(uint8_t*)("w  e  l  c  o  m  e"));
	}
	if(lcd_page==2)
	{
	if(line_flag==1)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}
LCD_DisplayStringLine(Line1,(uint8_t*)("11111111111"));
	if(line_flag==2)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}	
LCD_DisplayStringLine(Line2,(uint8_t*)("22222222222"));	
	if(line_flag==3)
	{LCD_SetBackColor(Yellow);}
	else
	{LCD_SetBackColor(White);}
LCD_DisplayStringLine(Line3,(uint8_t*)("33333333333"));
	}
	
}

按键 

void key_proc(void)
{
key_val=key_scan();
	key_down=key_val&(key_val^key_old);
	key_up=~key_val&(key_val^key_old);
	key_old=key_val;
	if(key_down==3)
{  
	LCD_Clear(White);
     lcd_page++;
	if(lcd_page==3)
	{lcd_page=1;}
}
if(key_down==4)
{
     line_flag++;
	if(line_flag==4)
	{line_flag=1;}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值