GPIO->ODR |= 0<<0;
P0 = 0XFE; // 总线操作
sbit LED1 = P0^0; //位操作
LED1 = 0;
位带简介:
外设位带区
1 AliasAddr= =0x42000000+ (A-0x40000000)84 +n4
SRAM 位带区
1 AliasAddr= =0x22000000+ (A-0x20000000)84 +n4
“位带地址+位序号”转’换成别名区地址统一成一个宏。
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x02000000+((addr & 0x00FFFFFF)<<5)+(bitnum<<2))
main.c
#include "stm32f10x.h"
#include "bsp_led.h"
#include "bsp_key.h"
#define GPIOA_ODR_Addr (GPIOA_BASE+0X0C)
#define PAout(n) *(unsigned*)((GPIOA_ODR_Addr & 0xF0000000)+0x02000000+((GPIOA_ODR_Addr & 0x00FFFFFF)<<5)+(n<<2))
#define GPIOC_IDR_Addr (GPIOC_BASE+0X08)
#define PCin(n) *(unsigned*)((GPIOC_IDR_Addr & 0xF0000000)+0x02000000+((GPIOC_IDR_Addr & 0x00FFFFFF)<<5)+(n<<2))
void Delay(uint32_t count)
{
for(;count!=0; count--);
}
int main(void)
{
//来到这个系统时钟被配置成72M
LED_GPIO_Config();
KEY_GPIO_Config();
#if 0
while(1)
{
//LED_R(OFF);
//GPIO_SetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
PAout(8) = 1;
Delay(0xFFFFF);
//GPIO_ResetBits(LED_G_GPIO_PORT, LED_G_GPIO_PIN);
//LED_R(ON);
PAout(8) = 0;
Delay(0xFFFFF);
}
#else
while(1)
{
if( PCin(8) == KEY_ON );
{
while(PCin(8) == KEY_ON);
LED_G_TOGGLE;
}
}
#endif
}
位带操作不会被中断,避免数据的丢失。