Generate a random number using interrupt

Status
Not open for further replies.

Greital

Newbie level 4
hi

still working on my 8051 project using assembly language, and now I'm in phase 4 --->>>> the last phase

in this phase we should generate 2 random numbers as following:
1. one digit (1-9)
2. two digit (10-99)
and by using push button we pick randomly the number

we have done one digit perfectly, but we face a problem with the two digit

we used a counter with 99 numbers and decrements it each time until the user push a button to interrupt the function and show the number randomly
but the problem that it shows the one digit also :???:

we tried to make the counter to start from 10 and increment it each time until we reach 99 --->>> but also it didn't work :bang:

we tried and tried and tried :bang: but nothing work

the code :

Code:
    ORG 0H
LJMP MAIN
ORG 0003H ; EX0 interrupt vector address
LJMP EX0ISR
ORG 0030H
MAIN:
MOV IE,#10000001B ; Enable EX0 interrupts
SETB IT0 ;Make EX0 edge-triggered interrupt
LCALL INLCD ; Initialize LCD
LABEL:
MOV    R4,#99
LOOP:
DJNZ    R4,LOOP
SJMP LABEL
;---------------------------------------

EX0ISR:

MOV    A,R4
CJNE    R4,#09,GENERATE
COME_HERE:
DJNZ    R4,COME_HERE
SJMP    OUT

GENERATE:
MOV    44H,A
MOV A,#1000B ; Move cursor to 1st line - send high nibble
LCALL CMD
MOV A,#0000B ; send low nibble
LCALL CMD
LCALL LDELAY ; 4.1 msec required for this command
MOV    A,44H
MOV    B,#10
DIV    AB
MOV    36H,B
LCALL WCHR
MOV    A,36H
LCALL WCHR
OUT:
RETI

Mandar Joshi

Member level 2
You successfully did for one digit number...right? Then what happens when you go for two digit number? What do you see on display?
If it shows only single number for two digit logic then problem could be in your display logic.
While displaying two digit number how do you separate higher and lower digit?

Arya Kumar

Member level 4
Write a C code and generate assembly from it.(there will be a command don't know which IDE are u using)
show it to ur teacher and then enjoy ur life.

Status
Not open for further replies.