//下面的全部是在stm32f10x.h文件里
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef struct
{
uint32_t CRL; //里面必须是具体的寄存器名称
uint32_t CRH;
uint32_t IDR;
uint32_t ODR;
uint32_t BSRR;
uint32_t BRR;
uint32_t LCKR;
}GPIO_TypeDef;
typedef struct
{
uint32_t CR;
uint32_t CFGR;
uint32_t CIR;
uint32_t AHBENR;
uint32_t APB2RSTR;
uint32_t APB1RSTR;
// uint32_t AHBRSTR; 不能有这个
uint32_t APB2ENR;
uint32_t APB1ENR;
uint32_t BDCR;
uint32_t CSR;
// uint32_t RCC_APB2ENR; //stm32f10x.h(48): error: #79: expected a type specifier
}RCC_TypeDef;
#define GPIOB ((GPIO_TypeDef*)GPIOB_BASE)
#define RCC ((RCC_TypeDef*)RCC_BASE)
//主函数如下
int main (void)
{
while(1)
{
//1:绿灯,通过结构体指针访问
RCC->APB2ENR |=((1)<<3); //打开时钟RCC
GPIOB->CRL &=((0x0f)<<(4*0));
GPIOB->CRL |=((1)<<(4*0)); //端口配置低寄存器CRL,配置PB0为通用推挽输出,最大速度10MHZ
GPIOB->ODR &=~((1)<<(0)); //配置ODR寄存器,(ODR为端口输出数据寄存器),写0才能亮
GPIOB->BRR &=~((1)<<(0)); //使用端口位清除寄存器点亮LED
}
}