Let's now turn our attention to communicating by means of the I2C protocol. In particular, here you'll learn how to write and read data to and from an I2C EEPROM. Such a device is tremendously useful for storing menu displays, or maybe for recording logged sensor data.

The demo uses a serial terminal to monitor what's going on. See the preceding three exercises if serial communication is new to you.

I'll be using the 24LC256 EEPROM here. Check out the data sheet for more info:

This exercise invokes two library units I've written. The first ("SoftI2C.pas") provides all of the low level I2C support. The second ("I2CEEPROM.pas") then calls upon that to specifically manipulate the memory chip. There are tons of comments in these units giving full details on how to use them, so be sure to read them over.

Here's the schematic for the project:

Connect up with your terminal program, then turn on the PIC and just follow the on-screen instructions. You'll see the PIC generate a table of squares, then print them to the terminal. Next, you'll be given a chance to enter your name, and the PIC will strip off your first name and spit it back to you. Maybe not all that useful, but it does illustrate how to read and write both character and numeric data. Check out the code to see how easy it all is. Here's a screen shot from when I ran it:

Click to get the source code.
Click to get the schematic PDF.

Next Project: I2C -- DS1307 Real Time Clock

No comments:

Post a Comment