单片机内容
1.在sys.h内有端口设置比如说,GPIOA口对应PAout(1),也可以直接调动其内部对于端口的设置:
#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
#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))
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //Êä³ö
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //ÊäÈë
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //Êä³ö
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //ÊäÈë
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //Êä³ö
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //ÊäÈë #define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n)
2.将其放置在关于GPIO的点h里,然后在相关的芯片的.h文件内容里,加入类似:
#define SCLOCK PAout(0)
#define SDI PAout(1)
#define SDO PAout(2)
//#define CSB GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)
#define RESET PAout(3)
//#define IORST GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4)
#define FUD PAout(7)
#define PS0 PCout(2)
#define PS1 PCout(1)
#define PS2 PCout(0)
void write1byte(uint8_t byte);
void write5byte(uint8_t addr,uint8_t byte0,uint8_t byte1,uint8_t byte2,uint8_t byte3);
void write6byte(uint8_t addr,uint8_t byte0,uint8_t byte1,uint8_t byte2,uint8_t byte3,uint8_t byte4);
void write9byte(uint8_t addr,uint8_t byte0,uint8_t byte1,uint8_t byte2,uint8_t byte3,uint8_t byte4,uint8_t byte5,uint8_t byte6,uint8_t byte7);
void writeSCBandFUD(void);
.h文件除了端口设置外,还要添加相关的在.c文件内调用的函数如上;(例子在DDS-Test);
3.STM32强制类型转换
- *c;取内容符号;将地址c指向的数据获取出来;
- &c;取地址符号;将c的值的地址取出来;
- 如何将一个48bit的FTW十进制数据转为十六进制数据,可以选择强制类型转换;
将FTW的地址取出来,在取出此地址的指针指向的数据,每隔8位取一次,一共取值六次;则将十进制数据转为十六进制;write9byte(0x06,0x00,0x00,(((uint8_t *)(&FTW))[5]),(((uint8_t *)(&FTW))[4]),(((uint8_t *)(&FTW))[3]),(((uint8_t *)(&FTW))[2]),(((uint8_t *)(&FTW))[1]),(((uint8_t *)(&FTW))[0]));