newrudeman

LiChuang Development Board*Ziyun Qingshan [NES Game Console]

 
Overview

## Preface

This is a game console expansion board based on the design of Lichuang Liangshan School. The official one is called Tiankuixing, and the traffic light expansion board is called Tiangangxing. So I'll call it Tianjixing! Hahaha!

## Project Requirements

1. It has a UI interface and can play a variety of games by selection.
2. The screen is small and the brightness is adjustable.
3. Output sound through the speaker or insert wired headphones, and the vibration motor gives the user certain feedback.
4. Use the combination of joystick and buttons to get a good gaming experience.
5. Independent power supply, Type-C rechargeable design, power detection, and support for long press to start and long press to shut down.

## Device Selection

1. Screen:
![image.png] Use 1.69-inch IPS screen
2. Headphone jack, speaker and amplifier IC:
![image.png] The speaker needs to be purchased on Taobao.
![image.png] 8002A
3. 3D joystick
![image.png] Personally, I think this 3D joystick has a better feel than the official one. Then I bought a joystick button cap on Taobao and installed it.
4. Button
![image.png] After comprehensive consideration, although this switch does not feel as good as the official expansion board, this touch switch can be equipped with keycaps, which looks better.
5. EEPROM
![image.png] M24C02
6. Vibration motor
![image.png] 7. Charging IC
![image.png] LP4056HSPF
8. Boost IC
![image.png] ME2159AM6G
boosts the voltage of the lithium battery from 3.7V to 5V to power the board.

## Schematic diagram design description

1. MOS switch circuit:
![image.png] Long press to start function: When the START touch switch is pressed, the gate of the PMOS tube is connected to a low potential, causing its source and drain to be turned on, which is equivalent to turning on the switch. At this time, the microcontroller has been powered on. In order to achieve the effect of long press to start, when the pressing time is less than 2S, the microcontroller controls the screen to be off, and the PE6 port outputs a low level. As long as the touch switch is released, the source and drain will be cut off. The single-chip computer is powered off. When the button is pressed for more than 2 seconds, the PE6 port outputs a high level, so that the emitter and collector of the S8050 transistor are turned on. Regardless of whether the button is pressed or not, the single-chip computer will not be powered off. In this way, the function of long-pressing to turn on the computer is realized.
Long-press shutdown function: The PE5 pin uses an external interrupt and a pull-up input. When the button is pressed, the PE5 level is pulled low. The single-chip computer detects the pressing time. When the pressing time is greater than the set threshold, PE6 outputs a low level and turns off the screen, giving the user the feeling of shutting down the computer. However, the single-chip computer is not actually powered off. When the hand moves away from the button, the PMOS gate potential is pulled high, and the source and drain are cut off. How can the real power off be achieved?
2. Charging circuit:
![image.png] ![image.png] The charging IC uses LP4056HSPF, and the ISET pin is connected to a 2K resistor. By looking up the data sheet, we know that the charging current is 0.5A. The output levels of the STAT1 and STAT2 pins are different when charging and when charging is completed. Connecting the two pins to the corresponding pins of Liangshan School can detect whether the game console is charging and whether the charging is completed. The charging interface uses TYPE-C. Since the VBAT network is located at the source end of the PMOS tube, charging can be performed regardless of whether the game console is turned on or not.
3. Boost circuit:
![image.png] The boost IC uses ME2159AM6G, which increases the voltage of 3.7V to 5V to power the board. When charging, the voltage of the 5V_CG network turns on the collector and emitter of the MMBT3904 transistor, the EN pin is set low, and the boost IC stops boosting, so that the battery and the external power supply can be prevented from powering the board at the same time. The voltage detection is performed by using two 510K resistors in series to divide the voltage. As shown in the figure above, since the VCC network is located at the drain end of the PMOS tube, when the game console is turned off, the ADC voltage detection will not form a loop and cause discharge.
4. Key circuit:
![image.png] In order to facilitate wiring, some key pins are treated as "non-connected".
The rest of the circuit design is basically the same as the official expansion board, so I will not go into details.

## PCB design instructions

