What determines the value of a bit variable when it is given the value of a byte variable, such as when porta.0=<byte variable>. How is the value of porta.0 determined?
Announcement
Collapse
No announcement yet.
Byte variables assigned to Bit variables
Collapse
X
-
portd.0 CAN only be 0 or 1
the compiled asm code will look like this the value of varxxx bit 0 is all that is is considered
if (((_varxxx) & 007fh) <= 0bh)
CHK?RP _PORTD
btfsc _keys, 0
bsf _PORTD, 000h
btfss _keys, 0
bcf _PORTD, 000h
else
CHK?RP _keys
rrf _keys, W
CHK?RP _PORTD
btfsc STATUS, C
bsf _PORTD, 000h
btfss STATUS, C
bcf _PORTD, 000h
endif
-
not sure exactly what you are saying
a bit var WOULD be LED0 var BIT
a byte var leds var byte
porta.0 is not a var as such but bit 0 of sfr porta
so for a proper bit var or bit0 of a register
leds = 1
led0 = leds would set led0 to 1
porta.0 = leds would set porta.0 to 1
porta.0 = led0 would set porta.0 to 1
leds =3
porta.0 = leds would set porta.0 to 1
leds = 2
porta.0 = leds would set porta.0 to 0
Comment
-
I guess a good place to start in answering your question is with a question; define "Value of...". When we consider the number systems used in software, there is binary where all digits are either 1 or 0; the decimal system where individual digits can be any number between 0 and 9; and the hexadecimal system which has a decimal range of 0 to 15, using characters 0 to F.
Individual pins of the PIC processor belong to a PORT, be it PORTA, PORTC, etc. Any decimal number ranging from 0 to 255 or hexadecimal range of $00 to $FF can reflect each pin of a PORT, but only visually understandable when converted to binary; %0000 0000 to $1111 1111. PORTx = %xxxx xxxx means that each bit in the binary reflects the state of a PORT pin. From there, you can convert the binary (%xxxxxxxx) to hex ($xx) or decimal (xxx).
If this doesn't make sense, search the internet for tutorials explaining the differences of our familiar decimal system and hexadecimal and binary.We can crack this cotton PIC'n thang!
Comment
-
I frankly don't know how to ask my question any more clearly than I did. Perhaps an example would be better.
Perhaps if you explain what and why you are attempting
PORTA.0=128 makes little sense
if you mean to set the pin in a Boolean logic sense where low = zero and high is any value not = zero then perform the operation logically
PORTA.0 = PORTA.0 || 128 <==> PORTA.0=1
PORTA.0 = PORTA.0 || byte-var <==> PORTA.0= !! byte-var
otherwise it will be performed bitwise using bit0
PORTA.0=128 <==> PORTA.0=0
Comment
Comment