AT89C51 electronic quiz startup screen, 8051 quiz project, keypad and LCD, Proteus simulation

Electronic Quiz Project with 8051 Microcontroller

3M Views
40
700
60
25
60
PCBWay

Hello friends! In this tutorial, we will study an electronic quiz project with the 8051 microcontroller. The project combines a keypad, a character LCD and serial communication to create a small question-and-answer game. You can play alone or compete with a second player who enters answers through a computer terminal.

We will begin with the game rules, because the circuit only becomes useful when its behavior is clearly defined. Then we will follow the connections, organize the firmware and examine question selection, scoring and input handling. These are useful skills for menu systems, classroom projects and other embedded applications that accept input from more than one source.

The original project used an AT89C51, a 20x4 LCD and a 4x4 keypad in Proteus. Its screenshots and demonstration video remain below. The original complete project was offered separately; this page explains its architecture and provides focused implementation examples, rather than presenting those excerpts as a complete downloadable firmware package.

AT89C51 electronic quiz startup screen, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: AT89C51 electronic quiz startup screen.

How Does the Electronic Quiz Work?

A game consists of three questions selected from a bank of six. Each question has four numbered choices, and the program compares the selected choice with an answer key. The question bank is a table compiled into the microcontroller program; it is not a database server or an internet service.

At startup, the player chooses single-player or two-player mode. The firmware clears the scores, prepares the question order and starts the first round. After three questions, it displays the result and waits for a fresh keypress before returning to the menu. A held answer key should not also restart the game.

FeatureSingle-player modeTwo-player mode
InputsPlayer uses the keypadPlayer one uses the keypad; player two uses the serial terminal
Question display20x4 LCDLCD and terminal
Answer selectionEnter choice 1 to 4Press 0 to claim the first answer, then enter choice 1 to 4
Number of questionsThree per gameThree per game, with a possible rebound answer
Final resultTotal scoreBoth scores and the winner, or a draw

Single-Player Scoring

In single-player mode, a correct answer earns five points and an incorrect answer loses two. For example, two correct answers and one incorrect answer produce a score of 5 + 5 - 2 = 8. Across three questions, the possible minimum is -6 and the maximum is 15.

Use a signed variable for the score. An unsigned byte cannot represent a negative result and may wrap to a large positive value when points are deducted. The result should remain negative when the player earns a negative score; silently clamping it to zero would change the stated rules.

Single-player quiz scoring flowchart, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: Single-player quiz scoring flowchart.

Two-Player Scoring and Rebound Answers

Both players press 0 to request the first answer. Once the program accepts a player, only that player's choice from 1 to 4 should be considered. A correct first answer earns five points. An incorrect first answer loses three points and gives the other player a rebound opportunity.

A correct rebound earns five points; an incorrect rebound earns zero and loses nothing. The round then ends. Do not send the same question back to the first player after a failed rebound. Over three rounds, an individual player's score can range from -9 to 15 under these rules.

Answer situationCorrectIncorrect
Single player+5-2
First answer in two-player mode+5-3
Rebound answer in two-player mode+50

At the end, compare the two signed totals. Equal totals mean a draw. This explicit outcome prevents a common mistake where an if/else comparison awards every tied game to whichever player appears in the else branch.

Two-player quiz and rebound-answer flowchart, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: Two-player quiz and rebound-answer flowchart.

Components and Circuit Connections

The original schematic below uses an 11.0592 MHz crystal with the AT89C51. Keep that frequency consistent with the Proteus processor property and the firmware's serial timing. The crystal label on a drawing does not automatically correct an unrelated clock setting in the simulated processor.

AT89C51 quiz circuit with LCD keypad and serial terminal, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: AT89C51 quiz circuit with LCD keypad and serial terminal.
Part or connectionAssignment in this projectPurpose
AT89C51Main controllerRuns the quiz and maintains scores
LCD D0 to D7P2.0 to P2.7Eight-bit display data bus
LCD RS and EP3.7 and P3.6 respectivelySelect command/data and latch transfers
LCD R/WGroundWrite-only operation with appropriate delays
Keypad rows A to DP1.0 to P1.3Row scanning
Keypad columns 1 to 4P1.4 to P1.7Column sensing
Controller TXDP3.1 to terminal RXDSends questions and results
Controller RXDP3.0 from terminal TXDReceives player-two keypresses

Follow the electrical endpoints of the serial connections, rather than relying only on the names of net labels. Transmit connects to receive in each direction. The LCD contrast potentiometer adjusts visibility; it does not control the contents of the screen. A row of dark blocks can indicate power without successful initialization.

For a physical circuit, provide the controller's supply and ground, a suitable reset network, crystal components and local supply decoupling. EA must be high when executing the internal program. The AT89C51 datasheet gives its package connections and memory limits: 4 KB of program Flash and 128 bytes of internal RAM.

A Proteus Virtual Terminal represents logic-level serial communication. A real computer's RS-232 port uses different electrical levels, so it requires an appropriate interface. With a USB-to-UART adapter, check its signal voltage compatibility and connect the grounds. Do not treat every connector called serial as electrically interchangeable.

Organize the Firmware Around Game States

