Skip to content

Instantly share code, notes, and snippets.

@vduenasg
Last active May 6, 2016 23:06
Show Gist options
  • Select an option

  • Save vduenasg/3157952 to your computer and use it in GitHub Desktop.

Select an option

Save vduenasg/3157952 to your computer and use it in GitHub Desktop.
Interrupciones Externas
// * Author: Victor Dueñas Guardia
// * Info: www.netzek.com
// @Ejemplo:
// El programa cambia el estado del LED correspondiente cada vez que se active el pulsador.
// Pseudocódigo:
// - Configuramos Interrupciones
// - Al producirse una interrupción el LED cambia de estado.
.INCLUDE "M16DEF.INC //Incluye definición archivos ATmega16
.ORG $00
JMP PROGRAMA //Interrupción Reset
.ORG $02
JMP INTER0 //Interrupción 0
.ORG $04
JMP INTER1 //Interrupción 1
PROGRAMA:
LDI R16,HIGH(RAMEND) //Coloco la Pila al final de la RAM
OUT SPH,R16
LDI R16,LOW(RAMEND)
OUT SPL,R16
LDI R16,0B00000011
OUT DDRA,R16 //Puerto A Salida
LDI R16,0B00001010
OUT MCUCR,R16 //INT0 e INT1 Flanco de Bajada
LDI R16,0B11000000
OUT GICR,R16 //INT0 e INT1 Habilitada
SEI
BUCLE: RJMP BUCLE
//......INTERRUPCIONES
INTER0:
CALL RETARDO
LDI R17,0B00000001
CALL CAMBIAR
RETI
INTER1:
CALL RETARDO
LDI R17,0B00000010
CALL CAMBIAR
RETI
//......PROCEDIMIENTOS
CAMBIAR:
IN R16,PINA
EOR R16,R17 //Cambio el estado del LED
OUT PORTA,R16
RET
RETARDO:
LDI R25,31 //Configurado Evitar Rebote
Bucle_Externo:
LDI R24,255
Bucle_Interno:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DEC R24
BRNE Bucle_Interno
DEC R25
BRNE Bucle_Externo
RET
/*
* IntExt.c
*
* Author: Victor Dueñas Guardia
* Info: www.netzek.com
@Ejemplo:
El programa cambia el estado del LED correspondiente cada vez que se active el pulsador.
Pseudocódigo:
- Configuramos Interrupciones
- Al producirse una interrupción el LED cambia de estado.
*/
#include <avr/io.h>
//Incluyo las definiciones del ATmega16
#include <avr/interrupt.h>
//Incluyo las definiciones de las Interrupciones
#include "mdelay.h"
//Incluyo las definiciones de retardo
//__INTERRUPCIONES
ISR(INT0_vect)
{
_delay_ms(300);
//Delay para evitar efecto rebote
PORTA=PINA^0x01;
}
ISR(INT1_vect)
{
_delay_ms(300);
PORTA=PINA^0x02;
}
//__PROGRAMA PRINCIPAL
int main(void)
{
DDRA |= (1<<PA0) | (1<<PA1);
//Puerto A como salida
MCUCR |= (1<<ISC11) | (1<<ISC01);
//INT0 e INT1 Flanco de Bajada
GICR |= (1<<INT1) | (1<<INT0);
//INT0 e INT1 Habilitada
sei();
//Interrupciones habilitadas
while (1)
{
}
//Bucle Infinito
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment