最近开始学习STM32 ,按键IO口设置这儿始终不太明白
为甚么在在IO口设置成输入模式后,还要将PA0和PC13的ODR 寄存器设为输出啊
下面程序中PA0,PC13用于按键 ; PB0,PC3,PC4用于LED
RCC->APB2ENR |= 1<<3; //Enable clock of GPIOB
RCC->APB2ENR |= 1<<4; //Enable clock of GPIOC
RCC->APB2ENR |= 1<<2; //Enable clock of GPIOC
//ÉèÖÃLED¶Ë¿Úģʽ
GPIOB->CRL |= 0x00000001; //Set PB0 mode push output 10MHZ
GPIOB->ODR |= 1 << 0; //Set PB0 output 1 (GPIOÉèÖÃΪÊä³öºóĬÈÏΪ0£¬ËùÒÔÐèÒª½«¶Ë¿Ú¸³Öµ1£¬·ÀÖ¹Æô¶¯ºóLEDÁÁ)
GPIOC->CRL |= (0x00000001 << (4 * 3)); //Set PC3 mode push output 10MHZ
GPIOC->ODR |= 1 << 0; //Set PC3 output 1
GPIOC->CRL |= (0x00000001 << (4 * 4)); //Set PC4 mode push output 10MHZ
GPIOC->ODR |= 1 << 0; //Set PC4 output 1
//ÉèÖð´¼ü¶Ë¿Úģʽ
GPIOA->CRL &= 0xfffffff0; //Set PA0 INPUT
GPIOA->CRL |= 0x00000008;
GPIOC->CRH &= 0xfff0ffff; //Set PC13 INPUT
GPIOC->CRH |= 0x00080000;
GPIOA->ODR |= 1 << 0;
GPIOC->ODR |= 1 << 13;[/code] |