0
\$\begingroup\$

everyone. I'm new to embedded systems and I want to program a PIC12F675 for a project.

I have most of the code figured, and there is only one thing left. It's the analog input. I tried some tutorials, but they didn't work. They used the function "ADC_Read()" which isn't a standard function in XC8, which I'm using.

So can someone help me with this? Thank you.

The Config:

#pragma config FOSC = INTRCCLK  
#pragma config WDTE = OFF       
#pragma config PWRTE = OFF      
#pragma config MCLRE = OFF       
#pragma config BOREN = ON       
#pragma config CP = OFF         
#pragma config CPD = OFF 

The Code:

#include <xc.h>
#include "config.h"
#define _XTAL_FREQ 4000000

void dClock(int delay){
    GPIO2 = 1;
    __delay_ms(delay);
    GPIO2 = 0;
    __delay_ms(delay);
}

void main(void) {
    TRISIO2 = 0; //output
    TRISIO3 = 1; //mode
    TRISIO5 = 1; //pulse_button

    char pressed = 0;
    GPIO2 = 0;

    while(1){
        __delay_ms(50);

        if(GPIO3 == 0){
            int delay = ADC_Read(); //Supposed to read analog value here
            dClock(delay);
        }
        else{
            if(GPIO5 == 1 && pressed == 0){
                GPIO2 = 1;
                __delay_ms(500);
                GPIO2 = 0;
                pressed = 1;
            }
            else if(GPIO5 == 0 && pressed == 1){
                pressed = 0;
            }
        }
    }
    return;
}
\$\endgroup\$
  • \$\begingroup\$ Doesn't the datasheet share some insight on what to do? \$\endgroup\$ – Harry Svensson Jul 9 at 9:09
  • \$\begingroup\$ @HarrySvensson I don't know how to use the datasheet. I'm new to this and still learning. \$\endgroup\$ – Ali Abo Shady Jul 9 at 9:13
  • 1
    \$\begingroup\$ Oh well, page 43 (chapter 7) is there for the taking. \$\endgroup\$ – Harry Svensson Jul 9 at 10:24
  • 2
    \$\begingroup\$ I do not see any setup code for your ADC. You need to setup the ADC and TURN IT ON to be able to use it \$\endgroup\$ – Cerezo Jul 9 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.