请教F103系列例程的sys.h文件适用于F072系列cpu吗?半路出家,对于地址位什么的还没学懂。
#ifndef __SYS_H
#define __SYS_H
#include "stm32f0xx.h"
//////////////////////////////////////////////////////////////////////////////////
//本程序只供学习使用,未经作者许可,不得用于其它任何用途
//ALIENTEK STM32开发板
//正点原子@ALIENTEK
//技术论坛:
www.openedv.com
//修改日期:2012/8/18
//版本:V1.7
//版权所有,盗版必究。
//Copyright(C) 广州市星翼电子科技有限公司 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//0,不支持ucos
//1,支持ucos
#define SYSTEM_SUPPORT_UCOS 0 //定义系统文件夹是否支持UCOS
//位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入
void NVIC_Configuration(void);
#endif
感谢原子哥,感谢八度空间前辈,现在改好了,实验可用!
sys.h代码改为如下:
#ifndef __SYS_H
#define __SYS_H
#include "stm32f0xx.h"
//0,不支持ucos
//1,支持ucos
#define SYSTEM_SUPPORT_UCOS 0 //定义系统文件夹是否支持UCOS
//F0中没有位段操作,F1和F4都有,其他没用过,不清楚,所以自己就定义了一个用结构体
typedef struct
{
unsigned short int b0:1;
unsigned short int b1:1;
unsigned short int b2:1;
unsigned short int b3:1;
unsigned short int b4:1;
unsigned short int b5:1;
unsigned short int b6:1;
unsigned short int b7:1;
unsigned short int b8:1;
unsigned short int b9:1;
unsigned short int b10:1;
unsigned short int b11:1;
unsigned short int b12:1;
unsigned short int b13:1;
unsigned short int b14:1;
unsigned short int b15:1;
}REG16_TypeDef;
//位带操作,实现51类似的GPIO控制功能
//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+0x14) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+0x14) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+0x14) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+0x14) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+0x14) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+0x14) //0x40011A0C
#define GPIOA_IDR_Addr (GPIOA_BASE+0x10) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+0x10) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+0x10) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+0x10) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+0x10) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+0x10) //0x40011A08
//IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout ((volatile REG16_TypeDef*)GPIOA_ODR_Addr) //输出
#define PAin ((volatile REG16_TypeDef*)GPIOA_IDR_Addr) //输入
#define PBout ((volatile REG16_TypeDef*)GPIOB_ODR_Addr) //输出
#define PBin ((volatile REG16_TypeDef*)GPIOB_IDR_Addr) //输入
#define PCout ((volatile REG16_TypeDef*)GPIOC_ODR_Addr) //输出
#define PCin ((volatile REG16_TypeDef*)GPIOC_IDR_Addr) //输入
#define PDout ((volatile REG16_TypeDef*)GPIOD_ODR_Addr) //输出
#define PDin ((volatile REG16_TypeDef*)GPIOD_IDR_Addr) //输入
#define PEout ((volatile REG16_TypeDef*)GPIOE_ODR_Addr) //输出
#define PEin ((volatile REG16_TypeDef*)GPIOE_IDR_Addr) //输入
#define PFout ((volatile REG16_TypeDef*)GPIOF_ODR_Addr) //输出
#define PFin ((volatile REG16_TypeDef*)GPIOF_IDR_Addr) //输入
void NVIC_Configuration(void);
#endif
一周热门 更多>