It is tempting to write the quiz as a large collection of nested loops. That becomes difficult to maintain when a second player, rebound answers and restart handling are added. A state variable makes it clear which inputs are meaningful at each moment.

StateWork to performAccepted event
MenuShow the mode choicesA fresh 0 or 1 selection
Prepare questionRender the question and choices on the required displaysNo answer or buzzer event yet
Wait for buzzAccept one eligible player in two-player modeFresh 0 from either input
Wait for answerRead the selected player's choiceChoice 1 to 4 from that player
ReboundOffer the question to the other player after a wrong first answerChoice 1 to 4 from the other player
ResultShow totals after the third questionRelease followed by a new restart press

Store the round number, active player, current question index, mode and two scores separately. Increment the round number only when a question is finished. Otherwise, a wrong first answer and its rebound can accidentally count as two questions and shorten the game.

Question text and answer choices should be read-only program data. In Keil C51, use the appropriate program-memory declarations and matching pointer types for your string routines. Review the linker map: moving long strings into ordinary RAM can exhaust the small data space before the game even starts.

Keep Scoring in One Function

The following C51 excerpt expresses the original scoring rules. It is a helper for the game logic, not a complete program. Call it once after validating an answer, then change state so that repeated copies of the same input cannot award points again.

int score_change(bit correct, bit two_player, bit rebound)
{
    if (correct)
        return 5;
    if (!two_player)
        return -2;
    if (rebound)
        return 0;
    return -3;
}

/* Scores must be signed. */
int score_player1 = 0;
int score_player2 = 0;

Reject characters outside the expected input set before evaluating correctness. A terminal's carriage return is not a wrong answer, and a keypad operator key is not choice zero. Keeping input validation separate from marking prevents accidental penalties.

Select Three Questions Without Repetition

The older question-selection excerpt used a timer value modulo six and a collection of flags. Modulo six produces values from zero through five, whereas its question cases were numbered one through six. That mismatch can skip a case, and changing an index to avoid a duplicate can introduce another duplicate.

A clearer method is to initialize an array with all six question indices, shuffle it, then use its first three entries. The following example uses zero-based indices consistently. Every swap preserves the six distinct entries, so the selected questions cannot repeat within that game.

#include <stdlib.h>

unsigned char question_order[6];

void make_question_order(void)
{
    unsigned char i, j, temp;

    for (i = 0; i < 6; ++i)
        question_order[i] = i;

    for (i = 5; i > 0; --i) {
        j = (unsigned char)(rand() % (i + 1));
        temp = question_order[i];
        question_order[i] = question_order[j];
        question_order[j] = temp;
    }
}

/* Use question_order[0], [1] and [2] for the three rounds. */

Seed the pseudorandom generator once, rather than resetting it before every draw. A fixed seed is useful while debugging because it reproduces the same question order. A user-dependent timing value can vary games, but it is not a source of guaranteed randomness. Avoid taking the seed from a timer already restricted by UART baud generation.

This simple modulo implementation can have a small selection bias depending on the generator's range. Its purpose here is a repeat-free classroom quiz, not security or a formally fair prize draw. If uniform selection matters, use rejection sampling and document how the generator is seeded.

Check the Questions as Carefully as the Code

A working answer checker can still mark a badly written question incorrectly. The original bank included number sequences. State the intended pattern, since a finite sequence can have multiple mathematically possible continuations.

SequenceIntended ruleNext term
3, 8, 15, 24, 35Add consecutive odd differences 5, 7, 9, 11, then 1348
6, 14, 18, 28, 30Odd positions increase by 12; even positions by 1442
4, 1, 0, 1, 4Squares of consecutive integers starting at -29
-1, 4, 1, 6, 3Alternate adding 5 and subtracting 38
10, 21, 33, 46, 60Add 11, 12, 13, 14, then 1575

The original final question used the infinite expression 1 - 1 + 1 - 1 and offered one-half as an answer. Its ordinary partial sums alternate between one and zero, so the series does not converge in the usual sense. One-half requires a specified summability method. For a beginner quiz, replace it with an unambiguous question, such as 9 multiplied by 7, with 63 as the correct choice.

Handle the LCD, Keypad and Serial Terminal Together

A 20x4 LCD has twenty character positions on each row. Reserve space deliberately: a short prompt on the first row, choices on the next two and player status on the last. Longer questions need a controlled paging scheme. Do not assume that writing past column twenty moves to the next visible row.

Bound each output routine by the available columns and terminate at the end of its string. When replacing a long line with a shorter one, clear the remaining positions or write spaces. Otherwise, old characters can make an option or score appear incorrect even though the new string is correct.

For the keypad, scan rows and read columns, then debounce the resulting key. Generate one event after a stable press and require release before another event. Reject ambiguous multiple-key combinations on a matrix without individual isolation diodes. A held 0 must not repeatedly claim future questions.

Calculate the Serial Timing

With the classic 8051 UART in mode 1, Timer 1 in mode 2 and SMOD cleared, the baud rate is fosc / [384 × (256 - TH1)]. At 11.0592 MHz and TH1 = 253, this gives 11,059,200 / (384 × 3) = 9600 baud. You can cross-check these settings with the Keil 8051 baud-rate calculator.

