Вы находитесь на странице: 1из 11

Escuela Politcnica Nacional

Facultad de Ingeniera Elctrica y Electrnica


Sistemas Microprocesados
Deber N.1 Segundo Bimestre
Tema: Interrupciones y Barrido de Display
Elaborar un programa que permita tener tres jugadores de bsquet, a cada uno de ellos se los
controlar por medio de una interrupcin externa. Al aplastar el correspondiente switch de cada
jugador se incrementar un contador, mismo que al llegar a 20 en cualquiera de los casos encender
un led para posteriormente apagar todo e iniciar nuevamente.
.include "m164pdef.inc"
.def
.def
.def
.def

tempo=r16
aux=r17
aux1=r18
aux2=r19

.org 0x00
rjmp inicio
.org 0x06
rjmp playerA
.org 0x02
rjmp playerB
.org 0x04
rjmp playerC
.cseg
.org 0x0E
inicio:
clr tempo
out ddrd, tempo
out ddrb, tempo
out ddrc, tempo
ser tempo
out portd, tempo
out portb, tempo
out portc, tempo
ldi tempo, 0b00000111
out ddra, tempo
ldi tempo, 0b11111000
out porta, tempo
in tempo, mcucr
andi tempo, 0b11101111
out mcucr, tempo
ldi tempo, high (ramend)
out sph, tempo
ldi tempo, low (ramend)
out spl, tempo
ldi tempo, 0b00101010
sts EICRA, tempo
ldi tempo, 0b00000111
out EIMSK, tempo
out EIFR, tempo

sei
lazo:
cpi aux, 20
breq encenderA
clr tempo
out porta, tempo
cpi aux1, 20
breq encenderB
clr tempo
out porta, tempo
cpi aux2, 20
breq encenderC
clr tempo
out porta, tempo
rjmp lazo
playerA:
push r16
in r16, sreg
push r16
inc aux
pop r16
out sreg, r16
pop r16
reti
playerB:
push r16
in r16, sreg
push r16
inc aux1
pop r16
out sreg, r16
pop r16
reti
playerC:
push r16
in r16, sreg
push r16
inc aux2
pop r16
out sreg, r16
pop r16
reti
encenderA:
ldi tempo, 0b00000001
out porta, tempo
rcall retardo
ret
encenderB:
ldi tempo, 0b00000010
out porta, tempo
rcall retardo
ret
encenderC:

ldi tempo, 0b00000100


out porta, tempo
rcall retardo
ret
retardo:
ldi r22,100
_lazo_retardo1s:
rcall _retardo_10m
dec r22
brne _lazo_retardo1s
ret
_retardo_10m:
ldi r21,100
_lazo_retardo2:
ldi r20,200
_lazo_retardo1:
dec r20
nop
brne _lazo_retardo1
dec r21
brne _lazo_retardo2
ret

Simulacin:

Variacin del Programa: A continuacin se presenta el mismo programa, realizado nicamente para
dos jugadores de baloncesto, en el cual se ha utilizado barrido de displays para representar el
marcador de cada uno
.include "m164pdef.inc"
.def
.def
.def
.def

tempo=r16
aux=r17
aux1=r18
aux2=r19

.dseg
binario: .byte 1
bcd0: .byte 2
dig0: .byte 2
.cseg
.org 0x00
rjmp inicio
.org 0x02
rjmp playerA
.org 0x04
rjmp playerB
inicio:

ldi tempo, 0b00001111


out ddrb, tempo
ser tempo
out portb, tempo
ldi tempo, 0b00000000
out ddrd, tempo
ldi tempo, 0b11111111
out portd, tempo
ldi tempo, 0b01111111
out ddra, tempo
out ddrc, tempo
ldi tempo, 0b10000000
out porta, tempo
out portc, tempo
in tempo, mcucr
andi tempo, 0b11101111
out mcucr, tempo
ldi tempo, high (ramend)
out sph, tempo
ldi tempo, low (ramend)
out spl, tempo
ldi tempo, 0b00101010
sts EICRA, tempo
ldi tempo, 0b00000111
out EIMSK, tempo
out EIFR, tempo
clr aux
clr aux1
sei
lazo:
call bin2bcd
call bcd7seg
call barridoA
cpi aux, 20
breq encenderA
clr tempo
out porta, tempo
cpi aux1, 20
breq encenderB
clr tempo
out porta, tempo
cpi aux2, 20
rjmp lazo
playerA:
push r16
in r16, sreg
push r16
inc aux
pop r16
out sreg, r16
pop r16
reti
playerB:
push r16

in r16, sreg
push r16
inc aux1
call encenderB
pop r16
out sreg, r16
pop r16
reti
encenderA:
sts binario, aux
call bin2bcd
call bcd7seg
call barridoA
ret
encenderB:
sts binario, aux1
call bin2bcd
call bcd7seg
call barridoB
ret

bin2bcd:
push r16
push r17
lds r16, binario
clr r17
decena:
subi r16, 10
brcs unidades
inc r17
rjmp decena
unidades:
subi r16, -10
sts bcd0+1, r17
sts bcd0, r16
pop r17
pop r16
ret
bcd7seg:
push
push
push
push
push
push
push
push
ldi
ldi
ldi
ldi
ldi

r16
r17
zh
zl
xl
xh
yl
yh

xh, high(bcd0)
xl, low(bcd0)
yh, high(dig0)
yl, low(dig0)
r17, 2

traer:
ldi zh, high(tabla<<1)
ldi zl, low(tabla<<1)

