Answers
Answers
Answers
1) Input(Button)
2) MCU(8051) – Controlling the Task
3) ULN2308A - Transistor Array IC
4) LEDS for Output Display
Dice2: 01000001 b
Dice3: 01001001 b
Dice4: 01010101 b
Dice5: 01011101 b
Dice6: 01110111 b
First we will generate random number. Now In interrupt service routine we will compare this
random generated value with 1 to 6. Let first compare that random value with 1 if equal then we will
write 00001000b(08H) on port it will turn on middle led as like one on dice. If it is not equal then we
will compare with 2. If equal then we will write 01000001b (41H) on port. So it will turn on two
corner led . so two leds becomes on as like two on dice. Same for 3,4,5,6 we will compare and write
49h,55h, 5Dh, 77h on port respectively. I used this convention for giving above ans.
First we have to make a list of code for each dice value;
Dice1 : 08h
Dice2 : 41h
Dice3 : 49h
Dice4 : 55h
Dice5 : 5Dh
Dice6 : 77h
Now in assembly code we compare random generated value which is available in R6 with 1 to 6 .and
if equal we will write above corresponding dice code to port. I write this login in interrupt service
routine.
OVER: RET
Generally the Push button is used to give the either 0 or 1 input to MCU.
We can do it by two way to detect the input. The one is with interrupt and second is with interrupt.
In first case the by using push button we can change the input to the MCU zero to 1 or 1 to 0. So
based on input change we can write the logic to display the random number on LEDs.
In second way. We can use the interrupt to detect input. In this case when button is pressed the
interrupt is generated. Now when interrupt is generated the MCU automatically execute the
interrupt service routine. In interrupt service routine we can write the logic for random number
display on LEDs.
We are using level trigger input. So once level trigger input is generated ISR get executed. if we want
we can capture that pin status in one of register for future use
.
Once pressed button the interrupt is generated. So in ISR we disable the interrupt . so during the
executing of present ISR. If any one pressed button for new dice number. Then also interrupt is not
going to generate. This how we can stop the system from registering a new press.
$MOD51 ; This includes 8051 definitions for the Metalink assembler
org 0000h
SJMP MAIN
Once button pressed . high to low signal is passed to MCU . so MCU get interrupted and ISR get
executed. I write to display two on LED when button pressed. I success fully get that.
delay:
mov R0,#0FFh ; load R0 with FFh value to repeat the loop for 256 times
DJNZ R1,back ;
RET
END
We can use this program to generate random . R6 continuously changing from 6 to 0. And we can
display that value with some delay. So it will continuous changing the output number while roll is
occurring.
END
As we can observe that when button pressed and released then random number is display on LED
dice which is 3.
org 0000h
SJMP MAIN
ORG 003H ; sets the starting address for the ISR
ACALL ISR ; calls the ISR subroutine when S2 is pressed
RETI ; return from interrrupt
END
Button Pressed Number on LED
Dice
1 1
2 3
3 1
4 6
5 2
6 1
7 3
8 2
9 4
10 1
As we can observe from above figure we will get random number on dice LEDS when every time
button pressed.