viernes, 7 de junio de 2013

EJERCICIO 5

Ejercicio 5.- Un programa que permita a través de un teclado 4x4 conectado al microcontrolador, realizar las 4 operaciones aritméticas básicas mostrando el resultado por medio de un LCD, tomando como referencia las siguientes leyendas:




SOLUCIÓN.


  • CÓDIGO DESARROLLADO EN MIKROC.

char  keypadPort at PORTD;
sbit LCD_RS at RB0_bit; sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN at RB1_bit; sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4 at RB2_bit; sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5 at RB3_bit; sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6 at RB4_bit; sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7 at RB5_bit; sbit LCD_D7_Direction at TRISB5_bit;

char teclas[] = {'7','8','9','/','4','5','6','*','1','2','3','-','.','0','=','+'};
char numero[9];
float lvalue, rvalue;
char op, flags, resultado[16];

#define CALCULO_OK flags.F0

#define NEGATIVO flags.F1
#define lcd_clear() lcd_cmd(_LCD_CLEAR);
#define LimparNumero for(i=0;i<8;i++) *(numero + i) = 0;


static char keyRead(char keys[])
{
 char key;

 key = keypad_key_press();
 if(key != 0) return keys[key-1];
 return 0;
}

void main()
{
char k, pos, op, i;

   keypad_init();
   Lcd_Init();
   Lcd_Cmd(_LCD_CLEAR);
   Lcd_Cmd(_LCD_CURSOR_OFF);

   while(1)
   {
       k = keyRead(teclas);

       if(CALCULO_OK)
       {
        pos = 0;
        CALCULO_OK = 0;
        lcd_clear();
        lcd_cmd(_LCD_RETURN_HOME);
        for(i=0;i<8;i++){
         *(numero + i) = 0;
          *(resultado + i) = 0;
          *(resultado +i + 8) = 0;
        }
       }

       if((k>='0' && k<='9') || k=='.')
       {
          *(numero + pos++) = k;
          if(pos >= 8) pos = 0;
          lcd_Out_CP((numero+(pos-1)));
       }
       else if(k == '+' || k=='-' || k=='/' || k=='*')
       {
           op = k;
           pos = 0;
           lcd_chr_CP(op);
           lvalue = atof(numero);
           LimparNumero;
       }
       else if(k == '=')
       {
           rvalue = atof(numero);
           NEGATIVO = 0;
           lcd_chr_CP('=');
           switch(op)
           {
            case '+':
             lvalue += rvalue;
             break;
            case '-':
            if(lvalue >= rvalue)
            {
               lvalue -= rvalue;
            }
            else
            {
               lvalue = rvalue - lvalue;
               NEGATIVO = 1;
            }
            break;
            case '/':
            if(rvalue!=0)lvalue /= rvalue;
            else lvalue = 0;
            break;
            case '*':
            lvalue *= rvalue;
            break;
           }


           floattostr(lvalue, (resultado  + NEGATIVO));
           if(NEGATIVO) *(resultado) = '-';
           lcd_out(1,1,"El resultado");
           Lcd_Cmd(_LCD_SECOND_ROW);
           delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);
           lcd_out(1,1,"de la:");


               switch(op)
               {
                case '+':
                  lcd_out(1,7,"suma");
                  break;
                case '-':
                  lcd_out(1,7,"resta");
                  break;
                case '*':
                  delay_ms(1000);
                  lcd_Cmd(_LCD_CLEAR);
                  lcd_out(1,2,"multiplicacion");
                  break;
                case '/':
                  lcd_out(1,7,"division");
                  break;
                }

           delay_ms(1000);
           Lcd_Cmd(_LCD_CLEAR);
           lcd_out(2,1,"es:");
           Lcd_Cmd(_LCD_SECOND_ROW);
           lcd_out(2, 5,resultado);
           delay_ms(2000);
           CALCULO_OK = 1;
           }
   delay_ms(200);
}

  • DIAGRAMA DE FLUJO DE LA SOLUCIÓN.



  • IMAGEN DEL CIRCUITO DESARROLLADO EN PROTEUS.

FIG.1- Diagrama del circuito desarrollado en PROTEUS.


  • VÍDEO EXPLICATIVO.

miércoles, 5 de junio de 2013

EJERCICIO 3

Ejercicio 3.- Un programa que permita, a través de 2 grupos con 4 interruptores (entrada de datos) y 1 con 2 pulsadores (selección de la operación) conectados al puerto B y A del microcontrolador respectivamente, realizar las 4 operaciones aritméticas fundamentales, mostrando el resultado correspondiente en 2 displays de 7 segmentos.




SOLUCION.

  • CODIGO DESARROLLADO EN MIKROC.

 int num1=0;
 int num2=0;
 int result=0;

 void main()
 {
       ADCON1=0x06;
       TRISA=0x03;
       TRISB=0xFF;
       TRISC=0;  

       while(1){
 
                num1 = portb & 0x0F;
                num2 = portb & 0xF0;
                num2 = num2>>4;
 
                 switch (PORTA)
                     {
                        case 0x00:            
                        result=num1+num2;
                        break;
                        case 0x01:            
                        result=num1-num2;    
                        break;
                        case 0x02:            
                        result= num1*num2;        
                       break;
                       case 0x03:            
                       result=num1/num2;
                       break;
                   }
            portc=result;
     }

}


  DIAGRAMA DE FLUJO DE LA SOLUCION

  • IMAGEN DEL CIRCUITO DESARROLLADO EN PROTEUS
FIG.1.- IMAGEN DEL CIRCUITO EN PROTEUS

  • VIDEO EXPLICATIVO.

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.

domingo, 2 de junio de 2013

PORTADA

INSTITUTO TECNOLÓGICO DE OAXACA 


INGENIERÍA ELECTRÓNICA


MICROCONTROLADORES Y MICROPROCESADORES
GRUPO: E1U


EJERCICIOS DE LA  UNIDAD III 


PROFESOR:
ING. CABALLERO CABALLERO MARCO ANTONIO


PRESENTA:
LAGUNAS JIMENEZ  MARCO ANTONIO 

NUM. CONTROL: 09160467



EJERCICIO 1.

Un programa que permita a través del Puerto D mostrar el incremento binario (haciendo uso de LEDs) de una cantidad inicialmente en 0, de acuerdo a la selección realizada por medio de dos interruptores conectados al Puerto B del microcontrolador.


SOLUCION.
  • CODIGO DESARROLLADO EN MIKROC
void main()                                         
{
      TRISD=0b00000000;                 

      PORTD=0b00000000;                 .

      INTCON=0b10010000;               

      OPTION_REG.INTEDG=1;        

         while(1)                                     
          {
          }
}                                                     

void interrupt()                               
{
     PORTD++;                                

     INTCON.INTF=0;                       

}                                                     



Diagrama de flujo de la solución.



  • IMAGEN DEL CIRCUITO DESARROLLADO EN PROTEUS


Fig.1.- Circuito desarrolado en PROTEUS.



  • VIDEO EXPLICATIVO

               
Nota: Favor de ampliar el vídeo para poder apreciarlo mejor. Gracias.