PBP 16F876A 2 Way Communication


Closed Thread
Results 1 to 14 of 14
  1. #1
    dmugan's Avatar
    dmugan Guest

    Default PBP 16F876A 2 Way Communication

    I am fairly new to PICs and PBP (v2.47). I have designed a small general purpose A/D I/O interface card utilizing a PIC 16F876A. It will be used by my students to gather and graph data using LabVIEW graphical programming language. It must communicate through a USB converter module (FTDI UM232R) because my students are online and use Macs or laptop PCs with no serial port.

    Eventually, I would like to have the card execute several commands, and so need two way communication. So far, I have the Defines setup and a program written to read AD port 0 and send 10 bit result to the hardware serial port. It sends data continuously without a request from the PC. It works fine, except that if I stop receiving data, the serial buffer fills or overflows and when I start receiving data again, it is erratic for many seconds before it returns to normal operation. I need a program that tells the PIC chip to read A/D Port 0 and send result to the hardware serial port just once and then wait for another command. Any thread or archive with such a program? Any suggestions for writing one? Thanks for your help.

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Why not send a character, take a conversion, and then sit in a loop waiting for a character to come in using HSERIN? When the character is received (it can be *any* character, or a specific one of your own choosing),
    then send another character...

    If the sample has to be current (i.e. taken just before the command), you could continuously take A/D readings in a loop. In that loop check PIR1.5 = 1. If it is set, grab the character with HSERIN. If it the right character - send...
    Charles Linquist

  3. #3
    dmugan's Avatar
    dmugan Guest


    Did you find this post helpful? Yes | No

    Default PBP 16876FA 2 way communication

    Charles,

    I understand only part of what you are saying. If I send a charactor from the PC and the PIC program running has a HSERIN comand in the loop, it will set bit 5 of the PIR register? How to I cause a result to be sent back to the PC? In other words, how do I read the PIR flag or register? Could you provide an example of this loop? Thanks for your help.

  4. #4
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Something like -


    LoopTop:

    If PIR1.5 = 1 THEN ' Check to see if Character was received
    HSERIN[Char] ' Grab the character out of the UART
    HSEROUT [ADVAL] ' Send the last A/D value
    ENDIF

    ADCIN 1, ADVAL ' Continuously sample the A/D

    GOTO LoopTop

    ;---------------------------------------------------------------

    PIR1.5 will be set (to "1") whenever ANY character has been received
    in the USART. HSERIN grabs that character and sets PIR1.5 to "0" at
    the same time. Then it sends the A/D value out.

    If no character is received, the A/D converter converts merrily along...
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    Steve

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

  6. #6
    dmugan's Avatar
    dmugan Guest


    Did you find this post helpful? Yes | No

    Default PBP 16F876A 2 Way Communication

    Thank you Charles Linquis and Mister E. Both of your suggestions were helpful. I have incorporated your suggestions in the program below, but I get an error when the compiler reaches the HSERIN command.

    ERROR Line 38: Expected '['.

    I have tried many different ways to confugure the HSERIN command, but always get this or sometimes additional errors. Any suggestions?

    Thanks again for your help.

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 10
    adcVar VAR WORD
    TRISA = %11111111
    ADCON1 = %10000010
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLOERR 1
    PAUSE 005

    main:
    If PIR1.5 = 1 THEN
    HSERIN[char]
    HSEROUT [DEC adcvar, 10, 13]
    ENDIF
    ADCIN 0, adcVar
    PAUSE 50
    GOTO main

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


    Did you find this post helpful? Yes | No

    Default

    I think you forgot to declare "char"
    char var byte

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default

    And put a space before '['

    Ioannis

  9. #9
    dmugan's Avatar
    dmugan Guest


    Did you find this post helpful? Yes | No

    Default PBP 16F876A 2 way Communication

    Thanks Mat and Ioannis,

    The HSERIN command now reads:

    HSERIN [char var byte]

    I still get the same error

    ERROR Line 38: Expected '['.

    Anything else I should try? Thanks everyone.

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


    Did you find this post helpful? Yes | No

    Default

    There is al small misunderstanding.
    You should do this !
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 10
    adcVar VAR WORD

    char VAR BYTE

    TRISA = %11111111
    ADCON1 = %10000010
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 9600
    DEFINE HSER_CLOERR 1
    PAUSE 005

    main:
    If PIR1.5 = 1 THEN

    HSERIN [char] 'and than this

    HSEROUT [DEC adcvar, 10, 13]
    ENDIF
    ADCIN 0, adcVar
    PAUSE 50
    GOTO main

  11. #11
    dmugan's Avatar
    dmugan Guest


    Did you find this post helpful? Yes | No

    Default PBP 16876A 2 way Communication

    Mat,

    Thanks a million. The program now compiles ok, but it seems to hang during execution of the program. I have tried re-arranging the order of the instructions, but so far no luck. I will appreciate more suggestions

  12. #12
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    I'm going to tell you to READ THE PBP MANUAL now.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    a little typo error...
    Code:
    DEFINE HSER_CLOERR 1
    should be
    Code:
    DEFINE HSER_CLROERR 1
    Steve

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

  14. #14
    dmugan's Avatar
    dmugan Guest


    Did you find this post helpful? Yes | No

    Default PBP 16F876A 2 Way Communication

    Thanks to everyone, and a second time to Mister E for finding my typo. It now works like a charm! Have a great day!

Similar Threads

  1. 2 PIC, serial communication
    By lightgreen in forum Serial
    Replies: 6
    Last Post: - 21st November 2009, 15:20
  2. Help with 2 way communication
    By jessey in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd April 2007, 09:11
  3. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  4. PIC 2 PIC communication
    By Mario in forum Forum Requests
    Replies: 16
    Last Post: - 28th April 2006, 01:56
  5. hpwm more than 2 ch possible in pbp?????????
    By oscar in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 10th March 2006, 07:28

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