lunes, 3 de diciembre de 2012

sdcc pic16f877a adc 10bits

adc.h
#include <pic16f877a.h>

void config_adc()
{
  ADFM=1;
  PCFG0=0;
  PCFG1=0;
  PCFG2=0;
  PCFG3=0; 
}


unsigned int Leer_ADC(unsigned int canal)
{  
 unsigned int byteh,bytel,aux, dato;
 //FOSC/32
 ADCS0=0;
 ADCS1=1;
 //Seleccionamos el canal AD
 aux=ADCON0 & 0b11000111;
 ADCON0=aux | (canal << 3);
 
 ADON=1; //Encender AD
 ADIF=0; //Limpio flag del conversor
 GO=1;   //Comenzando
 while(ADIF==0); 
 
 byteh=ADRESH;
 bytel=ADRESL;
 
 dato=(int)byteh<<8|bytel;
 return (dato);
}

IRC

#freenode->#usljujuy

Seguidores

Eventos n_n

Tira Ecol Nano,Bilo y Luca