![image.png] Considering the use of another 3D joystick, which is relatively high, if the screen is still attached to the middle of the main board, the effect may not be particularly good, so here the screen is welded to another small board, and then the two boards are welded together through the pad.

## Software Description

1. The configuration code of PE5 PE6 pins that control the power on and off is as follows:

```
void output_Init(void)
{
rcu_periph_clock_enable(RCU_GPIOE);
gpio_mode_set(GPIOE, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,GPIO_PIN_6);
gpio_output_options_set(GPIOE, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_6);
}

void On(void)
{
gpio_bit_set(GPIOE,GPIO_PIN_6);//PE6 is set high, the board will be powered regardless of whether the button is pressed or not
}

void Off(void)
{
gpio_bit_reset(GPIOE,GPIO_PIN_6);//PE6 is set low, when the hand is released from the button, the board is truly powered off
}

void input_EXTI_Init(void)//Detect if the START button is pressed
{
/* Turn on the clock*/
rcu_periph_clock_enable(RCU_GPIOE);
rcu_periph_clock_enable(RCU_SYSCFG);

/* Configure GPIO mode*/
gpio_mode_set(GPIOE,GPIO_MODE_INPUT,GPIO_PUPD_PULLUP,GPIO_PIN_5);//Pull-up

inputnvic_irq_enable(EXTI5_9_IRQn,2U,0U);
syscfg_exti_line_config(EXTI_SOURCE_GPIOE,EXTI_SOURCE_PIN5);


exti_init(EXTI_5,EXTI_INTERRUPT,EXTI_TRIG_FALLING);
exti_interrupt_enable(EXTI_5);
exti_interrupt_flag_clear(EXTI_5);
}
```

2. Delayed boot part: When the START button is pressed, the Off() function is executed first, and then the On() function is executed after a delay of 2S. At the same time, the screen is turned on to prompt the user to release the button. Below is the location of the code:

```
systick_config();
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);

output_Init();
Off();//If the button is pressed for less than two seconds and then removed, the board will be powered off
delay_1ms(2000);//Delay 2S

usart0_init();
adc_config();
adc_bat_init();
key_init();
led_init();
ui_main_set_init();

On();//Because the power-on logo display function below also has a delay part to achieve the loading effect, the On() function is placed in this line for execution

ui_main_lcd_init();//Power-on logo display

//....codes omitted.....//

ui_main_init_show();
input_EXTI_Init();//PE5 pin input initializationwhile
(1)
{
//....codes omitted.....//
}

```
When you want to turn off the game console, press the START button, the PE5 pin generates a falling edge, and the program execution immediately enters the external interrupt callback function. The specific function and code have been mentioned above and will not be repeated here. The callback function code is as follows:
```
void EXTI5_9_IRQHandler(void)//interrupt callback function
{
if(exti_interrupt_flag_get(EXTI_5) == SET)
{
delay_1ms(20);
if(gpio_input_bit_get(GPIOE,GPIO_PIN_5) == RESET)
{
uint8_t i;
for(i=0;i<10;i++)//2s long press to shut down, check every 200ms
{
delay_1ms(200);
if(gpio_input_bit_get(GPIOE,GPIO_PIN_5) == RESET && i==9)
{
Off(); // PE6 is set low, and when the hand is released from the button, the board is truly powered off
LCD_Fill(0,0,240,280,0x0000); // The screen goes out, causing the shutdown phenomenon
while(1); // Infinite loop
}
else if(gpio_input_bit_get(GPIOE,GPIO_PIN_5) == SET)
{
break; // Exit the loop if the condition is not met
}
}
}
exti_interrupt_flag_clear(EXTI_5); // Clear the interrupt flag
}
}
```
2. Power-on LOGO display and loading effect
LCD_ShowPicture1 function can display pictures, and the last parameter is the name of the array after the picture is converted to an array.
The power-on LOGO in the official sample program is the words of the LiChuang development board, and I replaced it with a picture of my own design.
```
//Startup logo display
void ui_main_lcd_init(void)
{
LCD_Init();
LCD_timer_config();
LCD_ShowPicture1(0,0,LCD_W,LCD_H,START_BMP); //Startup logo
LCD_ShowString(((240-strlen("Loading")*12)/2),0,"Loading!",LCEDA,WHITE,2 4,0);
delay_1ms(1200);
LCD_ShowString(((240-strlen("*Loading!*")*12)/2),0,"*Loading!*",LCEDA,WHITE,24,0);
delay_1ms(900);
LCD_ShowString(((240-strlen("**Loading!**")*12)/2),0,"**Loading! **",LCEDA,WHITE,24,0);
delay_1ms(600);
LCD_ShowString(((240-strlen("***Loading!***")*12)/2),0,"***Loading!***",LCEDA,WHITE,24,0);
delay_1ms(300);
timer_channel_output_pulse_value_config(TIMER2,TIMER_CH_1,50+ui_set.luminance*10);
}

```
Image to array can be converted using a software called Image2Lcd:
![image.png] After the conversion is completed, copy and paste the array to the corresponding position of image.h.
![image.png] This picture is the boot LOGO I designed

