Vous êtes sur la page 1sur 73

GUAVA PI- MICROCONTROLLER TRAINER KIT WITH

USB PROGRAMMER

Jointly Developed By: KITSNSPARES & Technido


GUAVA PI

GUAVA PI MICROCONTROLLER TRAINER KIT


TABLE OF CONTENTS

1. System Introduction 3
2. System Specification 4
3. System Versions 5
4. System Installation 7
5. Hardware Description 11
6. Keil Environment 13
7. Description of Microcontroller 15
8. Sample Program 1: Interfacing of LED 21
9. Sample Program 2: Interfacing of LCD 25
10. Sample Program 3: Interfacing of Seven Segments* 31
11. Sample Program 4: Interfacing of Keypad* 41
12. Sample Program 6: Interfacing of Serial Port 47
13. Sample Program 7: Interfacing of DC Motor* 53
14. Sample Program 9: Interfacing of RTC* 60
15. How to program other ICs using Guava-PI 72
16. Warranty 73

* Additional modules are require for interfacing.

Page 2
GUAVA PI

SYSTEM INTRODUCTION

General description:
Guava PI is a single board Microcontroller Training /Development Kit configured
around the ATMEL AT89S52 Microcontroller. This kit can be used to train engineers,
to control any industrial process and to develop software for 8051 systems.
The kit has been designed to operate in the max. mode. It allows developer to develop
various different projects and applications.
The kit contains an onboard USB Programmer the gives user the facility of easy and
fast programming. In this process SPI protocol (Serial Peripheral Interface) use. The
kit also provides facility to program AT89AS52 IC through serial cable directly.
Each port is having its own 10 pin box connector that act as an interface connector to
the microcontroller board. We can interface several modules using this FRC
connector. There are LCD and LED interfacing on board section which get power
from same board and have its own 10 pin box connector.
The board drives power from an external 12V, 1Amps power adapter. This power is
then dropped down to 5V by the use of power regulation circuitry.

Page 3
GUAVA PI

SYSTEM SPECIFICATIONS

Open ports with box connector and pin headers


8051 Core with AT89S52 Controller
On-board 16x2 LCD display with contrast and brightness control
On-board LEDs for testing and debugging
On-board RS-232 communication interface(for PC interfacing)
Supports ISP programming

Page 4
GUAVA PI

DIFFERENT VERSION OF GUAVA PI

Diamo
nd
Platin
Gold um

Guav
a-PI

Page 5
GUAVA PI

KIT CONTENTS

VERSION GOLD DIAMOND PLATIUM

Guava PI Kit Yes Yes Yes

AT89s52 Chip No Yes Yes

10 pin FRC 2 No Yes Yes

USB Cable No Yes Yes

LCD 16 2 No No Yes

12 volt Adapter No No Yes

Page 6
GUAVA PI

SYSTEM INSTALLATION

There are a few basic software and drivers required for running the board. These are:
1. Windows drivers for USB Programmer- USB ASP Drivers
2. Flash Utility for Programmer - ProISP
3. Keil Software - Evaluation Version

1. For Installation of drivers please follow the below procedure:


Step1: Connect the USB cable with PC and other side to Programmer
Step2: The below window will open up:

Page 7
GUAVA PI

Page 8
GUAVA PI

Page 9
GUAVA PI

Page 10
GUAVA PI

HARDWARE DESCRIPTION

LED Section Power


Microcontroller
Switch
AT89S52

Serial Port
LCD Display USB
Programmer

Page 11
GUAVA PI

1. Power Switch: This is a simple ON/OFF switch that makes and breaks current onto
main board.

2. LED Section: This section consists of eight LEDs that have anode connected as
common. When we need to make any LED ON then we have to send a signal LOW.

3. USB Programmer: The section is a onboard USB Programmer the gives user the
facility of easy and fast programming.

4. Microcontroller Section: This is the main section of the board that consists of
microcontroller AT89S52. It also has a reset circuitry to restart the microcontroller. A
power indicator LED is also there that symbolizes activeness of the board. It also has
a JTAG/ISP connector that used to program the microcontroller.

5. Serial Communication: In simple words serial communication is the exchange of


data between two devices serially i.e. through single or two wires. In our case serial
communication is referred to as communication between microcontroller and
computer or between microcontroller and microcontroller. Serial communication is
done using RS-232 Protocol that is a standard.

6. LCD Display: The most commonly used Character based LCDs are based on
Hitachi's HD44780 controller or other which are compatible with HD44580. In this
section, we will discuss about character based LCDs, their interfacing with
microcontrollers, special stuff and tricks you can do with these simple looking LCDs
which can give a new look to your application.

Page 12
GUAVA PI

USING KEIL ENVOIRMENT

KEIL uVision is the name of software dedicated to the development and testing of a
family of microcontrollers based on 8051 technology, like the AT89S52 which we are
going to use along this tutorial. You can download an evaluation version of KEIL at
their website: http://www.keil.com/c51/. Most versions share merely the same
interface, this tutorial uses KEIL C51 uVision 3 with the C51 compiler v8.05a.

To create a project, write and test the previous example source code, follow the
followingsteps:

Open Keil and start a new project:

You will prompted to chose a name for your new project, Create a separate folder
where all the files of your project will be stored, chose a name and click save. The
following window will appear where you will be asked to select a device for Target
'Target 1':

From the list at the left, seek for the brand name ATMEL, then under ATMEL, select
AT89S52. You will notice that a brief description of the device appears on the right.
Leave the two upper check boxes unchecked and click OK. The AT89S52 will be
called your 'Target device', which is the final destination of your source code. You will
be asked whether to 'copy standard 8051 startup code' click No.

Click File, New. The box named 'Text1' is where your code should be written later.

Now you have to click 'File, Save as' and chose a file name for your source code
ending with the letter '.c'. You can name it as 'technido.c' for example and click save.
Then you have to add this file to your project work space at the left.

After right-clicking on 'source group 1', click on 'Add files to group...', then you will
be prompted to browse the file to add to 'source group 1', chose the file that you just
saved, eventually 'technido.c' and add it to the source group. You will notice that the
file is added to the project tree at the left.

In some versions of this software you have to turn ON manually the option to
generate HEX files. make sure it is turned ON, by right-clicking on target 1, Options
for target 'target 1', then under the 'output' tab, by checking the box 'generate HEX
file'. This step is very important as the HEX file is the compiled output of your project
that is going to be transferred to the microcontroller.

You can then start to write the source code in the window titled 'technido.c' then
before testing your source code; you have to compile your source code, and correct

Page 13
GUAVA PI

eventual syntax errors. In KEIL IDE, this step is called 'rebuild all targets' and has this
icon: .

You can use the output window to track eventual syntax errors, but also to check the
FLASH memory occupied by the program (code = 49) as well as the registers
occupied in the RAM (data = 9). If after rebuilding the targets, the 'output window'
shows that there is 0 error, then you are ready to test the performance of your code.
In keil, like in most development environment, this step is called Debugging, and has
this icon: . After clicking on the debug icon, you will notice that some part of the
user interface will change, some new icons will appear, like the run icon.

You can click on the 'Run' icon and the execution of the program will start. In our
example, you can see the behavior of the pin 0 or port one, but clicking on
'peripherals, I/O ports, Port 1'. You can always stop the execution of the program by
clicking on the stop button ( ) and you can simulate a reset by clicking on the 'reset'
button .
You can also control the execution of the program using the following icons:
which allows you to follow the execution step by step. Then, when
you're finished with the debugging, you can always return to the programming
interface by clicking again on the debug button ( ).
There are many other features to discover in the KEIL IDE. You will easily discover
them in first couple hours of practice.

Page 14
GUAVA PI

DESCRIPTION OF MICROCONTROLLER

A micro-controller can be compared to a small stand-alone computer; it is a very


powerful device, which is capable of executing a series of pre-programmed tasks and
interacting with other hardware devices. Being packed in a tiny integrated circuit (IC)
whose size and weight is usually negligible, it is becoming the perfect controller for
robots or any machines requiring some kind of intelligent automation. A single
microcontroller can be sufficient to control a small mobile robot, an automatic washer
machine or a security system. Any microcontroller contains a memory to store the
program to be executed, and a number of input/output lines that can be used to
interact with other devices, like reading the state of a sensor or controlling a motor.

Nowadays, microcontrollers are so cheap and easily available that it is common to use
them instead of simple logic circuits like counters for the sole purpose of gaining
some design flexibility and saving some space. Some machines and robots will even
rely on a multitude of microcontrollers, each one dedicated to a certain task. Most
recent microcontrollers are 'In System Programmable', meaning that you can modify
the program being executed, without removing the microcontroller from its place.

Today, microcontrollers are an indispensable tool for the robotics hobbyist as well as
for the engineer. Starting in this field can be a little difficult, because you usually can't
understand how everything works inside that integrated circuit, so you have to study
the system gradually, a small part at a time, until you can figure out the whole image
and understand how the system works.

The 8051 Microcontroller Architecture

The 8051 is the name of a big family of microcontrollers. The device which we are
going to use along this tutorial is the 'AT89S52' which is a typical 8051
microcontroller manufactured by Atmel . Note that this part doesn't aim to explain
the functioning of the different components of a AT89S52 microcontroller, but rather
to give you a general idea of the organization of the chip and the available features,
which shall be explained in detail along this tutorial.

The block diagram provided by Atmel in their datasheet showing the architecture
the AT89S52 device can seem very complicated, and since we are going to use the C
high level language to program it, a simpler architecture can be represented as the
figure 1.2.A.

This figure shows the main features and components that the designer can interact
with. You can notice that the AT89S52 has 4 different ports, each one having 8
Input/output lines providing a total of 32 I/O lines. Those ports can be used to output
DATA and orders do other devices, or to read the state of a sensor, or a switch. Most
of the ports of the AT89S52 have 'dual function' meaning that they can be used for
two different functions: the first one is to perform input/output operations and the
second one is used to implement special features of the microcontroller like counting
external pulses, interrupting the execution of the program according to external

Page 15
GUAVA PI

events, performing serial data transfer or connecting the chip to a computer to update
the software.

Each port has 8 pins, and will be treated from the software point of view as an 8-bit
variable called 'register', each bit being connected to a different Input/output pin.

You can also


notice two
different memory
types: RAM and
EEPROM. Shortly,
RAM is used to
store variable
during program
execution, while
the EEPROM
memory is used to
store the program
itself, that's why it
is often referred to
as the 'program
memory'. The
memory
organization will
be discussed in
detail later.

The special
features of the
AT89S52 Figure 1.2.A
microcontroller are
grouped in the
blue box at the
bottom of figure
1.2.A. At this stage
of the tutorial, it is
just important to
note that the
AT89S52
incorporates
hardware circuits
that can be used to
prevent the
processor from
executing various
repetitive tasks and
save processing
power for more
complex
calculations. Those

Page 16
GUAVA PI

simple tasks can


be counting the
number of external
pulses on a pin, or
generating precise
timing sequences.

It is clear that the CPU (Central Processing Unit) is the heart of the microcontrollers,
It is the CPU that will Read the program from the FLASH memory and execute it by
interacting with the different peripherals discussed above.

Figure 1.2.B shows the pin configuration


of the AT89S52, where the function of
each pin is written next to it, and, if it
exists, the dual function is written
between brackets. The pins are written in
the same order as in the block diagram of
figure 1.2.A, except for the VCC and
GND pins which I usually note at the top
and the bottom of any device.

Note that the pin that have dual functions,


can still be used normally as an
input/output pin. Unless you program uses
their dual functions, All the 32 I/O pins of
the microcontroller are configured as
input/output pins.

Most of the function of the pins of the


AT89S52 microcontroller will be
discussed in detail, except for the pins
required to control an external memory,
which are the pins number 29, 30 and 31.
Since we are not going to use any external
memory, pins 29 and 30 will be ignored
through all the tutorial, and pin 31 (EA)
always connected to VCC (5 Volts) to
enable the micro-controller to use the
internal on chip memory rather than an Figure 1.2.B
external one (connecting the pin 31 to
ground would indicate to the
microcontroller that an external memory
is to be used instead of the internal one).

Memory organization

Page 17
GUAVA PI

A RAM stands for Random Access Memory, it has basically the same purpose of the
RAM in a desktop computer, which is to store some data required during the
execution time of different programs. While an EEPROM, also called FLASH
memory is a more elaborated ROM (Read Only Memory) which is the memory where
the program being executed is stored. Even if that's not exactly true, you can compare
an EEPROM to the Hard-Disk of a desktop computer from a general point of view.
The EEPROM term stands for Electronically Erasable and Programmable Read Only
Memory.

In microcontrollers, like in any digital system,


memory is organized in Registers, Which is the basic
unit of construction of a memory. Each register is
composed of a number of bits (usually 8) where the
data can be stored. In the 8051 family of
microcontrollers for example, most registers are 8-bit D7 D6 D5 D4 D3 D2 D1 D0
register, capable of storing values ranging from 0 to Figure 1.3.A
255. In order to use bigger values, various register can
be used simultaneously. Figure 1.3.A shows a typical
8-bit registers, where the notation D0 to D7 stands for
the 8 DATA bits of the register.

As you shall see, the RAM memory of the AT89S52, which contains 256 registers, is
divided into to main parts, the GPR part, and the SFR part. GPR stands for 'General
Purpose Register' and are the registers that you can use to store any data during the
execution of your program. SFRs (Special function Register) are registers used to
control the functioning of the microcontroller and to assist the processor through the
various operations being executed. For example, SFRs can be used to control
Input/output lines, to retrieve data transmitted through the serial port of a desktop
computer, or to configure one of the on-chip counters and timers.

In a memory each register has a specific address which is used


by the processor to read and write from specific memory
location. Figure 1.3.B shows the memory organization of the
256 registers of the RAM of the AT89S52 microcontroller.
The address is noted in Hexadecimal format as this notation
simplifies digital logic calculations for the designers, 00
corresponds to the first location and FF which is equal to 256
corresponds to the last location.

A programmer that would use the assembly language, have to


take this memory organization into consideration while
choosing the locations where his variables are stored, as
writing general purpose data into special function registers
could prevent the microcontroller from working correctly, but
Figure 1.3.B
since we will use the C language using the KEIL IDE
(integrated development environment), this part will be totally
handled by the compiler.

Clock concept

Page 18
GUAVA PI

The clock concept is found in all modern digital electronics, it is a simple circuit that
will generate pulses of electricity at a very specific frequency. Those pulses will
cadence all the events happening inside a microcontroller, those pulses will also
assure the synchronization of the events between various components inside the
microcontroller. For example, if the CPU is waiting for some result of mathematical
operation from the ALU (Arithmetic and Logic Unit), it will be known - according to
very specific protocol - when and where the resulting data will be delivered to the
CPU. The synchronization of those two devices is maintained because they share the
same clock.

The clock has another very important role which is to enable the microcontroller to
count timing. Without a precise clock, it would be impossible to build a 'Real Time
System', or any other device that relies on time measurements. It can be deduced that
the precision of the timing of a microcontroller depends on the frequency of its clock.

In the AT89C52 microcontroller, the clock can be fixed to different value by


connecting a crystal to the pins 18 and 19. Those crystals are sold with the frequency
written on them in Mega Hertz. The maximum operating frequency of the AT89C52 is
33 MHz, however other manufacturers like Philips built similar 8051 microcontrollers
that can run at frequencies up to 120 MHz

Life cycle of a microcontroller project

Before passing to the next part of the tutorial, is important to have a general idea of
the steps that are followed to realize a project, from the very beginning when you get
an idea to the very end when you finalize your project.

As you can see in figure 1.5.A, after you settle on the choice of your project in the
'brain storming' part, its imperative to imagine how it can be implemented from the
hardware point of view, before passing to the programming phase, because
programming is much more flexible than the hardware design. In other words, you

Page 19
GUAVA PI

start by designing the hardware, then you work on the programming while taking in
consideration the eventual constraints imposed by the hardware design.

The hardware design includes all the aspects of the electronic connections between
other devices, like the compatibility of the voltage levels, or the required number of
pins, etc...

After you're done with a first version of your program, you can transfer it to the
microcontroller mounted on the board that you realized already, resulting in a first
prototype. The transfer of the code is done using a special device called 'burner' or
'programmer' that connect to the computer, reads the HEX file generated by the
compiler, and sends it to the 'program memory' of the microcontroller. The prototype
will be used to test your project, correct eventual errors and enhance its performance,
tacking in account the famous rule that statesUSB/EXT
that any project never works the first
time; at least it does not work as you expected! For Power Supply
Selection

PRG/RUN
Jumper USB
To
Computer

NOTE During uploading the program remove the jumper select switch to program
mode and during run the program join the jumper & select the switch to Run mode

Page 20
GUAVA PI

SAMPLE PROGRAM 1: Interfacing of LEDs

Objective: To interface LED with microcontroller and make flashing light sequence.
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
Theory:

It demonstrates the principle behind interfacing LEDs with 8051 microcontroller.


Here we have demonstrated the aforesaid principles by blinking LEDs continuously
i.e., switching them on and off.

LEDs are by far the most widely used means of taking output. They find huge
application as indicators during experimentations to check the validity of results at
different stages. They are very cheap and easily available in a variety of shape, size
and colors.

The principle of operation of LEDs is simple. The commonly available LEDs (3mm)
have a drop voltage of 1.7 V and need 20 mA to glow at full intensity. The following
circuit describes how to glow an led.

The value of resistance R can be calculated using the equation, R= (V-1.7)/10 mA.
Since most of the controllers work on 5V, so substituting V= 5V, the value of
resistance comes out to be 330 ohm. The resistance 220 ohm, 470 ohm is commonly
used substitute in case 330 ohm is not available.

AT89S52 is a 40 pin microcontroller which belongs to 8051 series of microcontroller.


It has four ports each of 8 bits P0, P1, P2 and P3.The AT89C51 has 4K bytes of
programmable flash. The port P0 covers the pin 32 to pin 39, the port P1 covers the
pin 1 to pin 8, the port P2 covers the pin 21 to pin 28 and the port P3 covers the pin 10

Page 21
GUAVA PI

to pin 17. Pin 9 is the reset pin. The reset is active high. Whenever the controller is
given supply, the reset pin must be given a high signal to reset the controller and bring
the program counter to the starting address 0x0000. The controller can be reset by
manually connecting a switch or by connecting a combination of resistor and
capacitor as shown in the circuit diagram. A 12 MHz crystal is connected between pin
18 pin 19. Pin 40 is Vcc and pin 20 is ground. Pin 31, is connected to Vcc as we are
using the internal memory of the controller.

LEDs are connected to the port P2. LEDs need approximately 10mA current to flow
through them in order to glow at maximum intensity. However the output of the
controller is not sufficient enough to drive the LEDs, so if the positive leg of the LED
is connected to the pin and the negative to ground as shown in the figure, the LED
will not glow at full illumination.

To overcome this problem LEDs are connected in the reverse order and they run on
negative logic i.e., whenever 1 is given on any pin of the port, the LED will switch off
and when logic 0 is provided the LED will glow at full intensity.

As soon as we provide supply to the controller, the LEDs start blinking i.e., they
become on for a certain time duration and then become off for the same time duration.
This delay is provided by calling the delay function. The values inside the delay
function have been set to provide a delay in multiples of millisecond (delay (100) will
provide a delay of 100 millisecond).

Page 22
GUAVA PI

Connection Diagram:

Page 23
GUAVA PI

Program Code:

#include<reg51.h> //Header file inclusion


#define Led P2

Void MSdelay(unsigned int rtime) // Generates delays in mili seconds


{
{
unsigned int r,s;

for(r=0;r<rtime;r++)

for(s=0;s<1275;s++);
}
}

