Shop OBEX P1 Docs P2 Docs Learn Events
serial out 9 bits? — Parallax Forums

serial out 9 bits?

ArchiverArchiver Posts: 46,084
edited 2001-11-05 19:27 in General Discussion
Hi all,
I am trying to set up some serial communication between a BSII and an PIC16F84
for my current project.

I have found some code to do serial coms in software on the PIC (it has no
hardware UART) but from reading the code it appears it is expecting 1 start
bit, 8 data bits, no stop bit. I have written some test code for my BSII using
the serin and serout commands.

My question is how do I serout 9 bits, and is serout the most appropriate stamp
command to be using for this?

Thanks for any help,
James Fitzsimons

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-02 03:57
    the start bit is not actually a bit it is the first transition from high
    to low and is called a mark. I had a project that used the exact same
    chip. I have exactly what your looking for, if you have a fax number i
    could fax it to you . Do you have a pic programer?


    On Fri, 02 Nov 2001 16:25:09 +1300 (NZDT) jamesfit@p...
    writes:
    > Hi all,
    > I am trying to set up some serial communication between a BSII and
    > an PIC16F84
    > for my current project.
    >
    > I have found some code to do serial coms in software on the PIC (it
    > has no
    > hardware UART) but from reading the code it appears it is expecting
    > 1 start
    > bit, 8 data bits, no stop bit. I have written some test code for my
    > BSII using
    > the serin and serout commands.
    >
    > My question is how do I serout 9 bits, and is serout the most
    > appropriate stamp
    > command to be using for this?
    >
    > Thanks for any help,
    > James Fitzsimons
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-02 22:08
    Hi Kelvin,
    thanks for you response! I guess I have mis-understood the meaning of start
    bit.... I am a bit confused now. How do you get that transition if you don't
    send a high bit to start with?

    I don't have a fax number at home, only email. You could fax it to me at
    work on +64 4 4957308 but I do live in New Zealand!

    I am using a PIC programmer I built from a kit I brought from
    www.phanderson.com It is called the morgan PIC programmer.

    Thanks again for you help,
    regards
    James Fitzsimons


    > the start bit is not actually a bit it is the first transition from high
    > to low and is called a mark. I had a project that used the exact same
    > chip. I have exactly what your looking for, if you have a fax number i
    > could fax it to you . Do you have a pic programer?
    >
    > >
    > > My question is how do I serout 9 bits, and is serout the most
    > > appropriate stamp
    > > command to be using for this?
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-05 05:53
    Hi James

    Sorry your confused . I guess I should have been more clear.
    After the first high to low transition the program waits 1 bit time (the
    start bit) after which
    it checks the serial pins state , this next bit is the first data bit.
    There is also a stop bit, the same as the start bit ,but thats not
    mentioned aymore.

    If your ready heres the serial program.
    I used the 84 chip as a mirror for the bs2,I set up a counter and sent
    the number to the 84 which sent it back to the bs2 so I could read it .
    This program is at the end.
    I dont thin I have any typeOs
    Let me know how it goes.

    The baud rate is tested at 2400 max (the program is set to 2400)
    The recieve and transmit pin is portA pin2
    If you want to make the baud rate 1200, double the bit_k value.
    4mhz xtal , use square metal can type
    watchdog timer off


    list p=16c84
    radix hex
    w equ 0
    f equ 1
    status equ 0x03
    carry equ 0x00
    bit_k equ d'103' ;bit delay value, use to change baud rate
    del_cnt eqy 0x0c
    bit_cnt equ 0x0d
    dx equ 0x02
    count1 equ 0x0f
    count2 equ 0x10
    rec_reg equ 0x11
    port_a equ 0x05

    org 0x00
    recv movlw 0x02
    tris port_a ;make porta input
    start nop
    nop
    btfsc port_a,dx ;check for start bit
    goto start
    movlw 0x08 ;set for 8 bits
    movwf bit_cnt
    clrf rec_reg
    r_next
    call bit_del ;delay 1 bit time
    btfss port_a,dx ;check pin for high
    bcf status,carry
    btfsc port_a,dx ;check pin for low
    bsf status,carry
    rrf rec_reg,f ;shift bit in register
    decfsz bit_cnt,f ;decrement 8 bit counter
    goto r_next
    call bit_del ; stop bit
    movf rec_reg,w
    call pause ;slow things down a little
    ;************************************************
    ;this is almost the same as above except bits are shifted out instead of
    in

    ; transmit

    trans
    movlw 0x00
    tris port_a ;make porta output
    clrf port_a
    clrf count1
    clrf count2
    clrf del_cnt
    bcf status,carry
    xmtr movlw 0x08
    movlw bit_cnt
    bcf port_a.dx
    call bit_del
    x_next
    bcf status,carry
    rrf rec_reg,f
    btfsc status.carry
    bsf port_a,dx
    btfss status,carry
    bcf port_a,dx
    call bit_del
    decfsz bit_cnt,f
    goto x_next
    x_stop bsf port_a,dx
    call bit_del
    goto recv

    ;*********bit delay********************************

    bit_del
    movlw bit_k
    movwf del_cnt
    dec_cnt
    nop
    decfsz del_cnt,f
    goto dec_cnt
    return


    ;***************************************
    Bs2 comm84

    x var byte
    dat var byte

    loop:
    x = x + 1
    serout 7,396,[noparse][[/noparse]x]
    serin 2,396,300,skip,[noparse][[/noparse]dat]
    skip:
    debug ? x ,cr
    debug ? dat,cr
    goto loop
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-05 07:36
    HI James

    I need to make a correction, I left out a routine. Its late after
    midnight here,sorry

    I need you to add this to the end of the program.
    What this if for is to give the stamp time to get ready to receive the
    transmition
    form the 84 chip
    ; pause between transmitions

    pause
    movlw 0xfb
    movwf count1
    loadn
    movlw 0xfb
    movwf count2
    deccn
    decfsz count2,f
    goto deccn
    decfsz count1.f
    goto loadn
    return
    end

    This is just a time delay loop within a time delay loop.
    Its done to make longer time delays. Calling this time delay 3 times will
    give about
    a half second delay. It may be useful to you with other programs.

    good luck
    Kelvin
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-05 19:27
    Hi Kelvin,
    just wanted to say a big thank you for the code you sent through. I really
    appreciate your taking the time.

    kind regards,
    James Fitzsimons
Sign In or Register to comment.