我在使中断工作时遇到问题。
我想在组装中制作一个交通灯,红/绿、红/黄、红/红和绿/红的顺序正常工作。问题在于中断。我希望中断使系统进入“紧急”模式并将展位灯设置为红色,在黄色一秒钟后,但当我按下按钮时它什么也没做......
这是代码。希望可以有人帮帮我:
.nolist
.include "m328pdef.inc" ; ATMega328p definition file
.list
;---------------------------------------------------
; Semaphore definition
; (to be adjusted case by case)
;---------------------------------------------------
.equ semaphore=PORTB
.equ GreenNS=0 ; Bit 0
.equ YellowNS=1 ; Bit 1
.equ RedNS=2 ; Bit 2
.equ GreenEW=3 ; Bit 3
.equ YellowEW=4 ; Bit 4
.equ RedEW=5 ; Bit 5
.equ fq = 16000000 ;xtal frequency
;----------------------------------------------------
.dseg ; Variable definition in SRAM
;----------------------------------------------------
.org SRAM_START
state: .db 0 ; present state
;----------------------------------------------------
.cseg ; Code segment
;----------------------------------------------------
.org 0
rjmp main
RESET:
rjmp main
.org 0x0002
;mov r19, r16
in r16, SREG
rjmp State_emr0
;reti
;rjmp main
main:
rcall initsystem
dispatcher:
lds r16,state
cpi r16,0
breq State0
cpi r16,1
breq State1
cpi r16,2
breq State2
cpi r16,3
breq State3
cpi r16,4
breq State4
cpi r16,5
breq State5
cpi r16,6
breq State6
; more code with the states
; and now the part with the initializations and the interrupt function
State_emr0:
;---------------------------------------------------
ldi r16,(1<<YellowEW)+(1<<YellowNS)
out semaphore,r16
;wait 1s
ldi r16, 10
rcall r16delay
;ldi r16,10
;sts state, r16
ldi r16,(1<<RedEW)+(1<<RedNS)
out semaphore,r16
;wait 15s
ldi r16, 150
rcall r16delay
;ldi r16, 7
;sts state, r16
out SREG, r16
reti
initsystem:
ldi r16,LOW(RAMEND)
out SPL,r16
ldi r16,HIGH(RAMEND)
out SPH,r16
ldi r16, 0b00111111 ;set PB0, 1, 2, 3, 4 and 5 as output
out DDRB, r16
out PORTB, r16
ldi r16, 0x00 ;
out DDRD, r16 ; set port D as input (signal from button
out PORTD, r16 ; arrives on pin 2)
ldi r16, 0b00000001 ; activate INT0
sts EIMSK, r16
ldi r16, 0b00000101 ; set both INT's to be triggered by any logical
sts EICRA, r16 ; change
ldi r16,0 ; define initial state
sts state, r16
ldi r19,0
sei
rjmp dispatcher
很抱歉代码太长,但我想给你一切你需要的帮助我。
提前致谢