void main()
{
Led = 0x00;

while(1) //Infinite loop

{
Led=0xFF; //Set port P2 high

MSdelay(100); // delay of 100 mili-seconds

Led=0x00; //Set port P2 low

MSdelay(100); // delay of 100 mili-second


}

Page 24
GUAVA PI

SAMPLE PROGRAM 2: Interfacing of LCDs

Objective: To interface LCD with microcontroller and display Strings.


Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
Theory:
LCD Interface
The most commonly used Character based LCDs are based on Hitachi's HD44780
controller or other which are compatible with HD44580. In this section, we will
discuss about character based LCDs, their interfacing with microcontrollers, special
stuff and tricks you can do with these simple looking LCDs which can give a new
look to your application.

Pin Description
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4
Line LCDs which have only 1 controller and support at most of 80 characters,
whereas LCDs supporting more than 80 characters make use of 2 HD44780
controllers.
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins (two
pins are extra in both for back-light LED connections). Pin description is shown in the
table below.

Page 25
GUAVA PI

Figure 1: Character LCD type HD44780 Pin diagram

Pin No. Function

1 Ground

2 Supply +5V

3 Contrast Adjust

4 Register Select

5 Read/write

6 Enable

7-14 Data Lines

15 Backlight Supply

16 Backlight Ground

DDRAM - Display Data RAM

Display data RAM (DDRAM) stores display data represented in 8-bit character codes.
Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM
(DDRAM) that is not used for display can be used as general data RAM. So whatever
you send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, only
16 characters are visible, so whatever you write after 16 chars is written in DDRAM
but is not visible to the user.

Figures below will show you the DDRAM addresses of 1 Line, 2 Line and 4 Line
LCDs.

DDRAM Address for 1st Line LCD

DDRAM Address for 2nd Line LCD


BF - Busy Flag
Busy Flag is an status indicator flag for LCD. When we send a command or data to
the LCD for processing, this flag is set (i.e. BF =1) and as soon as the instruction is
executed successfully this flag is cleared (BF = 0). This is helpful in producing and

Page 26
GUAVA PI

exact amount of delay for the LCD processing.

To read Busy Flag, the condition RS = 0 and R/W = 1 must be met and The MSB of
the LCD data bus (D7) act as busy flag. When BF = 1 means LCD is busy and will
not accept next command or data and BF = 0 means LCD is ready for the next
command or data to process.

Instruction Register (IR) and Data Register (DR)


There are two 8-bit registers in HD44780 controller Instruction and Data register.
Instruction register corresponds to the register where you send commands to LCD e.g.
LCD shift command, LCD clear, LCD address etc. and Data register is used for
storing data which is to be displayed on LCD. When send the enable signal of the
LCD is asserted, the data on the pins is latched in to the data register and data is then
moved automatically to the DDRAM and hence is displayed on the LCD.
Data Register is not only used for sending data to DDRAM but also for CGRAM, the
address where you want to send the data, is decided by the instruction you send to
LCD.

Below is a brief list of useful commands which are used frequently while working on
the LCD.

Page 27
GUAVA PI

Frequently used commands and instructions for LCD

Connection Diagram:

Page 28
GUAVA PI

Program Code:

/*Connections: P2 to Data port & P0 to control port of LCD display module*/

#include<reg51.h> //Header file inclusion for 8051

sfr lcddata=0xA0; //Declaring LCDdata


sbit rs=P0^0; //The Register select Pin
sbit rw=P0^1; //The Read/Write Pin
sbit en=P0^2; //The Enable Pin

void delay(unsigned int time)


{
unsigned int a,b;
for(a=0; a<=time; a++)
{
for(b=0; b<=1275; b++)
{}
}
}

void lcmd(unsigned char sdata)


{
rs =0;
rw=0;
en=1; //Strobe the enable pin
lcddata=sdata; //Put the value on the pins
en=0;
}

void ldata(unsigned char ddata)


{
rs=1;
rw=0;
en=1;
lcddata=ddata;
en=0;
}

Page 29
GUAVA PI

void init(void)
{
lcmd(0x30); //1 line and 5x7 matrix
delay(10);
lcmd(0x38); //2 line and 5x7 matrix
delay(10);
lcmd(0x0C); //Display on, cursor off
delay(10);
lcmd(0x01); //Clear display Screen
delay(10);
lcmd(0x06); //shift cursor to right
delay(10);
}

void ldisp(unsigned char location, unsigned char *d)


{
lcmd(0x80|location);
delay(1);
while(*d)
{
ldata(*d++);

}
}

void main()
{
init();

while(1)
{
ldisp(0x80," TECHNIDO ");
ldisp(0xC0,"INDIA");
lcmd(0x18);
delay(20);
}

Page 30
GUAVA PI

SAMPLE PROGRAM 3: Interfacing of Seven Segments

Objective: To interface LCD with microcontroller and make flashing light sequence.
Caution: Not to supply under slandered package.(Need to supply extra)
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
Theory:
For the seven segment display we have used the LT-542 common anode. Each of the
segments of the display is connected to a pin on the 8051 .In order to light up a
segment on the pin must be set to 0V. To turn a segment off the corresponding pin
must be set to 5V. This is simply done by setting the pins on the 8051 to '1' or '0'.

LED displays are


Power-hungry (10ma per LED)
Pin-hungry (8 pins per 7-seg display)

But they are cheaper than LCD display

7-SEG Display is available in two types -1. Common anode & 2. common
cathode , but command anode display are most suitable for interfacing with 8051
since 8051 port pins can sink current better than sourcing it.

Page 31
GUAVA PI

CREATING DIGIT PATTERN

For displaying Digit say 7 we need to light segments -a ,b, c. Since we are using
Common anode display , to do so we have to provide Logic -0 (0 v) at anode of
these segments. so need to clear pins according to connection with microcontroller
and then need to calculate the hex value for a particular digit.

You can also do this for some characters like A ,E .. But not for D or B because it will
be same as that of 0 & 8 . So this is one of limitation of 7-seg display.

Since we can Enable only one 7-seg display at a time, we need to scan these display at
fast rate .The scanning frequency should be high enough to be flicker-free. At least
30HZ .Therefore time one digit is ON is 1/30 seconds

INTERFACING

Note that this board is using Common Anode display. So the common Anode pin is
tied to 5v .The cathode pins are connected to port 1 through 220 Ohm resistance
(current limiting).

Page 32
GUAVA PI

Connections:

Page 33
GUAVA PI

Program Code:

#include<reg51.h>
sbit f=P2^0;
sbit g=P2^1;
sbit a=P2^2;
sbit b=P2^3;
sbit e=P2^4;
sbit d=P2^5;
sbit r=P2^6;
sbit c=P2^7;

sbit t1=P0^0;
sbit t2=P0^1;
unsigned int i;

void delay(unsigned int time)


{
unsigned int p, q;
for(p=0; p<=time; p++)
{
for(q=0; q<=1275; q++)
{}
}

Page 34
GUAVA PI

Void type1 ()
{
a=1;
b=0;
c =0;
d =1;
e =1;
f =1;
g =1;
delay (1);
}

Void type2 ()
{
a=0;
b=0;
c =1;
d =0;
e =0;
f =1;
g =0;
delay (1);
}

Void type3 ()
{
a=0;
b=0;
c =0;
d =0;
e =1;
f =1;
g =0;
delay (1);
}

Void type4 ()
{
a=1;
b=0;
c =0;
d =1;
e =1;
f =0;
g =0;
delay (1);
}

Page 35
GUAVA PI

Void type5 ()
{
a=0;
b=1;
c =0;
d =0;
e =1;
f =0;
g =0;
delay (1);
}

Void type6 ()
{
a=0;
b=1;
c =0;
d =0;
e =0;
f =0;
g =0;
delay (1);
}

Void type7 ()
{
a=0;
b=0;
c =0;
d =1;
e =1;
f =1;
g =1;
delay (1);
}

Void type8 ()
{
a=0;
b=0;
c =0;
d =0;
e =0;
f =0;
g =0;
delay (1);
}

Void type9 ()

Page 36
GUAVA PI

{
a=0;
b=0;
c =0;
d =0;
e =1;
f =0;
g =0;
delay (1);
}

void main ()
{
while(1)
{
for(i=0; i<=24; i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type1 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type2 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type3 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();

Page 37
GUAVA PI

t1=0;
t2=1;
type4 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type5 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type6 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type7 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();
t1=0;
t2=1;
type8 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type1 ();

Page 38
GUAVA PI

t1=0;
t2=1;
type9 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type1 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type2 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type3 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type4 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();

Page 39
GUAVA PI

t1=0;
t2=1;
type5 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type6 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type7 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type8 ();
}

for(i=0;i<=24;i++)
{
t1=1;
t2=0;
type2 ();
t1=0;
t2=1;
type9 ();
}

Page 40
GUAVA PI

SAMPLE PROGRAM 4: Interfacing of Keypad

Objective: To interface LCD and keypad with microcontroller and make a basic
calculator.
Caution: Not to supply under slandered package.(Need to supply extra)
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
Theory:
Keypads are a part of HMI or Human Machine Interface and play really important
role in a small embedded system where human interaction or human input is needed.
Matrix keypads are well known for their simple architecture and ease of interfacing
with any microcontroller. In this part of tutorial we will learn how to interface a 4x4
matrix keypad with AVR and 8051 microcontroller. Also we will see how to program
then in Assembly and C.

Constructing a Matrix Keypad

Construction of a keypad is really simple. As per the outline shown in the figure

Page 41
GUAVA PI

below we have four rows and four columns. In between each overlapping row and
column line there is a key.

So keeping this outline we can construct a keypad using simple SPST Switches as
shown below:

Now our keypad is ready, all we have to do is connect the rows and columns to a port
of microcontroller and program the controller to read the input.

Scanning a Matrix Keypad

There are many methods depending on how you connect your keypad with your
controller, but the basic logic is same. We make the rows as i/p and we drive the
columns making them o/p, this whole procedure of reading the keyboard is called
scanning.

In order to detect which key is pressed from the matrix, we make columns lines low
one by one and read the rows. Lets say we first make Column1 low, then read the
rows. If any of the key in column1 is pressed it will make the corresponding row as
low i.e. if 4 key is pressed in column1, then row2 will give low. So we come to
know that key 4 of column1 is pressed. This is how scanning is done.

So to scan the keypad completely, we need to make columns low one by one and read
the rows. If any of the buttons is pressed in a column, it will take the corresponding
row to a low state which tells us that a key is pressed in that column.

Page 42
GUAVA PI

Connections:

Program Code:

#include<reg51.h>
#include<stdio.h>

sbit RS=P0^0;
sbit RW=P0^1;
sbit EN=P0^2;

Page 43
GUAVA PI

sfr lcddata = 0xA0;

sbit r1=P1^0;
sbit r2=P1^1;
sbit r3=P1^2;
sbit r4=P1^3;
sbit c4=P1^4;
sbit c3=P1^5;
sbit c2=P1^6;
sbit c1=P1^7;

void delay(unsigned int time)


{
unsigned int a,b;
for(a=0;a<=time;a++)
{
for(b=0;b<=1275;b++)
{}
}
}

/*This function makes one column to GND one by one and check the rows for key
press */

int keypress()
{
while(1)
{
c1=0;c2=1;c3=1;
if(r1==0){return 1;}
if(r2==0){return 4;}
if(r3==0){return 7;}

c1=1;c2=0;c3=1;
if(r1==0){return 2;}
if(r2==0){return 5;}
if(r3==0){return 8;}
if(r4==0){return 0;}

c1=1;c2=1;c3=0;
if(r1==0){return 3;}
if(r2==0){return 6;}
if(r3==0){return 9;}
}
}

void lcdcmd(unsigned char DATA)

Page 44
GUAVA PI

{
RS=0;RW=0;EN=1;
lcddata=DATA;
EN=0;
}

void lcddat(unsigned char DATA)


{
RS=1;RW=0;EN=1;
lcddata=DATA;
EN=0;
}

void initialize()
{
lcdcmd(0x30);
delay(1);
lcdcmd(0x38);
delay(1);
lcdcmd(0x0C);
delay(1);
lcdcmd(0x01);
delay(1);
lcdcmd(0x06);
delay(1);
}

void display(unsigned char location,unsigned char *d)


{
lcdcmd(0x80|location);
delay(1);
while(*d)
{
lcddat(*d++);
}
}

void main()
{
int p,q,r,num;
char abc[16];
initialize();
display(0x00," KEYPAD ");
display(0x40," ");

while(1)
{

Page 45
GUAVA PI

p = keypress();
sprintf(abc," %d ",p);
display(0x40,abc);
delay(50);
}
}

Page 46
GUAVA PI

SAMPLE PROGRAM 6: Interfacing of Serial Port

Objective: To interface Serial port with microcontroller and read value transfer from
PC and display corresponding on LCD.
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
4. Potentiometer
Theory:
In simple words serial communication is the exchange of data between two devices serially
i.e. through single or two wires. In our case serial communication is referred to as
communication between microcontroller and computer or between microcontroller and
microcontroller. Serial communication is done using RS-232 Protocol that is a standard.
RS-232 WAVEFORM

TTL/CMOS Serial Logic Waveform

The diagram above, shows the expected waveform from the UART when using the common
8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. The RS-232 line, when idle
is in the Mark State (Logic 1). A transmission starts with a start bit which is (Logic 0). Then
each bit is sent down the line, one at a time. The LSB (Least Significant Bit) is sent first. A
Stop Bit (Logic 1) is then appended to the signal to make up the transmission.

The data sent using this method, is said to be framed. That is the data is framed between a
Start and Stop Bit .

RS-232 Voltage levels

1. +3 to +25 volts to signify a "Space (logic 0)

2. -3 to -25 volts for a "Mark" (logic 1).

3. Any voltage in between these regions (i.e. between +3 and -3 Volts) is undefined.

The data byte is always transmitted least-significant-bit first.

The bits are transmitted at specific time intervals determined by the baud rate of the serial
signal. This is the signal present on the RS-232 Port of your computer, shown below.

Page 47
GUAVA PI

RS-232 Logic Waveform

RS-232 level converter


Standard serial interfacing of microcontroller (TTL) with PC or any RS232C Standard
device , requires TTL to RS232 Level converter . A MAX232 is used for this purpose. It
provides 2-channel RS232C port and requires external 10uF capacitors.
The driver requires a single supply of +5V.

MAX-232 includes a charge pump, which generates +10V and -10V from a single 5v supply.
Below is a typical circuit showing connections of MAX 232 with microcontroller also an
ADC is connected which can be utilized for taking any analog input such as input from LM
35.

Page 48
GUAVA PI

Connection:

To PC

Program Code:

Page 49
GUAVA PI

#include<reg51.h>

sbit L1=P2^0;
sbit L2=P2^1;
sbit L3=P2^2;
sbit L4=P2^3;
sbit L5=P2^4;
sbit L6=P2^5;
sbit L7=P2^6;
sbit L8=P2^7;

//LCD
sfr LCDdata=0x80;
sbit LCDrs=P1^0;
sbit LCDrw=P1^1;
sbit LCDen=P1^2;

void lcdcmd (unsigned char DATA)


{

LCDrs=0;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDrs=0;
LCDrw=0;
LCDen=0;
}

void delay (unsigned int a )


{
unsigned int k; unsigned char l;
for (k=0;k<a;k++)
{
for (l=0;l<10;l++)
{

}
}
}

void initialize (void)


{
lcdcmd (0x30);
delay(30);
lcdcmd (0x38);
delay(30);
lcdcmd (0x0c);
delay(30);
lcdcmd (0x01);
delay(30);
lcdcmd (0x06);
delay(30);
}

Page 50
GUAVA PI

void lcddat (unsigned int DATA)


{

LCDrs=1;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDrs=1;
LCDrw=0;
LCDen=0;
}

void display_lcd (unsigned char location, unsigned char *d)


{
lcdcmd(0x80 | location);
delay(1);
while(*d)
{
lcddat(*d++);
}
}

unsigned int i=0;


void main(void)
{
unsigned int AA=0;
P2=0xFF;
P1=0xFF;

TMOD=0x20;
TH1=0xFD;
SCON=0X50;
TR1=1;

initialize();

display_lcd(0x80, " TECHNIDO ");


display_lcd(0xC0, " Speech Recogn ");
P2=0xFF;
while(1)
{
while(RI==0);
AA=SBUF;

if (AA=='a') //gripper open


{
P2=0x7F;
display_lcd(0x80, " ONE ");
display_lcd(0xC0, " ");
}

Page 51
GUAVA PI

if (AA=='b') //gripper open


{
P2=0xBF;
display_lcd(0x80, " TWO ");
display_lcd(0xC0, " ");
}

if (AA=='c') //gripper open


{
P2=0xDF;
display_lcd(0x80, " THREE ");
display_lcd(0xC0, " ");
}

if (AA=='d') //gripper open


{
P2=0xEF;
display_lcd(0x80, " FOUR ");
display_lcd(0xC0, " ");
}

if (AA=='e') //gripper open


{
P2=0xF7;
display_lcd(0x80, " FIVE ");
display_lcd(0xC0, " ");
}

if (AA=='f') //gripper open


{
P2=0xFB;
display_lcd(0x80, " SIX ");
display_lcd(0xC0, " ");
}

if (AA=='g') //gripper open


{
P2=0xFD;
display_lcd(0x80, " SEVEN ");
display_lcd(0xC0, " ");
}

if (AA=='h') //gripper open


{
P2=0xFE;
display_lcd(0x80, " EIGHT ");
display_lcd(0xC0, " ");
}

RI=0;
}

Page 52
GUAVA PI

} SAMPLE PROGRAM 7: Interfacing of DC Motor

Objective: To interface DC Motor with microcontroller and make it clockwise and


anti-clockwise rotate.
Caution: Not to supply under slandered package.(Need to supply extra)
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
4. DC Motor
5. Screw Driver
Theory:
Stepper Motors work under a very similar principle to DC motors, except
they have many coils instead of just one. So to operate a stepper motor,
one must activate these different coils in particular patterns to generate
motor rotation. So stepper motors need to be sent patterned commands to
rotate. These commands are sent as high and low logic over several lines,
and must be pulsed in a particular order and combination. Steppers are
often used because each 'step,' separated by a set step angle, can be
counted and used for feedback control. For example, a 10 degree step
angle stepper motor would require 36 commands to rotate 360 degrees.
However external torque can force movement to a different step,
invalidating feedback. Therefore external torque must never exceed the
holding torque of a stepper.

Voltage

Polarized (current cannot be reversed)


Typically from 5-12V, but can range to extremes in special application motors
Higher voltages generally mean more torque, but also require more power
DC motor can run above or below rated voltage (to meet other design
requirements)
Most efficient at rated voltage

Current

When buying a motor, consider stall, holding, and operating current (max and
minimum)
Holding Current - The current a stepper motor requires when powered but not
signaled to rotate
It is best to determine current curves relating voltage, current, and required
torque for optimization

Page 53
GUAVA PI

Connections:

To Motor

Program Code:
#include<reg51.h>

sbit R1=P1^0;
sbit R2=P1^1;
sbit R3=P1^2;
sbit R4=P1^3;
sbit C4=P1^4;
sbit C3=P1^5;
sbit C2=P1^6;
sbit C1=P1^7;

sbit M1=P3^0;
sbit M2=P3^1;
sbit M3=P3^2;
sbit M4=P3^3;

//LCD
sfr LCDdata=0xA0;
sbit LCDrs=P0^0;

Page 54
GUAVA PI

sbit LCDrw=P0^1;
sbit LCDen=P0^2;

void lcdcmd (unsigned char DATA)


{
LCDrs=0;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDen=0;
}

void delay (unsigned int a )


{
unsigned int k; unsigned char l;
for (k=0; k<a; k++)
{
for (l=0;l<10;l++)
{}
}
}

void initialize (void)


{
lcdcmd (0x30);
delay(30);
lcdcmd (0x38);
delay(30);
lcdcmd (0x0c);
delay(30);
lcdcmd (0x01);
delay(30);
lcdcmd (0x06);
delay(30);
}

void lcddat (unsigned int DATA)


{
LCDrs=1;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDen=0;
}

void display_lcd (unsigned char location, unsigned char *d)


{
lcdcmd(0x80 | location);
delay(1);
while(*d)

Page 55
GUAVA PI

{
lcddat(*d++);
}
}

int key (void)


{
while(1)
{
P2=0xFF;

C1=0; C3=1;
if(R1==0)
{
return 1;
}

if(R2==0)
{
return 4;
}
if(R3==0)
{
return 7;
}
if(R4==0)
{
return 0;
}

C1=1; C2=0;
if(R1==0)
{
return 2;
}
if(R2==0)
{
return 5;
}
if(R3==0)
{
return 8;
}

C2=1; C3=0;
if(R1==0)
{
return 3;
}
if(R2==0)

Page 56
GUAVA PI

{
return 6;
}
if(R3==0)
{
return 9;
}
}
}

void main()
{
unsigned int a;
initialize();

display_lcd(0x80, " TECHNIDO ");


display_lcd(0xC0, " DC Motor Control ");
delay(100);

while(1)
{
a=key();

if(a==1)
{
display_lcd(0x80, "You Pressed 1 ");
display_lcd(0xC0, " M1 CW M2 OFF ");
M1=0;
M2=1;
M3=0;
M4=0;
a=0;
}

if(a==2)
{
display_lcd(0x80, "You Pressed 2 ");
display_lcd(0xC0, " M1 CCW M2 OFF ");
M1=1;
M2=0;
M3=0;
M4=0;
a=0;
}

if(a==3)
{
display_lcd(0x80, "You Press 3 ");
display_lcd(0xC0, " M1 OFF M2 CW ");
M1=0;

Page 57
GUAVA PI

M2=0;
M3=1;
M4=0;
a=0;
}

if(a==4)
{
display_lcd(0x80, "You Press 4 ");
display_lcd(0xC0, " M1 OFF M2 CCW ");
M1=0;
M2=0;
M3=0;
M4=1;
a=0;
}

if(a==5)
{
display_lcd(0x80, "You Press 5 ");
display_lcd(0xC0, " M1 CW M2 CW ");
M1=1;
M2=0;
M3=1;
M4=0;
a=0;
}

if(a==6)
{
display_lcd(0x80, "You Press 5 ");
display_lcd(0xC0, " M1 CCW M2 CCW ");
M1=0;
M2=1;
M3=0;
M4=1;
a=0;
}

if(a==7)
{
display_lcd(0x80, "You Press 5 ");
display_lcd(0xC0, " M1 OFF M2 OFF ");
M1=0;
M2=0;
M3=0;
M4=0;
a=0;
}

Page 58
GUAVA PI

}
}

Page 59
GUAVA PI

SAMPLE PROGRAM 9: Interfacing of RTC

Objective: To interface RTC with microcontroller and see time at LCD display.
Caution: Not to supply under slandered package.(Need to supply extra)
Apparatus Required:
1. Main Board
2. FRC Cables
3. USB Cables
Theory:
A real-time clock (RTC) is a computer clock (most often in the form of an
integrated circuit) that keeps track of the current time. Although the term
often refers to the devices in personal computers, servers and embedded
systems, RTCs are present in almost any electronic device which needs to
keep accurate time RTCs often have an alternate source of power, so they
can continue to keep time while the primary source of power is off or
unavailable. This alternate source of power is normally a lithium battery in
older systems, but some newer systems use a super-capacitor, because
they are rechargeable and can be soldered.

The alternate power source can also supply power to battery backed RAM.
Most RTCs use a crystal oscillator, but some use the power line
frequency.In many cases the oscillator's frequency is 32.768 kHz.This is
the same frequency used in quartz clocks and watches, and for the same
reasons, namely that the frequency is exactly 215 cycles per second,
which is a convenient rate to use with simple binary counter circuits. In
this condition, one of the two sets of contacts in the relay pictured is
closed, and the other set is open. Other relays may have more or fewer
sets of contacts depending on their function.

Page 60
GUAVA PI

Connections:

Program Code:

// interfacing ds1307 with AT89C51

#include<reg51.h>

void _nop_(void);

#define delay_us _nop_(); //generates 1 microsecond

#define LCD P2

sbit RS=P0^0; //connect p3.0 to rs pin of lcd

sbit EN=P0^2; //connect p3.2 to en pin of lcd

sbit RW=P0^1; //connect p3.1 to en pin of lcd

Page 61
GUAVA PI

sbit SCK=P1^1; //serial clock pin

sbit SDA=P1^0; //serial data pin

#define SCKHIGH SCK=1;

#define SCKLOW SCK=0;

#define SDAHIGH SDA=1;

#define SDALOW SDA=0;

void integer_lcd(int);

void init_lcd(void);

void cmd_lcd(unsigned char);

void write_lcd(unsigned char);

void display_lcd(unsigned char *);

void delay_ms(unsigned int);

void start(void);

void stop(void);

void send_byte(unsigned char);

unsigned char receive_byte(unsigned char);

void write_i2c(unsigned char,unsigned char,unsigned char);

unsigned char read_i2c(unsigned char,unsigned char);

//clock[ ]={seconds,minutes,hours,day_of_week,date,month,year};

unsigned char clock[ ]={0x00,0x40,0x17,0x06,0x24,0x03,0x06};

unsigned char *s[ ]={"SUN","MON","TUE","WED","THU","FRI","SAT"};

unsigned char slave_ack,add=0,c,k;

unsigned int num;

// Real Time Clock Mode

Page 62
GUAVA PI

void main(void)

init_lcd();

//cmd_lcd(0x01);

//display_lcd("UTL");

//delay_ms(1000);

while(add<=6) //update real time clock

write_i2c(0xd0,add,clock[add]);

add++;

// stop();

while(1)

c=read_i2c(0xd0,0x02);//read hours register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

write_lcd(':');

c=read_i2c(0xd0,0x01);//read minutes register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

write_lcd(':');

delay_ms(10);

Page 63
GUAVA PI

c=read_i2c(0xd0,0x00);//read seconds register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

write_lcd(' ');

display_lcd(s[read_i2c(0xd0,0x03)]);//read day register and display

cmd_lcd(0xc0);

c=read_i2c(0xd0,0x04);//read date register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

write_lcd('/');

c=read_i2c(0xd0,0x05);//read month register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

write_lcd('/');

write_lcd('2');

write_lcd('0');

c=read_i2c(0xd0,0x06);//read year register and display on LCD

write_lcd((c/16)+48);

write_lcd((c%16)+48);

delay_ms(100);

cmd_lcd(0x01);

}
}

//starts i2c, if both SCK & SDA are idle

Page 64
GUAVA PI

void start(void)

if(SCK==0) //check SCK. if SCK busy, return else SCK idle

return;

if(SDA==0) //check SDA. if SDA busy, return else SDA idle

return;

SDALOW //data low

delay_us

SCKLOW //clock low

delay_us

//stops i2c, releasing the bus

void stop(void)

SDALOW //data low

SCKHIGH //clock high

delay_us

SDAHIGH //data high

delay_us

//transmits one byte of data to i2c bus

void send_byte(unsigned char c)

unsigned mask=0x80;

do //transmits 8 bits

Page 65
GUAVA PI

if(c&mask) //set data line accordingly(0 or 1)

SDAHIGH //data high

else

SDALOW //data low

SCKHIGH //clock high

delay_us

SCKLOW //clock low

delay_us

mask/=2; //shift mask

}while(mask>0);

SDAHIGH //release data line for acknowledge

SCKHIGH //send clock for acknowledge

delay_us

slave_ack=SDA; //read data pin for acknowledge

SCKLOW //clock low

delay_us

//receives one byte of data from i2c bus

unsigned char receive_byte(unsigned char master_ack)

unsigned char c=0,mask=0x80;

do //receive 8 bits

SCKHIGH //clock high

delay_us

Page 66
GUAVA PI

if(SDA==1) //read data

c|=mask; //store data

SCKLOW //clock low

delay_us

mask/=2; //shift mask

}while(mask>0);

if(master_ack==1)

SDAHIGH //don't acknowledge

else

SDALOW //acknowledge

SCKHIGH //clock high

delay_us

SCKLOW //clock low

delay_us

SDAHIGH //data high

return c;

//writes one byte of data(c) to slave device(device_id) at given address(location)

void write_i2c(unsigned char device_id,unsigned char location,unsigned char c)

do

start(); //starts i2c bus

send_byte(device_id); //select slave device

Page 67
GUAVA PI

if(slave_ack==1) //if acknowledge not received, stop i2c bus

stop();

}while(slave_ack==1); //loop until acknowledge is received

