11.6:完善多任务和消息队列机制。

This commit is contained in:
2025-11-06 16:32:17 +08:00
commit 5f408b4ece
337 changed files with 257102 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
#include "DHT11.h"
//<2F><>λDHT11
void vDht11Rst(void)
{
vDht11Mode(OUT); //SET OUTPUT
DHT11_Low; //<2F><><EFBFBD><EFBFBD>DQ
vTaskDelay(20); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>18~30ms
DHT11_High; //DQ=1
vDelayUs(13); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>10~35us
}
//<2F>ȴ<EFBFBD>DHT11<31>Ļ<EFBFBD>Ӧ
//<2F><><EFBFBD><EFBFBD>1:δ<><CEB4><EFBFBD>⵽DHT11<31>Ĵ<EFBFBD><C4B4><EFBFBD>
//<2F><><EFBFBD><EFBFBD>0:<3A><><EFBFBD><EFBFBD>
uint8_t vDht11Check(void)
{
uint8_t retry=0;
vDht11Mode(IN);//SET INPUT
while (GPIO_ReadInputDataBit(DHT11_GPIO_PORT,DHT11_GPIO_PIN)&&retry<100)//DHT11<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>40~80us
{
retry++;
vDelayUs(1);
};
if(retry>=100)return 1;
else retry=0;
while (!GPIO_ReadInputDataBit(DHT11_GPIO_PORT,DHT11_GPIO_PIN)&&retry<100)//DHT11<31><31><EFBFBD>ͺ<EFBFBD><CDBA><EFBFBD><EFBFBD>ٴ<EFBFBD><D9B4><EFBFBD><EFBFBD><EFBFBD>40~80us
{
retry++;
vDelayUs(1);
};
if(retry>=100)return 1;
return 0;
}
//<2F><>DHT11<31><31>ȡһ<C8A1><D2BB>λ
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>1/0
uint8_t vDht11ReadBit(void)
{
uint8_t retry=0;
while(GPIO_ReadInputDataBit(DHT11_GPIO_PORT,DHT11_GPIO_PIN)&&retry<100)//<2F>ȴ<EFBFBD><C8B4><EFBFBD>Ϊ<EFBFBD>͵<EFBFBD>ƽ
{
retry++;
vDelayUs(1);
}
retry=0;
while(!GPIO_ReadInputDataBit(DHT11_GPIO_PORT,DHT11_GPIO_PIN)&&retry<100)//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ߵ<EFBFBD>ƽ
{
retry++;
vDelayUs(1);
}
vDelayUs(40);//<2F>ȴ<EFBFBD>40us
if(GPIO_ReadInputDataBit(DHT11_GPIO_PORT,DHT11_GPIO_PIN))return 1;
else return 0;
}
//<2F><>DHT11<31><31>ȡһ<C8A1><D2BB><EFBFBD>ֽ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t vDht11ReadByte(void)
{
uint8_t i,dat;
dat=0;
for (i=0;i<8;i++)
{
dat<<=1;
dat|=vDht11ReadBit();
}
return dat;
}
//<2F><>DHT11<31><31>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//temp:<3A><EFBFBD>ֵ(<28><>Χ:0~50<35><30>)
//humi:ʪ<><CAAA>ֵ(<28><>Χ:20%~90%)
//<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>0,<2C><><EFBFBD><EFBFBD>;1,<2C><>ȡʧ<C8A1><CAA7>
uint8_t vDht11ReadData(uint8_t *pucTemp,uint8_t *pucHumi)
{
uint8_t ucBuffer[5];
uint8_t i;
vDht11Rst();
if(vDht11Check()==0)
{
for(i=0;i<5;i++)//<2F><>ȡ40λ<30><CEBB><EFBFBD><EFBFBD>
{
ucBuffer[i]=vDht11ReadByte();
}
if((ucBuffer[0]+ucBuffer[1]+ucBuffer[2]+ucBuffer[3])==ucBuffer[4])
{
*pucHumi=ucBuffer[0];
*pucTemp=ucBuffer[2];
}
}
else return 1;
return 0;
}
//<2F><>ʼ<EFBFBD><CABC>DHT11<31><31>IO<49><4F> DQ ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>DHT11<31>Ĵ<EFBFBD><C4B4><EFBFBD>
//<2F><><EFBFBD><EFBFBD>1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>0:<3A><><EFBFBD><EFBFBD>
uint8_t vDht11Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(DHT11_GPIO_CLK, ENABLE); //ʹ<><CAB9>PA<50>˿<EFBFBD>ʱ<EFBFBD><CAB1>
GPIO_InitStructure.GPIO_Pin = DHT11_GPIO_PIN; //PG11<31>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(DHT11_GPIO_PORT, &GPIO_InitStructure); //<2F><>ʼ<EFBFBD><CABC>IO<49><4F>
GPIO_SetBits(DHT11_GPIO_PORT,DHT11_GPIO_PIN); //PG11 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
vDht11Rst(); //<2F><>λDHT11
return vDht11Check();//<2F>ȴ<EFBFBD>DHT11<31>Ļ<EFBFBD>Ӧ
}
void vDht11Mode(uint8_t ucMode)
{
GPIO_InitTypeDef GPIO_InitStructure;
if(ucMode)
{
GPIO_InitStructure.GPIO_Pin = DHT11_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
}
else
{
GPIO_InitStructure.GPIO_Pin = DHT11_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
}
GPIO_Init(DHT11_GPIO_PORT, &GPIO_InitStructure);
}

