led.c
#include"led.h"
#include"bitband.h"
void Led_Init(void)
{
GPIO_InitTypeDef GPIO_VALUE; //???
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//???
GPIO_VALUE.GPIO_Mode=GPIO_Mode_Out_PP;//???? ????
GPIO_VALUE.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;//????
GPIO_VALUE.GPIO_Speed=GPIO_Speed_50MHz;//????
GPIO_Init(GPIOC,&GPIO_VALUE);//???
}
void Led_On(int nu)
{
switch(nu)
{
case 0:PCOut(1)=1;break;
case 1:PCOut(2)=1;break;
case 2:PCOut(3)=1;break;
}
}
void Led_Off(int nu)
{
switch(nu)
{
case 0:PCOut(1)=0;break;
case 1:PCOut(2)=0;break;
case 2:PCOut(3)=0;break;
}
}
led.h
#ifndef __LED_H
#define __LED_H
#include "stm32f10x_conf.h"
extern void Led_Init(void);
extern void Led_On(int opt);
extern void Led_Off(int opt);
#endif
bitband.h
#ifndef __BITBAND_H
#define __BITBAND_H
#include "stm32f10x_conf.h"
#define BIT_BAND(ADDR,BITNUM) ((ADDR & 0xF0000000) + 0x2000000 + ((ADDR & 0xFFFFF) << 5) + (BITNUM << 2))
#define MEM_ADDR(ADDR) *(volatile unsigned int *)(ADDR)
#define BITBAND(ADDR,BITNUM) MEM_ADDR(BIT_BAND(ADDR,BITNUM))
#define GPIOA_IDR_ADDR (GPIOA_BASE + 0x08)
#define GPIOA_ODR_ADDR (GPIOA_BASE + 0x0C)
#define GPIOB_IDR_ADDR (GPIOB_BASE + 0x08)
#define GPIOB_ODR_ADDR (GPIOB_BASE + 0x0C)
#define GPIOC_IDR_ADDR (GPIOC_BASE + 0x08)
#define GPIOC_ODR_ADDR (GPIOC_BASE + 0x0C)
#define GPIOD_IDR_ADDR (GPIOD_BASE + 0x08)
#define GPIOD_ODR_ADDR (GPIOD_BASE + 0x0C)
#define PAOut(n) BITBAND(GPIOA_ODR_ADDR, n)
#define PAIn(n) BITBAND(GPIOA_IDR_ADDR, n)
#define PBOut(n) BITBAND(GPIOB_ODR_ADDR, n)
#define PBIn(n) BITBAND(GPIOB_IDR_ADDR, n)
#define PCOut(n) BITBAND(GPIOC_ODR_ADDR, n)
#define PCIn(n) BITBAND(GPIOC_IDR_ADDR, n)
#define PDOut(n) BITBAND(GPIOD_ODR_ADDR, n)
#define PDIn(n) BITBAND(GPIOD_IDR_ADDR, n)
#endif
main.c
#include "led.h"
int main(void)
{
Led_Init();
while(1)
{
Led_On(0);
Led_On(1);
Led_On(2);
}
return 0;
}