Você está na página 1de 5

Configurando Entrada Analgica CCS PIC C Compiler

No caso acima, configurei 3 entradas analgicas, para os pinos RA0, RA1 e RA3, com resoluo de 0 a 1023, ou seja: se a tenso de entrada for 0V, o valor da entrada analgica ser 0. Se a tenso de entrada for 5V, o valor da entrada analgica ser 1023. Se a tenso for 2,5V, portanto, fazendo regra de 3, sabemos que o valor da entrada analgica ser de 511. Ou seja, o valor da entrada analgica PROPORCIONAL tenso.

Exemplo 1 Lendo o valor de 1 entrada analgica e convertendo para valor de tenso

Cdigo Exemplo 1
#include "C:\Users\GabrielDell\Documents\picentradas\EntradaAnalogica.h" #define LCD_DATA_PORT getenv("SFR:PORTB") #include <LCD.C>

int16 leitura; void main() { setup_adc_ports(AN0_AN1_AN3); setup_adc(ADC_CLOCK_INTERNAL); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED);

setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); lcd_init();

inicio: printf(lcd_putc,"\fCORINTHIANS"); set_adc_channel(0); leitura = read_adc(); delay_us(10); printf(lcd_putc,"\n%lu",leitura); delay_ms(100); goto inicio; }

Exemplo 2 Lendo 2 entradas analgicas ao mesmo tempo

Cdigo Exemplo 2
#include "C:\Users\GabrielDell\Documents\picentradas\EntradaAnalogica.h" #define LCD_DATA_PORT getenv("SFR:PORTB") #include <LCD.C>

float leitura,leitura2; void main() { setup_adc_ports(AN0_AN1_AN3); setup_adc(ADC_CLOCK_INTERNAL); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);

setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); lcd_init();

inicio: printf(lcd_putc,"\fCORINTHIANS"); set_adc_channel(0); leitura = read_adc();

set_adc_channel(1); leitura2=read_adc();

delay_us(10); leitura = 5*leitura/1023; printf(lcd_putc,"\n%lf - %lf",leitura,leitura2); delay_ms(100); goto inicio; }

Você também pode gostar