• AVR Freaks

Hot!Is there a function for configuring serial communication?

Author
Nera
Super Member
  • Total Posts : 237
  • Reward points : 0
  • Joined: 2017/10/11 07:13:25
  • Location: 0
  • Status: offline
2020/05/22 06:48:44 (permalink)
0

Is there a function for configuring serial communication?

I need to communicate at 19200bps using pic16f877a. Is there a function that makes it easy to configure these parameters?
#1

12 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18667
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 07:04:42 (permalink)
    +1 (1)
    In C? Who’s compiler?
    Not in XC8. If you chose a newer PIC, you could use MCC.
    #2
    Nera
    Super Member
    • Total Posts : 237
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 07:20:02 (permalink)
    0
    NKurzman
    In C? Who’s compiler?
    Not in XC8. If you chose a newer PIC, you could use MCC.



    XC8 Compiler.
    pic16f877a
    #3
    katela
    Super Member
    • Total Posts : 1753
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 07:25:26 (permalink)
    +2 (2)
    Is there a good reason to use such an old PIC while there are newer better and cheaper alternatives?
     

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #4
    Nera
    Super Member
    • Total Posts : 237
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 07:53:44 (permalink)
    +1 (1)
    katela
    Is there a good reason to use such an old PIC while there are newer better and cheaper alternatives



    It's an old project.It's an old project.
    #5
    dan1138
    Super Member
    • Total Posts : 3496
    • Reward points : 0
    • Joined: 2007/02/21 23:04:16
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 08:28:39 (permalink)
    +1 (1)
    Neraildes
    katela
    Is there a good reason to use such an old PIC while there are newer better and cheaper alternatives

    It's an old project.

    Then use old tools like MPLAB 8.92, a PICSTART plus, XC8 1.35 with the peripheral libraries.
     
    p.s. This combination last work using Windows XP.
    post edited by dan1138 - 2020/05/22 08:29:52
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18667
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 08:46:46 (permalink)
    0
    Was there a PLIB for PIC16?
    #7
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 09:00:28 (permalink)
    +5 (5)
    Just read the PIC datasheet. There is only a handful of registers to setup -- that's all!  And you will learn more this way.
     
    post edited by 1and0 - 2020/05/22 09:01:32
    #8
    katela
    Super Member
    • Total Posts : 1753
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 09:38:59 (permalink)
    +1 (1)
    NKurzman
    Was there a PLIB for PIC16?

    For 8-bit, the plib was for PIC18F.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #9
    NKurzman
    A Guy on the Net
    • Total Posts : 18667
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 09:57:31 (permalink)
    0
    katela
    NKurzman
    Was there a PLIB for PIC16?

    For 8-bit, the plib was for PIC18F.

    That’s what I thought.
    #10
    Nera
    Super Member
    • Total Posts : 237
    • Reward points : 0
    • Joined: 2017/10/11 07:13:25
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 10:17:24 (permalink)
    +5 (5)
    Thank you all. I did my own serial initialization routine.
     
     
    void USART_init(unsigned long baudrate)
         {
         TRISCbits.TRISC6=1;
         TRISCbits.TRISC7=1;
         TXSTAbits.TXEN=1;
         RCSTAbits.CREN=1;
         RCSTAbits.SPEN=1;
         SPBRG = ((_XTAL_FREQ)/(16*baudrate))-1 ;
         TXSTAbits.BRGH=1;
         }

    #11
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/22 14:53:36 (permalink)
    +2 (2)
    Well done. Now you know more about how it works.
    Bear in mind, that does depend upon YOU correctly defining the _XTAL_FREQ value.
     

    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!
    #12
    pcbbc
    Super Member
    • Total Posts : 1691
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: Is there a function for configuring serial communication? 2020/05/25 01:07:51 (permalink)
    +2 (2)
    Do you need to switch baud rates on the fly?
    Seems wasteful of resources (as you start from a low starting point anyway with such a dinosaur part) to have to include the long integer division library routine just to configure a baud rate.
     

    #define BAUD_RATE 9600
    SPBRG = ((_XTAL_FREQ) / (16 *BAUD_RATE)) - 1;

    Then the compiler will do the maths for you.
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5