Files
SmartBin_STM_Woer/STM32_4路称重_Git提交精简工程/MCU2/src/USER/main.c
T

103 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
* 文件名 main.c
* 描 述 :主函数
* 版 本 V1.0
* 作 者 XuZhongPing
* 日 期 2017/03/05
*********************************************************************************/
#include "stm32f10x.h"
#include "device.h"
#include "data_typedef.h"
#include "m_s_comm.h"
void NVIC_Configuration(void);
void RegularUploadTask(void);
int main(void)
{
static timer waitingTimer_1s;
timer_set(&waitingTimer_1s, 10);
delay_init(); //延时函数初始化
NVIC_Configuration(); //设置NVIC中断分组
USART1_Init(2400); //秤2
USART2_Init(38400); //主从MCU通信接口
USART3_Init(2400); //秤1
USART4_Init(2400); //Scale 3
USART5_Init(2400); //秤4
TIM2_Int_Init(1000, 7200-1); //10Khz的计数频率,计数到1000为100ms (即每个周期为0.1ms
TIM3_Int_Init(100, 7200-1); //10Khz的计数频率(每个周期为0.1ms),定时10ms用于限位开关和按钮扫描
TIM4_Int_Init(5000, 7200-1); //10Khz的计数频率(每个周期为0.1ms),计数到5000为500ms
TIM5_Int_Init(50, 7200-1); //10Khz的计数频率(每个周期为0.1ms),计数到50为5ms
printf("\r\n***************System Running***************\r\n");
DeviceInit(); //硬件设备初始化
IWDG_Init(5, 625); //看门狗初始化,分频数为128,重载值为625,溢出时间为2s
while(1)
{
LED_Task(); //LED灯指示任务
WeightDetectionTask(); //称重检测
GetTemperatureTask(); //取得温度任务
GetDistanceTask(); //测距任务
KeysSendTask(); //按键状态发送任务
RegularUploadTask(); //定时上传任务
M_S_DataDecodeTask(); //主从机通信任务
SystemExceptionTask(); //系统异常处理任务
IWDG_FeedTask(); //看门狗喂狗任务
if(timer_expired(&waitingTimer_1s))
{
timer_restart(&waitingTimer_1s);
}
}
}
/*
***********************************************************************
* 函 数 名: RegularUploadTask
* 功能说明: 定时上传任务
* 形 参:无
* 返 回 值: 无
***********************************************************************
*/
void RegularUploadTask(void)
{
static timer sendDevStaTimer; //上传设备运行状态信息(温度、信号、测距)
static uint8_t timer_ok = 0;
if(timer_ok == 0)
{
timer_ok = 1;
timer_set(&sendDevStaTimer, 5);
}
//设备运行状态信息上传
if(timer_expired(&sendDevStaTimer))
{
timer_restart(&sendDevStaTimer);
M_S_CommandSend(0x01);
}
}
/*
***********************************************************************
* 函 数 名: RegularUploadTask
* 功能说明: 定时上传任务
* 形 参:无
* 返 回 值: 无
***********************************************************************
*/
void NVIC_Configuration(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
}
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/