Quantcast
Channel: Gadgetronicx
Viewing all articles
Browse latest Browse all 215

Random Number generator using 8051 Microcontroller

$
0
0
random-number-geneartor-circuit-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.

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 

  1. #include<regx51.h>
  2. int a,b;
  3. void delay();
  4. void main()
  5. {
  6.   IE=0x81;                   //External interrupt activation
  7.   while(1)
  8.   {
  9.   for(a=0;a<=9;a++)     //Number generation
  10.   {
  11.    for(b=0;b<=9;b++)
  12.     {
  13.       P2=a|b<<4;
  14.       delay();
  15.     }
  16.    }
  17.   }
  18. }
  19. void delay()
  20. {
  21.   int i;
  22.   for(i=0;i<=400;i++);
  23. }

  24. void extr0(void) interrupt 0     //Subroutine EX0 with interrupt number '0'
  25. {
  26.     P2=a|b<<4; 
  27.     while(1);
  28. }

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.


Viewing all articles
Browse latest Browse all 215

Trending Articles