stm32F103寄存器地址操作点灯

 
#define GPIOB_BASE 0x40010C00
#define GPIOC_BASE 0x40011000
#define GPIOA_BASE 0x40010800
 
#define RCC_APB2ENR (*(unsigned int *)0x40021018)
 
#define GPIOB_CRH (*(unsigned int *)0x40010C04)
#define GPIOC_CRH (*(unsigned int *)0x40011004)
#define GPIOA_CRL (*(unsigned int *)0x40010800)
 
#define GPIOB_ODR (*(unsigned int *)0x40010C0C)
#define GPIOC_ODR (*(unsigned int *)0x4001100C)
#define GPIOA_ODR (*(unsigned int *)0x4001080C)
	
 
 
void SystemInit(void);
void Delay_ms(volatile  unsigned  int);
void A_LED_LIGHT(void);
void B_LED_LIGHT(void);
void C_LED_LIGHT(void);
void Delay_ms( volatile  unsigned  int  t)
{
     unsigned  int  i;
     while(t--)
         for (i=0;i<800;i++);
}
 
void A_LED_LIGHT(){
	GPIOA_ODR=0x0<<4;		//PA4???
	GPIOB_ODR=0x1<<9;		//PB9???
	GPIOC_ODR=0x1<<15;		//PC15???
}
void B_LED_LIGHT(){
	GPIOA_ODR=0x1<<4;		//PA4???
	GPIOB_ODR=0x0<<9;		//PB9???
	GPIOC_ODR=0x1<<15;		//PC15???
}
void C_LED_LIGHT(){
	GPIOA_ODR=0x1<<4;		//PA4???
	GPIOB_ODR=0x1<<9;		//PB9???
	GPIOC_ODR=0x0<<15;		//PC15???	
}
 
int main(){
	int j=100;
	// ????
	RCC_APB2ENR |= (1<<3); // ?? GPIOB ??
	RCC_APB2ENR |= (1<<4); // ?? GPIOC ??
	RCC_APB2ENR |= (1<<2); // ?? GPIOA ??
	
	
	// ?? GPIO ?????
	GPIOB_CRH&= 0xffffff0f;	//??? ??		
	GPIOB_CRH|=0x00000020;  //PB9????
 
	GPIOC_CRH &= 0x0fffffff; //??? ??		
	GPIOC_CRH|=0x30000000;  //PC15????
 
 
	GPIOA_CRL &= 0xfff0ffff; //??? ??		
	GPIOA_CRL|=0x00010000; //PA4????
 
	// 3?LED??????(????)
	GPIOB_ODR |= (1<<9); 
	GPIOC_ODR |= (1<<15); 
	GPIOA_ODR |= (1<<4);  
	
	while(j){
		
		B_LED_LIGHT();
		Delay_ms(1000);
 
		C_LED_LIGHT();
		Delay_ms(1000);
 
		A_LED_LIGHT();
		Delay_ms(1000);
	}
	
}
 
 
void SystemInit(){
	
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值