PIC to RS232 interface


Closed Thread
Results 1 to 5 of 5
  1. #1
    thon's Avatar
    thon Guest

    Default PIC to RS232 interface

    Hi can anyone give me some tips or links where to find some samples on PIC16f877 to RS232 interface. I have a project that displays the output at the LCD. I want to connect my PIC to my PC via RS232 to display the output there using a GUI program maybe I'll be using Visual Basic 6.0 at the PC side.

    Can anyone give show me how to do this?

  2. #2
    thon's Avatar
    thon Guest


    Did you find this post helpful? Yes | No

    Default Re: PIC to RS232 interface

    I am using PIC Basic Pro at the PIC side and VB6 at the PC side. Im using MAX232 for the serial interface. can anyone help me with this I dont know how to start.

  3. #3
    Join Date
    Oct 2003
    Location
    holland
    Posts
    251


    Did you find this post helpful? Yes | No

    Default

    When I use this I do:
    for 2400 baud

    DEFINE SER2_BITS 8

    pinin VAR PORTC.7
    pinout VAR PORTC.6

    SerOut2 pinout,396,[B1]

    SerIn2 pinin,396,[B1]

    or

    SerIn2 pinin,396,50,verdr,[WAIT ("X"),B1]

    depents on the application look at page 132(5.72) and further.

    And in the pc I programm in qbasic(7.1)

    and this works always.

  4. #4
    bobthebud's Avatar
    bobthebud Guest


    Did you find this post helpful? Yes | No

    Cool

    Here are some working code snippets. This is from a standalone monitor which records the data into eprom and downloads to a Pocket PC when requested. it can also work live online to a standard PC. Unfortunately I do not have the VB code for the PC's as this is kept by my software guy. Embedded code is the territory of the hardware engineer.

    set registers:-

    INTCON=$80 '# sets global interrupt
    OPTION_REG=$C0 '# sets RB.0 interrupt to positive edge
    TXSTA=$24 '# sets transmit status register
    RCSTA=$90 '# sets receive staus register
    SPBRG=$81 '# sets baud rate register for 9600 baud
    PIE1=$20 '# enables usart receive intertupt

    rs232: '# This is the RS232 comms protocol

    INTCON=$80

    hserin 100,commerr2,[commin1]

    if (commin1="*") then goto rigdata

    if (commin1="=") then

    hserin 20,answer,[commin1]

    if (commin1<>"$") then goto commerr2

    answer:

    hserout ["OK",carret,newlin]

    hserin 2000,commerr2,[commin1]

    if (commin1="$") then

    hserout [serial1,serial2,dec serial3,carret,newlin]

    hserin 2000,commerr2,[commin2]

    if (commin2="+") then

    The registers are at the top of the code check the book for values. The remainder is the first part of the comms protocol. Here the decision is made as to what type of host is connected and the correct action taken(reroute for online(rigdata). In the case of the Pocket PC download the unit replies with its serial number, the rest of the code covers some classified stuff but what I have given you should put you on the right path. NOTE that I am setting the interrupt register directly as there can be latency problems using the PBP ENABLE INTERRUPT and DISABLE
    INTERRUPT commands.

    Best of luck and happy coding.

    Bob

  5. #5
    gpersha's Avatar
    gpersha Guest


    Did you find this post helpful? Yes | No

    Default

    I have always had trouble using Visual Basic to communicate via a RS-232 interface to my company's PIC devices. Perhaps, if I was a better programmer it might be different. About a year ago, I switched to Liberty Basic and never looked back. It interfaces to the COM port like a dream - never loose a byte now. The $30 US cost doesn't hurt either.

    Jerry

Similar Threads

  1. MXcom "C-BUS" interface to PIC question
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st May 2014, 03:59
  2. Interface Pic --> Max232 --> GSM Modem
    By SangkiMangki in forum GSM
    Replies: 1
    Last Post: - 28th September 2013, 12:57
  3. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  4. Interface a pic with a Iphone/Itouch
    By Luckyborg in forum General
    Replies: 1
    Last Post: - 6th May 2009, 16:02
  5. USB Interface using PIC
    By Tissy in forum mel PIC BASIC Pro
    Replies: 21
    Last Post: - 22nd May 2006, 16:04

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