標題:
2019電賽f題獲獎代碼,stm32戰(zhàn)艦開發(fā)板編寫
[打印本頁]
作者:
1248849442
時間:
2020-3-24 16:31
標題:
2019電賽f題獲獎代碼,stm32戰(zhàn)艦開發(fā)板編寫
單片機源程序如下:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "lcd.h"
#include "key.h"
#include "beep.h"
#include "w25qxx.h"
#include "ff.h"
#include "exfuns.h"
#include "text.h"
#include "2214.h"
#include "myiic.h"
#define count_t 35 //紙張上限
u8 w=0,K;
int main(void)
{
delay_init(); //延時函數(shù)初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置中斷優(yōu)先級分組為組2:2位搶占優(yōu)先級,2位響應(yīng)優(yōu)先級
uart_init(115200); //串口初始化為115200
LED_Init(); //LED初始化
KEY_Init(); //初始化按鍵
LCD_Init(); //初始化LCD
font_init(); //漢字初始化
LCD_Clear(WHITE); //屏幕清空
BEEP_Init(); //蜂鳴器初始化
IIC_Init(); //IIC通訊
InitMultiFDC2214(); //多通道設(shè)置
POINT_COLOR=BLUE;
Show_Str(120,30,240,24,"2019年 電子設(shè)計大賽",24,0);
Show_Str(140,98,200,24,"紙張計數(shù)顯示裝置",24,0);
POINT_COLOR=BLACK;
LCD_DrawRectangle(20,70,460,150); //畫表格
LCD_DrawRectangle(20,70,460,350);
LCD_DrawRectangle(20,150,240,350);
Show_Str(30,180,200,24,"通道1:",24,0);
Show_Str(30,240,200,24,"通道2:",24,0);
Show_Str(30,300,200,24,"當(dāng)前模式為:",24,0);
Show_Str(250,180,200,24,"極板狀態(tài):",24,0);
Show_Str(250,240,200,24,"紙張數(shù):",24,0);
Show_Str(250,300,200,24,"總重:",24,0);
POINT_COLOR=RED;
LCD_ShowxNum(355,300,0,1,24,0); //默認紙重
Show_Str(170,300,200,24,"待機",24,0);
POINT_COLOR=BLACK;
Show_Str(90,380,300,24,"學(xué)習(xí)+檢測",24,0); //KEY0
Show_Str(315,380,300,24,"紙重檢測",24,0); //KEY1
Show_Str(90,430,300,24,"進入學(xué)習(xí)",24,0); //KEY2
Show_Str(315,430,300,24,"紙張規(guī)格",24,0); //KEY2
POINT_COLOR=RED;
Show_Str(30,380,300,24,"KEY0:",24,0); //學(xué)習(xí)模式
Show_Str(250,380,300,24,"KEY1:",24,0); //重量檢測模式
Show_Str(30,430,300,24,"KEY2:",24,0);
Show_Str(250,430,300,24,"KEY3:",24,0);
POINT_COLOR=BLACK;
Show_Str(30,480,300,24,"紙張規(guī)格",24,0); //紙張規(guī)格
Show_Str(30,530,300,24,"重量",24,0);
Show_Str(30,580,300,24,"厚度",24,0);
while(1)
{
u8 key;
FDC2214Check(); //檢測系統(tǒng)工作狀態(tài)
just_test(); //顯示通道值
delay_ms(10);
key = KEY_Scan(0); //獲得鍵值
if(key == KEY0_PRES) //進入學(xué)習(xí)模式
{
StudyMode();//學(xué)習(xí)模式
K++;
POINT_COLOR=BLACK;
Show_Str(30,680,300,24,"K 按下次數(shù):",24,0);
POINT_COLOR=RED;
LCD_ShowxNum(170,680,K,1,24,0);
}
}
}
/***********************學(xué)習(xí)模式***********************/
u16 StudyMode()//獲取數(shù)據(jù),計算
{
u8 keyd,Count;
double Ch1,Ch2;
int i,j; //獲取數(shù)據(jù),計算
static double ab[4][count_t] /*分別對應(yīng)一通道左值右值二通道左值右值*/;
long double sum1 = 0,sum2 = 0,a[2][count_t] = {0};
double adf[2][(count_t-1)] /*對應(yīng)臨時差值*/;
keyd=KEY_Scan(1);
POINT_COLOR=BLACK;
for(i = 0;i<count_t;)
{
keyd=KEY_Scan(0);
if(keyd==KEY0_PRES) //按鍵KEY0按下錄入數(shù)據(jù)
{
K++;
POINT_COLOR=BLACK;
Show_Str(30,680,300,24,"K 按下次數(shù):",24,0);
POINT_COLOR=RED;
LCD_ShowxNum(170,680,K,1,24,0);
for(j=0;j<100;j++) //取平均值
{
sum1= sum1+ReadRegfdc2214(0x02);//讀取的通道1的值
sum2= sum2+ReadRegfdc2214(0x04);//讀取的通道2的值
}
a[0][i]=sum1/100;
a[1][i]=sum2/100;
POINT_COLOR=BLACK;
Show_Str(170,300,200,24,"學(xué)習(xí)",24,0);
Show_Str(160,500,200,24,"正在學(xué)習(xí)",24,0);
Show_Str(30,530,200,24,"學(xué)習(xí)次數(shù):",24,0);
Show_Str(30,500,300,24,"學(xué)習(xí)狀態(tài):",24,0);
POINT_COLOR=RED;
LCD_ShowxNum(100,180,a[0][i],8,24,0); //通道一學(xué)習(xí)參數(shù)
LCD_ShowxNum(100,240,a[1][i],8,24,0); //通道二學(xué)習(xí)參數(shù)
LCD_ShowxNum(160,530,i+1,2,24,0); //學(xué)習(xí)次數(shù)
sum1 = 0;
sum2 = 0;
i++;
keyd = 0;
}
delay_ms(1);
}
for(i=1;i<count_t;i++)
{
adf[0][i-1] = (a[0][i] - a[0][i-1])/2;
adf[1][i-1] = (a[1][i] - a[1][i-1])/2;
}
ab[0][0] = a[0][0] - adf[0][0];
ab[2][0] = a[1][0] - adf[1][0];
for(i=1;i<count_t;i++)
{
ab[0][i] = a[0][i] - adf[0][i-1];
ab[1][i-1] = a[0][i-1]+adf[0][i-1];
ab[2][i]=a[1][i]-adf[1][i-1];
ab[3][i-1]=a[1][i-1]+adf[1][i-1];
}
ab[1][count_t-1] = a[0][count_t-1]+adf[0][count_t-2];
ab[3][count_t-1] = a[1][count_t-1]+adf[1][count_t-2];
//上下限
/******************************************************************************************************************************
**********************************************分割線***************************************************************************
******************************************************************************************************************************/
Show_Str(150,500,300,24,"正在學(xué)習(xí)",24,0);
while(1) //學(xué)習(xí)模式
{
POINT_COLOR=RED;
Show_Str(150,500,300,24,"已完成學(xué)習(xí)",24,0);
keyd=KEY_Scan(0);
if(keyd == KEY0_PRES) // 錄入數(shù)值
{
K++;
POINT_COLOR=BLACK;
Show_Str(30,680,300,24,"K 按下次數(shù):",24,0);
POINT_COLOR=RED;
LCD_ShowxNum(170,680,K,1,24,0);
Ch2 = ReadRegfdc2214(0x04); //通道二
Ch1 = ReadRegfdc2214(0x02); //通道一
Count=0;
if((Ch1<1873) || (Ch2<1792))Count=0; //零張
for(i=0;i<count_t;i++)
{
if(((ab[0][i]<Ch1)&&(Ch1<ab[1][i])) || ((ab[2][i]<Ch2)&&(Ch2<ab[3][i]))) //i張紙
{
Count = i+1;
break;
}
}
LCD_ShowxNum(350,240,Count,4,24,0); //顯示被測紙張數(shù)
delay_ms(500);
BEEP=1; //發(fā)出蜂鳴聲
LED0=0; //伴隨紅燈閃爍
delay_ms(500);
BEEP=0;
LED0=1;
}
if(keyd == KEY2_PRES) //按下KEY2進行紙張標準重量調(diào)節(jié) 一共分為4擋
{
u8 z;
w++;
if(w==5) w=0;
z=Count*PaperWeight(w); //計算后的紙張重
POINT_COLOR=BLACK;
LCD_ShowxNum(355,300,z,5,24,0); //紙重
LCD_ShowxNum(286,600,PaperWeight(w),3,24,0); //顯示規(guī)格
}
}
}
復(fù)制代碼
所有資料51hei提供下載:
2019F紙張檢測程序.7z
(1.26 MB, 下載次數(shù): 42)
2020-3-24 17:59 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1