PIC16F877 ADC

Here you can ask for specific code examples and discuss about it with other forum members.
Post Reply
Author
Message
volkvanmyn25
Posts: 3
Joined: 03 Jul 2012 05:02

PIC16F877 ADC

#1 Post by volkvanmyn25 » 03 Jul 2012 05:14

Hi. I need some help. I'm trying to read an analogue value on AN0 on my PIC16F877. My conversion doesn't take place because the Go_nDone bit doesn't want to clear. The problem seems to be with my ADCON0 register. The conversion clock select bits ADCS0, ADCS1, seem to unstable and change by themselves. I'm displaying the Values of register ADCON0 and ADCON1 on my LCD. Here is my code:


//MASH TUN Temp Controller
//HITECH C Compiler (Lite)
//Pic16F877a.

//Analogue input connected to AN0

#ifndef _XTAL_FREQ
// Unless specified elsewhere, 4MHz system frequency is assumed
#define _XTAL_FREQ 4000000
#endif

#include <htc.h>
#include "lcd.h"
#include <stdlib.h>
#include <pic16f877a.h>


char buf[10];



void delay_s(int sec)
{
int i_sec;

for(i_sec=0;i_sec<sec;i_sec++)
__delay_ms(1000);
}


void adSetup(){

TRISA=0X3F; //Set all PORTA bits as inputs
//TRISE=0X07; //Set all PORTE bits as inputs


ADCON1,PCFG0 = 0; //SETTING ANALOGUE INPUTS
ADCON1,PCFG1 = 0; //
ADCON1,PCFG2 = 0; //
ADCON1,PCFG3 = 0; //
ADCON0,CHS0 = 0; //Selecting channel
ADCON0,CHS1 = 0; //
ADCON0,CHS2 = 0; //


ADCON1,ADCS2 = 0; //Selecting clock frequency
ADCON0,ADCS0 = 1; //
ADCON0,ADCS1 = 0; //

ADCON1,ADFM = 1; //Format selection

ADCON0,ADON = 1;

delay_s(1);

ADCON0,GO_DONE = 1;

}


void
main(void)
{

lcd_init();

lcd_clear();
lcd_goto(0);
lcd_puts("Step Mash");

adSetup();

while(GO_DONE){

itoa(buf,ADCON0,2);
lcd_goto(0);
lcd_puts(buf);

itoa(buf,ADCON1,2);
lcd_goto(0x40);
lcd_puts(buf);
}

lcd_clear();
lcd_goto(0);
lcd_puts("Conversion done");

itoa(buf,ADRESL,10);
lcd_goto(0x40);
lcd_puts(buf);

for(;;){}

}


Please if anyone can help me it would be greatly appreciated. Thanks.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PIC16F877 ADC

#2 Post by filip » 03 Jul 2012 07:50

Hi,

Which compiler are you using ?

Regards,
Filip.

volkvanmyn25
Posts: 3
Joined: 03 Jul 2012 05:02

Re: PIC16F877 ADC

#3 Post by volkvanmyn25 » 03 Jul 2012 16:48

Hi Filip. I'm using HITECH C Compiler (Lite).

filip wrote:Hi,

Which compiler are you using ?

Regards,
Filip.

volkvanmyn25
Posts: 3
Joined: 03 Jul 2012 05:02

Re: PIC16F877 ADC

#4 Post by volkvanmyn25 » 03 Jul 2012 19:25

Hi Filip. I'm using HITECH C compiler (lite).

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: PIC16F877 ADC

#5 Post by filip » 04 Jul 2012 07:25

Hi,

Since you are using non-mikroElektronika compiler, I am afraid I cannot help you further regarding this issue.
Maybe some of our users that work with HITECH compiler could help you.
Thank you for the understanding.

Regards,
Filip.

Post Reply

Return to “Code Requests”