Simple question about TRISB and similar statements.
I know, manual adresses this, but it says all that abstract, here's how I understand it, please correct me if I wrong.
From the included sample, I've borrowed the code for 16F628A:
Code:
TRISB = %11001111 ' Set PORTB.4,5 (LEDs) to output, rest to input
If I understand properly, the command TRISB addresses ports in the following manner, the first char on the left is for the PORTB.7 and last char from the left is PORTB.0, right?
So, if I want to modify this string to make ports 7,4,5,2 output, others as input, it should look like:
Code:
TRISB = %01001011 ' Set PORTB.7,4,5,2 (LEDs) to output, rest to input
Correct ?
Re: Simple question about TRISB and similar statements.
Hi,
That is correct, the most significant bit is to the left - just like it is when we type the same value in decimal: TRISB = 75 (same thing as TRISB = %01001011). See, the most significant digit is to the left. However, if you say TRISB = %10 (which I think is bad practice) then the left most bit is NOT bit 7, it's bit 1 because what you're really doing is setting the TRISB register to the value 2.
One little detail though, TRISB isn't really a command. It's a register in the PIC, the "command" in this case would be "=" sign meaning "assign" or "set" or something like that. You are assigning a value TO the register TRISB in the same way as you assign values to any other variable.
/Henrik.