///////////////////////////////////////
//AUTOR:george
//TITLE;Convertidor de analogo a digital
//DATE:23/JULIO/'09
///////////////////////////////////////
//CONFIGURACION///////////////////
#include<16F886.h> //Incluimos los registros del Micro
#fuses INTRC_IO,NOWDT,NOLVP,MCLR,NOPROTECT
//INTRC_IO = Reloj Interno
//NOWDT = No al perro guardian
//NLVP = No al Voltaje de programacion
//MCLR = Master Clean Activado
//NOPROTECT= No protegemos al codigo
#use delay(clock=8000000) //Reloj Interno trabajando a 8Mhz
unsigned int sA;
void main(void){
set_tris_a(0x01);
set_tris_c(0x00);
setup_comparator(NC_NC_NC_NC); //COMPRADORES APAGADOS
/************************************************
Canales PWM activados *****
*************************************************/
setup_ccp1(CCP_PWM);
[COLOR=Red] /************************************************
value=[(1/Frec)/(preescalarx(4/osc)]-1 ******
frec~1kHz ******
preescalar=16 ******
osc=8Mhz ******
value=124 ******
*************************************************/[/COLOR]
setup_timer_2(T2_DIV_BY_16,124,1);
set_pwm1_duty(0); //apagado
setup_adc(ADC_CLOCK_INTERNAL|VSS_VDD);
setup_adc_ports(sAN0);
while(TRUE){
delay_ms(100);
sA=read_adc();
set_pwm1_duty(sA);
}
}