Shenzhen ZTRON Microelectronics Co., Ltd
Telephone
0755-8299 4126

Personal consumer electronics

Game console circuit board microcontroller solution development


Mini games can not only help people relieve stress in daily life, but also exercise hand-eye coordination and emergency response abilities. Mini games do not take up too much time and can be used as a way to relax during study and work breaks, such as Tetris. , Snake, racing, masturbation, etc. This design uses a microcontroller as the controller to complete these contents. Beginners with microcontrollers can also complete this task and become interested in microcontroller control circuits, thus improving the fun of learning.


This design adopts STC15 single-chip microcomputer to control the whole system, and uses dot matrix to display various interfaces of the game. The clock of this system is generated by the internal oscillator of the single-chip microcomputer, and the real-time clock is provided to the display module at the same time to complete the display function. This game console can play games such as Tetris, Snake, racing, and masturbation. The games are controlled through the keyboard, and the game sound circuit will play game music at the same time, making the game play more realistic.


1. Game console system structure and hardware design


The STC15 series of microcontrollers used this time have the following characteristics: large-capacity on-chip RAM memory, running faster than ordinary microcontrollers, multiple working modes to reduce power consumption, multiple PWM and ADC functional unit outputs, and 6 A timer, easy to control, can also program the system clock output. This design uses the STC15F2K60S2 microcontroller as the controller and uses the clock provided by the internal oscillator; the large-capacity EEPROM on the microcontroller is used to complete the FLASH screen during the game; the external interrupt of the microcontroller is used to form a keyboard to control the game; the PWM function realizes the brightness of the LED display adjust.


In order to facilitate design and debugging, the game console system can be completed using the minimum system of a single-chip microcomputer, including: dot matrix screen circuit, game keyboard circuit, game sound effect circuit, and LED game scoring circuit. The game console hardware circuit diagram is shown in Figure 1.


图1 游戏机硬件电路图


1.1 Dot matrix screen display game screen circuit


This design uses dot-matrix display, the principle of which is shown in Figure 2 dot-matrix screen display circuit. In order to make the displayed image clearer, two 88 dot matrix display modules are needed. A dot matrix and its connections are shown in Figure 2. Each dot matrix module is composed of 64 light-emitting diodes, and each light-emitting diode is placed at the intersection of row lines and column lines. When a certain column is set to a high level and the corresponding row is set to a low level, the corresponding diode is lit. Through the control algorithm of ranks and columns, the display of dynamic Flsh animation can be completed. The I/O port of the STC15 series MCU has four working modes: quasi-bidirectional port, weak pull-up, strong push-pull, and strong pull-up. When the I/O port is used as an output, select the strong push-pull mode, and the output current of each port can reach 20mA, which is enough to light up the LEDs on the corresponding row without additional pull-up resistors. Therefore, the dot matrix can be directly connected with the I/O port of the single-chip microcomputer, which reduces the complexity of the circuit. For beginners, the hardware is simpler.


图2 点阵屏显示电路


1.2 Gaming keyboard design


In the design of game consoles, the keyboard is an essential input device. In this design, the function of the keyboard is to select the corresponding game interface through the keyboard when the game starts; during the game, the ongoing game is controlled through the keyboard. This game console has five buttons in total, namely K0 and K4. K0 is the selection key, which completes functions such as start, deformation, and acceleration; K1 and K4 are direction keys, K1 is the up key, K3 is the down key, K4 is the left key, and K2 is the right key. R1 and R5 are pull-up resistors, providing necessary drive for the I/O port.


1.3 Game sound effect circuit design


On the premise of meeting the requirements of the application, this design uses an ordinary buzzer as the sounding component of the game sound effects. Buzzers usually have relatively large operating currents and require a triode amplifier circuit to drive them. The positive polarity of the buzzer is connected to the +5V power supply, and the other end is connected to the emitter of the PNP tube. The base of the triode is controlled by the P5.5 port of the single-chip microcomputer to provide the necessary music for the game.


1.4 Game scoring circuit design


The game scoring circuit is implemented using a three-digit seven-segment digital tube. The trinity seven-segment digital tube display circuit has segment code address and bit code address. Control the digital tube to display different characters. In this way, to display three digits, it must be implemented using dynamic scanning. To put it simply, it is to display different numbers on different positions, and then quickly complete the display. In order for people to see the above numbers, it must be repeated many times. In this way, through the persistence effect of human vision and the afterglow characteristics of the digital tube, the three digits on the digital tube can be observed. The segment code of the three-digit digital tube is connected to the line data port of the dot matrix screen for game scoring.


游戏机控制板方案设计


2. Game console system software design


2.1 Software design process


Due to the complexity of the system, a modular design is required to facilitate subsequent debugging and verification. Separate different games, implement them with different functions, and then make a selection in the main function.


2.2 Design of main program


The program is designed according to the structured program, and all functions are completed through subroutine calls. The functions of the main program include designing the game GUI, constructing the basic model of the game interface, achieving the effect of screen translation, using the bottom layer of the LED dot matrix to drive point-by-point scanning to make the display brightness uniform, and using the software PWM to scan the screen in layers to form the contrast of the game screen and make the display screen Brightness is adjustable. Set global variables in the main program, scan keyboard input, control game speed, game scoring, game life, sound switch, display default brightness, etc.


2.3 Tetris game software design


The rule of the Tetris game is that within a limited space, the combination of cubes of various shapes will fall down one by one. During the falling process of the cubes, the player controls the shape of the falling cubes by controlling the buttons, so as to make the falling cubes fall as much as possible. The block is tightly bound to the block already below, leaving no gaps. When the grid meets the obstruction of other grids during the descent, it will stay at the current position. When a horizontal layer is completely occupied by blocks, all the blocks on this layer will disappear. Use the buttons to control the reasonable placement of the cubes, so that the cubes fill up a row and disappear by themselves, so that you can score points. It is the main point and method of Tetris.


