写出stm32F103的位带别名、位设置位清除、数据寄存器操作点亮LED灯的代码
时间: 2024-05-24 13:11:44 浏览: 7
位带别名:
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x02000000+((addr & 0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
#define GPIOA_ODR_Addr (GPIOA_BASE + 0x0C) //输出数据寄存器地址
#define GPIOB_ODR_Addr (GPIOB_BASE + 0x0C)
#define GPIOC_ODR_Addr (GPIOC_BASE + 0x0C)
#define GPIOD_ODR_Addr (GPIOD_BASE + 0x0C)
#define GPIOE_ODR_Addr (GPIOE_BASE + 0x0C)
#define GPIOF_ODR_Addr (GPIOF_BASE + 0x0C)
#define GPIOG_ODR_Addr (GPIOG_BASE + 0x0C)
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n)
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n)
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n)
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n)
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n)
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n)
位设置位清除:
//设置位
#define SET_BIT(addr, bitnum) (addr |= (1<<bitnum))
//清除位
#define CLEAR_BIT(addr, bitnum) (addr &= ~(1<<bitnum))
数据寄存器操作点亮LED灯:
RCC->APB2ENR |= 1<<4; //使能PORTC时钟
GPIOC->CRL &= 0xFFFFFFF0; //PC0设置推挽输出
GPIOC->CRL |= 0x00000003;
while(1)
{
PCout(0) = 1; //点亮LED灯
delay_ms(500);
PCout(0) = 0; //熄灭LED灯
delay_ms(500);
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)