河北水利局项目

This commit is contained in:
2025-12-15 16:07:49 +08:00
commit f11a7c2b95
1146 changed files with 452892 additions and 0 deletions

248
APP/Led.c Normal file
View File

@@ -0,0 +1,248 @@
/*——————————————————————————
* 文 件 名Led.c
* 文件说明Led源文件
*
* 当前版本V8.0
* 作 者ZL
* 开始日期2013-12-30
*———————————————————————————*/
#include "Led.h"
#include "include.h"
bool OLDNEW_VERSION_DETECT = false;//false 旧版本true 新版本
/*
st_gpio_config up_send_led = LED_INIT(UP_SEND);
st_gpio_config up_receive_led = LED_INIT(UP_RECEIVE);
st_gpio_config down_send_led = LED_INIT(DOWN_SEND);
st_gpio_config down_receive_led = LED_INIT(DOWN_RECEIVE);
st_gpio_config alarm_led = LED_INIT(ALARM);
st_gpio_config running_led = LED_INIT(RUNNING);
*/
/*
st_gpio_config running_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}; //PA1 运行
st_gpio_config alarm_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPU}; //PC3 告警
st_gpio_config plcRx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPU}; //PC0 PLC RX
st_gpio_config plcTx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPU}; //PC2 PLC TX
st_gpio_config up_RS485Rx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPU}; //PA12 4851RX 485上行
st_gpio_config up_RS485Tx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPU}; //PA11 4851TX
st_gpio_config MBUS1Rx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPU}; //PA8 MBUS1RX
st_gpio_config MBUS1Tx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPU}; //PC9 MBUS1TX
st_gpio_config dn_RS485Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPU}; //PC8 4852RX 485下行
st_gpio_config dn_RS485Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPU}; //PC7 4852TX
st_gpio_config MBUS2Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPU}; //PC6 MBUS2RX
st_gpio_config MBUS2Tx_led = {GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPU}; //PB15 MBUS2TX
*/
st_gpio_config led_boardharddetect[1] =
{
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}, //PA1 运行
};
st_gpio_config led_list[] =
{
#if HARDBOARD_VERSION == 0
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}, //PA1 运行
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPU}, //PC3 告警
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPU}, //PC0 PLC RX RED
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPU}, //PC2 PLC TX
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPU}, //PA12 4851RX RED
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPU}, //PA11 4851TX GREEN
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPU}, //PA8 MBUS1RX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPU}, //PC9 MBUS1TX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPU}, //PC8 4852RX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPU}, //PC7 4852TX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPU}, //PC6 MBUS2RX
{GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPU}, //PB15 MBUS2TX
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPD}, //PA1 运行
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPD}, //PC3 告警
//
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPD}, //PC0 PLC RX RED
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPD}, //PC2 PLC TX
//
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPD}, //PA12 4851RX RED
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPD}, //PA11 4851TX GREEN
//
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPD}, //PA8 MBUS1RX
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPD}, //PC9 MBUS1TX
//
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPD}, //PC8 4852RX
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPD}, //PC7 4852TX
//
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPD}, //PC6 MBUS2RX
// {GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPD}, //PB15 MBUS2TX
#else
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_Out_OD}, //PA1 运行
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_Out_OD}, //PC3 告警
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_Out_OD}, //PC0 PLC RX RED
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_Out_OD}, //PC2 PLC TX
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_Out_OD}, //PA12 4851RX RED
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_Out_OD}, //PA11 4851TX GREEN
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_Out_OD}, //PA8 MBUS1RX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_Out_OD}, //PC9 MBUS1TX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_Out_OD}, //PC8 4852RX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_Out_OD}, //PC7 4852TX
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_Out_OD}, //PC6 MBUS2RX
{GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_Out_OD}, //PB15 MBUS2TX
#endif
};
st_gpio_config * CurrentOperationLED = &led_list[0];
/*——————————————————————————
* 函 数 名LED_Init
* 输入参数led 灯
* 输出参数None
* 返 回 值None
* 功能说明初始化LED灯
*——————————————————————————*/
void LED_Init(st_gpio_config led)
{
gpio_init(led);
LED_Off(led);
}
void init_all_led(void)
{
LED_Init(led_boardharddetect[0]);
if(GPIO_ReadInputDataBit(led_boardharddetect[0].GPIO_port,led_boardharddetect[0].GPIO_Pin) == 0x01)
{
OLDNEW_VERSION_DETECT = true;
}
else
{
OLDNEW_VERSION_DETECT = false;
}
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
{
if(OLDNEW_VERSION_DETECT == false)
{
led_list[i].GPIO_mode = GPIO_Mode_IPU;
}
else
{
led_list[i].GPIO_mode = GPIO_Mode_Out_OD;
}
LED_Init(led_list[i]);
LED_Off(led_list[i]);
}
}
void test_led(void)
{
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
{
COM_led_on(i);
//vTaskDelay( 1000 / portTICK_RATE_MS );
//COM_led_off(i);
//vTaskDelay( 1000 / portTICK_RATE_MS );
}
printf("OK\r\n");
}
void COM_led_init(u8 led)
{
LED_Init(led_list[led]);
}
void COM_led_on(u8 led)
{
LED_On(led_list[led]);
}
void COM_led_off(u8 led)
{
LED_Off(led_list[led]);
}
/*——————————————————————————
* 函 数 名LED_On
* 输入参数led 灯
* 输出参数None
* 返 回 值None
* 功能说明点亮Led灯
*——————————————————————————*/
void LED_On(st_gpio_config led)
{
//#if HARDBOARD_VERSION == 0
if(OLDNEW_VERSION_DETECT == false)
led.GPIO_port->BSRR = led.GPIO_Pin;//GPIO_PIN[led]; //设置位为 1
//#else
else
led.GPIO_port->BRR = led.GPIO_Pin;
//#endif
}
/*——————————————————————————
* 函 数 名LED_Off
* 输入参数led 灯
* 输出参数None
* 返 回 值None
* 功能说明关闭Led灯
*——————————————————————————*/
void LED_Off(st_gpio_config led)
{
//#if HARDBOARD_VERSION == 0
if(OLDNEW_VERSION_DETECT == false)
led.GPIO_port->BRR = led.GPIO_Pin;//GPIO_PIN[led]; //清除位为 0
//#else
else
led.GPIO_port->BSRR = led.GPIO_Pin;
//#endif
}
/*——————————————————————————
* 函 数 名LED_Toggle
* 输入参数led 灯
* 输出参数None
* 返 回 值None
* 功能说明:电平反转
*——————————————————————————*/
void LED_Toggle(st_gpio_config led)
{
//#if HARDBOARD_VERSION == 0
if(OLDNEW_VERSION_DETECT == false)
led.GPIO_port->ODR ^= led.GPIO_Pin;//GPIO_PIN[led];
//#else
else
led.GPIO_port->ODR ^= led.GPIO_Pin;
//#endif
}
void off_all_led(void)
{
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
{
//LED_Init(led_list[i]);
LED_Off(led_list[i]);
}
}