Greital
New Member
hi,
I'm working with a multiple phases project in 8051 micro-controller
and phase one involved with check if a given number is prime or not
the way I've trying to do this code is :
1. assuming 2 numbers one is prime and other is not and save them in R1, and R2
2. create a counter from 99 and save it in R7 --->> 99 because in the following phases we have to check the prime number or not from 1 to 99 (a number that user enter using keypad)
3. making a loop and divide the desire number with 99 first then check if prime or not, then decrements and repeat the loop again until we finish
4. if its prime a led will flash using delay with counter R6=3
5. if its not prime another led will flash using the same delay and same counter
but I'm really stuck with the code, something wrong but I don't now what is ?
any help is appreciable
----->>> I'm using Edsim51D1 to check my code
----------Begining---------
START:
MOV R1,#9
MOV R2,#31
MOV R7,#99
MOV R6,#3
LOOP:
MOV A,R1
MOV B,R7
DIV AB
MOV R3,#0
MOV R3,B
CJNE R3,#0,NOTPRIME
DJNZ R7,LOOP
PRIME:
ACALL DELAY
CPL P1.3
DJNZ R6,PRIME
AJMP DONE
NOTPRIME:
ACALL DELAY
CPL P1.0
DJNZ R6,NOTPRIME
DONE:
DELAY:
MOV R5,#20
X3: MOV R4,#200
X2: MOV R3,#250
X1: DJNZ R3,X1
DJNZ R4,X2
DJNZ R5,X3
RET
END
-------------End------------
I'm working with a multiple phases project in 8051 micro-controller
and phase one involved with check if a given number is prime or not
the way I've trying to do this code is :
1. assuming 2 numbers one is prime and other is not and save them in R1, and R2
2. create a counter from 99 and save it in R7 --->> 99 because in the following phases we have to check the prime number or not from 1 to 99 (a number that user enter using keypad)
3. making a loop and divide the desire number with 99 first then check if prime or not, then decrements and repeat the loop again until we finish
4. if its prime a led will flash using delay with counter R6=3
5. if its not prime another led will flash using the same delay and same counter
but I'm really stuck with the code, something wrong but I don't now what is ?
any help is appreciable
----->>> I'm using Edsim51D1 to check my code
----------Begining---------
START:
MOV R1,#9
MOV R2,#31
MOV R7,#99
MOV R6,#3
LOOP:
MOV A,R1
MOV B,R7
DIV AB
MOV R3,#0
MOV R3,B
CJNE R3,#0,NOTPRIME
DJNZ R7,LOOP
PRIME:
ACALL DELAY
CPL P1.3
DJNZ R6,PRIME
AJMP DONE
NOTPRIME:
ACALL DELAY
CPL P1.0
DJNZ R6,NOTPRIME
DONE:
DELAY:
MOV R5,#20
X3: MOV R4,#200
X2: MOV R3,#250
X1: DJNZ R3,X1
DJNZ R4,X2
DJNZ R5,X3
RET
END
-------------End------------