User Manual - 8051
User Manual - 8051
2
Features:
General description
VT8051-2.2 provides a hardware platform for developing embedded system using ATMEL
AT89S52 device.
These features make VT8051-2.2 board ideal for instrumentation, communication and other
demanding application areas where flexibility and in-circuit hardware upgradeability is of
paramount important.
VT8051-2.2 board comes with complete drivers for windows98/Me/2000/XP/2007. 8051 code
examples and windows DLL interface which can be used to interface it to most common
programming language.
As it comes with complete with all Keil development software required and example code. it is
also ideal as classroom training too for colleges and universities as well as engineers wanting to
learn more about hardware development using 8051.
Relay
DIP Switch
Atmel 89S52
J10 is a standard DB9 serial connector. This connector is typically used for communication with host
computer using a standard 9-pin serial cable connected to a Com port. Level shifting buffer U8 (MAX232)
is used between computer and 89S52 device.VT8051-2.2 uses only the signals it needs, such as RXD
and TXD. Fig (2 ) shows the pin connection between the serial connector and 89s52 device.
Table (2) shows DB9 connector pin
Fig(2 )
DB9(J10)
1 2(TXD) 3(RXD) 4 5 6 7 8 9
Connector Pin
89S52 Pin No - 10 11 1 GND - - - -
89S52 Port No - P3.0 P3.1 - - - - - -
The power and I/O pins of the 89S52 device are brought out onto 26 pin Box header (J11).This
can be used for external special daughter board card interfaces. Fig (3) and table (3) shows
connections from Expansion connector.
J11
Table (3) Expansion connector pin Table.
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on,
and optionally when it is off
U11 is a RTC(PCF8963) device connected to AT89S52 Device and can be used for Real time
clock applications. On the 89S52, the RTC can be clocked by a separate 32.768 KHz oscillator.
Also, the RTC is powered by its own power supply pin, Vdd, which can be connected to a
battery or to the same 5 V supply used by the rest of the device.
Features.
NOTE: Switch on DSW14 and switch off all other dip switches.
PCF8563
1 2 3 4 5 6 7 8
Pin no
PCF8563 Pin
X1 X2 INT VSS SDA SCL CLK OUT VDD
Function
89S52 Pin No - - - GND 10 11 - -
89S52 Port No - - - - P3.0 P3.1 - -
EEPROM Device:
U11 is an 2K E2PROM device connected to AT89S52 Device and can be used for external
memory interface applications. Table (5) shows pin configuration.
NOTE: Switch on DSW13 and switch off all other dip switches.
A speaker is a device which converts electrical signal to audible signal.J9 is a two pin RMC
where we are connecting external speaker. We drove it through Q5 which in turn connected to
P3.0 via DIP switch DSW11.We need to send Logic ‘1’ to generate Tone.
NOTE: Switch on DSW14 and switch off all other dip switches. Jumper JP2 should be
shorted between 1and 2 for Buzzer and shorted between 2 and 3 for speaker. Table (6)
shows speaker /Buzzer pin connection Table
Table (6) Speaker /Buzzer pin connection Table.
1 10 P3.0
DC (direct current) motor rotates continuously. It has two terminals positive and negative.
Connecting DC power supply to these terminals rotates motor in one direction and reversing the
polarity of the power supply reverses the direction of rotation.
The speed of Dc motor can maintained at a constant speed for a given load by using “Pulse
Width Modulation (PWM)” technique. By changing the width of the pulse of applied to dc motor,
the power applied is varied thereby DC motor speed can be increased or decreased. Wider the
pulse Faster is the Speed, Narrower is the Pulse, and Slower is the Speed
U5 is L293 driver IC used to drive the dc motor. It has two enable lines which are used to switch
on the required DC motor. It is connected to P3.0 and P3.1 through Dip switch DSW8.Logic ‘1’
enables the driver and logic ‘0’ disables the driver.P2.0 and P2.1 which are connected through
Dip switch DSW7 are used for Motor 1 direction and speed control.
Table (7) shows pin
NOTE: Switch on DSW7 ,DSW8 and switch off all other dip switches. Connect the DC
Motor at J3
A stepper motor is a special type of electric motor that moves in increments, or steps, rather
than turning smoothly as a conventional motor does. Typical increments are 0.9 or 1.8 degrees,
with 400 or 200 increments thus representing a full circle. The speed of the motor is determined
by the time delay between each incremental movement.
U6 is a Driver Buffer (ULN2003) device connected to AT89S52 Device and can be used for
driving Stepper Motor. On the 89S52, P2.0 to P2.3 are used to generate the pulse sequence
required to run the stepper Motor. Also, the Stepper Motor is powered by its own power supply
pin (COM), which is connected to a 12V supply. Table (8) shows connections for stepper Motor.
NOTE: Switch on DSW9 and switch off all other dip switches. Connect the stepper
motor at J5
Table (8) Stepper Motor Pin connection table.
B 22 P2.1
C 23 P2.2
D 24 P2.3
Relay Configurations:
K1 is an electromagnetic relay which is connected to P3.0 through Dip switch DSW10.We need
to send logic ‘1’ to switch on relay.J6 is three pin PBT terminal used to connect external device
to relay. Table (9) shows connections for Relay.
NOTE: Switch on DSW10 and switch off all other dip switches.
Relay2 11 P3.1
The hex keypad is a peripheral that is organized in rows and Columns. Hex key Pad 16 Keys
arranged in a 4 by 4 grid, labeled with the hexadecimal digits 0 to F. An example of this can been
seen in Figure 1, below. Internally, the structure of the hex keypad is very simple. Wires run in
vertical columns (we call them C0 to C3) and in horizontal rows (called R0 to R3). These 8 wires
are available externally, and will be connected to the lower 8 bits of the port. Each key on the
keypad is essentially a switch that connects a row wire to a column wire. When a key is pressed,
it makes an electrical connection between the row and column. Table (10) shows connections
for HEX KEY Pad matrix.
NOTE: Switch on DSW6 and switch off all other dip switches.
VT8051-2.2 board provides eight individual KEYS connected to 89S52 device through PORT1.
S1 to S6,S11and S16 are connected to general purpose I/O pins on 89s52 device as shown in
table(11). 89S52 device port pin drives to Logic ‘0’ when the corresponding key is pressed. Table
(11) shows connections for USER KEY Pad connection.
USER
DEFINED S1(K1) S2(KY2) S3(KY3) S4(KY4) S5(KY5) S6(KY6) S11(KY7) S16(KY8)
KEYS
89S52 Pin
1 2 3 4 5 6 7 8
No
89S52
P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7
Port No
U11 is a DAC(AD5330) enables the 89S52 to generate a variable analog output. The maximum
DAC output voltage is the VREF (5V) voltage.
Features:
• Buffered output
• Power-down mode
In 89S52 the digital inputs are converter to analog output voltage at pin 4(DACOUT). The total
voltage provided by the DACOUT pin is function of binary number written on to pins 13(DB0) to
pin 20(DB7) of U2 DAC (AD5330) and Pin 7 WRITE pin, we need to send a high to low pulse for
each conversion. Table (12) shows DAC pin connection Table
NOTE: Switch on DSW4,DSW5 and switch off all other dip switches.Connect the CRO
probe between TP3 and TP4
Table (12) DAC Pin connection table.
3 VREF - -
4 DACOUT - -
5 GND - -
6 CS - -
7 WR 10 P3.0
8 GAIN - -
9 CLR - -
10 LDAC - -
11 PD - -
12 VDD - -
13 DB0(LSB) 28 P2.7
14 DB1 27 P2.6
15 DB2 26 P2.5
16 DB3 25 P2.4
17 DB4 24 P2.3
18 DB5 23 P2.2
19 DB6 22 P2.1
20 DB7(MSB) 21 P2.0
Analog to digital converters are the most widely used devices for data acquisition. It is very
much essential to convert the physical quantities like pressure, humidity, temperature and
velocity in to digital data for processing with digital computers. First these physical quantities are
converted into analog signals (either voltage or current) with the help of transducers or sensors.
Then these analog signals are converted into digital data using Analog to digital converters
(ADC), so that microcontrollers or processors can read digital data and process them. An ADC
has n-bit resolution where n can be 8,10,12,16 or 24 bits. The higher resolution ADC can
provide a smaller step size, where step size is the smallest change in analog data that an ADC
can convert in to digital data.
U1 is an 8 bit ADC (0804) connected to 89S52 device through Dip switch DSW2 and DSW3.
Table (13) shows the ADC pin connection table.
NOTE: Switch on DSW2,DSW3 and keep 1 on, 2 off in DSW1 .Switch off all other dip
switches. Measure the applied analog voltage between P3 and P4.
Table (13) ADC Pin connection table.
89S52
ADC Pin ADC Pin 89S52
Pin
No Functions Port No
No
1 CS - -
2 RD - -
3 WR 10 P3.0
CLK - -
4
5
INTR 11 P3.1
6 VI+ - -
7 VI- - -
8 AGND - -
9 VREF - -
10 GND - -
11 DB7(MSB) 28 P2.7
12 DB6 27 P2.6
13 DB5 26 P2.5
14 DB4 25 P2.4
15 DB3 24 P2.3
16 DB2 23 P2.2
17 DB1 22 P2.1
18 DB0(LSB) 21 P2.0
VT8051-2.2 board provides eight individual SMD led’s connected to 89S52 device through
74HC151driver IC.D3 to D10 are connected to general purpose I/O pins on 89s52 device as
shown in table(14) When 89S52 device drives Logic ‘1’ the corresponding LED turns on.
LED D3 D4 D5 D6 D7 D8 D9 D10
89S52 Pin
21 22 23 24 25 26 27 28
No
89S52 Port
P2.0 P2.1 P2.2 P2.3 P2.4 P2.5 P2.6 P2.7
No
D11, D12, D13 and D14 are Common Cathode segments connected to 89S52 device so that
each segment is individually controlled by a general purpose I/O pin. When the 89S52 device
drives logic ‘0’ the corresponding segment turns on. See fig(3) and table(15) for more details.
fig(3)
Seven Segment
g f a b p c d e
Data Lines
89S52 Pin No 39 38 37 36 35 34 33 32
89S52 Port No P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7
Display Encoding:
Digits to Hex
Display Segments
display code
g f a b p c d e
0 1 0 0 0 1 0 0 0 88
1 1 1 1 0 1 0 1 1 EB
2 0 1 0 0 1 1 0 0 4C
3 0 1 0 0 1 0 0 1 49
4 0 0 1 0 1 0 1 1 2B
5 0 0 0 1 1 0 0 1 19
6 0 0 0 1 1 1 1 0 18
7 1 1 0 0 1 0 1 1 CB
8 0 0 0 0 1 0 0 0 08
9 0 0 0 0 1 0 0 1 09
A 0 0 0 0 1 0 1 0 0A
B 0 0 1 1 1 0 0 0 38
C 1 0 0 1 1 0 0 0 98
D 0 1 1 0 1 0 0 0 68
E 0 0 0 1 1 1 0 0 1C
F 0 0 0 1 1 1 1 0 1E
16 X 2 LCD Display
An LCD display is specifically manufactured to be used with microcontrollers, which means that
it cannot be activated by standard IC circuits. It is used for displaying different mbessagesC on
a miniature liquid crystal display. It displays all the letters of alphabet, Greek letters,
punctuation marks, mathematical symbols etc. In addition, it is possible to display symbols
made up by the user. Other useful features include automatic message shift (left and right),
cursor appearance, LED backlight etc.
89S52
LCD Pin LCD Pin 89S52
Pin
No Functions Port No
No
1 GND - -
2 VCC - -
3 CONTRAST - -
4 RS 13 P3.3
5 R/W GND GND
6 EN 12 P3.2
7 DAT1 39 P0.0
8 DAT2 38 P0.1
9 DAT3 37 P0.2
10 DAT4 36 P0.3
11 DAT5 35 P0.4
12 DAT6 34 P0.5
13 DAT7 33 P0.6
14 DAT8 32 P0.7
15 VCC - -
16 GND - -
The required steps for creating application programs are listed below:
Configure Micro Controller Target describes how to change the startup-code and how to use the library
retarget file for Micro Controller devices.
Configure Cortex-M Target describes how to change the startup-code and how to use the library retarget
file for Cortex-M devices. In addition, this is a brief explanation of CMSIS.
6. Create File Group explains how to structure the code files for a better overview.
7. Specify Memory Layout describes how to change file and group attributes.
8. Build Project describes the build-options.
µVision4 maintains the files that belong to a project in one project file. It takes only a few steps to create
a new project file with µVision4:
When you create a new project, µVision4 asks you to select a microcontroller. This step customizes the
µVision4 environment with Pre-Configured options and sets the tool options, Peripherals, and dialogs for
that particular device. The Select Device for Target dialog shows the µVision Device Database.
1. Select the microcontroller you use. For this example, choose the Atmel→AT89S52.
2. Click OK.
3. Click YES to add the Startup-Code, Which is provided for most devices. The startup-code
Provides Configuration settings for the selected device.
Note: On some devices, additional parameters must be entered manually. Read carefully the
information provided under Description of the Select Device dialog. It might have additional
instructions for the device configuration.
Right Click on the Target Folder Select the “Options for Target ‘Target1’… ”
Set the Target→Xtal frequency to 12.0MHz, Click on Output Tab selecting the Create HEXFile Check
Box Options.
Item Description
Xtal (MHz) Specifies the XTAL frequency of the device; XTAL is used to configure the
debugger and Flash programmer. XTAL reflects the main oscillator connected
externally to the device.
Operating system Choose the operating system. For example, the RTX Kernel adds the correct
RTX library and enables kernel aware debugging.
Code Generation
Use Cross-Module Enables the linker feedback file, which allows further code optimizations.
Optimization
Use MicroLIB Changes the C run-time library-set to generate smallest application code.
MicroLIB is not fully ANSI compatible, but sufficient for most small embedded
applications.
Use Link-Time Code Instructs the compiler to create objects in an intermediate format to perform link-
Generation time code optimization.
Big Endian Defines the method used to access multi-byte data.
Read/Only Memory Areas
ROMx Specify the Read Only Memory areas, typically located in ROM space.
IROMx Internal Read Only Memory, typically configured by the startup-code.
Read/Write Memory Areas
RAMx Specify the ZI and RW areas, typically located in RAM space.
IRAMx Specify the ZI and RW areas, typically configured through the startup-code.
default The check box, in front of each entry, enables the area globally for the
application. Individual modules may be assigned in the Properties dialog to
specific areas.
For adding files Right click on the project name in the Project Window and click on “Add Files to Group
‘Source Group1’
Coding can be done in a new window. Click Ctrl+N for new window.
Build the Project and check for errors. Once the code is error free 0 Errors, 0 Warning is displayed in the
Build Output Window.
1. Open the SISP Setup Folder and click on the icon shown
2. Click on the setup file to install the driver. Wait for the installation to complete.
SISP Icon will be shown on the desktop screen, If Icon is not created than go for
Programs→SISP, right click on SISP and select Create Shortcut option, This creates an
additional name with the existing icon, drag and drop to the desktop,
1. Insert one end of the USB cable to the USB Port and Other end to kit.
2. Right Click on My Computer option from the desktop and select Manage Option as shown in the
below figure.
3. Click on Manage button and select the Device Manager Option as shown below
4. Expand Ports option on the right hand side to see the Serial port name of the USB Connected.
For Example : USB Serial Port(COM8)
5. Minimize the window once the Port Name is known and select SISP option from desktop
10. On click of Load Hex File will open a window for selecting the Code from the Computer
For Ex let us Load 7 Segment LED Code, Click on the respective file and Open
11. Once the Hex code is selected, File Loaded window is shown as below.
Chip Verification Success is shown once the code is loaded properly to the Chip. Reset Chip
Button is used for resetting the IC & Reload HEX button is used to reload the same program
which is selected earlier.
Example programs
/* Program to read analog value from POT using ADC Crystal freq 11.0592Mz Processor: 89S52
Here we need to vary the ADC-POT(R4) and observe the LED output and reading on LCD.For each
0.02V change in analog voltage one bit digital valve will be generated*/
#include <reg52.h>
#include <intrins.h>
#include "lcd.h"
/*------------------------------------------------
Read ADC C function
------------------------------------------------*/
unsigned char rdadc()
{
ASTART = 0;
_nop_();
_nop_();
while(AEOC == 1);
return(ADATA);
}
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
Unsigned char aval, hi, lo;
Unsigned char txt [2];
LCD_Init ();
LCD_Write16 (logo, FIRST_LINE);
LCD_Write16 (adcv, SECOND_LINE);
IE=0x00;
P3=0x00;
ADATA=0xFF;
ASTART=0;
AEOC=1;
While (1)
{
aval=rdadc ();
hi = msb[aval];
lo = lsb[aval];
WriteLCD (0xCA, CONTROL_REG);
bytetoa(hi,txt);
WriteLCD (txt[0], DATA_REG);
WriteLCD ('.', DATA_REG);
bytetoa (lo,txt);
WriteLCD (txt [1], DATA_REG);
WriteLCD (txt [0], DATA_REG);
DelayS (1);
}
}
/* Program to generate saw tooth wave using DAC Crystal freq 11.0592Mz Processor: 89S52.Down load
hex file and connect CRO probe between TP4 and TP3.You will get saw tooth wave*/
#include <reg52.h>
#include <intrins.h>
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
unsigned char dval;
IE=0x00;
P3=0X00;
DAC = 0x00;
DWR = 0;
_nop_();
DWR = 1;
dval = 0xFF;
While (1)
{
DAC = dval;
DWR = 0;
_nop_();
DWR = 1;
delay(1); //varying this value will wary the freq of the waveform
dval--;
}
}
/*Program to generate SQUARE wave using DAC Crystal freq 11.0592Mz Processor: 89S52. Down load
hex file and connect CRO probe between TP4 and TP3.You will get square wave */
#include <reg52.h>
#include <intrins.h>
for (j=0;j<tim;j++)
for (i=0; i<10;i++);
}
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
IE=0x00;
DAC = 0x00;
P3=0X00;
DWR=1;
while (1)
{
DAC = 0x00;
DWR = 0;
_nop_();
DWR = 1;
delay(50); //varying this value will wary the freq of the waveform
DAC = 0xFF;
DWR = 0;
_nop_();
DWR = 1;
delay(50); //varying this value will wary the freq of the waveform
}
}
#include <reg52.h>
#include <intrins.h>
#include <reg52.h>
#include <intrins.h>
#include <reg52.h>
#include <intrins.h>
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
unsigned char MOTOR;
unsigned char i;
IE = 0x00;
P3 = 0X00;
AKMIN = 1; // All Ports as Inputs
AKAVG = 1;
AKMED = 1;
AKMAX = 1;
CKMIN = 1;
CKAVG = 1;
CKMED = 1;
CKMAX = 1;
MOTOR=0;
DIR1=1; DIR2=1; //Motor stopped
PWM=1;
while (1)
{
if (AKMIN == 0) //Anti Clockwise Minimum speed
{
MOTOR = 10;
DIR1=1; DIR2=0;
goto quit;
}
if (AKAVG == 0) //Anti Clockwise Average speed
{
MOTOR = 50;
{
unsigned char i;
WriteLCD(Linenum,CONTROL_REG);
for(i = 0;i<16;i++)
{
WriteLCD(String[i],DATA_REG) ;
}
}
/*------------------------------------------------
MAIN C function
-----------------------------------------------*/
IE=0x00;
LCD_Init();
LCD_Write16(logo1,FIRST_LINE);
LCD_Write16(logo2,SECOND_LINE);
while(1);
}
#include <reg52.h>
#include <intrins.h>
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
IE = 0x00;
P2 = 0x00;
P3 = 0x00;
ON = 1; //Port as Input
OFF = 1; //Port as Input
while (1)
{
}
}
#include <reg52.h>
#include <intrins.h>
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
unsigned char cnt = 0;
unsigned char qot, rem;
unsigned char j;
unsigned int i;
IE=0x00;
P2=0x00;
while(1)
{
if (INC == 0) //INC key pressed
{
if (cnt == 99) goto disp;
cnt++;
goto disp;
}
disp:
qot = cnt / 10;
rem = cnt % 10;
for (i=0; i< 1000; i++) //change to inc/dec sensitivity of key press
{
DIGDAT = dig[qot];
DSP2 = 1;
for (j=0;j<10;j++); //change to inc/dec brightness of display
DSP2 = 0;
DIGDAT = dig[rem];
DSP1 = 1;
for (j=0;j<10;j++); //change to inc/dec brightness of display
DSP1 = 0;
DIGDAT = dig[0];
DSP3 = 1;
for (j=0;j<10;j++); //change to inc/dec brightness of display
DSP3 = 0;
DIGDAT = dig[0];
DSP4 = 1;
for (j=0;j<10;j++); //change to inc/dec brightness of display
DSP4 = 0;
}
}
}
/////////////////////////////////////////////
// Matrix Keypad Scanning Routine
//
// COL1 COL2 COL3 COL4
// 0 1 2 3 ROW 1
// 4 5 6 7 ROW 2
// 8 9 A B ROW 3
// C D E F ROW 4
//////////////////////////////////////////////
#include <reg52.h>
#include <intrins.h>
#include "lcd.h"
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
unsigned char key, i;
unsigned char rval[] = {0xFE,0xFD,0xFB,0xF7,0x0};
unsigned char keyPadMatrix[] =
{
'F','B','7','3',
'E','A','6','2',
'D','9','5','1',
'C','8','4','0'
};
/* we scan the keypad by turning on the row outputs and / reading the columns*/
COL1 = 1;
COL2 = 1;
COL3 = 1;
COL4 = 1;
IE=0x00;
P3=0x00;
LCD_Init();
while (1)
{
key = 0;
for( i = 0; i < 4; i++ )
{
// turn on row output
ROWPORT = rval[i];
// read colums - break when key press detected
if( COL1 == 0)
break;
key++;
if( COL2 == 0)
break;
key++;
if( COL3 == 0)
break;
key++;
if( COL4 == 0)
break;
key++;
}
if (key == 0x10)
LCD_Write16(logo2,SECOND_LINE);
else
{
WriteLCD(0xCE,CONTROL_REG);
WriteLCD(keyPadMatrix[key],DATA_REG);
}
}
}
#include <reg52.h>
#include <intrins.h>
sbit Relay = P3^0; //Relay control line
sbit ON = P1^0; //ON KEY
sbit OFF = P1^4; //OFF KEY
/*------------------------------------------------
MAIN C function
------------------------------------------------*/
void main (void)
{
IE = 0x00;
P2 = 0x00;
P3 = 0x00;
ON= 1; //Port as Input
OFF = 1; //Port as Input
while (1)
{
if (ON == 0) //ON key pressed
{
Relay=1;
}
if (OFF == 0) //OFF key pressed
{
Relay=0;
}
}
}