OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 2933|回复: 1

希望来个大佬帮我解决一下让我能用红外遥控输入任意数,包括小数,输错了可以按键删除重新输入。

[复制链接]

1

主题

2

帖子

0

精华

新手入门

积分
19
金钱
19
注册时间
2018-8-1
在线时间
3 小时
发表于 2018-8-1 20:32:47 | 显示全部楼层 |阅读模式
key=Remote_Scan(); //红外显示
  if(key)
  {  
  switch(key)
  {         
    case 162:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+1;
      xiaoshuweishu++;xiaoshuweishu=xiaoshuweishu%5;
      show_price_point_temp();
     }
     else
     {
      price_temp=price_temp*10+1;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     
     break;     
    case 98:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp+2/10;
      xiaoshuweishu++;
      word_len++;
      show_price_temp();
     }
     else
     {
      price_temp=price_temp*10+2;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;
    case 226:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+3;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+3;
      xiaoshuweishu++;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }  
     break;  
    case 34:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+4;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+4;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;     
    case 2:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+5;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+5;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;
    case 194:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+6;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+6;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;   
    case 224:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+7;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+7;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;     
    case 168:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+8;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+8;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;
    case 144:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+9;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+9;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;
    case 152:
     if(point_flag)//有 点
     {
      price_point_temp = price_point_temp*10+0;
      xiaoshuweishu++;
     }
     else
     {
      price_temp=price_temp*10+0;
      ok_flag = 0;
      word_len++;
      show_price_temp();
     }
     break;           
    case 56:
     if(ok_flag==0)
     {
      price = price_temp+price_point_temp/(pow(10,xiaoshuweishu));//
//      LCD_Fill(130,140,130+60,140+24,WHITE); //背景颜色
//      LCD_ShowNum(130,140,price,word_len,24);
      printf("price=%f",price);
      price_temp = 0;
      point_flag = 0;
      word_len = 0;
      xiaoshuweishu=0;
      price_point_temp=0;
     }
     ok_flag = 1;
     break;
     case 104:
      point_flag = 1;
      break;
    default:
     break;
   }   
  }

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

9

帖子

0

精华

初级会员

Rank: 2

积分
129
金钱
129
注册时间
2016-4-27
在线时间
34 小时
发表于 2018-8-2 09:07:15 | 显示全部楼层
刚好做了一个,大概流程这样
uint8_t UserInputCnt = 0;
uint8_t UserInputArray[16];

switch(按键码)
{
case 数值或小数点:
UserInputArray[UserInputCnt] = '字符';
UserInputCnt++;
break;
case 删除:
if(UserInputCnt > 0)
{
UserInputCnt--;
UserInputArray[UserInputCnt] = ' ';
}
break;
}
显示直接该字符串显示display(char *string);
获取数值调用C库函数
atoi((const char *)UserInputArray);(字符串转整型)
atof((const char *)UserInputArray);(字符串转浮点型)
回复 支持 2 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-1 02:26

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表