Skip to main content

Nowadays, who does not remember those arcade games with which everything started? Those times when you had to go to the arcade machines to play and you spent the weekly pay to have a good time surrounded by friends.

The project is based on microcontroller PIC16F877A and consists of a three-level arcade game, in which you can select your difficulty and see your final score. Therefore, the game can be divided into 3 different main stages:

  • Level selection menu: Selection of the 3 different levels of difficulty.
  • Game: Game screen with music in which a pause is included.
  • Score: Show your score after seeing a loser face with music.

 

The project can be divided into three main parts:

  1. Circuit connections: the electronic control circuit is based on a Microchip® PIC16F877A microcontroller connected to different sensors and actuators described below.
  2. Microcontroller programming: the microcontroller has been programmed in C using MPLAB integrated development environment.
  3. Video: Video making the connections with the microcontroller and showing the functioning of the arcade game.

Circuit Connections

In this section, the circuit connections are explained, as well as the operation modules employed. The project consists of some modules such as a joystick and a led matrix with a Johnson counter.

1. Joystick

The joystick counts with 5 terminals:

  • GND, +5Vjoystick3_afb5a6bd1b588a105a881c796dc7d25b2452e729.jpg
  • VRx, VRy: they provide an analogical signal between 0 V and 5 V proportional to the joystick’s position in axis X and axis Y respectively. These voltages are converted into a number between 0 and 1023 using the microcontroller’s 10-bit ADC (Analog-to-Digital Converter).
  • Switch: it is the output terminal for the joystick’s pushbutton and requires a pull-up resistor. When it is pressed, the laser on top of the servomotors is activated.

 

The connections with the microcontroller have been the following:

joy%2Bpic_44dd10b97be8ccf0eed894a8a7ed1dd9b1a0a8ff.png

2. Led matrix with Johnson counter

matriz_b1d39fe5d552d773a3fa7e579f4e1bee73898d8b.jpg

The LED matrix is formed by LED diodes arranged in the form of a matrix. In addition, through its 16 pins, it allows you to select both the column and the LED of the row to be illuminated.

In this case, the matrix used is a common anode, which means that if in column 1, for example, we set a HIGH, all the cathodes of the LEDs that are in LOW of that column will light up. This allows you to create figures, letters, numbers ...

jcim_7d47d32a6e1e19bf9e7ddf60597f93457b4363f2.png

 

For greater simplicity of the control of the matrix, a Johnson counter has been used, which allows illumination of the different columns one by one by means of a pulse sweep. The time that passes between the pulses from one column to another is defined by RE0, it will works like a clock at a fixed frequency that we define. RE1 works as the reset of the Johnson counter pulses. Because only 8 pins of the 10 available are used, this reset will occur upon reaching the eighth column.

 

The connections with both the microcontroller and the matrix are described in the following image:

jc%2Bledm_82f105a9c44087eb0f5029ac0937c822d2612482.png

 

3. Piezo Buzzer

This component reproduces the music programmed in the microcontroller. The CCP module operates in PWM mode with a 50% duty cycle. The duration of the pulse depends on the musical note because each one of them has a different frequency and therefore a period. The music code is included in the "Arcade game" program.

The image below shows the connections:

buz%2Bpic_01344c97696ac2e5d03c48159a6b242a6139e7fa.png

 

Control Program

The arcade game program and the inputs and outputs are explained in this section. As it was mentioned before, the microcontroller has been programmed in C using MPLAB integrated development environment. The program code is attached at the end of the article.

Inputs/Outputs

The inputs and outputs used are:

  • RE0: As digital output. Pulse sweep frequency of the Johnson counter
  • RE1: As digital output. Reset frequency of the Johnson counter.
  • RD0-RD7: As digital outputs. Control of the LED diodes of the rows of the matrix.
  • RC2: As analogic output. Generates the melodies of the buzzer (CCP1)
  • RB0: As digital input. Causes the interruption of the joystick button (SW)
  • RA1: As analogic input. Y position of the joystick (VRy)
  • RA3: As analogic input. X position of the joystick (VRx)

IN_OUT_dde6df9cc4db7fc1a8181542865123908585836e.png

 

 

 

 

 

 

 

 

 

 

 

 

The model used in the laboratory is shown in the following image. All connections can be seen on it.

Setup used for arcade game

 

Used Modules

For the development of the arcade game, different modules of the PIC have been configured:

  • Timer0 module. It is configured as a timer module every 500us, which causes an interruption when it overflows. In order to configure it, a pre-divider of 4 was used and the value 131 was loaded in the TMR0.

F1_9b80ef8dcab3555dd88b13ce43c1c79099abf953.png

 

 

 

  • CCP1 module. It has been set in PWM mode to control the different frequencies of the piezo buzzer notes. To achieve this, the Timer 2 adjusts the period of the notes and the CCPR1L the work cycle to 50%
  • Timer2 module. It is used to adjust the period of the PWM signal of the previously mentioned CCP1 module. The post divider of timer 2, when used in PWM mode, is irrelevant
  • 10-bit A/D converter module. It converts the analogical signal of the joystick into different digital samples with a resolution of 4,8876 mV/bit. The conversions are released every 2ms in the different channels (AN1 and AN3)

F2_e33982af61bd935d39de70596b692f68728f9617.png

 

 

Block Diagrams

To explain the operation of the program, a simplified main program block diagram is shown. This contains the three main stages of the Arcade game: level selection, game, score.

The block diagrams of the interruptions of RB0 and the A/D converter best explained are also shown.

  • Main program block diagram:

b1_36cda4a5ee9a19d377a2f0cf96c676eb3fcae57d.png

 

  • A/D converter interrupt block diagram:

b2_bb400a905a863896d60025ed8d43025d782f7f58.png

 

  • RB0(SW) interrupt block diagram:

b3_5d3ac644c1a964e36b528762a810a3f552b89574.png

The interruption of tmr0 has not been included in the block diagrams because it is only used as a 500us timer module. With this timer, you control both the music, the game, the sweep of the LED matrix, that is, everything that needs to be timed.

VIDEO

Downloads

Mikacel06 has not written a bio yet…
DesignSpark Electrical Logolinkedin