Digital Electronics - The 8051 Microcontroller - Discussion
Discussion Forum : The 8051 Microcontroller - General Questions (Q.No. 11)
11.
The following program will receive data from port 1, determine whether bit 2 is high, and then send the number FFH to port 3:
READ: MOV A,P1
ANL A,#2H
CJNE A,#02H,READ
MOV P3,#FFH
READ: MOV A,P1
ANL A,#2H
CJNE A,#02H,READ
MOV P3,#FFH
Discussion:
16 comments Page 1 of 2.
Dahlan Sitompul said:
3 years ago
READ: MOV A,P1; Copy the P1 content into the accumulator (A=P1).
ANL A,#2H; do logic AND between accumulator (A) and an immediate data 02h (00000010b), and it will force the content of the accumulator to be 02h.
CJNE A,#02H, READ; if A is not equal to 02 ( in this case A will be 02h) then jump to a statement labelled as READ.
MOV P3,#FFH; fill an immediate data FFh into the P3.
NB.
This program will always go to the statement MOV P3,#0FFH without taking into account the content read from P1 into the accumulator.
ANL A,#2H; do logic AND between accumulator (A) and an immediate data 02h (00000010b), and it will force the content of the accumulator to be 02h.
CJNE A,#02H, READ; if A is not equal to 02 ( in this case A will be 02h) then jump to a statement labelled as READ.
MOV P3,#FFH; fill an immediate data FFh into the P3.
NB.
This program will always go to the statement MOV P3,#0FFH without taking into account the content read from P1 into the accumulator.
(1)
Abhi said:
1 decade ago
1st : Copied to accumulator
2nd :ANDing operation
3rd : Compare jump if not equal
its always not equal
4th : Copied to port3 instruction
2nd :ANDing operation
3rd : Compare jump if not equal
its always not equal
4th : Copied to port3 instruction
Manish gundev said:
1 decade ago
Thanks abhi.
Imtiyaz said:
1 decade ago
Contents of Port1 should be mentioned clearly, so that we can perform or take decision on CJNE instruction rite !
Yash said:
1 decade ago
@Imtiyaz, they have asked to check the 2nd lsb i.e 2nd bit right why you want to know the whole digit.
Khyati said:
1 decade ago
In the operand of CJNE, there is a address or data? please reply.
Ruben said:
1 decade ago
Line1. A = P1 'Read P1 then save in Acc.
Line2. A = A and 00000010 'And Operation.
Line3. If A <> 00000010 Goto Line1 'Compare.
Line4 Else P3 = #0ffh 'Send ffh to port 3.
Line2. A = A and 00000010 'And Operation.
Line3. If A <> 00000010 Goto Line1 'Compare.
Line4 Else P3 = #0ffh 'Send ffh to port 3.
Edison said:
1 decade ago
@Ruben its correct by masking all bits except 2nd bit and checking whether second bit is high or low and jumping actions are taken.
Mahesh said:
1 decade ago
Line 1: We will move the content of P1 to accumulator.
Line2: Why to AND with 2H please reply, they have asked to find whether second bit is high, so what's the necessary of adding here.
Line2: Why to AND with 2H please reply, they have asked to find whether second bit is high, so what's the necessary of adding here.
Mahesh said:
1 decade ago
But what is the necessary of adding it with 2H, please answer me?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers