You are on page 1of 3

// CONFIG1

#pragma config FOSC = HS // Oscillator Selection (HS Oscillator, High-speed


crystal/resonator connected between OSC1 and OSC2 pins)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = ON // Power-up Timer Enable (PWRT enabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function
is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program
memory code protection is disabled)
#pragma config CPD = OFF // Data Memory Code Protection (Data memory code
protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled.
I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External
Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock
Monitor is enabled)

// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write
protection off)
#pragma config VCAPEN = OFF // Voltage Regulator Capacitor Enable (All VCAP pin
functionality is disabled)
#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack
Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out
Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = OFF // Low-Voltage Programming Enable (High-voltage on
MCLR/VPP must be used for programming)

// #pragma config statements should precede project file includes.


// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#define _XTAL_FREQ 20000000
#include <stdio.h>

unsigned char unidades, decenas, centenas, miles,diezmiles;


int digital,y;
unsigned int voltaje, aux;

void binbcd(void) {
diezmiles = 0;
miles = 0;
unidades = 0;
decenas = 0;
centenas = 0;
aux = voltaje;

while (aux >= 10000){


aux = aux - 10000;
diezmiles = diezmiles + 1;
}

while (aux >= 1000){


aux = aux - 1000;
miles = miles + 1;
}
while (aux >= 100) {
aux = aux - 100;
centenas = centenas + 1;
}
while (aux >= 10) {
aux = aux - 10;
decenas = decenas + 1;
}
unidades = aux;
}

void multiplex(void) {
for (y = 0; y <= 100; y++)
PORTD = 0x01;
PORTC = diezmiles;
__delay_ms(1);
PORTD = 0x02;
PORTC = centenas;
__delay_ms(1);
PORTD = 0x04;
PORTC = decenas;
__delay_ms(1);
}

void main() {

ANSELE = 0X01;
ANSELD = 0;
LATA = 0;
TRISE = 0X01;
ANSELB = 0;
TRISB = 0;
TRISC = 0x80;
TRISD = 0;
LATB = 0;
LATD = 0;
LATC = 0;
PORTD = 0;
PORTC = 0;

ADCON0 = 0X15;
ADCON1 = 0XF0;

while (1) {
GO = 1;
while (GO)
continue;

digital = (ADRESL + ADRESH * 256);


voltaje = digital * 49;
binbcd ();
multiplex();

}
}

You might also like