Random Number Generator using 8051
In this project, I will demonstrate how to generate a random number using an 8051 microcontroller by explaining the circuit and operation of a Random Number Generator.
When a push button is pressed, this project creates a random number between 0 and 100. This is a simple project, and embedded projects may not have any meaningful applications. The project work is merely an example.ran
- Circuit Principle of Random Number using 8051
- Circuit Diagram Random Number using 8051 Microcontroller
- Components Required
- Circuit Design of Random Number using 8051
- How to Write the Program?
- Random Number Generator using 8051 – Circuit Simulation Video
- How to Operate Random Number Circuit using 8051?
- Random Number Generator using 8051 Circuit Applications
- Random Number Generator using 8051 Project Output Video
Circuit Principle of Random Number Generator using 8051
When a button is pressed, a random number generator creates a number at random within a specified range. When the push button (which is attached to P3.0) is pressed, the LCD (liquid crystal display) displays the number at random.
The counter is rapidly advanced from 0 to 99 in this method. The LCD displays the current count value when you press the button. When the button is pressed, the 8051 Microcontroller selects a random number because the count is incrementing at a high rate.
Circuit Diagram Random Number Generator using 8051 Microcontroller
- AT89C51 (8051 Microcontroller)
- 8051 Programmer
- Programming cable
- 5V Power Supply
- 16×2 Alphanumeric LCD
- 2 Ceramic Capacitors – 33pF
- 11.0592 MHz Crystal
- Push Button – 3
- Electrolytic Capacitor – 10μF, 16V
- 10KΩ Resistor (1/4 watt) – 2
- 330Ω Resistor (1/4 watt) – 2
- POT – 10KΩ
- 1KΩ X 8 Resistor Pack
- Connecting Wires
Circuit Design of Random Number Generator using 8051
The 8051 microprocessor, 162 alphanumeric LCD display, push buttons, and a few passive components are used in the circuit. The AT89C51 Microcontroller is the circuit’s key component.
Two push buttons are connected to P3.0 and P3.1 in the above circuit, with one push button (Random – P3.0) generating a random number and the second push button (RST – P3.1) resetting the count.
The LCD data pins are connected to the microcontroller’s PORT2, while the control pins RS, RW, and En are connected to P2.0, GND, and P2.1. Because the LCD is wired in 8-bit mode, we must use all of the LCD’s data pins.
The reset circuit for the 8051 microcontroller is made up of a 10K resistor, a 10F capacitor, and a push button. The oscillator for the 8051 microcontroller is provided by two 33pF capacitors and an 11.0592 MHz Quarts Crystal.
The contrast of the LCD is controlled using a 10K potentiometer linked to the VEE pin of the LCD. We can change the contrast or brightness by increasing the pot’s resistance.
NOTE: If you want to reduce the data lines of LCD, you can use 4 bit mode.
How to Write the Program?
Now let’s look at how to programme an 8051 microcontroller to generate random numbers. To begin, create a count variable of type integer and set the LCD to 8 bits. To make the programme run indefinitely, use an unlimited while loop. In this endless WHILE loop, take the value of the integer and increment it till the button is pressed (by using another while loop).
Count up to 99, then back down to 0 and repeat the process until the count reaches 100 (the upper limit). Change the value in the loop to increase the upper limit of the random number generator. The count stops when the button is pressed, and the current count value is displayed on the LCD.
If you want to increase the top limit of the random number generator in this software, you can make minor changes. Because we’re using LCD, we can boost the top limit of the random number generator, which isn’t possible if you’re using two seven-segment panels (you have to increase the number of 7-Segment displays as well).
|#define lcd P0|
|unsigned int i=0;|
|void delay (int);|
|void display (unsigned char);|
|void cmd (unsigned char);|
|void string (char *);|
|void init (void);|
|void int_lcd(unsigned int);|
|void delay (int d)|
|unsigned char i=0;|
|void cmd (unsigned char c)|
|void display (unsigned char c)|
|void string (char *p)|
|void init (void)|
|void int_lcd(unsigned int n)|
|string(” Random Number “);|
|string(” Generator “);|
|string(“Press the button”);|
|string(“RAND NUM: “);|
Random Number Generator using 8051 – Circuit Simulation Video
How to Operate Random Number Generator Circuit using 8051?
- First, in Keil Vision Software, create a programme for a random number generator and a hex file.
- With the help of the 8051 Programmer, burn this hex file to the AT89C51 microcontroller.
- Connect the wires according to the circuit schematic.
- Ensure that the circuit’s power supply is 5V DC.
- Now, turn on the circuit’s power supply.
- On the LCD, you can see the string “Random Number Generator.”
- After that, you’ll be asked to press a button to produce a random number.
- When you press the push button, the LCD displays a random number. Until you push the RST button, this will be displayed (connected to P3.1).
- After pressing the RST button, you’ll be asked to hit it again to produce.
- This process continues until you switch off the power supply.
Random Number Generator using 8051 Circuit Applications
- This project is used in the applications where we need to generate Random number
- Used in noise generators
- Project is used as an alternative for the traditional dice while playing the games like monopoly, snake ladder.