ld r16, x+
add zl, r16
clr r16
adc zh, r16
lpm r16, Z
st y+, r16
dec r17
brne traer
pop yh
pop yl
pop xh
pop xl
pop zl
pop zh
pop r17
pop r16
barridoA:
push r16
push r17
push yh
push yl
push r18
ldi r17, 2
ldi r18, 0b11111110
ldi yh, high(dig0)
ldi yl, low(dig0)
barrido_1a:
ldi r16, 0b11111111
out portb, r16
ld r16, y+
out porta, r16
out portb, r18
call retardo_barrido
sec
rol r18
dec r17
brne barrido_1a
ldi r16, 0b11111111
out portb, r16
pop r18
pop yl
pop yh
pop r17
pop r16
retardo_barrido:
ldi r19, 0xFF
ret1:
dec r19
brne ret1
ret
barridoB:
push r16
push r17
push yh
push yl
push r18
ldi r17, 2
ldi r18, 0b11111110
ldi yh, high(dig0)
ldi yl, low(dig0)

barrido_1b:
ldi r16, 0b11111111
out portb, r16
ld r16, y+
out portc, r16
out portb, r18
call retardo_barrido
sec
rol r18
dec r17
brne barrido_1b
ldi r16, 0b11111111
out portb, r16
pop r18
pop yl
pop yh
pop r17
pop r16
tabla:
.db
.db
.db
.db
.db
.db
.db

0b10111111,0b10000110
0b11011011,0b11001111
0b11100110,0b11101101
0b11111101,0b10000111
0b11111111,0b11100111
0b11110111,0b11111100
0b10111001,0b11001000

Variacin del Programa: A continuacin se presenta el mismo programa, buscando realizar el barrido
para 6 displays
.include "m164pdef.inc"
.def
tempo = r16
.def
contador1=r17
.def
contador2=r18
.def
contador3=r19

.def

aux=r20

.dseg
C1H: .byte 1
C1L: .byte 1
C2H: .byte 1
C2L: .byte 1
C3H: .byte 1
C3L: .byte 1
dig1: .byte 1
dig2: .byte 1
dig3: .byte 1
dig4: .byte 1
dig5: .byte 1
dig6: .byte 1
binariobcd: .byte 6
numeros: .byte 6
.cseg
.org 0x00
rjmp inicio
.org 0x02
rjmp jugadorA
.org 0x04
rjmp jugadorB
.org 0x06
rjmp jugadorC
inicio:
ldi tempo, 0b11111111
out ddra,tempo
out ddrc,tempo
clr tempo
out ddrd,tempo
ser tempo
out portd,tempo
ldi tempo,0b00111000
out ddrb,tempo
ldi tempo,0b11000111
out portb,tempo
in tempo, mcucr
andi tempo,0b11101111
out mcucr,tempo
ldi tempo,high(RAMEND)
out sph,tempo
ldi tempo,low(RAMEND)
out spl,tempo
clr
clr
clr
clr

contador1
contador2
contador3
aux

ldi tempo,0b10111111
sts dig1,tempo
sts dig2,tempo
sts dig3,tempo
sts dig4,tempo
sts dig5,tempo
sts dig6,tempo

ldi tempo,0b00101010
sts EICRA,tempo
ldi tempo,0b00000111
out EIMSK,tempo
out EIFR,tempo
sei
lazo:
call bcd7seg
call barridodisplays
rjmp lazo
jugadorA:
push R16
in R16,SREG
push R16
inc contador1
call bin2bcd
sts C1L,tempo
sts C1H,aux
pop R16
out SREG,R16
pop R16
reti
jugadorB:
push R16
in R16,SREG
push R16
inc contador2
call bin2bcd
sts C2L,tempo
sts C2H,aux
pop R16
out SREG,R16
pop R16
reti
jugadorC:
push R16
in R16,SREG
push R16
inc contador3
call bin2bcd
sts C3L,tempo
sts C3H,aux
pop R16
out SREG,R16
pop R16
reti
bcd7seg:
push r16
PUSH r17
push zh
push zl
push xl
push xh
push yl
push yh
ldi xh,high(binariobcd)
ldi xl,low(binariobcd)
ldi yh,high(numeros)
ldi yl,low(numeros)
ldi R17,6

bcd7seg_1:
ldi zh,high(Tabla<<1)
ldi zl,low(Tabla<<1)
ld R16,x+
add zl,R16
clr R16
adc ZH,R16
lpm R16,z
st y+,R16
dec R17
brne bcd7seg_1
pop r16
pop r17
pop zh
pop zl
pop xl
pop xh
pop yl
pop yh
ret
barridodisplays:
push R16
push R17
push yh
push yl
push R18
ldi r17,6
ldi r18,0b11111110
ldi yh,high(numeros)
ldi yl,low(numeros)
bcd_7seg_01:
ldi R16,0b11111111
out porta,R16
ld R16,y+
out porta,R16
out portc,R18
call retardo
sec
rol r18
dec r17
brne bcd_7seg_01
ldi R16,0b1111111
out portA,r16
pop R16
pop R17
pop yh
pop yl
pop R18
ret
retardo:
ldi r19, 0xFF
ret1:
dec r19
brne ret1
ret
bin2bcd:
clr
bcd1:
subi
brcs
inc
rjmp

aux
tempo,10
bcd2
aux
bcd1

bcd2:
subi tempo,-10
ret
Tabla:

.db
.db
.db
.db
.db
.db
.db

0b10111111,0b10000110
0b11011011,0b11001111
0b11100110,0b11101101
0b11111101,0b10000111
0b11111111,0b11100111
0b11110111,0b11111100
0b10111001,0b11001000

Вам также может понравиться