Debugging 这是硬件问题还是软件问题?

Debugging 这是硬件问题还是软件问题?,debugging,assembly,arduino,hardware,led,Debugging,Assembly,Arduino,Hardware,Led,我正在使用Atmel Studio 6.1和带有Atmega328P微控制器的Arduino Uno板。下面是我的代码和硬件图片。我不知道这是硬件还是软件问题。。。所有LED都会熄灭。当按下按钮时,应将其更改为确定的模式。再次按下按钮会显示不同的图案。我不能使用C,也不能使用实时调试,因为我没有JTAG或其他支持调试的接口。最后发生的事情是按下按钮,我短路电路,电路板的电源复位。奇怪的是,这种模式只改变了一次,但再也不会改变了 .def counter = R23 .def TimeLoopMa

我正在使用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

无法对代码部分进行评论,但按钮周围的电路看起来像是短路的原因。本教程展示了一个良好的按钮电路。

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