Microcontrollers with assembly: Digital I/O

68 Views Asked by At

Write a program which controls 8 LEDs connected to Port 2 of the MSP430. A momentary switch (push button) should be connected to Port 1.5 When the button is pressed, the LEDs should form an 8-bit binary counter counting from 00h to FFh and then back to 00h. When the button is not pressed, the LEDs should be animated so that the light sweeps from side to side.

I am writing this program in TI Code Composer Studio assembly-only empty project using the MSP-EXP430FR6989. The assembly-only empty project uses MSP430 Assembler Code Template for use with TI Code Composer Studio. I have written this code:

            mov.b   #00h, P1SEL0    ;Set port 1 to I/O
            mov.b   #00h, P1SEL1

            mov.b   #0FFh - 1<<5, P1DIR
            mov.b   #1<<5, P1REN
                            
            clr.b   P1OUT

            mov.b   #00h, P2SEL0    ;Set port 2 to I/O
            mov.b   #00h, P2SEL1

            mov.b   #0FFh, P2DIR    ;Sets P2 as outputs

            clr.b   P2OUT           ;Clears

ifbtn:      cmp.b   #0, P1IN
            jeq     shiftleft
            mov.b   R12, P2OUT
            inc.b   R12
            mov.b   #0, R11
            mov.b   #01h, R10
            jmp     ifbtn

shiftleft:  mov     #0, R12         ;Shift left
            mov.b   R10, P2OUT
            cmp.b   #0, R11
            jne     shiftright
            rla     R10
            cmp     #80h, R10
            jne     end

shiftright: mov     #1, R11         ;Shift right
            rra     R10
            cmp     #1, R10
            jne     end
            mov     #0, R11

end:        nop
            nop

However, when I run the code I will sometimes get the error message "MSP430: Can't Single Step Target Program: Error during step; unknown state." When the code runs, the leds all light up at once when the button is pressed, and only the first when the button is not pressed.

0

There are 0 best solutions below