【问题标题】:AVR Switch InputAVR 开关输入
【发布时间】:2015-02-20 14:28:13
【问题描述】:

我们如何让这个程序从开关 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

【问题讨论】:

    标签: assembly avr atmel


    【解决方案1】:

    是的,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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-26
      相关资源
      最近更新 更多