FC controllers can be roughly divided into two types: one has an 11-pin controller socket, and the other has a 9-pin socket, which can be directly plugged into the DR9 serial port.
The FC controller has 10 buttons (actually only 8):
Up, Down, Left, Right, Start, Select, A, B, A Burst, B Burst.
A and A Burst are the same key value, and B and B Burst are also the same key value, but the Burst button will keep sending when you keep pressing it (convenient for quick keystrokes, such as firing shells).
The control circuit of the FC handle is composed of an 8-bit parallel-input and serial-output shift register (CD4021) and a time base integrated circuit (NE555, used for burst firing). Reading the handle key value is very simple: first latch (latch key value), then get the first key value (A, falling edge acquisition), then read the key values of other keys in turn under the action of 7 clocks, a total of 8 key values.
Read and write timing diagram:
Circuit connection diagram:
CODE:
#include "joypad.h" // Initialize the handle interface. void JOYPAD_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD, ENABLE); //Enable PB, PD port clock GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Push-pull output GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); //Initialize GPIO GPIO_SetBits(GPIOB,GPIO_Pin_11); //Pull up GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //Push-pull output GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); //Initialize GPIO GPIO_SetBits(GPIOD,GPIO_Pin_3); //Pull up GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //Pull-up input GPIO_Init(GPIOB, &GPIO_InitStructure); //Initialize GPIO GPIO_SetBits(GPIOB,GPIO_Pin_10); //Pull up} //Joypad delay function //t: delay time void JOYPAD_Delay(u16 t) { while(t--); }//Read the joystick button value.//FC joystick data output format://Each pulse is given, one bit of data is output, the output order is://A->B->SELECT->START->UP->DOWN->LEFT->RIGHT.//A total of 8 bits, for a joystick with a C button, pressing C is actually equivalent to pressing A+B at the same time.//Pressing is 1, releasing is 0.//Return value://[7]:Right//[6]:Left//[5]:Down//[4]:Up//[3]:Start//[2]:Select//[1]:B//[0]:Au8 JOYPAD_Read(void) { vu8 temp=0; u8 t; JOYPAD_LAT=1; //Latch current status JOYPAD_Delay(80); JOYPAD_LAT=0; for(t=0;t<8;t++) { temp>>=1; if(JOYPAD_DAT==0)temp|=0x80;//After LOAD, we get the first data JOYPAD_CLK=1; //Each time a pulse is given, a data is received JOYPAD_Delay(80); JOYPAD_CLK=0; JOYPAD_Delay(80); } return temp; }
Previous article:STM32 Series Chapter 29 --DS18B20
Next article:STM32 Series No. 27 - Infrared Remote Control
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- About the development process of the transmission control unit TCU
- Control System Design Guide (4th Edition)
- [AIoT Smart Smoke Detection System] Material Unboxing——SIPEED MAIX BIT KIT+LAUNCHXL-CC26X2R1
- [CY8CKIT-149 PSoC 4100S Evaluation] + LED switch counting and LCD display (final report)
- [Qinheng RISC-V core CH582] 3- Use of IO external interrupts
- Things to note when using MSP430
- What are the factors that have a huge impact on PCB assembly mechanism?
- Tantalum electrolytic capacitor replacement issues
- [NXP Rapid IoT Review] Hello BLE
- Making noise with MicroPython and Pi Pico