新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2023-9-17
- 在线时间
- 3 小时
|
2金钱
用 PA5 PA6 做io输出口,将PA5设为低电位,PA6不间断的设高设低,感觉没什么问题
以下是 led.h led.c main.c
led.h
#ifndef __LED_H
#define __LED_H
#include"sys.h"
#define LED0 PAout(5)
#define LED1 PAout(6)
void LED_Init(void);
#endif
led.c
#include"led.h"
#include"sys.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_ResetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6);
}
main.c
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include"led.h"
int main(void)
{
delay_init(168);
LED_Init();
//LED1=0;
LED1=1;
while(1)
{
LED1=!LED1;
delay_ms(500);
LED1=!LED1;
delay_ms(500);
}
}
|
|