ejercicos en atmega 164p uso de interrupciones y teclado matricial

7
ESCUELA POLITECNICA NACIONAL SISTEMAS MICROPROCESADOS NOMBRE: Wilmer Villegas FECHA: 10 04 2012 1. Realice un programa para contar objetos mediante interrupciones. 1 . Cuento el número de botellas con un pulsante 2 . Muestro en displays el número de cajas, usar Barrido de displays .include"m164pdef.inc" .def tempo=r17 .def aux=r18 .def conta=r19 .def conta1=r20 .org 0x00 jmp main .org 0x02 jmp contar main: ; defino como salidas ser tempo out ddra,tempo ; defino como entrada clr tempo out ddrd,tempo ; activo pull-up ldi tempo,0b00000100 out portd,tempo ; garantizo pull-up in tempo,mcucr andi tempo,0b11101111 out mcucr,tempo ; declaro el stack pointer ldi tempo,high(ramend) out sph,tempo ldi tempo,low(ramend) out spl,tempo ; habilito la int0 ldi tempo,0b00000001 out eimsk,tempo ;especifico como se desencadena l a interrupción como flanco de bajada ldi tempo,0b00000010 sts EICRA,tempo ;habilitacion global de interrupciones s e i clr conta clr conta1 l a z o : out porta,conta1 rjmp lazo c o n t a r : push tempo 12 botellas 1 caja

Transcript of ejercicos en atmega 164p uso de interrupciones y teclado matricial

ESCUELA POLITECNICA NACIO NAL SISTEMAS MICROPROCESADOS NOMBRE: Wil mer Villegas FECHA: 10 04 2012 1. Realice un programa para contar objet os mediante interrupciones .

12 botellas 1 caja

1. Cuento el nmero de botellas

con un pulsante

2. Muestro en displays el nmero de caj as, usar Barrido de displays

.include" m164pdef.inc" .def .def .def .def tempo=r17 aux=r18 conta=r19 conta1=r20

.org 0x00 j mp main .org 0x02 j mp contar main: ; defino como salidas ser tempo out ddra,tempo ; defino como entrada clr tempo out ddrd,tempo ; activo pull -up ldi tempo,0b00000100 out portd,tempo ; garanti zo pull -up in tempo,mcucr

andi tempo,0b11101111 out mcucr,tempo ; declaro el stack pointer ldi tempo,hi gh(ramend) out sph,tempo ldi tempo,low(ramend) out spl,tempo ; habilito la int0 ldi tempo,0b00000001 out ei msk,tempo ;especifico como se desencadena la interrupcin como flanco de baj ada ldi tempo,0b00000010 sts EICRA,tempo ;habilitacion global de interrupciones sei clr conta clr conta1 lazo: out porta,conta1 rj mp lazo contar: push tempo

in tempo,sreg push tempo inc conta cpi conta,12 brne contador clr conta inc conta1

contador: pop tempo out sreg,tempo pop tempo reti

Lo pri mero que voy hacer es revisar si el programa me funciona con el uso de leds a la salida para luego usar una subrutina para el barrido de displays.

Como podemos ver al presionar el pulsador y llegue hasta 12 botellas en los leds a salida me va dar sol amente el nmero de caj as.

Diagrama de f lujo:

2. Programa que m uestre en un display la tecla presionada del teclado matricial 4x4 Segundo mtodo: .include" m164pdef.inc" .def .def .def .def .def .equ .equ .equ .equ .equ .equ .equ .equ tempo=r17 tecla=r18 aux=r19 dato=r20 aux1=r21 fila1=3 fila2=2 fila3=1 fila4=0 colum1=7 colum2=6 colum3=5 colum4=4 ldi tecla,12 ldi tempo,0b00001111 out ddra,tempo ldi tempo,0b11110000 out porta,tempo rebote: ldi aux,255 lazo: dec aux brne lazo sbis pina,colum1 ldi tempo,0 sbis pina,colum2 ldi tempo,1 sbis pina,colum3 ldi tempo,2 sbis pina,colum4 ldi tempo,3 add tecla,tempo add r30,tecla clr aux1 adc r31,aux lpm dato,z out portb,aux ldi tempo,0b11110000 out ddra,tempo ldi tempo,0b00001111 out porta,tempo fin:rj mp fin ret tabla: .db 1,2,3,15,4,5,6,14,7,8,9,13,10,0,11,12

.cseg ldi tempo,0b11111111 out ddrb,tempo ldi tempo,0b11110000 out ddra,tempo ldi tempo,0b00001111 out porta,tempo ldi r30,low(tabla