Atmega328p中的汇编程序引脚更改中断 - 我做错了什么?

时间:2018-06-05 11:34:21

标签: assembly avr atmega

我正在尝试在Assembler中编写PCI的第一步。它适用于模拟器(AVR Studio),但上传到我的Arduino时不起作用。想法是在触发中断时切换灯。请帮我找出问题所在。

.include "m328pdef.inc"

.def temp0 = R16
.def select = R17
.def temp1 = R18
.def flagint = R20

.org $0000
            jmp SETUP
.org $0012
            jmp PCI_ROT

SETUP:      ldi temp0, low(RAMEND)
            out SPL, temp0
            ldi temp0, high(RAMEND)
            out SPH, temp0      

            ldi temp0, $FF
            out DDRD, temp0     ; Arduino Pins 22 - 29 (PORTA), Data Bit 0 - 7
            out PORTD, temp0
            ldi temp0, $00
            out DDRB, temp0

            ldi temp0, $01      ; PCI 0 activated, Arduino Pin 21
            sts PCICR, temp0
            ldi temp0, $03      ; PCI pins activated
            sts PCMSK0, temp0
            sei

MAIN:       nop
            jmp MAIN

PCI_ROT:    in select, PINB
            ldi flagint, $01
            rcall SWITCH
            reti

SWITCH:     in temp0, PIND
            ldi temp1, $FF
            eor temp0, temp1
            out PORTD, temp0
            ret 

1 个答案:

答案 0 :(得分:0)

我确实让PCI现在正常工作,问题是一个反弹的开关。我做了一个简单的去抖开关,带有两个电阻和一个冷凝器。看这里: https://www.allaboutcircuits.com/technical-articles/switch-bounce-how-to-deal-with-it/