View File

@@ -0,0 +1,34 @@
#ifndef __DHT11_H
#define __DHT11_H
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "FreeRTOS.h"
#include "task.h"
/* DHT11<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define DHT11_GPIO_CLK RCC_APB2Periph_GPIOB
#define DHT11_GPIO_PORT GPIOB
#define DHT11_GPIO_PIN GPIO_Pin_1
/* <20><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD> */
#define OUT 1
#define IN 0
/* <20><><EFBFBD><EFBFBD>DHT11<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߵ͵<DFB5>ƽ */
#define DHT11_Low GPIO_ResetBits(DHT11_GPIO_PORT,DHT11_GPIO_PIN)
#define DHT11_High GPIO_SetBits(DHT11_GPIO_PORT,DHT11_GPIO_PIN)
typedef struct {
uint8_t ucTemp;
uint8_t ucHumi;
} DHT11Data_t;
void vDht11Rst(void);//<2F><>λDHT11
uint8_t vDht11Check(void);//<2F><><EFBFBD><EFBFBD>DHT11
uint8_t vDht11ReadBit(void);//<2F><>ȡһλ<D2BB><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t vDht11ReadByte(void);//<2F><>ȡһ<C8A1><D2BB><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
uint8_t vDht11ReadData(uint8_t *pucTemp,uint8_t *pucHumi);//<2F><>ȡ<EFBFBD><C8A1>ʪ<EFBFBD><CAAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t vDht11Init(void);//<2F><>ʼ<EFBFBD><CABC>DHT11
void vDht11Mode(uint8_t ucMode);//DHT11<31><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
#endif

View File

@@ -0,0 +1,35 @@
#include "LED.h"
void vPc13LedInit(void)
{
RCC_APB2PeriphClockCmd(LED_PC13_GPIO_CLOCK,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = LED_PC13_GPIO_PIN; //PC13
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(LED_PC13_GPIO_PORT,&GPIO_InitStructure);
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* <20><><EFBFBD><EFBFBD>led<65>϶࣬<CFB6><E0A3AC><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>һ<EFBFBD><D2BB>LED_Set<65><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ƣ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>񿪻<EFBFBD><F1BFAABB>ǹ<EFBFBD> */
void vPc13LedOn(void)
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
void vPc13LedOff(void)
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
/* ʵ<>ְ<EFBFBD>һ<EFBFBD><D2BB>Ϩ<EFBFBD><CFA8><EFBFBD><EFBFBD><EFBFBD>ٰ<EFBFBD>һ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>LED<45><44>״̬ȡ<CCAC><C8A1><EFBFBD><EFBFBD>ʵ<EFBFBD>ֵ<EFBFBD>ƽ<EFBFBD><C6BD>ת<EFBFBD><D7AA>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD> */
void vPc13LedTurn(void)
{
if(GPIO_ReadOutputDataBit(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN) == 0)//<2F><><EFBFBD><EFBFBD>PA0<41><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>Ϊ0
{
GPIO_SetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN); //<2F><>PA0<41><30>1
}else
{
GPIO_ResetBits(LED_PC13_GPIO_PORT,LED_PC13_GPIO_PIN);
}
}

View File

@@ -0,0 +1,18 @@
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ֹͷ<D6B9>ļ<EFBFBD><C4BC>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>if not define<6E><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD>һ<EFBFBD><D2BB> */
#ifndef __LED_H__
#define __LED_H__
#include "stm32f10x.h" // Device header
/* PC13LED<45><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define LED_PC13_GPIO_CLOCK RCC_APB2Periph_GPIOC
#define LED_PC13_GPIO_PORT GPIOC
#define LED_PC13_GPIO_PIN GPIO_Pin_13
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void vPc13LedInit(void);
void vPc13LedOn(void);
void vPc13LedOff(void);
void vPc13LedTurn(void);
#endif

View File

@@ -0,0 +1,71 @@
#include "LoRa.h"
void vLoRaConnectionPkt(void)
{
vUsart3SendArray((uint8_t *)&xLoRaGateConfig, 3);
}
/**
* @brief LoRa<52><61><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>hex<65><78><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><><D2B2>LoRa<52>ڶ<EFBFBD><DAB6><EFBFBD>ģʽ<C4A3><CABD>ִ<EFBFBD>нڵ<D0BD><DAB5><EFBFBD>ͨ<EFBFBD>ŵ<EFBFBD><C5B5><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @note hex<65><78><EFBFBD>ݰ<EFBFBD><DDB0>ĸ<EFBFBD>ʽΪ<CABD>̶<EFBFBD><CCB6><EFBFBD><EFBFBD><EFBFBD>
* @param None
* @retval None
*/
void vLoRaToGateIdPkt(uint8_t ucNodeId)
{
if (ucNodeId == xLoRaNode1Config.ucLoRaNode1Identifier)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaNode1Config.ucLoRaNode1Identifier, 1);
} else if (ucNodeId == xLoRaNode2Config.ucLoRaNode2Identifier)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaNode2Config.ucLoRaNode2Identifier, 1);
}
}
void vLoRaToGateSenIdPkt(uint8_t ucSensorId)
{
if (ucSensorId == xLoRaSensorID.ucIdDht11)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaSensorID.ucIdDht11, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdMq2)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaSensorID.ucIdMq2, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdFire)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaSensorID.ucIdFire, 1);
} else if (ucSensorId == xLoRaSensorID.ucIdLight)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaSensorID.ucIdLight, 1);
}
}
void vLoRToGateExeIdPkt(uint8_t ucExeId)
{
if (ucExeId == xLoRaExecutorID.ucIdLed)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaExecutorID.ucIdLed, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdFan)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaExecutorID.ucIdFan, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdHumidifier)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaExecutorID.ucIdHumidifier, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdBuzzer)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaExecutorID.ucIdBuzzer, 1);
} else if (ucExeId == xLoRaExecutorID.ucIdServo)
{
/* code */
vUsart3SendArray((uint8_t *)&xLoRaExecutorID.ucIdServo, 1);
}
}