According to the above rules, the program design ideas are as follows. First use the function staticvoidRandBox to randomly load a box, after the falling time arrives, the current box moves down by one unit, and then reads the value of the keyboard key. If the movement key is pressed, it is judged whether it can be moved left or right, and if it is possible, the square moves one unit to the left or right. If it is a transformation key, according to the function tmpbuf[i]=blocks[tmpid][3-i], the current block is transformed according to regulations. After each unit falls, it is necessary to judge whether it is dead or not, and whether the specified floor has been filled. According to the function staticvoidRowFull {uint8p, k; uint8tmps = 0; for (p = 0; p < 16; p++)} check whether the row is full and deal with it accordingly. If the line is full, the line will be eliminated, and the score will be changed accordingly; if the squares are piled up within the specified range, the game will end and the game score will be displayed.


2.4 Snake game software design


The rule of the snake game is that the snake runs forward at a certain speed in a certain space. During the running process of the snake, you can control the direction of the snake head by pressing the buttons so that the snake can eat food. If the snake eats food, the length of the snake will grow by one unit, and the score will also increase. If the snake's head touches the wall or touches any part of its own body, the game is over.


The basic idea of designing the Snake game is to first make a snake body for Snake as a game point, that is, a basic lattice. Use the function staticvoidCreate_Food to randomly load the snake's food. Use timer 1 to set the time for 1 second. When the time of 1 second is reached, the snake will move forward one unit. To design the movement process of the snake, we need to pay attention to the following points: (1) Movement processing. According to the button value of the user's button, the flexible body transmission is performed, and the movement of the snake can be accelerated by pressing the selection button; (2) The processing of eating food. If food is eaten, the food flag is set to 0, and the body of the snake grows by one game point; (3) Place new food. Judge the food flag, if the food flag is 0, then place the food. In the process of placing food, it is also necessary to judge whether the new food overlaps with the snake body. If it overlaps, it needs to be relocated and judged again until the new food does not overlap with the snake body; (4) Death treatment. When the snake runs, if it touches a wall or its own body, the game ends and the game score is displayed.


2.5 Racing game software design


The rule of racing is that the car runs forward within a certain period of time, and other cars appear in front of it while running. Players can control the speed of the car, and move the car position left and right to avoid other cars. As the distance traveled by the car, the score will increase accordingly. In the game, if a car hits another car, the game is over.


The basic idea of designing a racing game is to first use the function voidRAC_Game to design the structure graphics of the racing car, and set a global variable RAC_flag, whose type is defined as unsigned char, which is used to record information such as the position of the racing car and the direction of movement of the racing car. Next, use Timer 2 to time 1s. When the 1s timing is up, the racing car and other racing cars will move forward one unit at the same time. Through the function, the racing car is generated immediately. When the selection button is pressed, the car accelerates (0.2s/unit). At the same time, press the left and right keys to avoid other racing cars and advance, and the game score increases accordingly. During the running of the car, if it hits other cars, the game will end and the game score will be displayed.


2.6 Game software design for playing planes


The rule of playing the plane is that a block of unit lattice randomly appears above the plane. The user shoots the randomly appearing block by controlling the left and right keys and the selection key (shooting). When the block is hit, the block is eliminated and the score increases at the same time. If the plane hits the block, then the game is over.


The basic design idea of designing a plane shooting game is to use the function staticvoidShot_Game_Init to draw the plane graphics, and at the same time initialize the display screen, and then randomly appear shooting blocks. Each square corresponds to a game point, that is, a basic lattice. Set a global variable Shot_flag, whose type is defined as an unsigned character, used to record information such as aircraft position, block position, and ballistic generation. Then shoot the blocks that appear randomly, the blocks that are hit will disappear, and the game score will increase. The block drops by one unit every 1s. If the plane hits the block, the game ends and the game score is displayed.


in conclusion


Because the circuit control part is relatively simple, it can be completed with the smallest system of ST15 single-chip microcomputer, and it is not difficult to complete. But you need to pay attention to the corresponding relationship between the pins of the dot matrix screen and the rows and columns, and the direction of the triode and buzzer. In terms of software, because the system is relatively large, it needs to be completed separately, that is, after the main program framework is built, the debugging of the Tetris game can be completed first, and then other small games can be added to the system.


This design analyzes the hardware schematic diagram and software logic of Tetris, Snake, racing, and airplane games using STC15F2K60S2 single-chip microcomputer, and completes the production of this game console. The hardware circuit of this game machine is simple, and the software programming logic is clear, which is convenient for beginners to complete the production of the system.


The above is the game console development example introduced to you by our Shenzhen Zuchuang Microelectronics Co., Ltd. If you have game solution development needs, you can trust us. We represent a variety of single-chip microcomputers, voice chips, dual-mode Bluetooth ICs, and wifi chips. Brands include Songhan MCU, Yingguang MCU, Jerry Bluetooth, Ankai Bluetooth, Allwinner, and Realtek. Our technical services include: PCB design, microcontroller development, Bluetooth solutions, software and hardware custom development, APP development, small program development, WeChat official account development, etc. It can also undertake the design of intelligent electronic products, the development of living appliances, the research and development of beauty equipment, the application of Internet of things platform, the smart home control system, the development of TWS earphones, Bluetooth earphone speakers, the development of children's educational toys, the design of electronic education products, etc.

  • TOP