Here's a procedure that even beginners can use to easily create a game using a microcontroller.
The RL78 microcontroller has a cheap and easy-to-use development environment available. For this tutorial, we used the RL78/G23 Fast Prototyping Board (FPB) to create a mole-catching game.
First, let me explain the mole-catching game. The game randomly lights up the segments of a 7-segment LED at fixed time intervals, and the player has to press the button at the moment when the decimal point is lit up. If the player manages to stop the decimal point, then they have successfully caught the mole (as shown in Figure 1).
To create the mole-catching game, please obtain the following necessary components from your favorite online shopping site or other sources.
- 1-digit 7-segment LED
- LEDs (blue, red)
- Tactile switch
- 120Ω resistor
- Sink-type transistor array
- Jumper wires
- Micro USB Type-B cable
- FPB (RL78/G23 64-pin)
Integrated Development Environment (IDE)
Next, let's prepare the development tools. Install the development tools while referring to the Start Developing with the RL78 - Essential for Microcomputer Beginners - Part 1 blog. For reference, I chose CS+ which is easy to understand even for beginners.
Let me briefly introduce the peripheral functions of the RL78/G23 that were used in programming the mole-catching game.
- Port function: Used to control the 7-segment LED display.
- Timer Array Unit (TAU): Generates interrupts at regular intervals to adjust the display time of the 7-segment LED.
- True Random Number Generator (TRNG): Used to generate random patterns of LED display.
Reference: RL78/G23 Product Information Page
Let's create the game by following the steps below.
- Download the code that has been created using C language from the following URL (available in Japanese only).
Code: Let's Make a Game Using a Microcontroller - Part 1: Sample Programs and More - Renesas Community
- We will wire the circuit according to the circuit diagram shown in Figure 2 and demonstrated with the boards in Figure 3 and Figure 4.
In this game's specifications, the blue LED lights up when the game is successful, and the red LED lights up when the game is lost.
- Connect jumper wires to the FPB as shown in Figure 5 and Figure 6.
Refer to Pages 16-18 of the "RL78/G23-64p Fast Prototyping Board User's Manual" for the terminal layout of the FPB.
- Connect the USB cable to both the PC and the microcontroller as shown in Figure 7.
- Debug the code using CS+, see Figure 8 for reference.
Debug the code that you downloaded earlier using CS+.
- Run the program.
After debugging, run the program as demonstrated in Figure 9. Once the program is debugged, it is written into the microcontroller. The program that was debugged once is stored in the microcontroller, so you can operate it just by supplying power without debugging with CS+ next time. However, if you want to operate the microcontroller alone without using a PC, you need to use programming software such as RFP to write the program again.
- It worked correctly.
That concludes the game creation process. By using the FPB and breadboard, you can connect to your PC with just one USB cable and eliminate the need for soldering work. I highly recommend using the FPB and breadboard for electronic projects. If you're interested in electronics, try creating your own project using the RL78 microcontroller.
Reference: Fast Prototyping Board for RL78 Family
The reference used for creating the mole-catching game is provided in the URL below. Please take a look if you are interested!
*The following URL is available in Japanese only.