Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About leighcom

  • Rank

Profile Information

  • Gender
  • Location
    Sri Lanka
  1. hi davidb, I tried what you advised to do but still no luck. what actually I am trying to do is to connect virtual power supply to AN0 and change it 0 to 5V. then I am trying to get the digital result from the bortB, this is just a part of a project to get the 10 bit digital result for analogue input at the AN0 input. Am I doing right? any other advices welcome.
  2. yes I tried ADC swithced on all the time but I don't see anything in the adres registers. any other clues appreciated.
  3. I tried the simulator and the real microcontroller, still no luck? program looks ok to me. I am using sourceboost 6.95v not 7. I only got the licence for 6.95. Any suggestions? thank you.
  4. Can any one help me to find the error on this program, It compiles OK but I cannot see any data in adres registers when I run the program. I only need to check analogue values in one channel (AN0). Thank you samith #include <system.h> #pragma CLOCK_FREQ 4000000 //#pragma DATA _CONFIG, _XT_OSC & _WDT_OFF & _LVP_OFF & _PWRTE_OFF & _CP_OFF unsigned int Read_adc(unsigned char ch); unsigned short adcvalue; void Adc_init(); void main() { //Initialise PortB trisb = 0; //configure port B portb = 0; //clear port B //initiolise portA trisa= 1; //porta as input Adc_init(); while(1) { unsigned int val; //Adc value val=Read_adc(0); //read channel 0 } portb=adcvalue; } //AD intiolisation void Adc_init() { set_bit( adcon1, ADFM ); // AD result needs to be right justified //clear_bit(adcon1,ADCS2); //this register only used for 877A clear_bit( adcon1, PCFG0 ); // one analogue in put set_bit( adcon1, PCFG1 ); // Vref+ = Vdd set_bit( adcon1, PCFG2 ); // Vref- = Vss set_bit(adcon1, PCFG3); clear_bit( adcon0, CHS0 ); // Channel 0 clear_bit( adcon0, CHS1 ); // clear_bit( adcon0, CHS2 ); // set_bit( adcon0, ADCS1 ); // Select Tad = 32 * Tosc (this depends on the Xtal here 10 MHz, should work up to 20 MHz) clear_bit(adcon0,ADCS0); } unsigned int Read_adc(unsigned char ch) { if(ch>4) return 0; clear_bit( adcon0, CHS0 ); // Channel 0 clear_bit( adcon0, CHS1 ); // clear_bit( adcon0, CHS2 ); // delay_us(100); set_bit(adcon0,ADON); set_bit(adcon0,GO); // Start conversion while(adcon0.GO==1); clear_bit(adcon0,ADON); MAKESHORT(adcvalue,adresl,adresh); return adcvalue; }
  5. Hello Dave, I tried your ADC sample program and followed instructions exactly mentioned beginning of the program using plugins, but it seems not working for me. would you help me if I have missed something. than you Samith
  6. Thank you very much, This will help me a lot to understand how to use ADC. Sam
  7. I have no experiance in this, Can anyone send me a sample program how to write a ADC program to 16F877 pic. please. Sam
  • Create New...