This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR4133: Using Assembler Instructions to Rotate

Part Number: MSP430FR4133

Tool/software: Code Composer Studio

Hi all,

I am using my MSP430 to light up 8 LEDs in a circle. I want each LED to light up in turn then go back to the beginning. My approach has been to use general purpose register R5, the lower byte, to store the current LED. I later do a comparison with each bit to decide which LED to turn on.

I am in the process of writing two segments of code, one to increment the current LED and one to decrement it:

                MOV.W         #0x01,R5                      ; Set General Purpose register R5 to 1.

;---------------------------------------------------------
;       This main loop executes indefinitely
;---------------------------------------------------------
main:           NOP                                   ; main program
                ;BIS.W         #LPM0+GIE,SR            ; Enter LPM0 w/ interrupt
                JMP             ledDown

ledUp:          RLA.B         R5                      ; Shift left R5 (First 8 bits only)
                JNC           main                    ; Jump if not carry, ie if not on LED 8
                MOV.W         #0x01,R5                ; If Carry, ie LED 8 is on, go back to 1
                JMP           main                   ; Return

ledDown:        RRA.B         R5                      ; Shift right R5 (First 8 bits only)
                JNC           main                    ; Jump if not carry, ie if not on LED 1
                MOV.W         #0x80,R5                ; If Carry, ie LED 1 is on, go back to 8
                JMP           main                 ; Return
;----------------------------------------------------------------

The ledUp segment works as I had intended. When I step through the code, R5 changes as follows:

R5 = 0000 0001

R5 = 0000 0010

R5 = 0000 0100

R5 = 0000 1000

R5 = 0001 0000

R5 = 0010 0000

R5 = 0100 0000

R5 = 1000 0000

R5 = 0000 0001

R5 = 0000 0010     and so on and so forth.....

However, when I use the ledDown segment, I get the following:

R5 = 0000 0001

R5 = 1000 0000

R5 = 1100 0000

R5 = 1110 0000

R5 = 1111 0000

R5 = 1111 1000

R5 = 1111 1100

R5 = 1111 1110

R5 = 1111 1111

R5 = 1000 0000     which is not what I want.

Can anyone suggest why this is as I am struggling to figure it out using the datasheet alone? When I use ledDown, I don't know why it keeps producing more 1s instead of just shifting the existing 1 to the right. Surely it should behave like an arithmetic /2

Any solutions are greatly appreciated!

**Attention** This is a public forum