2015-02-20 2 views
1

Как мы можем получить эту программу для чтения ввода от коммутатора 0 вместо переключателя 7. На данный момент я не уверен, где код проверяет ввод, и я не знаю, как изменить Это. Я думаю, что это нужно делать с брми, но я могу ошибаться. спасибоВход коммутатора AVR

;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 

ответ

0

Да, 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