Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
anyone have the code about how to control si570 with a pic via i2c??
i use c language with mplab. the pic type is 16f877a, i have not done anything about i2c, so i do know how to write the code...
Which C compiler are you using in MPlab? As far as I know the only free C compiler that comes with MPlab is the C18 compiler which you wouldn't be using with the 16F877A. Are you using CCS, HI-TECH C, other? Different compilers have different libraries for controlling I2C communication.
Once you figure out which compiler you are using and how to use thier specific I2C libraries the basic flow will go like this:
I2C Initialize;
I2C Start;
I2C Slave address:
I2C Register select;
I2C Write data;
I2C Stop;
Between each step you will likely have your code wait for the acknowledge signal which is a signal output by the slave basically saying "OK, I received the entire byte". The registers you write to and the data you write to them are device specific. You have to study the data sheet for your specific device to know what registers must be written to and when to control which functions.
i2c_init();
i2c_start();
i2c_write(slave_address);
i2c_write(first_register);
i2c_write(first_byte);
i2c_stop();
i2c_start();
i2c_write(slave_address);
i2c_write(second_register);
i2c_write(second_byte);
i2c_stop();
i2c_start();
i2c_write(slave_address);
i2c_write(third_register);
i2c_write(third_byte);
i2c_stop();
.
.
.
I'm not sure but this code looks like source for the different I2C library functions. Now you have to call the functions appropriately for your device. Something like:
Code:i2c_init(); i2c_start(); i2c_write(slave_address); i2c_write(first_register); i2c_write(first_byte); i2c_stop(); i2c_start(); i2c_write(slave_address); i2c_write(second_register); i2c_write(second_byte); i2c_stop(); i2c_start(); i2c_write(slave_address); i2c_write(third_register); i2c_write(third_byte); i2c_stop(); . . .
Once again for future reference, you can use the code brackets when posting code. It creates a scrolling field within your post so it won't be a billion lines long.