Hello,
I have a question that I would like someone to explain to me. I have been learning how to write code for the 8051 in C and assembly language. Now, when writing code in assembly, to read from a port pin we would write code such as:
MOV A,P1.6 ; READ PIN 6 OF PORT 1
; AND STORE IT IN ACCUMULATOR
OR
LOOP: JNB P1.6,LOOP ; STAY IN LOOP UNTIL THERE IS A HIGH ON
; PIN 6 OF PORT 1.
Now in C, it would look something like this, assuming we are using the Keil compiler and, we have defined:
sbit input_pin = p1^6;
So now to read this pin, we first have to write a 1 (logic HIGH) to it, then we are able to read this pin and use it in some kind of decision making, for example;
if ( input_pin == 0 )
{
// some code would go here
}
So my question is, why when programming in C we have to write a 1 to the port pin of interest, and in assembly language, it seems like we do not have to write to it before reading from it. I know that they are bi-directional, so it makes sense when writing in C that we have to write a HIGH to the pin of interest to "tell" it that it will be recieving input and not sending. But in assembly this is not the case. Is there something that I may have missed when reading my books on assembly language programming for the 8051? Please advise, thank you.
I have a question that I would like someone to explain to me. I have been learning how to write code for the 8051 in C and assembly language. Now, when writing code in assembly, to read from a port pin we would write code such as:
MOV A,P1.6 ; READ PIN 6 OF PORT 1
; AND STORE IT IN ACCUMULATOR
OR
LOOP: JNB P1.6,LOOP ; STAY IN LOOP UNTIL THERE IS A HIGH ON
; PIN 6 OF PORT 1.
Now in C, it would look something like this, assuming we are using the Keil compiler and, we have defined:
sbit input_pin = p1^6;
So now to read this pin, we first have to write a 1 (logic HIGH) to it, then we are able to read this pin and use it in some kind of decision making, for example;
if ( input_pin == 0 )
{
// some code would go here
}
So my question is, why when programming in C we have to write a 1 to the port pin of interest, and in assembly language, it seems like we do not have to write to it before reading from it. I know that they are bi-directional, so it makes sense when writing in C that we have to write a HIGH to the pin of interest to "tell" it that it will be recieving input and not sending. But in assembly this is not the case. Is there something that I may have missed when reading my books on assembly language programming for the 8051? Please advise, thank you.