ala aude
Newbie level 4
problem in ADC
please can anyone help me un this code
// #pragma org all
void Tone1() {
Sound_Play(659, 250); // Frequency = 659Hz, duration = 250ms
}
void Tone2() {
Sound_Play(698, 250); // Frequency = 698Hz, duration = 250ms
}
void Tone3() {
Sound_Play(784, 250); // Frequency = 784Hz, duration = 250ms
}
void main ()org 0x800 {
unsigned y;
float x;
ADCON0=0b00000001;
ADCON1=0b00001101;
ADCON2=0b00000010;
TRISA = 0xff ;
TRISB = 0x00 ;
y=0;
for(;{
y = adc_read(0) ;
// ADCON0=0b00000011;
x= ((y*1000*2.5)/9.8);\\convert to distance
ADCON0=0b00000001;
if (1<=x && x<30){
Sound_Init(&PORTB, 0);
//PORTB=0b00000001;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=0;
// delay_us(500);
//ADCON0=0b00000001;
}
else if(30<=x && x<80){
Sound_Init(&PORTB, 1);
Tone1();
//PORTB=0b00000010;
// PORTB.f0=0;
// PORTB.f1=1;
// PORTB.f2=0;
//delay_us(500);
// ADCON0=0b00000001;*/
}
else if(80<=x &&x<=120){
Sound_Init(&PORTB, 2);
Tone2();
//PORTB=0b00000100;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000100;
}
else {
Sound_Init(&PORTB, 3);
Tone3();
//PORTB.f0=1;
// PORTB.f1=1;
//PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000001;
}
}}
i used LV-MAXSONAR-EZ1 sensor and the if statment didint work in correct way and i want to convert the analog input to cm distance then test if statment i use pic18f2553 with 20Mhz
please can anyone help me un this code
// #pragma org all
void Tone1() {
Sound_Play(659, 250); // Frequency = 659Hz, duration = 250ms
}
void Tone2() {
Sound_Play(698, 250); // Frequency = 698Hz, duration = 250ms
}
void Tone3() {
Sound_Play(784, 250); // Frequency = 784Hz, duration = 250ms
}
void main ()org 0x800 {
unsigned y;
float x;
ADCON0=0b00000001;
ADCON1=0b00001101;
ADCON2=0b00000010;
TRISA = 0xff ;
TRISB = 0x00 ;
y=0;
for(;{
y = adc_read(0) ;
// ADCON0=0b00000011;
x= ((y*1000*2.5)/9.8);\\convert to distance
ADCON0=0b00000001;
if (1<=x && x<30){
Sound_Init(&PORTB, 0);
//PORTB=0b00000001;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=0;
// delay_us(500);
//ADCON0=0b00000001;
}
else if(30<=x && x<80){
Sound_Init(&PORTB, 1);
Tone1();
//PORTB=0b00000010;
// PORTB.f0=0;
// PORTB.f1=1;
// PORTB.f2=0;
//delay_us(500);
// ADCON0=0b00000001;*/
}
else if(80<=x &&x<=120){
Sound_Init(&PORTB, 2);
Tone2();
//PORTB=0b00000100;
// PORTB.f0=1;
// PORTB.f1=0;
// PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000100;
}
else {
Sound_Init(&PORTB, 3);
Tone3();
//PORTB.f0=1;
// PORTB.f1=1;
//PORTB.f2=1;
// delay_us(500);
//ADCON0=0b00000001;
}
}}
i used LV-MAXSONAR-EZ1 sensor and the if statment didint work in correct way and i want to convert the analog input to cm distance then test if statment i use pic18f2553 with 20Mhz