• AVR Freaks

TRISBbits.TRISB3 = 0 - documentation

Author
xcom2112
New Member
  • Total Posts : 11
  • Reward points : 0
  • Joined: 2016/10/23 08:01:15
  • Location: 0
  • Status: offline
2019/09/12 23:31:38 (permalink)
0

TRISBbits.TRISB3 = 0 - documentation

Hi,
 
in a lot of code example, I see the following codes "TRISBbits.TRISB3 = 0"
as far as I understand, this is a part of Microchip drivers for the PIC.
 
my question is: where can I find the 8-bit driver manual? I was looking everywhere....
 
Thank you,
 
Mike
 
#1

14 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28412
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/12 23:36:35 (permalink)
    +1 (1)
    There are no "Microchip drivers", which is why there is no manual.
    What you are looking at is just a structure defined in the header file for each PIC by the XC8 compiler.
    Which specific PIC are you talking about?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    ric
    Super Member
    • Total Posts : 28412
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/12 23:40:24 (permalink)
    +1 (1)
    Assuming you are using XC8 v2.10, the User Guide is at:
    C:\Program Files (x86)\Microchip\xc8\v2.10\docs\MPLAB_XC8_C_Compiler_User_Guide_for_PIC.pdf
    and contains:
    "2.4.2.5 HOW DO I FIND THE NAMES USED TO REPRESENT SFRS AND BITS?"
    and
    "4.3.7 Using SFRs From C Code"
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    xcom2112
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2016/10/23 08:01:15
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 00:17:33 (permalink)
    0
    Hi Ric,
     
    Thank you for your answer.
     
    they recommend reading the xc.h file.
    so it seems the best way to learn this is by examples, as the xc.h file is a very long file...
     
    #4
    JPortici
    Super Member
    • Total Posts : 1164
    • Reward points : 0
    • Joined: 2012/11/17 06:27:45
    • Location: Grappaland
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 00:36:42 (permalink)
    +1 (1)
    The principle is rather easy
    For every SFR there are two variables defined, one to access the whole register and one to access the individual filed in the register.
     
    So, TRISB can be read and written as a whole by reading/writing TRISB
    x = TRISB; TRISB = x

    but if you want to read/write a single field you read/write a field in TRISBbits
    x = TRISBbits.RB0; TRIBbits.RB0 = x

    and the fields names and positions corresponds 1:1 to what you will see in the datasheet.
     
    couldn't be easier.
     
    Other compilers such as MikroC use (or used, it's been long since i programmed in it) nonstandard variables for the SFRs.. They are bitfields but they can also be accessed as a whole without using a different variables, so there you have TRISB and TRISB.RB0 which you may find neat but it's non standard and i don't like non standand.
     
    Other companies instead tend to use a union so out example would become TRISB.w to access the whole word and TRISB.bits.RB0 for the single bit.
     
    A warning: If you use newer pics you may find incorrect or strange bits in interrupt registers.. It is because there is crap that has been ported over as a new pic replaced an old one and AFAIK it hasn't been corrected yes even though i reported it numerous times.
    #5
    ric
    Super Member
    • Total Posts : 28412
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 01:21:43 (permalink)
    +1 (1)
    xcom2112
    so it seems the best way to learn this is by examples, as the xc.h file is a very long file...

    What makes you say that?
    The xc.h that comes with XC8 v2.10 is precisely 43 lines long, and the last two lines are blank!
    It's just a stub which pulls in other header files. I was going to tell you which is the one to look in for your PIC, but you ignored my request to provide this vital detail!
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    xcom2112
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2016/10/23 08:01:15
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 01:22:44 (permalink)
    0
    Thanks for the detailed reply!
     
    on the XC8 manual there is an example:
     
    #include <xc.h>
    void main(void)
    {
    PORTA = 0x00;
    RA0 = 1;
    PORTAbits.RA2 = 1;
    }


    so, for example, if i can use "RA0 = 1" why should i use "PORTAbits.RA0 = 1" ?
    #7
    ric
    Super Member
    • Total Posts : 28412
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 01:27:19 (permalink)
    +1 (1)
    Only some devices provide macros to use the "RA0" version.
    PORTAbits.RA0 is the real name.
    Once again, I cannot tell you if this is true for your device because you haven't revealed that.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    xcom2112
    New Member
    • Total Posts : 11
    • Reward points : 0
    • Joined: 2016/10/23 08:01:15
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 01:31:24 (permalink)
    0
    ok :) got it.
     
    I'm sorry I can't provide a specific PIC model, as im only learning the subject in general and not for a specific project.
    (for now, I was exploring the PIC18F13K50.h file)
     
    thank you guys for all your help! much appreciated!
    #9
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 4003
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 04:26:04 (permalink)
    0
    Don't get that chip, it is ten Years old.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #10
    mpgmike
    Super Member
    • Total Posts : 473
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 07:18:03 (permalink)
    0
    Gort2015
    Don't get that chip, it is ten Years old.


    But there aren't many 8-bit USB capable offerings.  The PIC16F1459 has half the buffers & buffer size of the PIC18F13_4K50 (which is about half that of the 26_46K50).  Unfortunately, it still is the go-to for certain USB applications.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 4003
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 08:37:38 (permalink)
    0
    What has USB got to with the OP's post?

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    pcbbc
    Super Member
    • Total Posts : 1703
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 08:59:46 (permalink)
    0
    xcom2112On the XC8 manual there is an example:
    #include <xc.h>
    void main(void)
    {
    PORTA = 0x00;
    RA0 = 1;
    PORTAbits.RA2 = 1;
    }

    What a dreadful example. It makes one of the classic faux pas of beginner PIC programming:
    Careening out of the end of main, which then results in a device reset.
     
    Granted it did cover that earlier in section 5.10...
    void main(void)
    {
        // your code goes here
        // finished that, now just wait for interrupts
        while(1)
            continue;
    }

    ..but even so, it's fairly irresponsible to provide an example main that can terminate.
    #13
    mpgmike
    Super Member
    • Total Posts : 473
    • Reward points : 0
    • Joined: 2014/01/23 17:27:06
    • Location: NJ
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 17:02:24 (permalink)
    0
    Gort2015
    What has USB got to with the OP's post?


    I suppose nothing, at least directly.  My reply was tainted by the fact that I personally use the K50s for USB (and pretty much nothing else).  If he has no need for USB then there are definitely better choices.

    I don't need the world to know my name, but I want to live a life so all my great-grandchildren proudly remember me.
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 4003
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: TRISBbits.TRISB3 = 0 - documentation 2019/09/13 18:13:46 (permalink)
    0
    Not even directly, he is asking about TRISB.

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    Jump to:
    © 2020 APG vNext Commercial Version 4.5