miércoles, 5 de junio de 2013

PRACTICA 3 CALCULADORA CON PIC16F877A

/* PRACTICA 3: programa que permita, a travez de 2 grupos de
4 interuptores(entrada de datos"PORTB")y con 2 pulsadores adicionales(PORTA) seleccionar la operacion aritmeticas fundamentales mostrando en displey el resultado(PORTC)*/





const unsigned int DIGITO[] =
{
0x3F, //Código del dígito 0
0x06, //Código del dígito 1
0x5B, //Código del dígito 2
0x4F, //Código del dígito 3
0x66, //Código del dígito 4
0x6D, //Código del dígito 5
0x7D, //Código del dígito 6
0x07, //Código del dígito 7
0x7F, //Código del dígito 8
0x6F, //Código del dígito 9
};
void verdisplay(int numero);//funcion para visualizas valores display
int numero,val1,val2,x,y;
void main(){
ADCON1=7;
TRISA=3;    //ENTRADAS 11
TRISB=255;  //ENTRADAS
TRISC=0;    //salidas
TRISD=0;
PORTC=0;
PORTD=0;
        while(1)
        {
        x=PORTA;      //seleccion de operacion
        val1=PORTB&0b00001111; //filtro
        y=PORTB&0b11110000;
        val2=y>>4;             //filtro valor 2
     
        switch(x)
        {
         case 0: //suma
         numero=val1+val2;
         verdisplay(numero);//llamado de la funcion
         break;
         case 1:  //resta
         numero=val1-val2;
         verdisplay(numero);
         break;
         case 2:   //multiplicacion
         numero=val1*val2;
         verdisplay(numero);
         break;
         case 3:   //divicion
         numero=val1/val2;
         verdisplay(numero);
         break;
        }
        }
}
void verdisplay (int numero)
{
int U,D,C;
C=numero/100; //primer numero
D=(numero-C*100)/10; //segundo numero
U=numero-C*100-D*10; //tercer numero
PORTC=DIGITO[C]; //VALOR CENTENAS
PORTD=1;         //ENCENDEMOS
Delay_ms(50);
PORTD=0;
PORTC=DIGITO[D]; //VALOR DECENAS
PORTD=2;         //ENCENDEMOS
Delay_ms(50);
PORTD=0;
PORTC=DIGITO[U]; //VALOR UNIDADES
PORTD=4;         //ENCENDEMOS
Delay_ms(50);
PORTD=0;

}

SIMULACION Y CODIGO GENERADO EN MIKROC.
http://www.mediafire.com/?ebgf7d575eg1mth

3 comentarios:

  1. Muchisimas gracias por la información me fue muy útil

    ResponderBorrar
  2. gracias, esta completa tu info, solo que lasimulación me marca errores

    ResponderBorrar
  3. The Best Online Casinos in the Netherlands | LuckyClub
    Looking for a casino site that provides the luckyclub.live best real money casino games? Check out the list of top 10 list of the best online casinos in the Netherlands

    ResponderBorrar