Teste de circuito com Proteus.
Código testado e compilado:
#include <16F877A.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#use delay(clock=4000000)
#include <lcd.c>
int16 q1;
float p, q2;
void main()
{
lcd_init();
setup_adc_ports(AN0); //Canal 0 analógico
setup_adc(ADC_CLOCK_DIV_8); //
set_adc_channel(0); //Habilita canal 0
delay_us(20);
output_high(pin_B0);
while (TRUE)
{
q1 = read_adc(); //Ler canal 0
p = (q1 * 5)/1023.0;
q2 = p * 6;
if (q2 >= 13.8)
{
output_low(pin_b1);
}
if (q2 <= 11.0)
{
output_high(pin_b1);
}
printf(lcd_putc,"\fTensao:%2.2f", q2);
delay_ms (100);
}
}
Duvidas? Perguntas?
Nenhum comentário:
Postar um comentário