CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how to use ultrasonic MAX Sonar EZ1

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
siput



Joined: 14 Mar 2010
Posts: 3

View user's profile Send private message

how to use ultrasonic MAX Sonar EZ1
PostPosted: Mon Apr 19, 2010 1:55 am     Reply with quote

hello there.
Can someone teach me how to use simple coding for this sensor ?
I have done code on my own for this sensor by trial and error practise, but no output was produced.
I just want to look at the LED as output high when the sensor has detected that the voltage is higher than 2.5 V.
Coding that I have done is like below.

Hopefully someone can teach me about this sensor.
Code:

void main()
{
   float data1;
   long adcValue[3];
   int i;
   
   setup_adc_ports(ALL_ANALOG);
   setup_adc(ADC_CLOCK_DIV_32);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_1,118,1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(238);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);


    while(1){

   for(i=0;i<2;i++){
   set_adc_channel(i);
   delay_us(10);
   adcValue[i]=read_adc();
   }

   data1 = (float) (adcValue[0])*5/1023;
 
   printf("Analog Value1 = %f ", data1);
 
   delay_ms(1000);
 
   if((data1>2.50))
   {
      output_b(0b00000001);
   }
   else
   {
      output_b(0b00000000);
   }
   
   }   
}
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Apr 19, 2010 8:55 am     Reply with quote

You should post the FULL code, and your compiler version first.

So just edit your starting post with this information.

If this *IS* all of the code, then you're missing the mandatory startup items required to configure the PIC.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group