|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Thursday, April 24, 2008 5:05 PM
Posts: 8,
Visits: 12
|
|
Hi all,
I currently got the sensors after a long wait but after a lot of reading in the data-sheets, I couldn't know how to use the sensors.
Can anyone help me in reading the output of the sensors.
I use a PIC18F452 microcontroller. I have to follow a white line on a black floor. There are some turns.
The main problem is how to read the byte.
Please give me some example program.
Regards
|
|
|
|
|
Forum Member
      
Group: Moderators
Last Login: Wednesday, November 05, 2008 10:13 AM
Posts: 38,
Visits: 54
|
|
| If you are using the CCS compiler for the 452 then you must set up your I2C like this #use I2C(master, sda=PIN_c4, scl=PIN_c3,slow) Then to read the sensor use i2c_start(); // start condition i2c_write(ADDRESS + 1); value = i2c_read(0); i2c_stop();
where address is the address of the line sensor you are using. If you are using a different compiler or language then you will have to port this over to it. This will return a byte with either 5 or 7 bits set according to teh sensor status. If you have an older line sensor, it will have 5 bits, if it is a newer sensor with the holes on teh left and right to mount extra sensors then it will return 7 bits. Hope this helps. Ringo Ringo
Ringo Davis
|
|
|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Thursday, April 24, 2008 5:05 PM
Posts: 8,
Visits: 12
|
|
| We are using a c18 compiler to compile the C-code in microchip mplab ide
|
|
|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Thursday, April 24, 2008 5:05 PM
Posts: 8,
Visits: 12
|
|
|
|
|
|
Forum Member
      
Group: Moderators
Last Login: Wednesday, November 05, 2008 10:13 AM
Posts: 38,
Visits: 54
|
|
| #Use is part of the CCS compiler. It just tells the compiler how to set up the I2C port. I'm not familiar with the C18 compiler, but I believe microchip has forums and I know they have a help system where you can talk or email a tech questions. I just googgled "c18 compiler i2c" and it came up with lots of hits. Look for examples of code that talk to other devices, then just modify that to use the commands I listed above. This sensor is really eay to use since it only returns 1 byte, so any example you find should be good nough for you to modify. Ringo
Ringo Davis
|
|
|
|
|
Forum Newbie
      
Group: Forum Members
Last Login: Thursday, April 24, 2008 5:05 PM
Posts: 8,
Visits: 12
|
|
Im trying something lik this but this is not working? Do we have to set the pins as out/input of RC3,4
#include
#include
#include
unsigned char value;
//void StartI2C(void);
//void StopI2C(void);
void OpenI2C(unsigned char sync_mode,
unsigned char slew);
unsigned char WriteI2C(
unsigned char data_out);
unsigned char ReadI2C (void);
void configure_LEDS(void);
void display_on_LEDS(unsigned char value);
void main() {
while (1) {
configure_LEDS();
OpenI2C(MASTER, SLEW_ON);
//SSPADD = 0x50;
StartI2C();
WriteI2C(0x50 +1);
value = ReadI2C();
display_on_LEDS(value);
//StopI2C();
}
}
void configure_LEDS(void) {
TRISD = 0x00;
}
void display_on_LEDS(unsigned char value) {
LATD = value;
}
|
|
|
|
|
Forum Member
      
Group: Moderators
Last Login: Wednesday, November 05, 2008 10:13 AM
Posts: 38,
Visits: 54
|
|
|
|
|
|
Forum Member
      
Group: Moderators
Last Login: Wednesday, November 05, 2008 10:13 AM
Posts: 38,
Visits: 54
|
|
Oh yeah, do you have pullups on both I2C lines? Somehting around 1.8K?
Ringo Davis
|
|
|
| | |