viernes, 3 de septiembre de 2010

CONTEO DE 4 BITS CON INTERRUPCIONES USANDO IFS

#include /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#define ON 0
#define OFF 1
#define LED1 PTFD_PTFD0
#define LED2 PTFD_PTFD1
#define LED3 PTFD_PTFD3
#define LED4 PTFD_PTFD4
#define SW1 PTGD_PTGD0
#define SW2 PTGD_PTGD1

void escribeLEDs(char dato);

unsigned char x;

void main(void){
EnableInterrupts;
SOPT_COPE=0;

PTFDD_PTFDD0=1; //INICIALIZA PUERTO PARA LED
PTFDD_PTFDD1=1;
PTFDD_PTFDD4=1;
PTFDD_PTFDD5=1;
PTFDS_PTFDS0=1;
PTFDS_PTFDS1=1;
PTFDS_PTFDS4=1;
PTFDS_PTFDS5=1;


PTGDD_PTGDD0=0; //INICIALIZA PUERTO PARA SW
PTGDD_PTGDD1=0;
PTGPE_PTGPE0=1;
PTGPE_PTGPE1=1;

/*Inicializa KBI SW1 SW2*/
KBISC_KBIMOD=0; //SOLO TRANSICION
KBIPE_KBIPE0=1; //HABILITA PINES KBI
KBIPE_KBIPE1=1;
KBISC_KBIE=1; //HABILITA INTERRUPCION
x=0;
for(;;)
{ }
}

void interrupt 26 isrkbi(void){
if(SW1==ON)
{
if(x==15)
x=15;
else
x++;
}
if(SW2==ON)
{
if(x==0)
x=0;
else
x--;
}
KBISC_KBACK = 1; //Confirma haber recibido y atendido la interrupción
escribeLEDs(x);
}

void escribeLEDs(char dato){
char aux1,aux2;
aux1=PTFD & 0xCC;
aux2=dato<<2;
aux2=aux2&0x30 | dato&0x03;
aux1|=aux2;
PTFD=aux1^0x33;
}

No hay comentarios:

Publicar un comentario