Configure the terminal for 9600 baud, eight data bits, no parity and one stop bit. Each character then occupies ten bit periods. Sending sixty characters takes approximately 60 × 10 / 9600 = 62.5 milliseconds, before any software delays. That interval matters when two players are competing.

The old serial-output example disabled interrupts for an entire string. Do not use that approach while expecting asynchronous player input. A short receive interrupt should capture arriving bytes into a bounded buffer, while the main loop interprets them. Handle both receive and transmit interrupt flags correctly because the serial interrupt vector is shared.

Keep that buffer small enough for the AT89C51's memory budget, and record overflow instead of silently overwriting unread input. Do not print questions or update the LCD inside the receive interrupt. Long interrupt routines delay keypad service and can lose further serial characters.

What Does First to Press Really Mean?

The controller observes events after keypad scanning, debounce, terminal software and UART transport. Always checking the keypad first creates an additional preference for player one. This educational arrangement therefore cannot establish the exact physical order of two nearly simultaneous presses.

Display the complete question on both interfaces before arming the round, discard stale input, and provide a clear start indication. Define how near-simultaneous accepted events are handled. A replay or declared tie window is more transparent than an undocumented permanent player priority.

A serious competition would benefit from identical dedicated buzzer inputs and a timing design built around them. Here, the useful lesson is to document the input latency and keep game rules independent of the transport mechanism.

Run the Quiz in Proteus

  1. Build the schematic using the pin assignments above and confirm the controller clock.
  2. Compile the complete project with the intended C51 target and generate its HEX file. The excerpts on this page require the remaining drivers and game logic.
  3. Select that HEX file in the AT89C51 Program File property.
  4. Configure the Virtual Terminal and check the crossed TX/RX connections.
  5. Start with single-player mode. Answer one question correctly and another incorrectly while recording the expected score.
  6. Repeat in two-player mode, exercising both first-answer and rebound outcomes.
  7. Finish all three rounds, check a tied result and confirm that restart clears every game variable.
AT89C51 electronic quiz startup screen, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: AT89C51 electronic quiz startup screen.

The startup and menu screenshots show the original presentation. Treat them as reference output from that implementation. Revised question selection, input handling or question wording can produce different screens without changing the project's learning objectives.

Electronic quiz single-player and two-player menu, 8051 quiz project, keypad and LCD, Proteus simulation
Figure: Electronic quiz single-player and two-player menu.

A Useful Test Sequence

Use a fixed question order initially. Give player one a wrong first answer and player two a correct rebound: their totals should become -3 and 5. On the next round, let player two answer incorrectly and player one miss the rebound. Totals should now be -3 and 2. This distinguishes the rebound rule from the first-answer penalty.

Also try a held keypad key, repeated terminal characters, a newline after an answer and simultaneous keypad presses. None should create extra rounds or repeated scoring. Change the random seed only after these predictable tests behave as intended.

Troubleshooting and Project Review

SymptomLikely area to inspect
LCD powered but no readable menuContrast, initialization delays, RS/E assignments and program execution
Unreadable terminal textOscillator frequency, baud reload and terminal format
Player two sometimes cannot buzzInterrupt masking, receive-buffer overflow or input discarded in the wrong state
Question repeats within a gameIndex convention and question-order initialization
Score becomes a large positive number after a penaltyUnsigned score storage or incorrect number formatting
Game ends after a reboundRound counter incremented for answers instead of completed questions

This project is a useful exercise in coordinating several peripherals with a small controller. Its strongest teaching feature is the combination of visible game rules and internal state changes. The main limitations are the small question bank, restricted display space and unequal input paths. Expanding the bank or adding answer deadlines should come after the basic transitions are reliable.

The original demonstration video is retained below. It illustrates the historical project; it is not a test report for the revised implementation suggestions.

Frequently Asked Questions

Can I use an AT89C52 instead of the AT89C51?

A compatible replacement may provide more resources, but select the actual target in your tools and check its pinout, programming method and timing. Do not assume a HEX file built for an unrelated 8051 derivative has the same peripheral behavior.

Why are three questions selected from a bank of six?

That is the original game's size. A shuffled index array separates the bank size from the round count, making expansion easier. Check program memory and update both limits deliberately when adding questions.

Can both players use keypads?

Yes, but the wiring and scanning design must support two independent inputs. Separate input devices can reduce the transport difference introduced by the computer terminal. The scoring and game states can remain the same.

Is a timeout part of the original scoring rules?

No timeout rule is specified here as an original feature. If you add one, define whether it counts as an incorrect answer, an unanswered round or a rebound opportunity, and show the deadline to both players.

Is the complete firmware included in the examples above?

No. The examples explain scoring and repeat-free selection. A working build also needs the LCD driver, keypad scanner, UART handling, question data and state machine. Assemble and test those parts together before treating the project as finished.


Comments

2

Join the conversation

Reply1

Hi, I want to buy the project for the price that is given(20USD) but clicking the given button is just redirecting me to the same page itself. How do I buy the project code and the simulation?

1 reply