configure the TRISC register

Discussion in 'Programmer's Corner' started by ali8tor, Mar 15, 2013.

  1. ali8tor

    Thread Starter Member

    May 29, 2012
    43
    0
    How do i configure TRISC Register >





    main()
    {
    PORTC = 0x00; //Clear PortC port
    TRISC = Ox##; //Line 1 of code needs to be completed
    While (1==1)
    {
    //some code
    }
    }
    In reference to the above code, assuming you have a 20MHz oscillator on a PIC PIC 16F877a, configure the TRISC register (by adding the TWO Hexadecimal numbers for the sequence where ## is presently located) such that the port C pins will be configured as inputs or outputs according to the table below



    Outputs Inputs
    RC0 RC4
    RC5 RC1
    RC3 RC2
    RC7
    RC6


    Correct Hexadecimal values for ## in line 1
     
  2. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    Should this be in the "homework" section of the forum?

    If it is a real question, you should use a C compiler which allows binary constants! It's nuts to use a poor compiler that does not give you the necessary functionality.

    So you would do this in code;
    TRISC = 0b00010110; // RC1,2,4 are inputs
     
  3. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    I think there should be a generic response to such questions.

    People who can not work out the basics on their own are probably not made to become microcontroller engineers.

    Even if they can memorize stuff, this will not make them good programmers.

    Their solutions will at best be stale and uninnovative.

    Working with this technology means hard work, it is the only way to archieve results.

    I have learned MSDOS and BASIC when I was 13.

    I see these questions again and again, and it is really primary school level.

    A forum can not replace a good book, some investment of time, and a solid teaching.

    Even if the question gets answered, there will be countless others.

    Handling such questions is not a helping to the one's who ask them.

    Or if you wanted a shorter reply

    R.T.M. (read the manual).

    If you can not count things together then this technology is not the right thing to learn, as difficulty increases exponentially.
     
  4. takao21203

    Distinguished Member

    Apr 28, 2012
    3,577
    463
    You could ask: How do i configure TRISC Register

    I really don't like it when people are not able to discard the irrelevant stuff from a question.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,607
    Ignoring the sniping...

    LOOK at the data sheet for your device. Live with it. Print it out. Keep it with you. Read it. Read it when you have lots of time to kill. Leave another copy in the bathroom.

    And read it. Again. Cross check things.

    Then drop back to the section on Ports. I/O ports always have the same arrangement: output zero corresponds to bit zero, output one corresponds to bit one,and so on up to seven corresponding to seven. Same arrangement for the data (Port) or the direction (TRIS).

    The next handy thing to remember is setting TRIS to 1 is an 1nput, and to zero is an 0utput. 1 is IN, 0 is OUT, see the pattern?

    TRIS starts as inputs (it's safer when the device starts that way). So you need to clear bits to make them outputs.

    So you need to clear bits 0, 3, 5, 6, and 7 to make outputs. I've penciled in these settings on the data sheet to get it correct, but you can do it in text too:

    Code ( (Unknown Language)):
    1.  
    2. bits: 76543210
    3. TRIS: 00010110
    4.  
    Windows has a calculator, in scientific mode it will work in hexadecimal and binary mode. Change to binary, type in that number, then change to hexadecimal and you get the constant to use in your assignment.

    I actually prefer binary over hex to do this, makes it easier to see the bits

    Code ( (Unknown Language)):
    1.  
    2. //        76543210
    3. TRISC = 0b00010110;
    4.  
     
    ali8tor likes this.
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    And as usual sniping from Takao that makes no sense whatsoever.

    The other thing I would suggest is that you check your datasheet. If setting the pins as outputs, you need to check that the pins aren't also analog outputs. You will then may need to specifically set those pins as binary outputs.

    And you really should read the datasheet. For settings like the one you asked about, it is pretty straight forward.
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I'm getting a feeling it WAS a homework question, and the deadline's past now... :(
     
  8. ali8tor

    Thread Starter Member

    May 29, 2012
    43
    0
    awesome thanks alot, yeah it was a homework question, im not to familiar with this site next time i'll post on the correct thread.
     
Loading...