After dividing number by 10, how to check whether quotient lies between 10 and 20. May i use CMP command for comparing two numbers by carry in 8051?
MOV A,#105
CJNE A,#100,CHECK
EQUAL: MOV R0,A ;ACC = 100
AJMP EXIT
CHECK: JC SMALLER
GREATER:
MOV R2,A ;ACC > 100
AJMP EXIT
SMALLER:
MOV R1,A ;ACC < 100
HERE: AJMP HERE
The instruction set of the 8051 specifies that certain instructions can only be applied to certain registers. See attached file, for a complete view of what is possible and what is not.Thank you for your responses!
I have another question.If i would like to blink led of port 2 from msb to lsb. Should i have to use RR(rotate right) command? if yes then how to use it? RR P2, #No. correct/false?
The instruction set of the 8051 specifies that certain instructions can only be applied to certain registers. See attached file, for a complete view of what is possible and what is not.
In this case, RR, RL, RRC and RLC can only be applied to the accumulator, see pages 58 and 59.
Also, your question is not clear enough. You want to blink the led of P2 from the msb to the lsb of what register?
Thanks dear. it really help me to clear my concept.
You cannot rotate P2 directly, you have to first feed that value to A, rotate it, and then place it back into P2I
I used register R0-R7 in my code. To blink the led from msb to lsb of port 2. i used RR P2, #245 after completing code for delay
Glad to be of help.... read the instruction set that I posted more carefully. Each instruction explains its advantages and limitations... for instance, in the MOV instruction, indirection can only be used with registers R0 and R1.##cmartinez thank you for your help. I am now clear about RR instruction.
org 00h
mov tmod,#01 \\to use mode 1 and timer 0
mov p0, #0ffh \\use it as input
mov p1, #00h \\for output
mov p2, #00h = =
mov p3, #00h = =
Here: mov A, #240d
mov b, #10d
DIV AB \\A=24, B=0
MOV R0,A
MOV R1,B
SUB A,B \\A=A-B=24-0
MOV A,R0
SUB A,11 \\A=A-11=24-11
Label1: JNC, check1 \\If A>=11
Ljmp delay3
check1: MOV A,R0
SUB A,20 \\A=A-20=24-20
label2: JC, delay1 \\A<20
sjmp delay2
delay1:clr C
Here1: mov th0,# \\To use higher nibble of starting instruction value for 200ms
mov tl0,# \\To use lower nibble of starting instruction value for 200ms
setb tr0 \\run the timer
again: jnz tf0,again \\when instruction reach to FFFFH, Flag bit=1
mov a,#240
mov p0,a \\blink port0
clr tr0 {=
clr tf0
mov th0,#
mov tl0,#
setb tr0
again1: jnz tf0, again1
mov a,#240
mov p1,a
clr tr0
clr tf0
mov th0,# \\part of delay1 to blink led of port 0,1,2,3
mov tl0,#
setb tr0
again2: jnz tf0, again2
mov a,#240
mov p2,a
clr tr0
clr tf0
mov th0,#
mov tl0,#
setb tr0
again3: jnz tf0, again3
mov a,#240
mov p3,a
clr tr0
clr tf0
ljmp here1 = }
delay2:
here2:mov th0,#
mov tl0,#
setb tr0
poll: jnz tf0, poll
mov a,#240
rotation: mov p3,a
RR a,rotation \\here i use this to blink led from msb to lsb as question demand
clr tr0
clr tf0
Sjmp here2
delay3:
here3:mov th0,#
mov tl0,#
setb tr0
repeat: jnz tf0, repeat
mov a,#240
rotation2: mov p1,a
mov p2,a
RL a, rotation2 \\here i use this to blink led from lsb to msb as question demand
clr tr0
clr tf0
sjmp here3
end
org 00h
mov tmod,#01 ;to use mode 1 and timer 0
mov p0, #0ffh ;use it as input
mov p1, #00h ;for output
mov p2, #00h ;= =
mov p3, #00h ;= =
Here: mov A, #240d
mov b, #10d
DIV AB ;A=24, B=0
MOV R0,A
MOV R1,B
SUBB A,B ;A=A-B=24-0
MOV A,R0
SUBB A,11 ;A=A-11=24-11
Label1: JNC check1 ;If A>=11
Ljmp delay3
check1: MOV A,R0
SUBB A,20 ;A=A-20=24-20
label2: JC delay1 ;A<20
sjmp delay2
delay1: clr C
Here1: mov th0,#123 ;To use higher nibble of starting
;instruction value for 200ms
mov tl0,#123 ;To use lower nibble of starting
;instruction value for 200ms
setb tr0 ;run the timer
again: jnz tf0,again ;when instruction reach to FFFFH, Flag bit=1
mov a,#240
mov p0,a ;blink port0
clr tr0 ; {=
clr tf0
mov th0,#123
mov tl0,#123
setb tr0
again1: jnz tf0, again1
mov a,#240
mov p1,a
clr tr0
clr tf0
mov th0,#123 ;part of delay1 to blink led of port 0,1,2,3
mov tl0,#123
setb tr0
again2: jnz tf0, again2
mov a,#240
mov p2,a
clr tr0
clr tf0
mov th0,#123
mov tl0,#123
setb tr0
again3: jnz tf0, again3
mov a,#240
mov p3,a
clr tr0
clr tf0
ljmp here1 ; = }
delay2:
here2: mov th0,#123
mov tl0,#123
setb tr0
poll: jnz tf0, poll
mov a,#240
rotation: mov p3,a
RR a,rotation ;here i use this to blink led from
;msb to lsb as question demand
clr tr0
clr tf0
Sjmp here2
delay3:
here3: mov th0,#123
mov tl0,#123
setb tr0
repeat: jnz tf0,repeat
mov a,#240
rotation2: mov p1,a
mov p2,a
RL a,rotation2 ;here i use this to blink led
;from lsb to msb as question demand
clr tr0
clr tf0
sjmp here3
end
Ameer project PAGE 1
1 org 00h
2
3 mov tmod,#01 ;to use mode 1 and timer 0
4 mov p0, #0ffh ;use it as input
5 mov p1, #00h ;for output
6 mov p2, #00h ;= =
7 mov p3, #00h ;= =
8 Here: mov A, #240d
9 mov b, #10d
10 DIV AB ;A=24, B=0
11 MOV R0,A
12 MOV R1,B
13 SUBB A,B ;A=A-B=24-0
14 MOV A,R0
15 SUBB A,11 ;A=A-11=24-11
16 Label1: JNC check1 ;If A>=11
17 Ljmp delay3
18 check1: MOV A,R0
19 SUBB A,20 ;A=A-20=24-20
20 label2: JC delay1 ;A<20
21 sjmp delay2
22 delay1: clr C
23 Here1: mov th0,#123 ;To use higher nibble of starting
24 ;instruction value for 200ms
25 mov tl0,#123 ;To use lower nibble of starting
26 ;instruction value for 200ms
27 setb tr0 ;run the timer
28 again: jnz tf0,again ;when instruction reach to FFFFH, Flag bit=1
****ERROR: Too many operands, jnz can take only 1 operand
29 mov a,#240
30 mov p0,a ;blink port0
31 clr tr0 ; {=
32 clr tf0
33 mov th0,#123
34 mov tl0,#123
35 setb tr0
36 again1: jnz tf0, again1
****ERROR: Too many operands, jnz can take only 1 operand
37 mov a,#240
38 mov p1,a
39 clr tr0
40 clr tf0
41 mov th0,#123 ;part of delay1 to blink led of port 0,1,2,3
42 mov tl0,#123
43 setb tr0
44 again2: jnz tf0, again2
****ERROR: Too many operands, jnz can take only 1 operand
45 mov a,#240
46 mov p2,a
47 clr tr0
48 clr tf0
49 mov th0,#123
50 mov tl0,#123
51 setb tr0
52 again3: jnz tf0, again3
****ERROR: Too many operands, jnz can take only 1 operand
53 mov a,#240
54 mov p3,a
55 clr tr0
56 clr tf0
57 ljmp here1 ; = }
58 delay2:
59 here2: mov th0,#123
60 mov tl0,#123
61 setb tr0
62 poll: jnz tf0, poll
****ERROR: Too many operands, jnz can take only 1 operand
63 mov a,#240
64 rotation: mov p3,a
65 RR a,rotation ;here i use this to blink led from
****ERROR: Too many operands, rr can take only 1 operand
66 ;msb to lsb as question demand
67 clr tr0
68 clr tf0
69 Sjmp here2
70 delay3:
71 here3: mov th0,#123
72 mov tl0,#123
73 setb tr0
74 repeat: jnz tf0,repeat
****ERROR: Too many operands, jnz can take only 1 operand
75 mov a,#240
76 rotation2: mov p1,a
77 mov p2,a
78 RL a,rotation2 ;here i use this to blink led
****ERROR: Too many operands, rl can take only 1 operand
79 ;from lsb to msb as question demand
80 clr tr0
81 clr tf0
82 sjmp here3
83 end
ASSEMBLY COMPLETE, 8 ERRORS FOUND, NO WARNINGS
ERROR SUMMARY:
Line 28, ERROR: Too many operands, jnz can take only 1 operand
Line 37, ERROR: Too many operands, jnz can take only 1 operand
Line 46, ERROR: Too many operands, jnz can take only 1 operand
Line 55, ERROR: Too many operands, jnz can take only 1 operand
Line 66, ERROR: Too many operands, jnz can take only 1 operand
Line 70, ERROR: Too many operands, rr can take only 1 operand
Line 80, ERROR: Too many operands, jnz can take only 1 operand
Line 85, ERROR: Too many operands, rl can take only 1 operand
thank you sir for your help to highlight my mistake.For "jnz" istruction eg
repeat: jnz tf0,repeat
you can try repeat: cjne tf0,#00,repeat and see if it works.
For RR and RL instructions, you can refer to post #12. I thought @cmartines has explained it very well.
Allen
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
[8051] Edsim51 7 Segment Display Issue | Programming & Languages | 1 | ||
Edsim51 7 Segment Display Issue | Microcontrollers | 0 | ||
8051 need help with code:CCC | Microcontrollers | 6 | ||
M | alarm control 8051 assembly code help | Programming & Languages | 3 | |
C | Erasing AT89S52 error | Microcontrollers | 0 |