Outputting to port and checking register value...

Discussion in 'Programmer's Corner' started by majoritical, Apr 15, 2008.

  1. majoritical

    Thread Starter Member

    Nov 20, 2007

    I am trying to get information from an external EPROM into an AT89C51ED2 (8051 family) microcontroller. I am programming in assembly.

    1)Is there any way I could possibly check the register content afterwards to know if the right value is in there?

    2) How can I referr to a register value in my program so I could write a conditional statment based on this value to output to a certain port.

    e.g IF R0 is between 0 to 3 send a high to P1.1 (0 and 3 included in range)

    else IF R0 is between 3.1 to 5 send a high to P1.2 ( 3.1 and 5 included in range)

    Below is some part of my code which does the writing to the register. I could give the remaining part of my code on request. Thanks guys!!!!

    clr C ;Set carry bit to ’0’
    movx A, @DPTR ; get data bit and store in LSB of acc
    jnb ACC.0, zero_bit ; If LSB of accumulator ’1’ set carry bit to ’1’
    setb C
    mov A, R1 ; Load contents of register 1 to accumulator
    rlc A ; Rotate accumulator left through carry
    mov R1, A ; Load contents of accumulator to register 1
    djnz R0, loop2 ; Finish if last data bit is set
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    Assuming you know what each "right value" is, simply subtract it from the register contents and check the zero flag. If it ain't zero, it ain't the "right value".