Está en la página 1de 4

/*

* File: proyecto_1.c
* Author: Alexis Rodriguez
*
* Created on 20 de agosto de 2019, 07:26 PM
*/

#include <xc.h>
#pragma config OSC = XT //SELECCION DE OSCILADOR
#pragma config PWRT = ON // POWER-UP TIMER ENABLE CONTADOR
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF
#define _XTAL_FREQ 4000000 //FRECUENCIA A LA QUE SE TRABAJA
#define ENABLE1 LA4
#define ENABLE2 LA5

char ejecutar (char selector);


void visualizar(void);
char oper1,oper2,operacion,resultado;
void retardo (void);
void configuracion(void);
char opcion,x,selector;
char numeros[16][3]={
0XF8,0X88,0XF8,
0X02,0X04,0XF8,
0XB8,0XA8,0XE8,
0XA8,0XA8,0X50,
0XE0,0X20,0XF8,
0XE8,0XA8,0XB8,
0X08,0XB8,0XC0,
0XF8,0XA8,0XF8,
0XE0,0XA0,0XF8,
0XF8,0XA0,0XF8,
0XF8,0X28,0X38,
0X70,0X88,0X88,
0X38,0X28,0XF8,
0XF8,0XAB,0XA8,
0XF8,0XA0,0XA0
};
char simcharbolos[9][3]={
0X20,0XF8,0X20,
0X20,0X20,0X20,
0X50,0X20,0X50,
0X20,0XA8,0X20,
0X50,0X50,0X50,
0X40,0X50,0X40,
0X10,0XF0,0X10,
0X10,0X10,0X10,
0X58,0X20,0X58
};

void main(void)
{
configuracion();
while(1)
{

oper1=PORTD&0x0f;
oper2=(PORTD&0xf0)>>4;
operacion=PORTA&0x07;
resultado=ejecutar(operacion);
visualizar();
}

void configuracion(void)
{
TRISA= 0B00000111;
TRISB= 0x00;
TRISC= 0x00;
TRISD= 0xff;
ADCON1= 0x06;
}

void retardo (void)


{
__delay_ms(100);
}

char ejecutar (char selector)


{
char opcion;

switch (selector)
{
case 0 :
opcion=oper1+oper2;
break;
case 1:
opcion=oper1-oper2;
break;
case 2:
opcion=oper1*oper2;
break;
case 3:
opcion=oper1/oper2;
break;
case 4:
opcion=oper1&oper2;
break;
case 5:
opcion=oper1|oper2;
break;

case 6:
opcion=~(oper1|oper2);
break;
default:
opcion=oper1^oper2;
break;

}
return(opcion);
}

void visualizar(void)
{
char x;
while (a<1){

for (x=0;x<3;x++)
{
LATB=~numeros[oper1][x];
LATC=x; //PINES QUE VAN AL DECO
ENABLE1=1;
ENABLE2=0;
retardo();
}

for (x=0;x<3;x++)
{
LATB=~oper[operacion][x];
LATC=x+4; //PINES QUE VAN AL DECO
ENABLE1=1;
ENABLE2=0;
retardo();
}

for (x=0;x<3;x++)
{
LATB=~numeros[oper2][x];
LATC=x; //PINES QUE VAN AL DECO
ENABLE1=0;
ENABLE2=1;
retardo();
}

for (x=0;x<3;x++)
{
LATB=~0x12;
LATC=x; //PINES QUE VAN AL DECO
ENABLE1=0;
ENABLE2=1;
retardo();
}
a++;
}
while (a<1){
for (x=0;x<3;x++)
{
LATB=~numeros[(resultado&0xF0)>>4][x];
LATC=x+2; //PINES QUE VAN AL DECO
ENABLE1=1;
ENABLE2=0;
retardo();
}

for (x=0;x<3;x++)
{
LATB=~numeros[resultado&0x0F][x];
LATC=x+2; //PINES QUE VAN AL DECO
ENABLE1=0;
ENABLE2=1;
retardo();
}

a++;
}
}

void retardo (void)


{
__delay_ms(10);
}

for(x=0;x<3;x++)
{
LATB=numeros[oper1][x];
LATC=x;
ENABLE1=1;
ENABLE2=0;
retardo();
}
}

También podría gustarte