![image.png] This picture is the content of "About this machine". So you can also import the pictures you want to display according to your own preferences.
3. How to display Chinese characters without garbled characters.
Since there is no Chinese character library data in the SPI Flash on the Liangshan School board at the beginning, the Chinese characters will be garbled when running the NES system. At this time, you need to import the Chinese character library. The first step is to use an SD card (32GB is recommended, because some group members said that the selected SD card memory is too large or too small, which may cause unrecognizable phenomena). Create a new folder named font in the root directory and put the font file in it; the second step is to insert it into the Liangshan School SD card slot where the NES system program has been downloaded. When it is plugged in and started, it will automatically flash the font data to the flash. After that, whether the memory card is inserted or not, Chinese characters can be displayed normally!
4. Optimize the rustling sound of the speaker or headphones when not playing the game
because the audio output of the nes game has a DC bias of 0x80. If the signal output to the speaker or earphone has a sudden change, it will cause a very uncomfortable abnormal sound from the speaker. So the official NES system program may output a 0x80 offset to the audio when not playing the game for compatibility, but this will cause a big problem, that is, there will be a rustling sound, which makes the experience not good. Therefore, after my research on the code, the audio signal directly outputs zero when not entering the game, and adds 0->0x80 when entering the game, and adds a signal slow change of 0x80->0 when exiting the game, which can solve the rustling sound problem to a good extent.
The initialization audio of Timer3 outputs zero, and then the interrupt callback function of Timer3 is changed a lot. This part of the shit mountain code that I changed by myself is too long, so I won’t post it here. The rest is some details. If you need it, you can download the program I uploaded and copy the relevant content into your own code.
![image.png] ![image.png] ![image.png] ![image.png] ## Physical display
1. 3D shell The physical display
uses the 3D printing of Jiali Chuang 3D Monkey. The effect is very good, the surface is very smooth, and it is full of praise!
![image.png] ![image.png] 2. Panel display
Use the panel drawing function of Jiali Chuang EDA to draw a panel and send it to LiChuang Mall for printing. The color effect is also very good, and the size is also very corresponding, without deviation. The panel file is in the project.
![image.png] 3. Game console internal display
![image.png] 4. Game console overall display
![image.png] ## Innovation
1. Instead of using the official power module solution, the MOS tube switch circuit is designed by itself, with charging and boosting circuits to complete the hardware part of the power supply. The relevant code is added at the software level to realize the long press to start and long press to shut down functions, and the effect is very good.
2. The design of the 3D shell and panel gives the PCB a good-looking coat, and the experience of playing games is improved.
3. Optimize the code of the audio part of the NES system to solve the problem of rustling sound when not playing games.
## Future Plans
Because I have been very busy recently, I have not been able to make the game functions more colorful, but I hope to increase and enrich the program content in the future, and add interesting parts, such as listening to music, electronic clocks and other functions.
## Acknowledgements
First of all, I would like to thank Jia Li Chuang for providing great support to us electronics enthusiasts. "Not making money by selling boards, but cultivating Chinese engineers as their responsibility." Indeed, whether it is free PCB proofing, Li Chuang development board, or Li Chuang open source hardware platform, it makes electronic production low-cost and popular... It has made a great contribution to cultivating Chinese hardware engineers!
Thanks to Mr. Wu, Xiao Xu, and Sister Ni from Li Chuang Mall. Although I often bother them, they are still very enthusiastic to answer my questions. More importantly, they gave me coupons to reduce the cost of making game consoles, hahaha!
OK, just like that, I wrote it for a long time and finally finished it!
参考设计图片
×
 
