STM32点亮LED灯(结构体指针访问)

//下面的全部是在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  

        }

}         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值