cmcon with SEROUT2


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    Default cmcon with SEROUT2

    Greetings,

    I am using a PIC16F628A and I am trying to send serial data using SEROUT2. My code basically is
    --------------------------
    cmcon =7

    IF (PORTA.1 = 0) then pressed

    goto main

    pressed:

    SEROUT2...(etc)
    -------------------------
    I am getting a compile error stating that SEROUT2 is invalid. I think it has something to do with "cmcon =7" because when I delete it it compiles correctly (I need the cmcon line because without it the button will not work). Any help is appreciated!

    -Mike

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


    Did you find this post helpful? Yes | No

    Default

    there's no chance it have something to do with CMCON. Check your SEROUT2 syntax or post your whole code here.

    BTW, why are you using SEROUT2 when your PIC have a USART? HSEROUT on the right pins is far better.
    Steve

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

  3. #3
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Ooops! I caught my incredibly stupid error (I didn't define the serial modes). Sorry for wasting your time, mister_e. I do have a question though. What are the benefits of using the hardware serial ports over SEROUT2? Thanks for your time.

    -Mike

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


    Did you find this post helpful? Yes | No

    Default

    Have a look there => http://www.picbasic.co.uk/forum/showthread.php?t=4681

    Everything is covered and well explain.

    The ONLY limitation, is that you have to use the dedicated pins of the USART... i never felt it was a limitation so far
    Steve

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

  5. #5
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    Ok, here is all my code. I will change the two lines concerning serout2 and serin2 with the hardware serial ports code. Basically this program just receives the button input, outputs the serial data (to itself; it is a test circut so don't bother asking why...) and supposedly receives the data and turns on the LED. It isn't working though. Thanks for the link to the HSEROUT/HSERIN page, by the way.

    CODE:
    -----------------------------

    INCLUDE "modedefs.bas"

    Pre CON $A5
    Synch CON "~"

    CMCON =7

    main:
    if (PORTB.1 = 0) then pressed

    pressed:
    serout2 PORTB.2, N2400, [Pre, Synch,"1"]
    serin2 PORTB.3,N2400,[WAIT(Synch),in]
    if (in == "1") then
    high PORTB.4
    pause 250
    low OPRTB.4
    pause 250
    endif

    -----------------------
    Thank you very much for your help...

    -Mike

  6. #6
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    exclude the spelling errors from the code from my previous post...

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


    Did you find this post helpful? Yes | No

    Default

    Hi,
    Try this one and read carefully the SERIN2, SEROUT2 section about the baudrate stuff. You will also foind a table in appendix A for the various baudrate values
    Code:
    @ __CONFIG  _INTRC_OSC_NOCLKOUT & _MCLRE_ON  &  _LVP_OFF & _WDT_OFF & _PWRTE_ON  & _BODEN_ON  
    
    TRISB = %11101011 
    CMCON = 7
    Baud  con 16780 ' 2400 bauds
    Pre   CON $A5
    Synch CON "~"
    In    var byte
    
    LOW PORTB.2   ' inverted mode normal idle state
    pause 50   
    
    Main:
         if (PORTB.1 = 0) then pressed
         goto main
         
    Pressed:
        serout2 PORTB.2, baud, [Pre, Synch,"1"]
        serin2  PORTB.3, baud, [WAIT(Synch),in]
        if (in == "1") then
           high PORTB.4
           pause 250
           low PORTB.4
           pause 250
           endif
        goto main
    Steve

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

  8. #8
    Join Date
    Jul 2006
    Posts
    76


    Did you find this post helpful? Yes | No

    Default

    I compiled your code but I got this error:

    --> opcode expected instead of '__config'

    Please help.

    -Mike

Similar Threads

  1. Serout and 18F87J50
    By Glenn_Webber in forum Serial
    Replies: 8
    Last Post: - 20th November 2009, 14:26
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 02:38
  4. Gps with 16f628
    By dragons_fire in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 8th June 2006, 03:38
  5. TMR1 interrupt question
    By ronjodu in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th February 2006, 03:02

Members who have read this thread : 0

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