martes, 4 de junio de 2013

EJERCICIO 2

Ejercicio 2.- Un programa que permita por medio de 3 pulsadores conectados a la entrada del puerto A, generar 4 secuencias diferentes en 8 leds verdes conectados a través del puerto C, cada secuencia con al menos 5 pasos distintos, 2 pulsadores adicionales modificaran la velocidad, en múltiplos de 300mS, con la que se visualizara cada cambio.

SOLUCIÓN.-

  • CODIGO DESARROLLADO EN MIKROC.
int tiempo =1;                  
 int i;                        
 void Retardo (int tiempo);     
 void interrupt (PORTB)         
 {
 if(INTCON.RBIF)               
  {
  switch(PORTB)                 
  {
      case 0x10:
      tiempo = 3;               
      break;
      case 0x20:
      tiempo = 5;               
      break;
      case 0x30:
      tiempo = 10;
      break;
      default:                 
      tiempo = 1;
      break;
  }
    INTCON.RBIF=0;             
   }
 }
void main()                     
{
 ADCON1=0x06;                   
 trisa=0x03;                    
 trisc=0;                       
 trisb=0X30;                    
 PORTC=0;                       
 INTCON=0x88;                   

 while(1)                        
 {

      if(PORTA.RA0==0)              
{
     PORTC=0x55;                   
     Retardo(tiempo);              
     PORTC=0xAA;
     Retardo(tiempo);
     PORTC=0x55;
     Retardo(tiempo);
     PORTC=0xAA;
     Retardo(tiempo);
     PORTC=0x55;
     Retardo(tiempo);
}
     if(PORTA.RA1==0 )             
  {
     PORTC=0xFF;                   
     Retardo(tiempo);              
     PORTC=0x00;
     Retardo(tiempo);
     PORTC=0xFF;
     Retardo(tiempo);
     PORTC=0x00;
     Retardo(tiempo);
     PORTC=0xFF;
     Retardo(tiempo);
  }
      if(PORTA.RA2==0)               
  {
      PORTC=0xC3;                    
      Retardo(tiempo);               
      PORTC=0x3C;
      Retardo(tiempo);
      PORTC=0xC3;
      Retardo(tiempo);
      PORTC=0x3C;
      Retardo(tiempo);
      PORTC=0xC3;
      Retardo(tiempo);
  }
      if(porta.RA0==1 && porta.RA1==1 && porta.RA2==1 )      
  {
      PORTC=0x0F;                                            
      Retardo(tiempo);                                       
      PORTC=0xF0;
      Retardo(tiempo);
      PORTC=0x0F;
      Retardo(tiempo);
      PORTC=0xF0;
      Retardo(tiempo);
      PORTC=0x0F;
      Retardo(tiempo);
  }
 }
}
    void Retardo (int tiempo)                   
 {
     for(i=0; i<=tiempo; i++)                   
     {
     delay_ms(300);                            
     }
}
  • IMAGEN DEL CIRCUITO DESARROLLADO EN PROTEUS.

FIG.1.- Imagen del circuito en PROTEUS


  • VIDEO EXPLICATIVO.

No hay comentarios.:

Publicar un comentario