send_byte(location); //send address location

send_byte(c); //send data to i2c bus

stop(); //stop i2c bus

delay_ms(4);

//reads one byte of data(c) from slave device(device_id) at given address(location)

unsigned char read_i2c(unsigned char device_id,unsigned char location)

unsigned char c;

do

start(); //starts i2c bus

send_byte(device_id); //select slave device

if(slave_ack==1) //if acknowledge not received, stop i2c bus

stop();

}while(slave_ack==1); //loop until acknowledge is received

send_byte(location); //send address location

stop(); //stop i2c bus

start(); //starts i2c bus

send_byte(device_id+1); //select slave device in read mode

c=receive_byte(1); //receive data from i2c bus

stop(); //stop i2c bus

return c;

Page 68
GUAVA PI

/*display of 16bit(integers) values on LCD

void integer_lcd(int n)

unsigned char c[6];

unsigned int i=0;

if(n<0)

write_lcd('-');

n=-n;

if(n==0)

write_lcd('0');

while(n>0)//Split integer to 2 bytes and send on 8bit line.

c[i++]=(n%10)+48;

n/=10;

while(i-->=1)

write_lcd(c[i]);

}*/

//initialize lcd

void init_lcd(void)

delay_ms(10); //delay 10 milliseconds

cmd_lcd(0x0e); //lcd on, cursor on

