AVR 开关量输入

AVR Switch Input

我们如何让这个程序从开关 0 而不是开关 7 读取输入。目前我不确定代码在哪里检查输入,我不知道如何更改它.我认为它与 brmi 正确有关,但我可能是错的。非常感谢

    ;Program to sequence LEDs on port C, uses the MSB on switches to change direction 

;Stack and Stack Pointer Addresses 
.equ     SPH    =E              ;High Byte Stack Pointer Address 
.equ     SPL    =D              ;Low Byte Stack Pointer Address 
.equ     RAMEND =F             ;Stack Address 

;Port Addresses 
.equ     DDRA   =A              ;Port A Data Direction Register Address 
.equ     PINA   =              ;Port A Input Address 
.equ     PORTC  =              ;Port C Output Address 
.equ     DDRC   =              ;Port C Data Direction Register Address 

;Register Definitions 
.def     leds   =r0               ;Register to store data for LEDs 
.def     temp   =r16              ;Temporary storage register 
.def     chdir  =r20              ;Register determining sequence direction of LEDs 

;Program Initialisation 
;Set stack pointer to end of memory 
         ldi    temp,high(RAMEND) 
         out    SPH,temp          ;Load high byte of end of memory address 
         ldi    temp,low(RAMEND) 
         out    SPL,temp          ;Load low byte of end of memory address 

;Initialise Input Ports 
         ldi    temp,[=10=]    
         out    DDRA,temp         ;Set Port A for input by sending [=10=] to direction register 

;Initialise Output Ports 
         ldi    temp,$ff    
         out    DDRC,temp         ;Set Port C for output by sending $FF to direction register 

;Initialise Main Program 
         sec                      ;Set carry flag to 1 
         clr    leds              ;Clear leds 

;Main Program 
forever: out    PORTC,leds        ;Display leds to port C 
         rcall  delay             ;Call delay subroutine 
         rcall  pollswt           ;Poll switches to check direction change 
         tst    chdir             ;Test if negative 
         brmi   right             ;If switch 7= 1 chase right else if if switch 7 = 0 chase left

;Rotate leds left
left:     rol    leds              ;Rotate leds left by 1 bit through carry flag 
         rjmp   forever 

;Rotate leds right
right:   ror    leds              ;Rotate leds right by 1 bit through carry flag 
         rjmp   forever 

;Polling Subroutine 
pollswt: in     chdir,PINA        ;Read switches on switch light box    
         ret 

;delay section of code (25.348 ms @ 1MHz) - utilises r25,r24 
delay:   ldi    r24,          ;Initialise 2nd loop counter 
loop2:   ldi    r25,$FF          ;Initialise 1st loop counter 
loop1:   dec         r25              ;Decrement the 1st loop counter 
         brne   loop1            ;and continue to decrement until 1st loop counter = 0 
         dec    r24              ;Decrement the 2nd loop counter 
         brne   loop2            ;If the 2nd loop counter is not equal to zero repeat the 1st loop, else continue 
        ret                   ;Return

是的,tst chdir; brmi right 查看第 7 位,因为那是符号位。 当然有很多方法可以将其更改为#0 位,但最简单的方法可能是使用 bstT 标志:

bst chdir, 0 ; copy bit to T flag, use any bit number you like
brts right   ; use brtc to reverse condition