11.8 PROJECT 11.8 – The High/Low Game
This project uses a 4 × 4 keypad to create the classical a High/Low game. For those of you who are not familiar with the game, here are the rules for this version of the game:
- The computer will generate a secret random number between 1 and 32 767.
- The top row of the LCD will display ‘Guess Now . . .’
- The player will try to guess what the number is, by entering a number on the keypad and then pressing the ENTER key.
- If the guessed number is higher than the secret number, the bottom row of the LCD will display ‘HIGH – Try Again’.
- If the guessed number is lower than the secret number, the bottom row of the LCD will display ‘LOW – Try Again’.
- If the player guesses the number, then the bottom row will display ‘Well Done . . .’
- The program waits for 5 seconds and the game re-starts automatically.
Before going into the design of the project, it is worthwhile to learn a bit more about how the keypads work and the mikroC Pro for PIC commands available to use a keypad.
11.8.1 Keypads
A 4 × 4 keypad consists of 16 keys with internal mechanical switches at each key position. Figure 11.32 shows a typical 4 × 4 keypad connected to PORT D of a PIC microcontroller.
The keypad operates on the principle of ‘scan and detect’, where in Figure 11.32, RD0, RD1, RD2 and RD3 are configured as inputs and ...
Get Using LEDs, LCDs and GLCDs in Microcontroller Projects now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.