|
- #include "stm32f10x.h"
- #include "sys.h"
- #include "led.h"
- #include "Beep.h"
- #include "delay.h"
- #include "stdio.h"
- #include "usart.h"
- #include "key.h"
- #include <fdc2214.h>
- #include <oled.h>
- #include <niming.h>
- #include <text.h>
- #include <Menu.h>
- #include <SortArr.h>
- #include "time5.h"
- unsigned char EntryFigerTimes=0;//錄入54321時(shí),所需記錄的次數(shù)
- unsigned char EntryFistTimes =0;//錄入石頭剪刀布時(shí),所需記錄的次數(shù)
- //相應(yīng)標(biāo)志位
- unsigned char Interrupt_Flg=1,InterruptFlg=0;//按下按鍵 產(chǎn)生的相應(yīng)標(biāo)志位
- unsigned char Train_Figer_Entry_Flg=0,Train_Fist_Entry_Flg=0;//進(jìn)入猜拳訓(xùn)練 劃拳訓(xùn)練 相應(yīng)標(biāo)志位
- unsigned char Judge_Figer_Flg=0,Judge_Fist_Flg=0;//進(jìn)入猜拳判決 劃拳判決 相應(yīng)標(biāo)志位
- //數(shù)組排序次數(shù)
- unsigned char SortTimes=0;//錄入結(jié)束后,對數(shù)組進(jìn)行排序的次數(shù)
- //電容值存放數(shù)據(jù)
- float temp0=0,temp1=0,temp2=0,temp3=0;//四路通道值存放的變量
- float Total_Value;//四路通道總值
- //待存錄入數(shù)組
- float ArrayData[10]={0};//錄入手勢時(shí),四路通道總值要存放的數(shù)組(在錄入手勢時(shí)采集了十次數(shù)據(jù),并且采用濾波算法)
- float ArrayA[8]={0};//錄入54321時(shí) 存放54321數(shù)據(jù)的數(shù)組
- float ArrayB[8]={0};//錄入石頭剪刀布時(shí) 存放石頭剪刀布數(shù)據(jù)的數(shù)組
- //按鍵數(shù)據(jù)
- int Page_New=0;//OLED菜單頁面
- int ConfirmKey=0;//確認(rèn)鍵(確認(rèn)鍵按下: 1)
- int KeyUpDownFlg=0;//記錄上下按鍵相對變化,正常按上鍵加1,按下鍵減1
- int KeyRightLeftFlg=0;//按鍵右與左(兩個(gè)按鍵采用一個(gè)變量 右鍵: 1 左鍵: -1)
- //加載中 次數(shù)
- long int Loding_Times=0;//加載中 相應(yīng)判斷次數(shù)
- void GetFouChVal(void);//讀取四路通道值的函數(shù)
- int main()
- {
- delay_init(); //延時(shí)函數(shù)初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設(shè)置中斷優(yōu)先級分組2
- uart_init(115200); //串口初始化為115200
- TIM5_init(79,7199); //10ms中斷
- Beep_Init(); //蜂鳴器初始化
- IIC_Start(); //IIC初始化
- Oled_Init(); //oled初始化
- LED_Init(); //led初始化
- //Key_Init(); //初始化五向按鍵和開關(guān)按鍵,可使用Key_Scan()函數(shù)得到返回值
- //key_exti_test(); //按鍵檢測
- while(FDC2214_Init()); //fdc2214初始化 成功:0 失敗:1
- Beep=0;delay_ms(10);Beep=1; //蜂鳴器提示
- UI_TILTLE(); //標(biāo)題
- while(1)
- {
- Loding_Times=0; //加載中函數(shù)的加載次數(shù)
- //在頁面0 顯示四路通道值
- //if(Page_New==0)
- //{
- Oled_Printf_U32(28,3,(unsigned long int)temp0,0);
- Oled_Printf_U32(28,4,(unsigned long int)temp1,0);
- Oled_Printf_U32(28,5,(unsigned long int)temp2,0);
- Oled_Printf_U32(28,6,(unsigned long int)temp3,0);
- //}
- /**
- **在按鍵按下時(shí) oled菜單界面進(jìn)行相應(yīng)的切換
- **并且相應(yīng)標(biāo)志位被重新賦值
- **/
- /*if(Interrupt_Flg==1)//按一次方向按鍵'Interrupt_Flg'變量會(huì)被置1
- {
- if(Page_New==0)
- {
- ConfirmKey=0;
- }
-
- OLED_Page_Show(KeyRightLeftFlg, KeyUpDownFlg,ConfirmKey);//此函數(shù)為oled菜單顯示函數(shù)(參數(shù)分別為: 按鍵左右值 按鍵上下值 以及確認(rèn)鍵)
- ConfirmKey=0;
- Interrupt_Flg=0;
- InterruptFlg =0;
- KeyUpDownFlg =0;
- KeyRightLeftFlg=0;
- }
- InterruptFlg=0;//此標(biāo)志位為 錄入手勢時(shí)所需的標(biāo)志位
- /**
- ** 在進(jìn)入'Figer'訓(xùn)練界面時(shí)'Train_Figer_Entry_Flg'標(biāo)志位被置1
- ** 在此訓(xùn)練期間,不會(huì)跳出此循環(huán) 除非強(qiáng)制返回或錄入結(jié)束
- ** 相應(yīng)標(biāo)志位在此處被賦值
- **/
- /*while(Train_Figer_Entry_Flg)
- { SortTimes=0;
- Loading();
-
- if(InterruptFlg==1)
- {
- EntryFiger();
- InterruptFlg=0;
- }
-
- ConfirmKey=0;
- KeyUpDownFlg=2;
- Interrupt_Flg=1;
- KeyRightLeftFlg=-1;
- }
- /**
- **'Figer'訓(xùn)練期間如果強(qiáng)制返回則代表錄入失敗
- ** 相應(yīng)所存放數(shù)據(jù)的數(shù)組被清零
- **/
- /* if(EntryFigerTimes!=0)
- {
- unsigned char i;
-
- for(i=0;i<6;i++)
- {
- ArrayA[i]=0;
- }
-
- EntryFigerTimes=0;//錄入手勢時(shí)的次數(shù)
- KeyUpDownFlg=0;
- }
- /**
- ** 在進(jìn)入'JudgeNum'判決界面時(shí)'Judge_Figer_Flg'標(biāo)志位被置1
- ** 因?yàn)樵阡浫胧謩輹r(shí)不需要按照順序,所以此處用到冒泡排序算法
- ** oled顯示相應(yīng)結(jié)果
- **/
- /* if(Judge_Figer_Flg==1)
- {
- if(SortTimes==0)//錄入一次數(shù)據(jù)只排序一次
- {
- SortArr(ArrayA,6);//冒泡排序算法
- JudgmentFigerRange();//對手勢范圍進(jìn)行整定
- }
- switch(JudgmentFiger())
- {
- case 0: OLED_ShowCN(52,4,35);OLED_ShowCN(52,5,35); break;
- case 1: OLED_ShowStr(52,4,"1",2); break;
- case 2: OLED_ShowStr(52,4,"2",2); break;
- case 3: OLED_ShowStr(52,4,"3",2); break;
- case 4: OLED_ShowStr(52,4,"4",2); break;
- case 5: OLED_ShowStr(52,4,"5",2); break;
- default: break;
- }
-
- SortTimes=1;
- }
- /**
- ** 在進(jìn)入'Fist'訓(xùn)練界面時(shí)'Train_Fist_Entry_Flg'標(biāo)志位被置1
- ** 在此訓(xùn)練期間,不會(huì)跳出此循環(huán) 除非強(qiáng)制返回或錄入結(jié)束
- ** 相應(yīng)標(biāo)志位在此處被賦值
- **/
- /* while(Train_Fist_Entry_Flg)
- {
- Loading();
- SortTimes=0;
- if(InterruptFlg==1)
- {
- EntryFist();
- InterruptFlg=0;
- }
-
- ConfirmKey=0;
- KeyUpDownFlg=2;//訓(xùn)練結(jié)束,回到上級菜單時(shí),光標(biāo)直接跳到猜拳判決處
- Interrupt_Flg=1;
- KeyRightLeftFlg=-1;
- }
- /**
- **'Fist'訓(xùn)練期間如果強(qiáng)制返回則代表錄入失敗
- ** 相應(yīng)所存放數(shù)據(jù)的數(shù)組被清零
- **/
- /* if(EntryFistTimes!=0)
- {
- unsigned char i;
- for(i=0;i<4;i++)
- {
- ArrayB[i]=0;
- }
-
- EntryFistTimes=0;//錄入手勢時(shí)的次數(shù)
- KeyUpDownFlg=0;
- }
- /**
- ** 在進(jìn)入'JudgeFist'判決界面時(shí)'Judge_Fist_Flg'標(biāo)志位被置1
- ** 因?yàn)樵阡浫胧謩輹r(shí)不需要按照順序,所以此處用到冒泡排序算法
- ** oled顯示相應(yīng)結(jié)果
- **/
- /* if(Judge_Fist_Flg==1)
- {
- if(SortTimes==0)//錄入一次數(shù)據(jù)只排序一次
- {
- SortArr(ArrayB,4);
- JudgmentFistRange();
- }
- switch(JudgmentFist())
- {
- case 0: OLED_ShowCN(48,5,35); OLED_ShowCN(64,5,35);break;//空格
- case 1: OLED_ShowCN(48,5,30); OLED_ShowCN(64,5,31);break;//石頭
- case 2: OLED_ShowCN(48,5,32); OLED_ShowCN(64,5,33);break;//剪刀
- case 3: OLED_ShowCN(48,5,34); OLED_ShowCN(64,5,35);break;//布
- default: break;
- }
- SortTimes=1;
- }*/
- }
- }
- /**
- **可在此函數(shù)中直接采集四路通道值
- **/
- void GetFouChVal()
- {
- temp0= Cap_Calculate(0);
- temp1= Cap_Calculate(1);
- temp2= Cap_Calculate(2);
- temp3= Cap_Calculate(3);
- Total_Value=(temp0+temp1+temp2+temp3)/10000;
- }
- /**
- **定時(shí)器5中斷函數(shù) 10ms
- **在定時(shí)器中采集四路通道值,并計(jì)算總值
- **/
- void TIM5_IRQHandler(void)
- {
-
- if(TIM5->SR&0X0001)//溢出中斷
- {
- temp0= Cap_Calculate(0);
- temp1= Cap_Calculate(1);
- temp2= Cap_Calculate(2);
- temp3= Cap_Calculate(3);
- Total_Value=(temp0+temp1+temp2+temp3)/10000;
-
- }
- TIM5->SR&=~(1<<0);
- }
復(fù)制代碼
全部資料51hei下載地址:
Gesture-KEIL.7z
(225.37 KB, 下載次數(shù): 76)
2019-8-8 17:54 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|