Subroutine that waits for button

This topic contains 1 reply, has 1 voice, and was last updated by  Data 2 years, 8 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #31959

    Data
    Member

    I have written the following program which I want to write a subroutine for:

    #include
    .set noreorder
    .text
    .globl start
    .ent start

    start:
    jal fix
    nop
    jal wait # Wait for button click
    nop
    lui s0, 0xbf90 # Load switch port address
    lb s1, 0x0(s0) # Read first number from switches
    nop
    jal wait # Wait for button click
    nop
    lb s2, 0x0(s0) # Read second number from switches
    nop
    add s3, s1, s2 # Perform an arithmetic operation
    sb s3, 0x0(s0) # Write the result to LEDs
    b start # Repeat all over again
    nop

    wait:
    # some polling command, a call to register 0xBFA0000 and then specify K2?
    jr $31 # jump back after the subroutine is finished
    nop

    .end start

    I want to write a subroutine that will wait until the button K2 is pressed, then wait until the button is released, and then just return. It should read from the address
    0xbfa00000 until it receives a 1 in bit position 0 from this read operation, and then read until the bit becomes zero again, and then return.

    I want to call the subroutine with the instruction jal wait, as shown in the main program above.

    I’m not sure how to write this subroutine. I know there should be some polling command to react when button K2 is pressed, but I’m not sure which one or how to write it. I think one can use an “interrupt” method with a call to address 0xBFA00000. But I don’t know exactly how to write this or how to make it react on button K2.

    Please help me how to write this subroutine.

    #39436

    Data
    Member

    Is this a difficult question? I don’t understand why noone replies anything.

Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.