feat: add STM32 four-channel weighing firmware
This commit is contained in:
Executable
+137
@@ -0,0 +1,137 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :led.c
|
||||
* 描 述 :LED驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/02
|
||||
*********************************************************************************/
|
||||
#include "led.h"
|
||||
#include "timer.h"
|
||||
|
||||
#define SYS_RUNNING_LED_PeriphClock RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO
|
||||
#define SYS_RUNNING_LED_PORT GPIOB
|
||||
#define SYS_RUNNING_LED_PORT_PIN GPIO_Pin_4
|
||||
|
||||
uint8_t ledON_OFF_Status = 0;
|
||||
uint8_t fillLightMask = 0;
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LED_Init
|
||||
* 功能说明: 初始化LED灯接口
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LED_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
|
||||
RCC_APB2PeriphClockCmd(SYS_RUNNING_LED_PeriphClock, ENABLE);
|
||||
|
||||
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);
|
||||
|
||||
GPIO_InitStructure.GPIO_Pin = SYS_RUNNING_LED_PORT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_Init(SYS_RUNNING_LED_PORT, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedOn
|
||||
* 功能说明: 点亮LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedOn(void)
|
||||
{
|
||||
GPIO_ResetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
ledON_OFF_Status = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedOff
|
||||
* 功能说明: 熄灭LED灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedOff(void)
|
||||
{
|
||||
GPIO_SetBits(SYS_RUNNING_LED_PORT, SYS_RUNNING_LED_PORT_PIN);
|
||||
ledON_OFF_Status = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: SetLedToggle
|
||||
* 功能说明: LED灯反转
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void SetLedToggle(void)
|
||||
{
|
||||
if(ledON_OFF_Status)
|
||||
{
|
||||
SetLedOff();
|
||||
}else{
|
||||
SetLedOn();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
* 函 数 名: LED_Task
|
||||
* 功能说明: LED灯运行状态指示灯
|
||||
* 形 参: 无
|
||||
* 返 回 值: 无
|
||||
***********************************************************************
|
||||
*/
|
||||
void LED_Task(void)
|
||||
{
|
||||
static uint8_t ledStatus = 0;
|
||||
|
||||
static timer ledOnTimer;
|
||||
static timer ledOffTimer;
|
||||
static uint8_t timer_ok = 0;
|
||||
|
||||
if(timer_ok == 0)
|
||||
{
|
||||
timer_ok = 1;
|
||||
timer_set(&ledOnTimer, 1);
|
||||
timer_set(&ledOffTimer, 19);
|
||||
}
|
||||
|
||||
switch(ledStatus)
|
||||
{
|
||||
case 0x00:
|
||||
SetLedOff();
|
||||
if(timer_expired(&ledOffTimer))
|
||||
{
|
||||
timer_restart(&ledOnTimer);
|
||||
ledStatus = 0x01;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
SetLedOn();
|
||||
if(timer_expired(&ledOnTimer))
|
||||
{
|
||||
timer_restart(&ledOffTimer);
|
||||
ledStatus = 0x00;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ledStatus = 0x00;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
/*************************** (C) COPYRIGHT 2017 YNHB ****************************
|
||||
* 文件名 :led.h
|
||||
* 描 述 :LED驱动代码
|
||||
* 版 本 :V1.0
|
||||
* 作 者 :XuZhongPing
|
||||
* 日 期 :2017/09/02
|
||||
*********************************************************************************/
|
||||
#ifndef __LED_H
|
||||
#define __LED_H
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
extern uint8_t fillLightMask;
|
||||
|
||||
void LED_Init(void); //初始化
|
||||
void SetLedOn(void);
|
||||
void SetLedOff(void);
|
||||
|
||||
void SetLedToggle(void);
|
||||
void LED_Task(void);
|
||||
|
||||
#endif
|
||||
|
||||
/******************** (C) COPYRIGHT 2017 YNHB *****END OF FILE*******************/
|
||||
Reference in New Issue
Block a user