This project implements a number guessing game using a PIC microcontroller, programmed in C (PIC C / CCS C compiler).
The assignment was to program the guess game application according to the provided keypad circuit and instructions.
The repository contains:
main.cβ Source code for the guess game (CCS PIC C).main.hexβ Compiled hex file to load into the circuit.Guess Game Circuit.simuβ Circuit simulation file for SimulIDE.
The game behaves as follows:
-
First Player (secret number setup):
- Enters a 4-digit number using the keypad (it is taken into account that the user will always insert 4 different digits).
- Digits are shown on the first line of the LCD.
- After the 4th digit, the number is saved and
"SAVED"is displayed for 2 seconds, then the screen clears.
-
Second Player (guessing):
- Has up to 10 guesses to find the number.
- Each guess is displayed as
"Guess#"followed by the entered digits. - After each guess, a hint is displayed in the format:
+nβ number of digits in the correct place-mβ number of digits that exist but are in the wrong place
- Example: if secret =
1357and guess =1325, hint shown is+2-1.
-
Winning condition:
- If guessed correctly within 10 tries β
"YOU WIN"is shown for 5 seconds. - LED at PIN_B7 turns on for 5 seconds.
- If guessed correctly within 10 tries β
-
Losing condition:
- If not guessed in 10 tries β
"YOU LOSE"is shown, and the secret number is displayed for 5 seconds.
- If not guessed in 10 tries β
-
After either outcome, the game resets and starts over.
To run this project, you need:
- SimulIDE β for circuit simulation.
-
Open the circuit in SimulIDE:
- Launch SimulIDE.
- Open the file
Guess Game Circuit.simu.
-
Load the compiled code into the microcontroller:
- In the circuit, click on the PIC microcontroller component.
- Load the provided
main.hexfile.
-
Run the simulation:
- Press the Play button in SimulIDE.
- First player enters a 4-digit number.
- Second player makes guesses using the keypad.
- Observe the results and hints on the LCD.
This project was created as part of Epoka University Course CEN389 β Embedded Systems homework.