#include "sys.h"
#include "delay.h"
#include "uart.h"
#include "led.h"
int main(void)
{
delay_init();
Relay_Init();
while(1)
{
//relay connected on PB13
Relay = !Relay;
delay_ms(1000);
}
}
led.h
#ifndef __LED_H
#define __LED_H
#include "sys.h"
//////////////////////////////////////////////////////////////////////////////////
//¿ª·¢°å
//LEDÇý¶¯´úÂë
//////////////////////////////////////////////////////////////////////////////////
//#define LED4 PAout(15) // PA15
//#define LED3 PBout(3) // PB3
//#define LED2 PBout(4) // PB4
#define Relay PBout(13) // PB13-relay is connected at that pin
void Relay_Init(void);//³õʼ»¯
#endif
led.c
void Relay_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE); //¿ªÆôGPIOA,GPIOBʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);//¿ªÆô¸´ÓÃʱÖÓ£¬Õâ¸öÒ»¶¨Òª¿ª
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//ʧÄÜJTAG£¬Ê¹ÄÜSW
/* GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
Relay = 1;
}
No comments:
Post a Comment