You are on page 1of 2

#include <18F4550.

h>
#device adc = 8
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay(clock = 20 000000)
#byte porta = 0xF80
#byte portd = 0xF83
#byte portb = 0xf81
#define LCD_DATA_PORT getenv("SFR:PORTD")
#include <lcd.c>

int16 lecturaADC = 255;

void inicioADC(){
set_tris_a(0xff);
set_tris_d(0x00);
set_tris_b(0x00);
output_d(0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(AN0);
set_adc_channel(0);
}

void main(void){
lcd_init();
inicioADC();
float voltaje;
float conversion;

while(TRUE){
set_adc_channel(0);
delay_us(10);
lecturaADC = read_adc();
lcd_gotoxy(1,1);
printf(lcd_putc, "VOLTAJE:");
delay_us(100);

voltaje = (5.0 / 255) * lecturaADC;


lcd_gotoxy(10,2);
printf(lcd_putc, " %.2FV ", voltaje);
delay_us(10);

conversion=(lecturaADC);
lcd_gotoxy(1,2);
printf(lcd_putc, " %.1F ", conversion);
delay_us(10);

if(voltaje<=2){
output_b(0b1010);

if(voltaje>2){
output_b(0b0000);

if(voltaje>=4){
output_b(0b0101);
}

}
}

You might also like