fmq.c
#include"fmq.h"
#include"bitband.h"
void Fmq_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_7;
GPIO_VALUE.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_VALUE);
}
void Fmq_On(void)
{
//GPIO_SetBits(GPIOC,GPIO_Pin_7);
PCOut(7)=1;//λ´ø
}
void Fmq_Off(void)
{
//GPIO_ResetBits(GPIOC,GPIO_Pin_7);
PCOut(7)=0;//λ´ø
}
fmq.h
#ifndef __FMQ_H
#define __FMQ_H
#include "stm32f10x_conf.h"
extern void Fmq_Init(void);
extern void Fmq_On(void);
extern void Fmq_Off(void);
#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"fmq.h"
int main(void)
{
int i=0,j=0;
Fmq_Init();
for(i=0;i<3;i=(i+1)%3)
{
Fmq_On();
for(j=0;j<1000000;j++);
Fmq_Off();
for(j=0;j<1000000;j++);
}
return 0;
}