STM32F4应用笔记(七)触屏计算器改进版

STM32F4应用笔记第七篇,作者优化了之前触屏计算器的代码,解决了第六篇中提出的问题,但运算符优先级判断尚未实现,目前仅支持顺序运算。
摘要由CSDN通过智能技术生成

整个项目的源码在:
https://pan.baidu.com/s/1nuTrIbR
今天花了几个小时优化了一下代码,解决了(六)中提到的问题,最后的程序如下:

#include "sys.h"
#include "delay.h"  
#include "usart.h"   
#include "led.h"
#include "beep.h"
#include "ili93xx.h" 
#include "touch.h"
#include "gui.h"
#include    "24cxx.h"
#include  "ucos_ii.h"  
#include  "string.h"  //需要用到字符串处理函数
#include  "stdio.h" //sprintf转换要用到

#include  "FRAMEWIN.h" 
#include  "BUTTON.h"  
#include  "EDIT.h" 
#include  "LISTBOX.h" 


int t;

//计算器的模块构建部分!定义为全局变量,省去了传递参数的麻烦,当然,这不够规范
FRAMEWIN_Handle  hFrame;  
//FRAMEWIN_Handle在#include  "FRAMEWIN.h" 当中
BUTTON_Handle  hButton1; 
BUTTON_Handle  hButton2; 
BUTTON_Handle  hButton3; 
BUTTON_Handle  hButton4; 
BUTTON_Handle  hButton5; 
BUTTON_Handle  hButton6; 
BUTTON_Handle  hButton7; 
BUTTON_Handle  hButton8; 
BUTTON_Handle  hButton9; 
BUTTON_Handle  hButton0; 
BUTTON_Handle  hButton_jia; 
BUTTON_Handle  hButton_jian; 
BUTTON_Handle  hButton_chen; 
BUTTON_Handle  hButton_chu; 
BUTTON_Handle  hButton_equal; 
BUTTON_Handle  hButton_backspace;
BUTTON_Handle  hButton_dort; 
BUTTON_Handle  hButton_ac; 

EDIT_Handle hEdit;
LISTBOX_Handle hListBox;
GUI_PID_STATE Button_State; //输入设备状态


char num1[50]={
  ""};  
char num2[50]={
  ""};
char num3[50]={
  ""};
char temp1[50]={
  ""}; //临时数组1——放第一个运算数
char temp2[50]={
  ""}; //临时数组1——放第二个运算数
static double a=0.0;   //必须用double,一开始用的float有时好用有时不好用
//还以为自己程序写错了
static double b=0.0;
static double f=0.0; //存放最终结果

static int middle_flag=0; //中间运算符标志

int len;//获取字符串长度
int Type=0; //默认是=0,表示没有运算符按下
//=1:加;=2:减;=3:乘;=4:除
/UCOSII任务设置///
//START 任务
//设置任务优先级
#define START_TASK_PRIO                 10 //开始任务的优先级设置为最低
//设置任务堆栈大小
#define START_STK_SIZE                  64
//任务堆栈  
OS_STK START_TASK_STK[START_STK_SIZE];
//任务函数
void start_task(void *pdata);   

//触摸屏任务
//设置任务优先级
#define TOUCH_TASK_PRIO             7 
//设置任务堆栈大小
#define TOUCH_STK_SIZE                      256
//任务堆栈
OS_STK TOUCH_TASK_STK[TOUCH_STK_SIZE];
//任务函数
void touch_task(void *pdata);


 /***************************************************************************
* 计算器框架的初始化部分 *
***************************************************************************/
void Calculator_Init(void) 
{
  hFrame = FRAMEWIN_Create("Calculator", NULL, WM_CF_SHOW, 0,0,480,800);
    //WM_CF_SHOW/* Show window after creation */
  FRAMEWIN_SetActive(hFrame, 1);
  FRAMEWIN_SetMoveable(hFrame, 1);    //设置为可移动的
  FRAMEWIN_SetFont(hFrame, &GUI_Font16B_ASCII);
  FRAMEWIN_SetTextColor(hFrame, GUI_RED);
  FRAMEWIN_SetBarColor(hFrame, 0, GUI_GREEN);
  FRAMEWIN_SetTextAlign(hFrame, GUI_TA_HCENTER);
  FRAMEWIN_AddMaxButton(hFrame, FRAMEWIN_BUTTON_RIGHT, 0);
  FRAMEWIN_AddMinButton(hFrame, FRAMEWIN_BUTTON_RIGHT, 0);
  hButton1 = BUTTON_CreateAsChild(10,120,70, 70,hFrame,101,WM_CF_SHOW);  
    //注意这里的ID,每一个空间都有自己的一个ID
  hButton2 = BUTTON_CreateAsChild(10,200,70, 70,hFrame,102,WM_CF_SHOW);
  hButton3 = BUTTON_CreateAsChild(10,280,70, 70,hFrame,103,WM_CF_SHOW);
  hButton4 = BUTTON_CreateAsChild(90,120,70, 70,hFrame,104,WM_CF_SHOW);
  hButton5 = BUTTON_CreateAsChild(90,200,70, 70,hFrame,105,WM_CF_SHOW);
  hButton6 = BUTTON_CreateAsChild(90,280,70, 70,hFrame,106,WM_CF_SHOW);
  hButton7 = BUTTON_CreateAsChild(170,120,70, 70,hFrame,107,WM_CF_SHOW);
  hButton8 = BUTTON_CreateAsChild(170,200,70, 70,hFrame,108,WM_CF_SHOW);
  hButton9 = BUTTON_CreateAsChild(170,280,70, 70,hFrame,109,WM_CF_SHOW);
  hButton0 = BUTTON_CreateAsChild(250,120,70, 70,hFrame,100,WM_CF_SHOW);
  hButton_jia = BUTTON_CreateAsChild(250,200,70, 70,hFrame,110,WM_CF_SHOW);
  hButton_jian = BUTTON_CreateAsChild(250,280,70, 70,hFrame,111,WM_CF_SHOW);
  hButton_chen = BUTTON_CreateAsChild(330,120,70, 70,hFrame,112,WM_CF_SHOW);
  hButton_chu = BUTTON_CreateAsChild(330,200,70, 70,hFrame,113,WM_CF_SHOW);
  hButton_equal = BUTTON_CreateAsChild(330,280,70, 70,hFrame,114,WM_CF_SHOW);
    hButton_dort = BUTTON_CreateAsChild(410,200,70, 70,hFrame,115,WM_CF_SHOW);
  hButton_backspace = BUTTON_CreateAsChild(410,120,70, 70,hFrame,116,WM_CF_SHOW);
    hButton_ac = BUTTON_CreateAsChild(410,280,70, 70,hFrame,117,WM_CF_SHOW);

  BUTTON_SetText(hButton0, "0");
    BUTTON_SetFont(hButton0, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton1, "1");
    BUTTON_SetFont(hButton1, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton2, "2");
    BUTTON_SetFont(hButton2, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton3, "3");
    BUTTON_SetFont(hButton3, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton4, "4");
    BUTTON_SetFont(hButton4, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton5, "5");
    BUTTON_SetFont(hButton5, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton6, "6");
    BUTTON_SetFont(hButton6, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton7, "7");
    BUTTON_SetFont(hButton7, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton8, "8");
    BUTTON_SetFont(hButton8, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton9, "9");
    BUTTON_SetFont(hButton9, &GUI_Font32B_ASCII);
  BUTTON_SetText(hButton_jia, "
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值