很简单就是个函数的调用
main.c代码
#include "stm32f10x.h"
#include "led.h"
void delay(unsigned int time)
{
int x =time, y;
for(x = 0; x < time; x++)
for(y = 0; y < 1000; y++)
{
}
}
void led(unsigned int num)
{
switch(num)
{
case 0:
GPIO_ResetBits(GPIOC, GPIO_Pin_0);
break;
case 1:
GPIO_ResetBits(GPIOC, GPIO_Pin_1);
break;
case 2:
GPIO_ResetBits(GPIOC, GPIO_Pin_2);
break;
case 3:
GPIO_ResetBits(GPIOC, GPIO_Pin_3);
break;
case 4:
GPIO_ResetBits(GPIOC, GPIO_Pin_4);
break;
case 5:
GPIO_ResetBits(GPIOC, GPIO_Pin_5);
break;
case 6:
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
break;
case 7:
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
break;
}
}
int main()
{
u8 i=0;
LED_init();
while(1)
{
//GPIO_ResetBits(GPIOC, GPIO_Pin_7);
if(i>7)
{
i=0;
GPIO_SetBits(GPIOC,LED_PIN);
}
led(i);
delay(500);
//delay(500);
i++;
}
}
led.c
#include "led.h"
void LED_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(LED_PORT_RCC, ENABLE);
GPIO_InitStructure.GPIO_Pin=LED_PIN;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_SetBits(LED_PORT,LED_PIN);
}
led.h
#ifndef _LED_H
#define _LED_H
#include "stm32f10x.h"
void LED_init(void);
#define LED_PIN (GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7)
#define LED_PORT_RCC RCC_APB2Periph_GPIOC
#define LED_PORT GPIOC
#endif