Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
USB PROGRAMMER
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 5: Interfacing of Serial Port 47
13. Sample Program 6: Interfacing of DC Motor* 53
14. Sample Program 7: Interfacing of RTC* 60
15. How to program other ICs using Guava-PI 72
16. How to program ATMEGA16A using Guava-PI 73
Page 2
GUAVA PI
SYSTEM INTRODUCTION
General description:
Guava PI is a single board Microcontroller Training/Development
Board configured around the ATMEL AT89S52 Microcontroller. This board 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
Page 4
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 – PROGISP 1.68 / PROGISP 1.72
3. Keil uVISION Software
Page 7
GUAVA PI
Page 8
GUAVA PI
Page 9
GUAVA PI
Page 10
GUAVA PI
HARDWARE DESCRIPTION
LED Power
Microcontroller Section Switch
AT89S52
Serial
LCD Port USB
Display 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 ASP Programmer: The section is a onboard USB ASP 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.
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
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 or 4 with the C51 compiler v8.05a.
To create a project, write and test the previous example source code, follow the
followingsteps:
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
eventual syntax errors. In KEIL IDE, this step is called 'rebuild all targets' and has this
icon: .
Page 13
GUAVA PI
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
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 is the name of a big family of microcontrollers. The device which we are
going to use 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.
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.
Page 16
GUAVA PI
Memory organization
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.
Page 17
GUAVA PI
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.
Clock concept
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.
Page 18
GUAVA PI
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, it’s 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
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 states that any project never works the first
time; at least it does not work as you expected!
Page 19
GUAVA PI
PRG/RUN USB
Jumper To
Computer
USB/EXT
For Power
Supply Selection
NOTE – During uploading the program remove the jumper select switch to Program
mode (PRG) and during run the program join the jumper & select the switch to Run
mode (RUN)
Page 20
GUAVA PI
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.
Page 21
GUAVA PI
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 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:
for(r=0;r<rtime;r++)
for(s=0;s<1275;s++);
}
}
void main()
{
Led = 0x00;
{
Led=0xFF; //Set port P2 high
Page 24
GUAVA PI
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
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.
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.
Page 26
GUAVA PI
Below is a brief list of useful commands which are used frequently while working on
the LCD.
Page 27
GUAVA PI
Connection Diagram:
Page 28
GUAVA PI
Program Code:
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 main()
{
init();
while(1)
{
ldisp(0x80," TECHNIDO ");
ldisp(0xC0,"INDIA");
lcmd(0x18);
delay(20);
}
Page 30
GUAVA PI
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. Guava Pi 8051 Development Board
2. FRC Cables
3. USB Cables
4. Embedded Launch Pad (Not included in the development kit.)**
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'.
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
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 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;
Page 34
GUAVA PI
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);
}
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);
}
Page 35
GUAVA PI
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 ()
{
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 ();
Page 36
GUAVA PI
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 ();
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 ();
Page 37
GUAVA PI
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 ();
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 ();
Page 38
GUAVA PI
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 ();
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 ();
Page 39
GUAVA PI
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
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
4. Embedded Launch Pad (Not included in the development kit.)**
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.
Construction of a keypad is really simple. As per the outline shown in the figure
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:
Page 41
GUAVA PI
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.
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. Let’s 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:
Page 43
GUAVA PI
Program Code:
#include<reg51.h>
#include<stdio.h>
sbit RS=P0^1;
sbit RW=P0^2;
sbit EN=P0^0;
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;
/*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;}
Page 44
GUAVA PI
c1=1;c2=1;c3=0;
if(r1==0){return 3;}
if(r2==0){return 6;}
if(r3==0){return 9;}
}
}
void initialize()
{
lcdcmd(0x30);
delay(1);
lcdcmd(0x38);
delay(1);
lcdcmd(0x0C);
delay(1);
lcdcmd(0x01);
delay(1);
lcdcmd(0x06);
delay(1);
}
Page 45
GUAVA PI
void main()
{
int p,q,r,num;
char abc[16];
initialize();
display(0x00," KEYPAD ");
display(0x40," ");
while(1)
{
p = keypress();
sprintf(abc," %d ",p);
display(0x40,abc);
delay(50);
}
}
Page 46
GUAVA PI
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
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 .
Page 47
GUAVA PI
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
Page 49
GUAVA PI
Program Code:
#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^1;
sbit LCDrw=P1^2;
sbit LCDen=P1^0;
LCDrs=0;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDrs=0;
LCDrw=0;
LCDen=0;
}
}
}
}
Page 50
GUAVA PI
LCDrs=1;
LCDrw=0;
LCDen=1;
LCDdata=DATA;
LCDrs=1;
LCDrw=0;
LCDen=0;
}
TMOD=0x20;
TH1=0xFD;
SCON=0X50;
TR1=1;
initialize();
Page 51
GUAVA PI
RI=0;
}
}
Page 52
GUAVA PI
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
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
Page 54
GUAVA PI
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^1;
sbit LCDrw=P0^2;
sbit LCDen=P0^0;
Page 55
GUAVA PI
lcdcmd (0x0c);
delay(30);
lcdcmd (0x01);
delay(30);
lcdcmd (0x06);
delay(30);
}
C1=0; C3=1;
if(R1==0)
{
return 1;
}
if(R2==0)
{
return 4;
}
if(R3==0)
{
return 7;
}
if(R4==0)
{
return 0;
Page 56
GUAVA PI
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)
{
return 6;
}
if(R3==0)
{
return 9;
}
}
}
void main()
{
unsigned int a;
initialize();
while(1)
{
a=key();
if(a==1)
{
display_lcd(0x80, "You Pressed 1 ");
display_lcd(0xC0, " M1 CW M2 OFF ");
M1=0;
Page 57
GUAVA PI
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;
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;
}
Page 58
GUAVA PI
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 59
GUAVA PI
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
4. Embedded Launch Pad (Not included in the development kit.)**
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:
Page 61
GUAVA PI
Program Code:
#include<reg51.h>
void _nop_(void);
#define LCD P2
void integer_lcd(int);
void init_lcd(void);
void start(void);
void stop(void);
Page 62
GUAVA PI
//clock[ ]={seconds,minutes,hours,day_of_week,date,month,year};
void main(void)
init_lcd();
//cmd_lcd(0x01);
//display_lcd("UTL");
//delay_ms(1000);
write_i2c(0xd0,add,clock[add]);
add++;
// stop();
while(1)
Page 63
GUAVA PI
write_lcd((c/16)+48);
write_lcd((c%16)+48);
write_lcd(':');
write_lcd((c/16)+48);
write_lcd((c%16)+48);
write_lcd(':');
delay_ms(10);
write_lcd((c/16)+48);
write_lcd((c%16)+48);
write_lcd(' ');
cmd_lcd(0xc0);
write_lcd((c/16)+48);
write_lcd((c%16)+48);
write_lcd('/');
write_lcd((c/16)+48);
write_lcd((c%16)+48);
Page 64
GUAVA PI
write_lcd('/');
write_lcd('2');
write_lcd('0');
write_lcd((c/16)+48);
write_lcd((c%16)+48);
delay_ms(100);
cmd_lcd(0x01);
}
}
void start(void)
return;
return;
delay_us
delay_us
void stop(void)
Page 65
GUAVA PI
delay_us
delay_us
unsigned mask=0x80;
do //transmits 8 bits
else
delay_us
delay_us
}while(mask>0);
delay_us
Page 66
GUAVA PI
delay_us
do //receive 8 bits
delay_us
delay_us
}while(mask>0);
if(master_ack==1)
else
SDALOW //acknowledge
delay_us
delay_us
return c;
}
Page 67
GUAVA PI
do
stop();
delay_ms(4);
unsigned char c;
do
stop();
Page 68
GUAVA PI
return c;
void integer_lcd(int n)
if(n<0)
write_lcd('-');
n=-n;
if(n==0)
write_lcd('0');
c[i++]=(n%10)+48;
n/=10;
Page 69
GUAVA PI
while(i-->=1)
write_lcd(c[i]);
}*/
//initialize lcd
void init_lcd(void)
delay_ms(10);
delay_ms(10);
delay_ms(10);
delay_ms(10);
cmd_lcd (0x80);
EN=1;
Page 70
GUAVA PI
RW=0;
while(*s)
write_lcd(*s++);
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++)
{ }
Page 71
GUAVA PI
We can use Guava PI board for programming not only AT89S52 but other ICs also
those ICs are listed in progISP ver 1.72.
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.
Keep all dip switches to Off condition. Place IC into separate Module /Bread board
and connect those 6-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. DIP switches must
be in OFF condition. Do the same process as we use in programing of AT89S52. Use
same software ProgISP for burning. We already explain burning process.
After burning remove the connection and use the IC for application.
Page 72
GUAVA PI
1.) Connect MOSI, MISO, SCK and RST of Guava-PI board to ATmega16A
module.
2.) Connect 5V and GND from Guava-PI to ATmega16A module.
5V and GND
Page 73
GUAVA PI
GND
Page 74