Page 69
GUAVA PI

delay_ms(10);

cmd_lcd(0x38); //8 bit initialize, 5x7 character font, 16x2 display

delay_ms(10);

cmd_lcd(0x06); //right shift cursor automatically after each character is displayed

delay_ms(10);

cmd_lcd(0x01); //clear lcd

delay_ms(10);

cmd_lcd (0x80);

//transmit command or instruction to lcd

void cmd_lcd(unsigned char c)

EN=1;

RW=0;//set enable pin

RS=0; //clear register select pin

LCD=c; //load 8 bit data

EN=0; //clear enable pin

delay_ms(2); //delay 2 milliseconds

//transmit a character to be displayed on lcd

void write_lcd(unsigned char c)

EN=1; //set enable pin

RW=0;

RS=1; //set register select pin

LCD=c; //load 8 bit data

EN=0; //clear enable pin

Page 70
GUAVA PI

delay_ms(2); //delay 2 milliseconds

//transmit a string to be displayed on lcd

void display_lcd(unsigned char *s)

while(*s)

write_lcd(*s++);

//generates delay in milli seconds

void delay_ms(unsigned int i)

unsigned int j;

while(i-->0)

{
for(j=0;j<500;j++)

{ }

How to program other ICs using Guava PI

We can use Guava PI board for programming not only AT89S52 but other ICs also
those can include in ProgISP device list.
For this task we concentrate on 6-pins which are used during burning process in
Guava PI. These are MISO, MOSI, SCK, RST, 5V, GND.

Page 71
GUAVA PI

Keep all dip switches to Off condition. Place IC into separate base/ Bread board and
connect these pins to corresponding IC pins. For knowing IC pins go to data sheet of
that IC.
Now there is no need for place jumper from PRG and Run mode. No need to ON DIP
switches. DIP switches must be in OFF condition. Do the same process as we use in
programing of AT89S52. Use same software ProgISP for burning.
After burning remove the connection and use the IC
for application. Pins uses during burning

WARRANTY

1. We guarantee the instrument against all manufacturing defects during 12


months from the date of sale by us or through our dealers.

Page 72
GUAVA PI

2. The guarantee covers manufacturing defects in respect of indigenous


components and material limited to the warranty extended to us by the original
manufacturer and defect will be rectified as far as lies within our control.
3. The guarantee will become INVALID.
a) If the instrument is not operated as per instruction given in the instruction
manual.
b) If the agreed payment terms and other conditions of sale are not followed.
c) If the customer resells the instrument to another party.
d) Provided no attempt have been made to service and modify the instrument.
4. The non-working of the instrument is to be communicated to us immediately
giving full details of the complaints and defects noticed specifically mentioning
the type and sr. no. of the instrument, date of purchase etc.
5. The repair work will be carried out, provided the instrument is dispatched
securely packed and insured with the railways. To and fro charges will be to the
account of the customer.

DISPATCH PROCEDURE FOR SERVICE

Should it become necessary to send back the instrument to factory please observe the
following procedure:
1. Before dispatching the instrument please write to us giving full details of the
fault noticed.
2. After receipt of your letter our repairs dept. will advise you whether it is
necessary to send the instrument back to us for repairs or the adjustment is
possible in your premises.
Dispatch the instrument (only on the receipt of our advice) securely packed in original
packing duly insured and freight paid along with accessories and a copy of the details
noticed to us at our factory address.

Page 73