Random Number generator using 8051 Microcontroller

Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest
random-number-geneartor-using-8051-microcontroller
Random Number generators are something which is used to draw out a random number and use it for a specified purpose. The purpose may differ it might be lottery draw , competition or whatever it may be the above generator using 8051 will do a pretty good job also the complexity level of the program is very simple. Here is a simple random number generator using 8051 which will serve the purpose well at low cost and requires less programming skill.

IC 74LS48:

The IC 74LS48 or 7448 is a simple BCD to 7 segment decoder which was used to reduce the usage of pins dedicated to the 7 segment display. It consists of 4 input pins namely 1,2,3,4 which is used to feed 4 bit data input to the IC. The fed 4 bit input binary data in turn decoded by the IC and output is obtained from the pins a, b ….. f  which is connected to the corresponding pins of the 7 segment display. This will display the correct digit in the 7 segment display.

DESIGN:

In the above design i have used two 7448 IC to interface two 7 segments in a single port, this will save the pin usage from the microcontroller. You can also go for direct interfacing of  a 7 segment with a dedicated port if you don’t have 7448 IC in your possession. 
 
Interrupt 0 feature of the Microcontroller was used here, therefore a simple push button was interfaced with the pin INT0 pin of the 8051 controller. Reset button was used with the pin 9 to reset the operation and start running the program from the beginning.

NUMBER GENERATION PROCESS:

  • Initially the number keeps running from 0 to 99 in the display at high speed in a loop, so it will barely visible to human eye. 
  • Pressing the interrupt button fetches the random number and displays it in the 7 segment display.
  • The the reset button should be pressed to initialize the program and counting again.

 

CODE: 

This code was built using Keil Uvision 4 
#include<regx51.h>
int a,b;
void delay();
void main()
{
  IE=0x81;                   //External interrupt activation
  while(1)
  {
  for(a=0;a<=9;a++)     //Number generation
  {
   for(b=0;b<=9;b++)
    {
      P2=a|b<<4;
      delay();
    }
   }
  }
}
void delay()
{
  int i;
  for(i=0;i<=400;i++);
}
void extr0(void) interrupt 0     //Subroutine EX0 with interrupt number '0'
{
    P2=a|b<<4; 
    while(1);
}

NOTE:

  • Resistors for 7 segment are omitted for the simplicity of the schematic diagram, hook up a 470 ohm resistor to each pins connecting from 74LS48 to 7 segment pins.
Share on FacebookShare on Google+Tweet about this on TwitterShare on RedditShare on StumbleUponPin on Pinterest

Related Designs and Schematics

The following two tabs change content below.

Frank Donald

Junior Network Engineer at Tata Communications
Frank Donald is an Electronics and Communication Engineer who is very passionate about his subject. Reading, Surfing and Blogging are the things he loves.

Ask your query

1 Comment on "Random Number generator using 8051 Microcontroller"

Notify of
avatar
Sort by:   newest | oldest | most voted
randeep
Guest

without reset the 8051 can we change the number ??what is change in code if..once a number was displayed than that number will display after 99 time later…or if we reset the controller…plz tell me

wpDiscuz