【问题标题】:Is this a hardware or Software issue?这是硬件问题还是软件问题?
【发布时间】:2014-05-06 06:32:24
【问题描述】:

我正在使用 Atmel Studio 6.1 和带有 Atmega328P 微控制器的 Arduino Uno 板。下面包括我的代码和我的硬件图片。我不知道这是硬件还是软件问题……所有 LED 灯都亮了。当按钮被按下时,它应该变成一个确定的模式。再次按下按钮会导致显示不同的模式。我不能使用 C 语言,也不能使用实时调试,因为我没有 JTAG 或其他一些支持调试的接口。最终发生的是按钮被按下并且我正在短路电路并且电路板的电源被重置。奇怪的是,模式改变了一次,但再也没有改变过。

.def counter = R23
.def TimeLoopMax = R24
.def AllOnes = R16
.def DisplayPattern = R17
.def AllZeros = R18

MAIN:
    LDI AllOnes, 0xFF   ; assign 1 - make an output
    LDI DisplayPattern, 0x00    ; start with all the LEDS ON; Holds the Light Pattern
    LDI AllZeros, 0x00  ; assign 0 - make an input
    LDI r19, 0x00   ; to hold the value read from PORTB0
    LDI counter, 0x00   ; value for counter
    LDI TimeLoopMax, 0x70
;According to the breakout board, PORTB5 is connected on spot 13 on the board
OUT DDRD, AllOnes   ;set PORT D as an output

;make PORTB an input
OUT DDRB, AllZeros  ;set PORT B as an input

;Start by turning all LEDS OFF
OUT PORTD, DisplayPattern

LOOP:
    ;read in the value from PORTB0 (ie the push button)
    IN r19, PORTB0
    ;CPI r19, 0x05 ; might need to do a compare; compare with 5 since we're using 5V
    CP r19, AllZeros
    BRNE LOOP
    JMP IncreasePatternCounter

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Blinking Pattern Definitions ;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;This defines a blinking sequence for Pattern 0 
P0:
    ;P0, start at a value of 1, and shift the bit to the MSB
    LDI DisplayPattern, 0x01
P0_LOOP:
    OUT PORTD, DisplayPattern

    LSL DisplayPattern          ;Logic shift Left
    ;need to check butotn press every time the light switches
    ; since we are not using interrupts

    /*IN r19, PORTB0
    SBRC r19, 0 ;skip if Bit in Reg. is clear
    JMP IncreasePatternCounter*/

    JMP TimeWastingLoop 


;This defines a blinking sequence for Pattern 1
P1:
    ;P1, start at a value of AA, and shift the bit to the MSB
    LDI DisplayPattern, 0xAA
P1_LOOP:
    OUT PORTD, DisplayPattern
    LSL DisplayPattern
    /*IN r19, PORTB0
    SBRC r19, 0
    JMP IncreasePatternCounter*/
    JMP TimeWastingLoop

;This defines a blinking sequence for Pattern 1
P2:
    ;P1, start at a value of AA, and shift the bit to the MSB
    LDI DisplayPattern, 0xFF
P2_LOOP:
    OUT PORTD, DisplayPattern
    LSR DisplayPattern
    /*IN r19, PORTB0
    SBRC r19, 0
    JMP IncreasePatternCounter*/
    JMP TimeWastingLoop

    ;This defines a blinking sequence for Pattern 1
P3:
    ;P1, start at a value of AA, and shift the bit to the MSB
    LDI DisplayPattern, 0x00
P3_LOOP:
    OUT PORTD, DisplayPattern
    INC DisplayPattern
    /*IN r19, PORTB0
    SBRC r19, 0
    JMP IncreasePatternCounter*/
    JMP TimeWastingLoop


IncreasePatternCounter:
    INC counter
SequenceSelect:
    CPI counter, 0x01
    BREQ P0;

    CPI counter, 0x02
    BREQ P1;

    CPI counter, 0x03
    BREQ P2

    CPI counter, 0x04
    BREQ P3

    JMP P0

; Time wasting loop registers: r20,21,22
;   R16 is all 1's
TimeWastingLoop:
LDI R20, 0x05
LDI R21, 0x05
LDI R22, 0x04

OutMostLoop:
    CP TimeLoopMax, R20;(TLM - R20)
    BREQ EndLoop

    FirstInnerLoop:
        /*IN r19, PORTB0
        SBRC r19, 0
        JMP IncreasePatternCounter*/
        CP TimeLoopMax, R21; (TLM - R21)
        BREQ EndOutMostLoop

        SecondInnerLoop:

            IN r19, PORTB0
            SBRC r19, 0
            JMP IncreasePatternCounter

            CP TimeLoopMax, R22; (TLM - R22)
            BREQ EndSecondInnerLoop
            INC R22
            JMP SecondInnerLoop
        EndSecondInnerLoop:
            CLR R22 ;reset the register for the next pass
            INC R21 ; increment 1st inner loop counter
            JMP FirstInnerLoop
EndOutMostLoop:
    CLR R21
    INC R20
    JMP OutMostLoop
EndLoop:        
    ;this is where we do the compare statements with counter
    ;Need to perform a compare here to see which loop we bounce back in
    CPI counter, 0x01
    BREQ P0_TWL ; Pattern0 Time Wasting Loop
    CPI counter, 0x02
    BREQ P1_TWL
    CPI counter, 0x03
    BREQ P2_TWL
    ;OUT PORTD, counter

P0_TWL:
    CPI DisplayPattern, 0b00000000
    BREQ BtnPressCheckP0
    BRNE P0_LOOP
P1_TWL:
    CPI DisplayPattern, 0b00000000
    BREQ P1
    BRNE P1_LOOP
P2_TWL:
    CPI DisplayPattern, 0b00000000
    BREQ P2
    BRNE P2_LOOP

BtnPressCheckP0:
    IN r19, PORTB0
    SBRC r19, 0
    JMP IncreasePatternCounter
    JMP LOOP

【问题讨论】:

  • 为什么您的按钮没有连接到端口和/或复位引脚?短路电源似乎不是一个好主意。至于代码,如果没有物理调试,请使用模拟器。

标签: debugging assembly arduino hardware led


【解决方案1】:

无法评论代码部分,但按钮周围的电路看起来像是造成短路的原因。 This教程展示了一个不错的按键电路。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-25
    相关资源
    最近更新 更多