Related Devices
Devices Class introduce Datasheet
C0603X5R106M160NT Passive components;The patch capacitance Accuracy: ±20% Capacitance: 10uF Rated voltage: 16V Temperature drift coefficient (dielectric material): X5R X5R Download
CR0603J1K00P05Z Download
CR0603J10K0P05Z Download
S8050 Discrete semiconductor;triode Transistor type: NPN Collector current Ic: 500mA Collector-emitter breakdown voltage Vce: 25V Rated power: 225mW NPN Download
8002A Analog mixed-signal IC;Audio power amplifier Download
CR0603FA1002G Passive components;SMD resistor Resistance (ohms): 10K Accuracy: ±1% Power: 1/10W Temperature coefficient: ±100ppm/°C 1/10W Download
AC0603DR-0768KL Passive components;SMD resistor Resistance (ohms): 68K Accuracy: ±0.5% Power: 1/10W Temperature coefficient: ±100ppm/°C Download
HPCR0603F22K0K9 Passive components;High power SMD resistor Power: 200mW Resistance (ohms): 22K Accuracy: ±1% 0.2W, rated power is twice that of ordinary chip resistors Download
CR0603F1K00P05Z Download
CR0603JA0103G Passive components;SMD resistor Resistance (ohms): 10K Accuracy: ±5% Power: 1/10W Temperature coefficient: ±200ppm/°C Download
1N4148W Discrete semiconductor;Switching diode Reverse recovery time (trr): 8ns DC reverse withstand voltage (Vr): 75V Average rectified current (Io): 150mA Forward voltage drop (Vf): 1V @ 10mA Download
CR0603FA20R0G Passive components;SMD resistor Resistance (ohms): 20 Accuracy: ±1% Power: 1/10W Temperature coefficient: ±100ppm/°C Download
3D161 accessories;Five to switch Multi-directional joystick Download
SI2301 Discrete semiconductor;MOS (field effect tube) Drain-source voltage (Vdss): 20V Continuous drain current (Id) (at 25°C): 2.8A Gate-source threshold voltage: 950mV @ 250uA Drain-source on-resistance: 130mΩ @ 2.8A, 4.5V Maximum power dissipation (Ta=25°C): 1.25W Type: P-channel Download
1N5819 Discrete semiconductor;Schottky diode DC reverse withstand voltage (Vr): 40V Average rectified current (Io): 1A Forward voltage drop (Vf): 600mV @ 1A 40V, 1A, VF=0.6V@1A Download
SS24A Discrete semiconductor;Schottky diode DC reverse withstand voltage (Vr): 40V Average rectified current (Io): 2A Forward voltage drop (Vf): 500mV @ 2A Download
TMPC0502HP-4R7MG-D Passive components;Power inductor Accuracy: ±20% Inductance value: 4.7uH DC resistance (internal resistance): 103mΩ Rated current: 2.8A Download
AC0805FR-0788K7L Passive components;SMD resistor Resistance (ohms): 88.7K Accuracy: ±1% Power: 1/8W Temperature coefficient: ±100ppm/°C Download
AC0805FR-0712KL Passive components;The resistor Fixed Resistor, Metal Glaze/thick Film, 0.125W, 12000ohm, 150V, 1% +/-Tol, 100ppm/Cel, Surface Mount, 0805, CHIP Download
MMBT3904 Discrete semiconductor;triode Rated power: 350mW Collector current Ic: 200mA Collector-emitter breakdown voltage Vce: 40V Transistor type: NPN Download
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2024-11-14 23:42:15

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号