Está en la página 1de 7

Interrupciones

.def tempo=r16 OUT PORTB,tempo

.def cuenta=r17 OUT PORTD,tempo

.def aux=r18 OUT DDRA,tempo

.def cont=r19 LDI tempo,0b11111000

.def barrer=r20 OUT PORTC,tempo

.dseg IN tempo, MCUCR

score1: .byte 1 ANDI tempo,0b11101111

score2: .byte 1 OUT MCUCR, tempo

score3: .byte 1

leds1: .byte 1 LDI tempo,HIGH(RAMEND)

leds2: .byte 1 OUT SPH,tempo

leds3: .byte 1 LDI tempo,LOW(RAMEND)

.cseg OUT SPL,tempo

.org 0x00

rjmp inicio LDI tempo,0b00101010

.org 0x02 STS EICRA, tempo

rjmp jugador1 LDI tempo,0b00000111

.org 0x04 OUT EIMSK,tempo

rjmp jugador2 OUT EIFR,tempo

.org 0x06 SEI

rjmp jugador3 barrido:

LDI XH, HIGH(leds1)

inicio: LDI XL, LOW (leds1)

LDI tempo,0x00 LDI cont,3

OUT DDRB,tempo LDI barrer,0b11111110

OUT DDRD,tempo SER aux

LDI tempo,0b00000111 OUT PORTC, aux

OUT DDRC,tempo otro_barrido:

LDI tempo,0xFF LD aux,x+


OUT PORTA,aux PUSH ZH

OUT PORTC,barrer PUSH ZL

RCALL BARRIDO_RET

SER aux LDS tempo,score1

OUT PORTC,aux CPI tempo,6

SEC BREQ salir1

rol barrer inc tempo

dec cont STS score1,tempo

BRNE otro_barrido RCALL BIN_LED

BARRIDO_RET: STS leds1,tempo

LDI aux,255

otro_ret: POP ZL

LDI R21,255 POP ZH

otro_ret1: POP cont

LDI R22,4 POP cuenta

otro_ret2: POP aux

dec R22 POP tempo

BRNE otro_ret2 OUT SREG, tempo

dec r21 POP tempo

BRNE otro_ret1 RETI

dec aux salir1:

BRNE otro_ret CLI

RET RET

jugador1: jugador2:

PUSH tempo PUSH tempo

IN tempo,SREG IN tempo,SREG

PUSH tempo PUSH tempo

PUSH aux PUSH aux

PUSH cuenta PUSH cuenta

PUSH cont PUSH cont


PUSH ZH PUSH ZH

PUSH ZL PUSH ZL

LDS tempo,score2 LDS tempo,score3

CPI tempo,6 CPI tempo,6

BREQ salir2 BREQ salir3

inc tempo inc tempo

STS score2,tempo STS score3,tempo

RCALL BIN_LED RCALL BIN_LED

STS leds2,tempo STS leds3,tempo

POP ZL POP ZL

POP ZH POP ZH

POP cont POP cont

POP cuenta POP cuenta

POP aux POP aux

POP tempo POP tempo

OUT SREG, tempo OUT SREG, tempo

POP tempo POP tempo

RETI RETI

salir2: salir3:

CLI CLI

RET RET

jugador3: BIN_LED:

PUSH tempo LDI ZH, HIGH(tabla_bin_led<<1)

IN tempo,SREG LDI ZL, LOW(tabla_bin_led<<1)

PUSH tempo ADD ZL,tempo

PUSH aux CLR tempo

PUSH cuenta ADC ZH, tempo

PUSH cont LPM tempo,Z


RET columna1:
ldi tempo,1
sts columna,tempo
rcall paso2
tabla_bin_led: rcall barrido_filas
rcall bin_7seg
.db 0b00000000,0b00000001 lds tempo, columna_7seg
out portb,tempo
.db 0b00000011,0b00000111 lds tempo, fila_7seg
out portd,tempo
.db 0b00001111,0b00011111 rjmp inicio

.db 0b00011111,0b00000000 columna2:


