標題:
使用stm32mini板實現(xiàn)簡易計算器功能 源程序
[打印本頁]
作者:
sttttttttttty
時間:
2020-9-12 10:28
標題:
使用stm32mini板實現(xiàn)簡易計算器功能 源程序
由于mini板和開發(fā)板之間有些串口不同的區(qū)別,一個用GPIO,一個用FSMC,可能會白屏。
程序初始化時,必須初始化串口1,否則程序會卡死在那里,具體原因尚未找到...
1.GUI_Calculate_v1.0版本根號鍵、百分號、反比例函數(shù)鍵尚未編寫相應(yīng)的程序。
單片機源程序如下:
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "math.h"
#include "stdio.h"
#include "led.h"
#include "timer.h"
#include "gui.h"
#include "touch.h"
#include "WM.h"
#include "button.h"
#include "progbar.h"
#include "CHECKBOX.h"
#include "listbox.h"
#include "framewin.h"
#include "SCROLLBAR.h"
#include "edit.h"
// -------------------- 結(jié)構(gòu)變量 --------------------- //
GUI_PID_STATE STATE; //該變量為GUI觸屏的x y位置存儲坐標(內(nèi)部已將其換算為屏幕坐標了)
FRAMEWIN_Handle hFrame;
BUTTON_Handle hButton_1;
BUTTON_Handle hButton_2;
BUTTON_Handle hButton_3;
BUTTON_Handle hButton_4;
BUTTON_Handle hButton_5;
BUTTON_Handle hButton_6;
BUTTON_Handle hButton_7;
BUTTON_Handle hButton_8;
BUTTON_Handle hButton_9;
BUTTON_Handle hButton_0; // 10
BUTTON_Handle hButton_Point; // 11
BUTTON_Handle hButton_Add; // 12
BUTTON_Handle hButton_Sub; // 13
BUTTON_Handle hButton_Mul; // 14
BUTTON_Handle hButton_Div; // 15
BUTTON_Handle hButton_Equ; // 16
BUTTON_Handle hButton_Inv; // 17
BUTTON_Handle hButton_Per; // 18
BUTTON_Handle hButton_Bac; // 19
BUTTON_Handle hButton_CE; // 20
BUTTON_Handle hButton_AC; // 21
BUTTON_Handle hButton_Neg; // 22
BUTTON_Handle hButton_Sqrt; // 23
EDIT_Handle hEdit;
// -------------------- 計算變量 ---------------------- //
double Result=0;
u8 AC_Flag=0; // 0:剛剛清零,重新開始計算 1:計算過程中
u8 Operator=0; // 0:運算符號清空 1:+ 2:- 3:* 4:/
u8 Operator_Last=0;
u8 Update_Var=0;
double Variable=0; // 加減乘除運算的變量
u8 Inte_Digits=0; // 整數(shù)位數(shù)
u8 Deci_Digits=0; // 小數(shù)位數(shù)
u8 Point_Flag=0; // 0:沒有小數(shù)點 1:有小數(shù)點
unsigned char str[9];
unsigned char Inv_str[10];
u8 Deci_Len;
int Inverse_Flag=1;
// --------------------- 分界線 ----------------------- //
void Result_To_String(void);
void Inverse_Key(void);
// -----------------------------------------------------//
//
void Touch_Process(void)
{
GUI_TOUCH_GetState(&STATE);
// GUI_DispStringAt("x:", 0, 300);
// GUI_DispDec(STATE.x, 3);
// GUI_DispStringAt("y:", 50, 300);
// GUI_DispDec(STATE.y, 3);
if (STATE.Pressed == 1)
{
GUI_CURSOR_SetPosition(STATE.x,STATE.y);
// GUI_CURSOR_Show();
}
}
//
//
void Button_Process(void)
{
float temp1,temp2;
switch(GUI_GetKey())
{
case 10:// 0
Operator_Last=Operator;
if(Update_Var==1)
{
Update_Var=0;
Variable=0;
EDIT_SetText(hEdit,"0");
}
if(Point_Flag!=0) // 出現(xiàn)小數(shù)點,開始輸入小數(shù)
{
if(Deci_Digits<7)
{
Deci_Digits++;
EDIT_AddKey(hEdit,'0');
}
}
else
{
if(Variable!=0)
{
if(Inte_Digits<8)
{
Inte_Digits++;
Variable*=10;
EDIT_AddKey(hEdit,'0');
}
}
}
break;
case 1: Operator_Last=Operator;
if(Update_Var==1)
{
Update_Var=0;
Variable=0;
}
if(Point_Flag!=0) // 出現(xiàn)小數(shù)點,開始輸入小數(shù)
{
if(Deci_Digits<7)
{
Deci_Digits++;
Variable+=1/pow(10,Deci_Digits)*Inverse_Flag;
EDIT_AddKey(hEdit,'1');
}
}
else
{
if(Inte_Digits<8)
{
if(Inte_Digits==0)
{
EDIT_SetText(hEdit,NULL);
}
Inte_Digits++;
Variable*=10;
Variable+=1*Inverse_Flag;
EDIT_AddKey(hEdit,'1');
}
}
break;
case 2: Operator_Last=Operator;
if(Update_Var==1)
{
Update_Var=0;
Variable=0;
}
if(Point_Flag!=0) // 出現(xiàn)小數(shù)點,開始輸入小數(shù)
{
if(Deci_Digits<7)
{
Deci_Digits++;
Variable+=2/pow(10,Deci_Digits)*Inverse_Flag;
EDIT_AddKey(hEdit,'2');
}
}
else
{
if(Inte_Digits<8)
{
if(Inte_Digits==0)
{
EDIT_SetText(hEdit,NULL);
}
Inte_Digits++;
Variable*=10;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
GUI_Calculate_v1.0.7z
(434.67 KB, 下載次數(shù): 50)
2020-9-12 14:30 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
lyshhh
時間:
2020-12-15 09:52
兄弟,這怎么解壓,我打不開這文件
作者:
Nevergp
時間:
2020-12-16 17:52
可能你還沒初始化串口就先使用串口發(fā)送數(shù)據(jù),多半是printf函數(shù)
作者:
lyshhh
時間:
2020-12-17 09:10
lyshhh 發(fā)表于 2020-12-15 09:52
兄弟,這怎么解壓,我打不開這文件
解決了,關(guān)于7z的壓縮方式用得少,百度了一下,設(shè)置rar也能解壓7z的壓縮包
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1