SEROUT workaround for 16F676


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

    Post SEROUT workaround for 16F676

    After much pain, I discovered that SEROUT nor SEROUT2 do not work on a 16F676.
    (4 Mhz internal OSC)
    The exact same simple code...
    SEROUT PORTC.0, N1200, ["Hello world"]
    when talking to my linux box works with a 16F690.

    I tried many combos of stty on linux, windows boxes, and the PIC code.

    In the end I wrote a serial out routine in PIC Basic and tuned it for 1200 baud.
    Code:
        xmitout VAR PORTC.0
    
        serdelayusec VAR word
        ' By experiment the range is 800 usec for 1200 baud with all the overhead
        ' in the routine sendserbyte
        ' Stable limits are 836 to 941 so take the middle
        serdelayusec = 888
        serbyte var byte
    
    ' Send serbyte as RS232 standard.
    ' 8 bits, 1 start bit, 1 stop bit, no parity bit.
    ' After this routine the xmitout is LOW.
    ' The start bit is xmitout HIGH.
    ' A data bit 1 is xmitout LOW
    ' A data bit 0 is xmitout HIGH
    sendserbyte: 
        ' Start bit, transmitter on 
        if serbyte & $ff then
            HIGH xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        ' Send MSb first. Data is inverted, no signal is a 1, signal is a 0
        if serbyte & $01 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $02 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $04 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $08 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $10 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $20 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $40 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        if serbyte & $80 then
            LOW xmitout
        else
            HIGH xmitout
        endif
        call waitdelay
        
        ' Stop Bit, transmitter off
        if serbyte & $ff then
            LOW xmitout
        else
            LOW xmitout
        endif
        call waitdelay
                
        return
        
    waitdelay:
        PAUSEUS serdelayusec
        return
    In addition, on Mandrivia Linux the single serial port on the back (used for the mous in windows) is /dev/ttyS0
    You first make sure it is not a login port by checking /etc/inittab and commenting out the entry for /dev/ttyS0 if there is one.
    Then use stty to setup the port.

    stty -F /dev/ttyS0 1200 raw cs8
    check it with
    stty -F /dev/ttyS0 -a

    Then read the port with
    cat /dev/ttyS0
    or if it is raw unreadable data,
    cat /dev/ttyS0 | od -x
    for a hex dump.
    Last edited by Darrel Taylor; - 15th February 2006 at 21:57. Reason: added [code][/code] tags

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Serout to serial servo
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 12th August 2009, 16:46
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Keypad unlock (as in garage door possibly)
    By Fred in forum Code Examples
    Replies: 5
    Last Post: - 2nd April 2006, 04:26
  5. Replies: 11
    Last Post: - 13th July 2005, 19:26

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