Assembly AVR开关输入

Assembly AVR开关输入,assembly,avr,atmel,Assembly,Avr,Atmel,我们如何让这个程序从开关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 =$3E ;High Byte Sta

我们如何让这个程序从开关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    =$3E              ;High Byte Stack Pointer Address 
.equ     SPL    =$3D              ;Low Byte Stack Pointer Address 
.equ     RAMEND =$25F             ;Stack Address 

;Port Addresses 
.equ     DDRA   =$1A              ;Port A Data Direction Register Address 
.equ     PINA   =$19              ;Port A Input Address 
.equ     PORTC  =$15              ;Port C Output Address 
.equ     DDRC   =$14              ;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,$00    
         out    DDRA,temp         ;Set Port A for input by sending $00 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,$21          ;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,但最简单的方法可能是使用bst和T标志:

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