View File

@@ -0,0 +1,131 @@
#ifndef __LORA_H__
#define __LORA_H__
#include "USART3.h"
#define LORA_MODE
/* LoRa<52>ľ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD> */
#define LORA_MODE_INIT 1
#define LORA_GPIO_PIN_TX GPIO_Pin_10
#define LORA_GPIO_PIN_RX GPIO_Pin_11
#define LORA_GPIO_PIN_ATK_AUX GPIO_Pin_4 //PA4
#define LORA_GPIO_PIN_ATK_MD0 GPIO_Pin_3 //PB3
#define LORA_GATE_ADDR_HIGH 0x03
#define LORA_GATE_ADDR_LOW 0xE9
#define LORA_GATE_CHANNEL 0x17
#define LORA_NODE1_ADDR_HIGH 0x03
#define LORA_NODE1_ADDR_LOW 0xEA
#define LORA_NODE1_CHANNEL 0x17
#define LORA_NODE1_IDENTIFIER 0xD1
#define LORA_NODE2_ADDR_HIGH 0x03
#define LORA_NODE2_ADDR_LOW 0xEB
#define LORA_NODE2_CHANNEL 0x17
#define LORA_NODE2_IDENTIFIER 0xD2
#define LORA_SENSOR_DHT11 0xEA
#define LORA_SENSOR_MQ2 0xEB
#define LORA_SENSOR_LIGHT 0xEC
#define LORA_SENSOR_FIRE 0xED
#define LORA_EXECUTOR_LED 0xFA
#define LORA_EXECUTOR_FAN 0xFB
#define LORA_EXECUTOR_HUMIDIFIER 0xFC
#define LORA_EXECUTOR_BUZZER 0xFD
#define LORA_EXECUTOR_SERVO 0xFE
#define LORA_EXECUTOR_STATUS_ON 0x01
#define LORA_EXECUTOR_STATUS_OFF 0x00
typedef struct {
uint8_t ucLoRaGateAddrHigh;
uint8_t ucLoRaGateAddrLow;
uint8_t ucLoRaGateChannel;
} LoRaGateConfig_t;
typedef struct {
uint8_t ucLoRaNode1AddrHigh;
uint8_t ucLoRaNode1AddrLow;
uint8_t ucLoRaNode1Channel;
uint8_t ucLoRaNode1Identifier;
} LoRaNode1Config_t;
typedef struct {
uint8_t ucLoRaNode2AddrHigh;
uint8_t ucLoRaNode2AddrLow;
uint8_t ucLoRaNode2Channel;
uint8_t ucLoRaNode2Identifier;
} LoRaNode2Config_t;
typedef struct {
uint8_t ucIdDht11;
uint8_t ucIdMq2;
uint8_t ucIdLight;
uint8_t ucIdFire;
} LoRaSensorID_t;
typedef struct {
uint8_t ucIdLed;
uint8_t ucIdFan;
uint8_t ucIdHumidifier;
uint8_t ucIdBuzzer;
uint8_t ucIdServo;
} LoRaExecutorID_t;
typedef struct {
uint8_t ucStatusOn;
uint8_t ucStatusOff;
} LoRaExecutorFlag_t;
typedef struct {
uint8_t ucRxState; //״̬<D7B4><CCAC><EFBFBD><EFBFBD>S=0
uint8_t ucRxReadIndex; //ָʾ<D6B8><CABE><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t ucRxNodeIndex;
uint8_t ucRxExecutorIndex;
} LoRaUsart3Rx_t;
static LoRaGateConfig_t xLoRaGateConfig = {
.ucLoRaGateAddrHigh = LORA_GATE_ADDR_HIGH,
.ucLoRaGateAddrLow = LORA_GATE_ADDR_LOW,
.ucLoRaGateChannel = LORA_GATE_CHANNEL
};
static LoRaNode1Config_t xLoRaNode1Config = {
.ucLoRaNode1AddrHigh = LORA_NODE1_ADDR_HIGH,
.ucLoRaNode1AddrLow = LORA_NODE1_ADDR_LOW,
.ucLoRaNode1Channel = LORA_NODE1_CHANNEL,
.ucLoRaNode1Identifier = LORA_NODE1_IDENTIFIER,
};
static LoRaNode2Config_t xLoRaNode2Config = {
.ucLoRaNode2AddrHigh = LORA_NODE2_ADDR_HIGH,
.ucLoRaNode2AddrLow = LORA_NODE2_ADDR_LOW,
.ucLoRaNode2Channel = LORA_NODE2_CHANNEL,
.ucLoRaNode2Identifier = LORA_NODE2_IDENTIFIER
};
static LoRaSensorID_t xLoRaSensorID = {
.ucIdDht11 = LORA_SENSOR_DHT11,
.ucIdMq2 = LORA_SENSOR_MQ2,
.ucIdLight = LORA_SENSOR_LIGHT,
.ucIdFire = LORA_SENSOR_FIRE
};
static LoRaExecutorID_t xLoRaExecutorID = {
.ucIdLed = LORA_EXECUTOR_LED,
.ucIdFan = LORA_EXECUTOR_FAN,
.ucIdHumidifier = LORA_EXECUTOR_HUMIDIFIER,
.ucIdBuzzer = LORA_EXECUTOR_BUZZER,
.ucIdServo = LORA_EXECUTOR_SERVO
};
static LoRaExecutorFlag_t xLoRaExecutorStatus = {
.ucStatusOn = LORA_EXECUTOR_STATUS_ON,
.ucStatusOff = LORA_EXECUTOR_STATUS_OFF,
};
static LoRaUsart3Rx_t xLoRaUsart3Rx = { 0 };
void vLoRaConnectionPkt(void);
void vLoRaToGateIdPkt(uint8_t ucNodeId);
void vLoRaToGateSenIdPkt(uint8_t ucSensorId);
void vLoRToGateExeIdPkt(uint8_t ucExecutorId);
#endif

