GammaRay86
New Member
Hi guys,
I'm very new to programming PICs. I'm trying to do an A/D conversion of a voltage given obtained from a sensor. I'm using the PIC12CE674 for now and programming in C.
Here is my code:
Here's a link to the datasheet: https://www.electro-tech-online.com/custompdfs/2009/12/PIC12LCE674-04-P.pdf
It compiles fine in MPLAB but when I go to program it into the PIC with PICSTART PLUS, it gives an error of "device NOT blank: Program Memory". What does this mean? Why would the program memory not be blank considering the PIC is brand new?
I was reading on some things and I came across MCLR. What exactly does this do and do I need to use this somehow? I would appreciate the help.Thanks a lot.
I'm very new to programming PICs. I'm trying to do an A/D conversion of a voltage given obtained from a sensor. I'm using the PIC12CE674 for now and programming in C.
Here is my code:
Code:
#pragma chip PIC12CE674
#include "delay.h"
void main(void){
int adval; // adval is the ADC value
TRIS.0 = 1; // Set GP0/AN0 as input
TRIS.4 = 0; // Set GP4/AN3 as output
ADCON1 = 0b.0000.0010; // Set GP4 as Digital and GP0 as Analog, Vref = Vdd
while(1){
//Do the sensor conversion
delay_us(50); // Set delay of 50 us for sampling (TAD)
ADCON0 = 0b.1100.0101; // Set oscillator to FRC, Analog Channel 0 (GP0/AN0) selected, Go/Done=1, ADON=1
while(ADCON0.2 == 1){} // A/D conversion started, continue to check Go/Done, when 0 it is completed
// Bit 1 of ADCON0 is cleared when finished
adval = ADRES; // Read ADRES into adval
if(adval >100){ // LED on at GP4/AN3 (pin 3) when AN0 > 1.8V, off < 1.8V
GPIO = 0b.0001.0000;
}
else {
GPIO = 0b.0000.0000;
}
}
}
Here's a link to the datasheet: https://www.electro-tech-online.com/custompdfs/2009/12/PIC12LCE674-04-P.pdf
It compiles fine in MPLAB but when I go to program it into the PIC with PICSTART PLUS, it gives an error of "device NOT blank: Program Memory". What does this mean? Why would the program memory not be blank considering the PIC is brand new?
I was reading on some things and I came across MCLR. What exactly does this do and do I need to use this somehow? I would appreciate the help.Thanks a lot.
Last edited: