HI,
I need help in my programming. I am using accelerometer which gives analog signal. I need to convert this signal into digital in order for my microcontroller to read. I am having trouble in my programming part, not sure to write the conversion part.
this is the example of my programming:
Is there anything wrong with my programming?
Thanks
I need help in my programming. I am using accelerometer which gives analog signal. I need to convert this signal into digital in order for my microcontroller to read. I am having trouble in my programming part, not sure to write the conversion part.
this is the example of my programming:
#include<p18f4520.h>
#include<delays.h>
void main(){
int t;
ADCON0 = 0b00000001;//READ ANALOG VOLTAGE FROM RA0
ADCON1 = 0b00001110;//CONFIGURE ADC, RA0
ADCON2 = 0b10000001;
TRISA = 0b00000001;// RA0 INPUT
while(1){
Delay10TCYx(12);
ADCON0bits.GO = 1;
while(ADCON0bits.DONE);
t=ADRESH+256;
if(t>255){
int x=t;
}
}
}
Is there anything wrong with my programming?
Thanks