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 support@ccsinfo.com

I2C interface for photocell sensor

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



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

I2C interface for photocell sensor
PostPosted: Sun Jul 17, 2005 3:48 pm     Reply with quote

I would like to interface a photocell sensor with pic18F8720 using i2c interface. I never used i2c, if somebody has code to read data using i2c for similar sensor application then it would be very useful to me.

thanks in advance
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Sun Jul 17, 2005 5:16 pm     Reply with quote

In short. Hook up the analog output of your photocell to a suitable I2C A/D converter. If you post the part number for your photocell, I'll be able to give you a more detailed explanation.

Cheers,
Kender
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

thanks
PostPosted: Mon Jul 18, 2005 7:54 am     Reply with quote

hey
thanks for reply. it s actually a range finder by acroname. I wanted to measure relative distance using it. I am pasting the link to the page


[http://www.acroname.com/robotics/parts/R145-SRF08.html]


take care
cs[/url]
Ttelmah
Guest







PostPosted: Mon Jul 18, 2005 8:27 am     Reply with quote

Guess what. :-)
99% of it is already done for you!.
The key comes when you look at the data:
[http://www.robot-electronics.co.uk/htm/srf08tech.shtml]

Note the comment, that the unit behaves like the 24xx EEPROMs, except that the actual device address is different, and that the actual registers are 36 registers starting at address 0.
Complete drivers for the 24xx EEPROMs, are included with the CCS compiler, in the 'drivers' directory. Use the smallest and simplest (2401.c).
In this code, there are three locations where the value '0xA0' is used, and one where '0xA1' is used. Change these to the address of the device (0xE0, and E1 - the low 'bit' here signifies read/write control).
If you then try 'read_ext_eeprom(0)', you should get back the firmware revision of the unit.
If you try:
Code:

//Obviously you will have to include this in some suitable 'main' code.

union {
    int16 range;
    int8 b[2];
} reading;

write_ext_eeprom(0,81);
//set to range in centimetres
delay_ms(65);
reading.b[0]=read_ext_eeprom(3);
reading.b[1]=read_ext_eeprom(2);


Then reading.range, should be the distance to the first echo in cm.

Best Wishes
csshah



Joined: 28 Feb 2005
Posts: 24

View user's profile Send private message

thnaks a lot
PostPosted: Wed Jul 20, 2005 8:23 am     Reply with quote

Hey Ttelmah

thanks a lot for ur help u made my life easier. I will try to do the way u suggested.

cheers
cs
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