Simple question about TRISB and similar statements.


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default 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 ?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default 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.

Similar Threads

  1. TRISA, TRISB setting ?
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th January 2011, 20:32
  2. something similar to DEC command
    By mischl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st May 2009, 23:24
  3. clrf TRISB & 0x07F HELP..
    By chip_select in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 9th April 2008, 17:23
  4. INTCON (RB0/INT) and TRISB
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th September 2006, 20:38
  5. what's similar to the 16f84a?
    By kenpo in forum General
    Replies: 11
    Last Post: - 18th February 2005, 18:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts