You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
incubator_embeded/HARDWARE/Relays.c

132 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "stm32f10x.h" // Device header
#include "USART.h"
#include "SysTick.h"
#include "Relays.h"
void HC595_Pin_Init(void){
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO,ENABLE );
PWR_BackupAccessCmd( ENABLE );/* 允许修改RTC和后备寄存器*/
RCC_LSEConfig( RCC_LSE_OFF ); /* 关闭外部低速时钟,PC14+PC15可以用作普通IO*/
BKP_TamperPinCmd(DISABLE); /* 关闭入侵检测功能,PC13可以用作普通IO*/
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_14 | GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
PWR_BackupAccessCmd(DISABLE);/* 禁止修改RTC和后备寄存器*/
GPIO_SetBits(GPIOC,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
//BKP_ITConfig(DISABLE); /* 禁止TAMPER 中断*/
}
//void Relays_Init(void)
//{
// GPIO_InitTypeDef GPIO_InitStructure;
//
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
//
// GPIO_ResetBits(GPIOB,GPIO_Pin_0);//接压缩机
// delay_ms(20);
//
//// printf("relays_init!!!\r\n");
//
//}
void HC595_Send_Data(u8 data)
{
u8 i = 0;
for (i = 0; i < 8; i++)
{
if (data & 0x80) //先传输高位通过与运算判断第八是否为1
SER = 1; //如果第八位是1则与 595 DS连接的引脚输出高电平
else //否则输出低电平
SER = 0;
SRCLK = 0;
delay_ms(5);
SRCLK = 1;
data <<= 1;
}
}
void HC595_Send_Byte(u8 dat1)//,u8 dat2,u8 dat3,u8 dat4,u8 dat5,u8 dat6,u8 dat7,u8 dat8
{//
SRCLK = 1;
RCLK = 1;
HC595_Send_Data(dat1);
// HC595_Send_Data(dat2);
// HC595_Send_Data(dat3);
// HC595_Send_Data(dat4);
// HC595_Send_Data(dat5);
// HC595_Send_Data(dat6);
// HC595_Send_Data(dat7);
// HC595_Send_Data(dat8);
RCLK = 0;
delay_us(2);
RCLK = 1;
delay_us(2);
RCLK = 0;
}
/* GPIO1->PB1 GPIO2->PB0 GPIO3->PA0 GPIO4->PD1 GPIO5->PD0 GPIO6->PC13 GPIO7->PB9 GPIO8->PB8 */
//void Relays_Init(void)
//{
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
//
//
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_15;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
// GPIO_Init(GPIOA, &GPIO_InitStructure);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1|GPIO_Pin_8| GPIO_Pin_9;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOC, &GPIO_InitStructure);
//
// GPIO_ResetBits(GPIOA,GPIO_Pin_0|GPIO_Pin_15);
// delay_ms(20);
// GPIO_ResetBits(GPIOB,GPIO_Pin_0| GPIO_Pin_1| GPIO_Pin_9);
// delay_ms(20);
// GPIO_ResetBits(GPIOC,GPIO_Pin_13);
// delay_ms(20);
//// printf("relays_init!!!\r\n");
//
//}
//void GPIO8_Init(void)
//{
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
//
// GPIO_InitTypeDef GPIO_InitStructure;
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
// GPIO_Init(GPIOB, &GPIO_InitStructure);
//}