1. Scientech Learning Center
project
I2C protocol of Serial programming using AT24c04
with AT89c251
Submitted To
Mr. AdityaDubey
Submitted By
Mr. SHUBHAM SHIVHARE
B.E. SEVENTH SEMESTER
ELECTRONICS & COMMUNICATION
ENG.
SAGARINSTITUTEOF RESEARCH AND
TECHNOLOGYEXCELENCE.
2. ACKNOWLEDGEMENT
I take this opportunity to express my deep sense of gratitude to all those who have contributed
significantly by sharing their knowledge and experience in the completion of this project and
greatly obliged to Mr. AdityaDubey for his step by step guidance throughout the project.
I am also thankful to Mr. BrejeshChoudhary, Mr. VijaykumarSatpute, Mr. ShivamYadavand all
the staff members for knowledge sharing and support during the training.
Mr. SHUBHAM SHIVHARE
3. CERTIFICATE
This is to certify that SHUBHAM SHIVHARE, B.E. Seventh Semester, SAGAR INSTITUTE OF
RESEARCH AND TECHNOLOGY EXCELLENCE BHOPAL. has completed his project regarding “I2C
protocol of serial communication using AT24c04 with AT89c51” in Scientech Learning Center,
Indore from 07/07/14 to 02/08/14.
During the project, his work was found satisfactorily and I wish him all the best for his future.
Mr. AdityaDubey
4. INTRODUCTION
Today, electronics is used in home appliances for wide purposes including the motor regulation
of a washing machine, the control of a vacuum cleaner, the light dimming of a lamp or the
heating in a coffee machine etc. This pervasion increases rapidly because appliances require
enhanced features, easy to build and modify as electronics based solutions become cheaper
and more sophisticated. Within this evolution, the microcontrollers (MCU) progressively
replace analog controllers and discrete solutions even in low cost applications.
They are more flexible, often need less components and provide faster time to market. With an
analog IC, the designer is limited to a fixed function frozen inside the device. Remote control
facilitates variety of operation around the home or office from a distance such as fan regulators
and mains power supply. It provides a system that is easy to understand and also to operate, a
system that would be cheap and affordable, reliable and easy to maintain the system of remote
control and offers long durability. It adds more comfort to everyday living by removing the
inconvenience of having to move around to operate a fan regulator.
5. AT89C2051 Microcontroller
The AT89C2051 is a low-voltage, high-performance CMOS 8-bit microcomputer with 2K bytes of
Flash programmable and erasable read-only memory (PEROM). The device is manufactured
using Atmel’s high-density nonvolatile memory technology and is compatible with the industry-
standard MCS-51 instruction set. By combining a versatile 8-bit CPU with Flash on a monolithic
chip, the Atmel AT89C2051 is a powerful microcomputer which provides a highly-flexible and
cost-effective solution to many embedded control applications.
1. Pin Configuration
2. Pin Description
1. VCC
Supply voltage.
2. GND
Ground.
3. Port 1
The Port 1 is an 8-bit bi-directional I/O port. Port pins P1.2 to P1.7 provide internal
pull-ups. P1.0 and P1.1 require external pull-ups. P1.0 and P1.1 also serve as the
positive input (AIN0) and the negative input (AIN1), respectively, of the on-chip
precision analog comparator. The Port 1 output buffers can sink 20 mA and can drive
LED displays directly. When 1s are written to Port 1 pins, they can be used as inputs.
When pins P1.2 to P1.7 are used as inputs and are externally pulled low, they will
source current because of the internal pull-ups.
4. Port 3
Port 3 pins P3.0 to P3.5, P3.7 are seven bi-directional I/O pins with internal pull-ups.
P3.6 is hard-wired as an input to the output of the on-chip comparator and is not
accessible as a general purpose I/O pin. The Port 3 output buffers can sink 20 mA.
6. When 1s are written to Port 3 pins they are pulled high by the internal pull-ups and
can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will
source current (IIL) because of the pull-ups.Port 3 also serves the functions of
various special features of the AT89C2051 as listed below:
Port Pin Alternate Functions
P3.0 RXD (serial input port)
P3.1 TXD (serial output port)
P3.2 INT0(external interrupt 0)
P3.3 INT1(external interrupt 1)
P3.4 T0 (timer 0 external input)
P3.5 T1 (timer 1 external input)
Port 3 also receives some control signals for Flash programming and verification.
5. RST
Reset input. All I/O pins are reset to 1s as soonas RST goes high. Holding the RST pin
high for two machine cycles while the oscillator is running resets the device. Each
machine cycle takes 12 oscillator or clock cycles.
6. XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
7. XTAL2
Output from the inverting oscillator amplifier.
3. Features
1. 2.7V to 6V Operating Range
2. Fully Static Operation: 0 Hz to 24 MHz
3. 128 x 8-bit Internal RAM
4. 15 Programmable I/O Lines
5. Two 16-bit Timer/Counters
6. Six Interrupt Sources
7. Direct LED Drive Outputs
7. I2c protocol
The I²C (Inter-Integrated Circuit) protocol, referred to as I-squared-C, I-two-C, or IIC) is two
wire serial communication protocol for connecting low speed peripherals to a micrcontroller or
computer motherboard.
A sample schematic with one master and three slaves
The I²C simply require only two wires for communication. One is called the Serial Data (SDA)
and the other is Serial Clock (SCL) as shown.
There are various modes and configurations in which it can be used. Let us start simply with a
single master and a single slave.
The Master generates the clock for serial communication(SCL). A stream of data bits(B1 to BN)
is transferred between the start and the stop bits.
I2C Timings and Conditions.
Figure below shows the timing diagram for I²C.
Fig: I2C data transfer
Start Condition(S)
As seen from the timing diagram, a data transfer is initiated with the Start(S) condition. The start
occurs when SCL is high and SDA goes from high to low.
8. Data bits transfer(B1...Bn)
A bit is transmitted at every high level of the clock (SCL) after the start condition. As shown in
the image bits B1 to Bn are transmitted at high level of every successive clock cycles.
Stop bit (P)
To stop the data transfer, the clock(SCL) is held high, while data(SDA) goes from low to high.
Interfacing Microcontroller to I2C devices
Usually, following procedure is used to communicate with the peripherals.
Master initializes the communication by sending the slave address on the bus.
Master reads or writes data or commands from and to the slaves depending on the
interfaced devices.
Communication in I2C:
Figure 2 shows the communication in I2C.
The I2C signaling protocol provides device addressing, a read/write flag, and a simple
acknowledgement mechanism. Other elements of I2C protocol are general call (broadcast) and 10-bit
extended addressing. Standard I2C devices operate up to 100Kbps, while fast-mode devices operate
at up to 400Kbps. Most often, the I2C master is the CPU or microcontroller in the system. Some
microcontrollers even feature hardware to implement the I2C protocol. You can also build an all-
software implementation using a pair of general-purpose I/O pins. Since the I2C master controls
transaction timing, the bus protocol doesn't impose any real-time constraints on the CPU beyond
those of the application. For a fixed I2C, the high and low logics are defined at 3.0 V and 1.5 V. For
dependant I2C, these are defined at 0.7*Vdd and 0.3*Vdd respectively. The pull-up resistor values
required for I2C are typically at 1K for 3.0V of Vdd and 1.6K for 5V of Vdd. Typical operating
temperatures are between -40 degrees and +85 degrees Centigrade.
9. Addressing in I2C:
Figure 3 shows the SDA and SCL for I2C
Figure 3: I2C addressing
The following table shows I2C addresses
reserved for special purposes: 10 bit
addresses, binary noted, MSB is left
Purpose
0000000 0 General Call
0000000 1 Start Byte
0000001 X CBUS Addresses
0000010 X Reserved for Different Bus Formats
0000011 X Reserved for future purposes
00001XX X High-Speed Master Code
11110XX X 10-bit Slave Addressing
11111XX X Reserved for future purposes
10. Code for Programming
#include<reg51.h>
#include<intrins.h>
sbit sda=P1^0;
sbit scl=P1^1;
sbit led=P0^3;
bit ack;
sbit led1=P0^1;
sfr lcd_data_pin=0xA0;
sfr output=0x80;
sbit rs=P3^0;
sbit rw=P3^1;
sbit en=P3^6;
unsigned char read,write,write2,i,j;
unsigned int temp;
void delay(unsigned int count)
{
int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm)
{
lcd_data_pin=comm;
en=1;