View File

@@ -0,0 +1,24 @@
#include "Relay.h"
void vPa0RelayInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(PA0_RELAY_CLK, ENABLE); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
GPIO_InitStructure.GPIO_Pin = PA0_RELAY_GPIO_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(PA0_RELAY_GPIO_PORT,&GPIO_InitStructure);
vPa0RelayOff();
}
void vPa0RelayOn(void)
{
GPIO_SetBits(PA0_RELAY_GPIO_PORT,PA0_RELAY_GPIO_PIN);
}
void vPa0RelayOff()
{
GPIO_ResetBits(PA0_RELAY_GPIO_PORT,PA0_RELAY_GPIO_PIN);
}

View File

@@ -0,0 +1,18 @@
#ifndef __RELAY_H__
#define __RELAY_H__
#include "stm32f10x.h"
#define vFanRelayInit(void) vPa0RelayInit(void)
#define vFanOn(void) vPa0RelayOn(void)
#define vFanOff(void) vPa0RelayOff(void)
#define PA0_RELAY_CLK RCC_APB2Periph_GPIOA
#define PA0_RELAY_GPIO_PIN GPIO_Pin_0
#define PA0_RELAY_GPIO_PORT GPIOA
void vPa0RelayInit(void);
void vPa0RelayOn(void);
void vPa0RelayOff(void);
#endif