Random Number generator 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
           
            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.

1 Comment

  1. randeep

    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

    Reply

Leave a Comment

Your email address will not be published.Required fields are marked*

Baidu
map