#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#device adc=10
#use delay (clock=20000000)
#use rs232 (BAUD = 9600 , XMIT = PIN_C6 , RCV = PIN_C7 , BITS = 8)
#include "LCD.c"
#include "KBD.c"
//declaracion de puertos
#byte PORTA=0x05
#byte TRISA=0x85
#byte PORTC=0x07
#byte TRISC=0x87
#byte PORTD=0x08
#byte TRISD=0x88
#byte PORTB=0x06
#byte TRISB=0x86
#define R_SHUNT 0.01
char valor;
//unsigned long AD_read=0;
#int_rda
void serial_isr()
{
valor = getc();
}
void PORT_init(void)
{
TRISA=0xFF;
TRISD=0x00;
TRISC=0x00;
TRISB=0x00;
PORTC=0x00;
PORTD=0x00;
}
void MCU_Init(void)
{
Port_init();
setup_adc(ADC_CLOCK_DIV_32);
setup_adc_ports(ALL_ANALOG);
lcd_init();
kbd_init();
port_b_pullups(true);
}
void main()
{
int16 q;
float v1,v2,ISH;
char k;
int opt;
MCU_Init();
enable_interrupts(global);
enable_interrupts(int_rda);
printf(lcd_putc,"SENSOR CORRIENTE");
delay_ms(1000);
lcd_gotoxy(1,1);
printf(lcd_putc,"\fElija una opcion");
lcd_gotoxy(1,2);
printf(lcd_putc,"Voltajes(1,2)");
delay_ms(1000);
while(TRUE)
{
delay_ms(500);
output_high(pin_b0);
delay_ms(500);
output_low(pin_b0);
/*k = kbd_getc();
opt=k-48;
set_adc_channel(0);
delay_us(20);
q = read_adc();
v1 = 5.0*q/1024.0;
set_adc_channel(1);
delay_us(20);
q = read_adc();
v2 = 5.0*q/1024.0;
//calculo de la corriente que pasa por la resistencia Shunt
ISH = (v1 - v2)/R_SHUNT;
switch(opt)
{
case 1:
printf(lcd_putc,"\fVoltaje1: %01.2fV",v1);
delay_ms(50);
break;
case 2:
printf(lcd_putc,"\fVoltaje2: %01.2fV",v2);
delay_ms(50);
break;
default:
break;
}
printf(lcd_putc,"\fVoltaje1: %01.2fV",v1);
printf(lcd_putc,"\nVoltaje2: %01.2fV",v2);
printf("\fCorriente: %01.2fA",ISH);
delay_ms(100);*/
}
}