Serial Communications initialising PIC USART


Closed Thread
Results 1 to 2 of 2
  1. #1
    Bevo's Avatar
    Bevo Guest

    Default Serial Communications initialising PIC USART

    G'Day all,
    I'm looking for working C++ code to setup the USART in a 16f877 PIC in async to send and receive data from a PC via RS232 (using Matlab). At the moment I'm having no luck in sending or receiving anything, the circuit setup is fine as I've had it checked. I just want to send an echo from the computer to make sure that the communication link is fine before moving. The USART setup and an extract from the code is shown below...any help or even a nudge in the right direction would be appreciated:

    void initUSART (void)
    {SPBRG=0x19; //set baud rate to 2400
    RCSTA=0x90;
    TXSTA=0x24;}

    void interruptFlag(void)
    { GIE=0; //disable global interrupts
    if(RCIF)
    {
    flag=1;
    TXREG=RCREG;
    flag=0;}
    }
    void main(void)
    {
    init_portB(); //the port setup is in my original code
    initUSART();

    while(1)
    {
    {if(flag>0)
    flag=0;
    PORTB=RCREG;
    }}}

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    be sure you'd set TRISC and you have the right SPBRG for the right OSC. And you interrupt handling looks weird... and... and.. and.. sorry

    BTW, unfortunately you didn't choose the right forum. Melabs PICBasic here.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  2. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  3. Serial com PIC <> PC - what is best?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd January 2007, 08:37
  4. send serial data to PIC 16f84 ausing VB6
    By win_832001 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2006, 21:14
  5. serial comm from Pic to STAMP
    By d1camero in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th April 2004, 23:58

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