ldi tempo,2
sts columna,tempo
rcall paso2
Barrido de teclado rcall barrido_filas
rcall bin_7seg
.def tempo=r16 lds tempo, columna_7seg
.def aux=r17 out portb,tempo
.dseg lds tempo, fila_7seg
out portd,tempo
columna: .byte 1 rjmp inicio
fila: .byte 1
columna_7seg: .byte 1 columna3:
fila_7seg: .byte 1 ldi tempo,3
sts columna,tempo
.cseg rcall paso2
.org 0x00 rcall barrido_filas
rcall bin_7seg
ldi tempo,0b11111111 lds tempo, columna_7seg
out ddrb,tempo out portb,tempo
out ddrd,tempo lds tempo, fila_7seg
ldi tempo,0b00000000 out portd,tempo
out portb,tempo rjmp inicio
out portd,tempo
ldi tempo,high(ramend) columna4:
out sph,tempo ldi tempo,4
ldi tempo,low(ramend) sts columna,tempo
out spl,tempo rcall paso2
rcall barrido_filas
inicio: rcall bin_7seg
ldi tempo,0b00001111 lds tempo, columna_7seg
out ddra,tempo out portb,tempo
ldi tempo,0b11110000 lds tempo, fila_7seg
out porta,tempo out portd,tempo
in tempo,mcucr rjmp inicio
andi tempo,0b11101111
out mcucr,tempo
barrido_filas:
sbis pina,0
principal: ldi tempo,1
sbis pina,4 sbis pina,1
rjmp columna1 ldi tempo,2
sbis pina,5 sbis pina,2
rjmp columna2 ldi tempo,3
sbis pina,6 sbis pina,3
rjmp columna3 ldi tempo,4
sbis pina,7 sts fila,tempo
rjmp columna4 ret
rjmp principal
paso2: out portc,tempo
ldi tempo,0b11110000 ldi tempo,high(ramend)
out ddra,tempo out sph,tempo
ldi tempo,0b00001111 ldi tempo,low(ramend)
out porta,tempo out spl,tempo
in tempo,mcucr
andi tempo,0b11101111 principal:
out mcucr,tempo ldi tempo,0b00110000
ret sts columna1,tempo
ldi tempo,0b00110110
bin_7seg: sts columna2,tempo
ldi aux,2 sts columna3,tempo
ldi xh,high(columna) sts columna4,tempo
ldi xl,low(columna) ldi tempo,0b00000110
ldi yh,high(columna_7seg) sts columna5,tempo
ldi yl,low(columna_7seg)
bcd_7seg_lazo: lazo:
ldi zh,high(tabla_7seg<<1) rcall barrido
ldi zl,low(tabla_7seg<<1) rjmp lazo
ld tempo,x+
add zl,tempo
clr tempo barrido: ;barrido de leds
adc zh,tempo ldi xh,high(columna1)
lpm tempo,z ldi xl,low(columna1)
st y+,tempo ldi aux,5
dec aux ldi control,0b00000001
brne bcd_7seg_lazo barrido_lazo:
ret clr tempo
out porta,tempo
tabla_7seg: ; tabla de displays ld tempo,x+
.db 0b00111111, 0b00000110 out portc,tempo
.db 0b01011011, 0b01001111 out porta,control
.db 0b01100110, 0b01101101 rcall retardo
.db 0b01111101, 0b00000111 clr tempo
.db 0b01111111, 0b01100111 out porta,tempo;se apaga los displays
.db 0b01110111, 0b01111100 clc
.db 0b00111001, 0b01011110 rol control
.db 0b01111001, 0b01110001 dec aux
brne barrido_lazo
ret

Matriz de leds retardo:


push r24
push r23
.def tempo=r16 ldi r24,50
.def aux=r17 salto1:
.def control=r18 ldi r23,255
salto2:
.dseg dec r23
columna1: .byte 1 brne salto2
columna2: .byte 1 dec r24
columna3: .byte 1 brne salto1
columna4: .byte 1 pop r23
columna5: .byte 1 pop r24
ret
.cseg
.org 0x00

