Some time ago because the project needs to draw a stm32f103 minimum system board, the project requires a lot of hardware resources so I will be PB mouth as a separate key input port, the board proofing back to test everything else is also good but in the independent key test, there is a problem, the test is to use the scanning method, The key supports continuous drinking in two different ways, the following problems occur:
1, a single button without any reaction
2, continuous mode PB3 under the control of the LED has been flashing, other key trigger is not normal.
Today suddenly remembered to solve this problem, so Baidu for a long time only to find PB3 and Jtag multiplexing, and then closed jtag solved the problem, and now share the hope for everyone to be useful. The Independent key scanning method is as follows (using the PB port to turn Jtag off with red font markings):
#ifndef __key_h
#define __key_h
#include "stm32f10x.h"
#include "Delay.h"
#define KEY0 gpio_readinputdatabit (GPIOB,GPIO_PIN_0)//right
#define Key1 gpio_readinputdatabit (gpiob,gpio_pin_1)//middle
#define KEY2 gpio_readinputdatabit (gpiob,gpio_pin_2)//down
#define Key3 gpio_readinputdatabit (gpiob,gpio_pin_3)//left
#define KEY4 gpio_readinputdatabit (gpiob,gpio_pin_4)//up
#define Key_right 1
#define KEY_MID 2
#define Key_down 3
#define KEY_LEFT 4
#define KEY_UP 5
void Key_init (void)
{
Gpio_inittypedef gpio_initstructure;
Rcc_apb2periphclockcmd (rcc_apb2periph_gpiob| rcc_apb2periph_afio,enable); Configuring the Clock
Gpio_pinremapconfig (gpio_remap_swj_jtagdisable,enable); Close
gpio_initstructure.gpio_pin=gpio_pin_0| gpio_pin_1| gpio_pin_2| gpio_pin_3| Gpio_pin_4;
gpio_initstructure.gpio_mode=gpio_mode_in_floating;
Gpio_init (gpiob,&gpio_initstructure);
}
U8 Key_scan (U8 mode)
{
Static U8 Key_p=1;
if (mode) key_p=1;
if (key_p&& (key0==0| | key1==0| | key2==0| | key3==0| | key4==0))
{
Delay_ms (100);
Key_p=0;
if (key0==0) return key_right;
else if (key1==0) return key_mid;
else if (key2==0) return key_down;
else if (key3==0) return key_left;
else if (key4==0) return key_up;
}
else if (key0==1&&key1==1&&key2==1&&key3==1&&key4==1) key_p=1;
return 0;
}
#endif
stm32f103 PB Port as a standalone button