software uart

Discussion in 'Programmer's Corner' started by baftab, Oct 8, 2007.

  1. baftab

    Thread Starter New Member

    Oct 8, 2007
    1
    0
    i got this code from a site, but i cant assemble it in keil
    which assembler whould i use??
    or is there some fault with the code itself??
    the '*' are giving some problem

    "djnz r1,*" for instance



    TXD EQU P1.0 Transmit on this pin
    RXD EQU P1.1 Receive on this pin
    * The serial baud rate is determined by the processor crystal, and
    * this constant which is calculated as: (((crystal/baud)/12) - 5) / 2
    BITTIM EQU 45 (((11059200/9600)/12) - 5) / 2
    *
    * Transmit character in A via TXD line
    *
    putc CLR TXD Drop line for start bit
    MOV R0,#BITTIM Wait full bit-time
    DJNZ R0,* For START bit
    MOV R1,#8 Send 8 bits
    putc1 RRC A Move next bit into carry
    MOV TXD,C Write next bit
    MOV R0,#BITTIM Wait full bit-time
    DJNZ R0,* For DATA bit
    DJNZ R1,putc1 write 8 bits
    SETB TXD Set line high
    RRC A Restore ACC contents
    MOV R0,#BITTIM Wait full bit-time
    DJNZ R0,* For STOP bit
    RET
    *
    * Receive a character from the RXD line and return in A
    *
    getc JB RXD,* Wait for start bit
    MOV R0,#BITTIM/2 Wait 1/2 bit-time
    DJNZ R0,* To sample in middle
    JB RXD,getc Insure valid
    MOV R1,#8 Read 8 bits
    getc1 MOV R0,#BITTIM Wait full bit-time
    DJNZ R0,* For DATA bit
    MOV C,RXD Read bit
    RRC A Shift it into ACC
    DJNZ R1,getc1 read 8 bits
    RET go home
     
  2. Xray

    Well-Known Member

    Nov 21, 2004
    58
    1
    Hi baftab,
    I designed a software UART during the 1980's when I worked for a medical device manufacturer. It worked in a similar fashion to the code that you show here, but mine was much more complex because we needed extra code for exception handling and noise rejection.

    The "*" indicates that a comment follows. It tells the assembler to disregard anything it sees to the right of it. A comment is simply a note that the Programmer added so that he/she will remember what was done at a later time when the software needs to be debugged or altered. I do not understand why some of the lines in your code do not show a "*" ahead of the comments. Many assemblers us a ";" before a comment.

    Most of my software career back then was developing software for devices that used the Intel 8085 microprocessor. I also did some Motorola uP programming, but very little of it.

    Regards,
    Xray
     
  3. RiJoRI

    Well-Known Member

    Aug 15, 2007
    536
    26
    In some assemblers the * character refers to the program counter's current value. The following are equivalent:

    Label: jnz Label
    and
    jnz *
    and
    jnz $

    Although, as xray said, in some assemblers "*" is used as a comment indicator.

    --Rich
     
Loading...