ldi tempo,0b11111111
out ddra,tempo
out ddrc,tempo
ldi tempo,0b00000000
out porta,tempo
barrido de teclado normal brcs salto5
RCALL HEX_7SEG
salto5:
.def tempo=r16 RCALL barrido
.def ante=r17 rjmp principal
.def tecla=r18
.def aux=r19
.def aux2=r20
.def control=r21 BARRER:
.def conta=r22 LDI tecla,16
.def tecla_control=r23 LDI tempo,0b11111110
.dseg OUT PORTA, tempo
SBIS PINA,4
tcontrol: .byte 1 LDI tecla,15
bcd0: .byte 1 SBIS PINA,5
bcd1: .byte 1 LDI tecla,0x00
bcd2: .byte 1 SBIS PINA,6
bcd3: .byte 1 LDI tecla,14
SBIS PINA, 7
dig0: .byte 1 LDI tecla,13
dig1: .byte 1 LDI tempo,0b11111101
dig2: .byte 1 OUT PORTA, tempo
dig3: .byte 1 SBIS PINA,4
dig4: .byte 1 LDI tecla,0x01
SBIS PINA,5
.cseg LDI tecla,0x02
.org 0x00 SBIS PINA,6
LDI tecla,0x03
LDI tempo,0b00001111 SBIS PINA, 7
OUT DDRA,tempo LDI tecla,12
LDI tempo,0x00 LDI tempo,0b11111011
OUT DDRC,tempo OUT PORTA, tempo
LDI tempo,0b01111111 SBIS PINA,4
OUT DDRB, tempo LDI tecla,0x04
OUT DDRD,tempo SBIS PINA,5
LDI tempo,0b11110000 LDI tecla,0x05
OUT PORTA, tempo SBIS PINA,6
LDI tempo,0b10000000 LDI tecla,6
OUT PORTB, tempo SBIS PINA, 7
OUT PORTD, tempo LDI tecla,11
LDI tempo,0xFF LDI tempo,0b11110111
OUT portC,tempo OUT PORTA, tempo
IN tempo, MCUCR SBIS PINA,4
ANDI tempo, 0b11101111 LDI tecla,7
OUT MCUCR, tempo SBIS PINA,5
;stack LDI tecla,8
LDI tempo, HIGH(RAMEND) SBIS PINA,6
OUT SPH,tempo LDI tecla,9
LDI tempo, LOW(RAMEND) SBIS PINA, 7
OUT SPL,tempo LDI tecla,10
clr conta
LDI ante, 16 CP tecla, ante
rcall inicial BREQ salir
MOV ante, tecla

principal: CPI tecla,16


cpi conta,5 BREQ salir
breq salto MOV tempo, tecla
rcall barrer cpi tecla,10
salto: brcc condicion
cpi conta,1
breq salto5 guardado:
cpi tecla_control,14 ld tempo,-x
breq guardar_numeros out portd,tempo
out portb,control
salir: rcall retardo
ret ser tempo
out portb,tempo;se apaga los displays
guardar_numeros: sec ;se activa el carry
ldi xh,high(tcontrol) rol control
ldi xl,low(tcontrol) dec aux
clr aux brne barrido_lazo
add xl,conta ret
adc xh, aux
ST x,tecla retardo:
inc conta push r24
rjmp salir push r23
ldi r24,10
salto1:
inicial: ldi r23,255
ldi tempo,0b01000000 salto2:
sts dig0,tempo dec r23
sts dig1,tempo brne salto2
sts dig2,tempo dec r24
sts dig3,tempo brne salto1
ret pop r23
pop r24
ret
condicion:
mov tecla_control,tecla tabla_7seg:
rjmp guardado .db 0b10111111,0b10000110
.db 0b11011011,0b11001111
entrar: .db 0b11100110,0b11101101
rjmp principal .db 0b11111101,0b10000111
.db 0b11111111,0b11100111
.db 0b11110111,0b01111100
HEX_7SEG: .db 0b10111001,0b01011110
mov aux,conta .db 0b11111001,0b11110001
subi aux,1
ldi xh,high(bcd0)
ldi xl,low(bcd0)
ldi yh,high(dig0)
ldi yl,low(dig0)
bcd_7seg_lazo:
ldi zh,high(tabla_7seg<<1)
ldi zl,low(tabla_7seg<<1)
ld tempo,x+
add zl,tempo
clr tempo
adc zh,tempo
lpm tempo,z
st y+,tempo
dec aux
brne bcd_7seg_lazo
ret

barrido: ;barrido de displays


ldi xh,high(dig4)
ldi xl,low(dig4)
ldi aux,4
ldi control,0b11111110
barrido_lazo:
ser tempo
out portb,tempo

También podría gustarte