Professional Documents
Culture Documents
Expt no 1
THEORY:
Vision Overview
The Vision IDE is a Windows-based software development platform that combines
a robust editor and project manager. Vision5 integrates all tools including C compiler,
macro assembler, linker/ locator and HEX file generator. Vision5 helps expedite the
development process of embedded applications.
Create Project File Folder and Specify Project Name
To create a new project file, from Vision5 menu, select Project/New/Vision
Project...The window appears as shown in Fig. 1.1. This opens a standard Windows dialog
that asks you for the new project file name. Use separate folder each project. To get a new
empty folder, use the icon Create New Folder in the dialog.
Select this folder and enter the file name for the new project, i.e., project1. Vision5
creates a new project file with the name PROJECT1.UV2 that contains a default target and
file group name. You can see these names in the Project Workspace-Files.
College of
College of
Modify the existing source code or add new source files to the project. The Build Target
toolbar button translates only modified or new source files and generates the executable
file. Vision5 maintains a file dependency list and knows all the included files used
within a source file. Even the tool options are saved in the file dependency list, so that
Vision5 can rebuild files when it is needed. With the Rebuild Target command, all
source are translated, regardless of modifications.
Test programs with the Vision5 Debugger. The Vision5 Debugger offers two opening
modes simulator allows verifying applications on PC, or Target Debugging with an
Evaluation Board.
To program your application into Flash ROM, Vision5 integrates command-line
driven Flash Utilities ULINK USB JTAG. Create HEX file to use Flash programming
utilities.
Single Stepping
Vision5 supports various methods of single stepping through your application. The
various options are available on the menu as shown in Fig.1.4.
Click the Step Into button on the toolbar to execute a single instruction or line of code.
Step into all called functions.
Click the Step Over button on the toolbar to execute a single instruction or line of
code. Step Over executes all called functions without stepping into them.
ECE Department
Engineering, Trikaripur
College of
Click the Step Out button on the toolbar to step out of a function and return to the
caller.
Click the Run to Cursor button on the toolbar to begin executing your target program
until the current line is reached
Burning the Hex File to Program Memory
Click open the Bitsforge 8051 programmer V 2.0. A window as shown in Fig.1.5
appears on the screen. Select the Com1/Com2 port to which the target microcontroller is
connected. Select the target device, e.g., AT89S52.
Browse the target hex file (e.g. test.hex). Click auto icon on the window. Observe
the message window at the bottom. It erases and then program the flash memory. When
burning of the program is completed, the message finished is displayed. Then, the target
board is ready for the intended application.
RESULT:
Familiarised the environment of Keil icrovision.
ECE Department
Engineering, Trikaripur
College of
SCHEMATIC DIAGRAM:
ECE Department
Engineering, Trikaripur
College of
ALGORITHM:
1.
2.
3.
4.
PROGRAM:
/* LED BLINKING */
#include<reg52.h>
void delay(long g)
{
unsigned int i,j;
DELAY
//FUNCTION TO IMPLEMENT
for(i=0;i<g;i++){
for(j=0;j<255;j++);
}
}
void main()
{
P2=0;
while(1) {
P2=0x00;
delay(700);
ECE Department
Engineering, Trikaripur
//LED BLINKING
6
College of
/* LED SHIFTING*/
#include<reg52.h>
void delay(long g)
{
unsigned int i,j;
DELAY
//FUNCTION TO IMPLEMENT
for(i=0;i<g;i++){
for(j=0;j<255;j++);
}
}
void main()
{
P2=0X01;
while(P2!=0x80)
{
delay(700);
P2=P2<<1;
}
while(P2!=0x01)
{
delay(700);
P2=P2>>1;
ECE Department
Engineering, Trikaripur
College of
RESULT:
The program to test the 8051 system and its ports was written and executed
successfully.
ECE Department
Engineering, Trikaripur
College of
SCHEMATIC DIAGRAM
ECE Department
Engineering, Trikaripur
College of
ECE Department
Engineering, Trikaripur
10
College of
Exp No: 3
LCD INTERFACING
AIM:
To interface the LCD display with 8051 microcontroller and to verify data on LCD display.
THEORY:
Liquid Crystal Display (LCDs) provides a cost effective way to put a text output
unit for a microcontroller. This display has 2 lines and can display 16 characters on each
line. Nonetheless, when it is interfaced with the microcontroller, we can scroll the messages
with software to display information which is more than 16 characters in length.
LCD Internal Controller
The LCD is a simple device to use but the internal details are complex. Most of the
16x2 LCDs use a Hitachi HD44780 or a compatible controller. The Display Controller
takes commands and data from a external microcontroller and drivers the LCD panel
(LCDP). It takes an ASCII value as input and generates a pattern for the dot matrix.
HD44780 based LCD consists of two 8 bit registers. One is Instruction register
which consists of instruction given to LCD while another is called Data register which
temporarily stores data to be written to or read from DDRAM (Display Data RAM) or
CGRAM(character generation RAM).
Busy Flag
D7 pin of LCD can be used to read the status of busy flag. When busy flag is at logic HIGH
state, it means it is busy doing its internal operation and during this period neither an
instruction is send to LCD nor a data can be send to LCD. When this flag is at logic LOW
state it is free from its internal operation and this is the time when we send an instruction or
data which has to be displayed tin LCD.
DDRAM
DDRAM which stands for display data RAM stores the data which has to be displayed in
LCD. The first line of DDRAM begins with address 80h and second line begins with C0h
in 16*2 LCD.
Basic Commands
LCD can be interfaced in 8 bit mode or in 4 bit mode. The LCD controller uses RS and RW
lines along with E to operate the LCD.
Resister Select (RS): Determines whether a command (RS = 0) is sent (to set up the
display) or actual data (RS=1) is sent.
Read/Write RW=0; writes to the LCD. RW=1; Reads from the LCD.
ECE Department
Engineering, Trikaripur
11
College of
COMMAND
FUNCTION
0F
01
Clear screen
02
Return home
04
Decrement cursor
06
Increment cursor
0E
80
C0
38
83
3C
08
C1
OC
C1
C2
PIN
NUMBER
FUNCTION
Ground
VCC
ECE Department
Engineering, Trikaripur
12
College of
10
11
Bit 4
12
Bit 5
13
Bit 6
14
Bit 7
15
Back-light Anode(+)
16
Back-Light Cathode(-)
ALGORITHM:
Writing to LCD
Data are written in Instruction Register (IR) and Data register (DR). Data written in
IR are used to send command to the LCD and data send to DR are used to display in
LCD. While writing data in IR of LCD, RS and RW pin should be at LOW logic level and
the logic state of Enable pin should change from HIGH to LOW logic state.
Reading from LCD
Reading data from DDRAM or CGRAM of LCD can be accomplished when RS
and RW are both at HIGH logic state and when EN changes its logic state from LOW to
HIGH.
PROGRAM:
#include<reg52.h>
sbit LCD_EN
OF PORT3
= P3^7;
char temp,nam[8]="HELLO";
int i,k,l;
void delay()
ECE Department
Engineering, Trikaripur
13
College of
//Data/cmd reg
P0=temp;
LCD_EN =1;
//enable LCD
delay();
LCD_EN =0;
}
void dat(char temp)
{
LCD_RS = 1;
P0=temp;
LCD_EN =1;
delay();
LCD_EN =0;
}
void print(char *ptr)
{
while(*ptr!=0)
{
dat(*ptr);
ECE Department
Engineering, Trikaripur
14
College of
cmd(0X38);
delay();
cmd(0X01);
//
delay();
cmd(0X0C);
//
delay();
cmd(0X06);
//
delay();
ECE Department
Engineering, Trikaripur
15
College of
delay();
for(i=0;i<5;i++)
{
P0=nam[i];
dat(nam[i]);
}
cmd(0xc0);
print("CETKR");
while(1);
}
RESULT:
The program for interfacing LCD display with 8051 microcontroller was written
and executed successfully.
ECE Department
Engineering, Trikaripur
16
College of
SCHEMATIC DIAGRAM:
ECE Department
Engineering, Trikaripur
17
College of
INTERRUPT PROGRAMMING
AIM:
To program the external interrupt of 8051 microcontroller.
THEORY:
For the 8051 Microcontroller there are six interrupt sources as shown in the table below: Interrupt
Reset
External HW Interrupt 0 (INT0)
Timer 0 Interrupt (TF0)
External HW Interrupt 1 (INT1)
Timer 1 Interrupt (TF1)
Serial Comm. Interrupt (RI & TI)
ROM Location
0000
0003
000B
0013
001B
0023
Pin
9
P3.2(12)
P3.3(13)
-
Interrupt No. in C
--0
1
2
3
4
D6
-
D5
ET2
D4
ES
D3
ET1
D2
EX1
D1
ET0
D0
EX0
EA: 0; Disables all interrupts. 1; Enables all interrupts. It is kind of master control,
before enabling any of the interrupts this bit should be 1. For all the below
interrupts, setting (1) the bit enables the interrupt, 0 disables it.
ET2: Timer 2 Overflow interrupt(8052)
ES: Serial Port Interrupt
ET1:Timer 1 overflow interrupt
EX1:External Interrupt 1 on P3.3
ET0:Timer 0 overflow interrupt
EX0:External Interrupt 0 on P3.2
PROGRAM:
/*BUZZER IS CONNECTED TO 0TH PIN OF PORT1. A SWITCH IS CONNECTED
TO EXTERNAL INTERRUPT PIN OF CONTROLLER*/
ECE Department
Engineering, Trikaripur
18
College of
<reg52.h>
RESULT:
The program for external interrupt was written and executed successfully.
ECE Department
Engineering, Trikaripur
19
College of
CIRCUIT DIAGRAM:
ECE Department
Engineering, Trikaripur
20
College of
Exp No: 5
THEORY:
UART (Universal Asynchronous Receiver Transmitter), a hardware component
which are available in almost every microcontroller is used to transmit a byte of data
serially through a single wire. It converts a parallel sequence of data into serial data.
There are two ways to connect a microcontroller to a computer.
Using RS232 protocol to the legacy serial port.
Using a USB to serial convertor.
From microcontroller programming point of view, there is fundamentally no difference.
The communication between the computer and microcontroller is asynchronous and full
duplex.
Asynchronous: There is no fixed clock to synchronize transmission of data; rather a
fix bit rate is specified at both transmitter and receiver, termed as Baud Rate. In
simple words, it specifies number of bit received/transmitted in 1 second. With that
transmitter and receiver get to know time duration for each bit transfer.
Full Duplex: Both computer and microcontroller have the hardware capability to
transmit and receive at the same time
To perform communication between a PC and devices supporting UART, a line driver is
required which converts a line voltage (RS232 voltage level in serial port of PC) to TTL
level. One of most commonly used line driver is MAX232.
The protocol
RS232: It is a legacy standard for serial communication. The standard defines the electrical
characteristics and timing of signals, the meaning of signals, and the physical size and pinout of connectors.
RS232 Signals
ECE Department
Engineering, Trikaripur
21
College of
+3 to +25V
-3 to -25V
+3 to -3V
Serial Interface
AT89s52 provides synchronous and asynchronous communication modes. It
operates as a UART in three full-duplex modes (Mode1, Mode 2, and Mode3). Data
transfer rates known as Baud Rate in serial communication are measured in bps (bits per
second).Standard Baud Rate are multiple of 9600bps. Among 4 communication mode
(Mode0, Mode1, Mode2, Mode3), Mode 2 is mostly used.
The important registers for serial communication are:
SBUFF: Serial buffer register
SBUFF, it is a serial buffer for data. It holds 8 bit data that needs to be transmitted or the
data that is received. Since the serial port of 8051 is full duplex, the microcontroller
internally manages to transmit and receive data into the buffer register simultaneously.
SBUFF
D7
D6
D5
D4
D3
D2
D1
D0
SCON
ECE Department
Engineering, Trikaripur
22
College of
D7
D6
D5
D4
D3
D2
D1
D0
SM0
SM1
SM2
REN
TB8
RB8
TI
RI
SM0 - Serial port mode bit 0 is used for serial port mode selection.
SM
0
SM
1
Operatio
n
Description
Mode 0
Mode 1
8 bit UART
Mode 2
9 bit UART
Mode 3
9 bit UART
SM2 - Serial port mode 2 bit, also known as multiprocessor communication enable
bit. When set, it enables multiprocessor communication in mode 2 and 3, and
eventually mode 1. It should be cleared in mode 0.
REN - Reception Enable bit enables serial reception when set. When cleared, serial
reception is disabled.
TB8 - Transmitter bit 8. Since all registers are 8-bit wide, this bit solves the problem
of transmitting the 9th bit in modes 2 and 3. It is set to transmit a logic 1 in the 9th
bit.
RB8 - Receiver bit 8 or the 9th bit received in modes 2 and 3. Cleared by hardware
if 9th bit received is a logic 0. Set by hardware if 9th bit received is a logic 1.
TI - Transmit Interrupt flag is automatically set at the moment the last bit of one
byte is sent. It's a signal to the processor that the line is available for a new byte
transmit. It must be cleared from within the software.
RI - Receive Interrupt flag is automatically set upon one byte receive. It signals that
byte is received and should be read quickly prior to being replaced by a new data.
This bit is also cleared from within the software.
ECE Department
Engineering, Trikaripur
23
College of
The crystal frequency Fclk is divided by 12 internally which is used to execute instructions
also known as Machine Clock, Mclk. The timer again divides the Mclk by 32 and uses it as
timer frequency, say Tclk.
Usually an 11.0592 MHz crystal oscillator is used to provide clock to 8051.
To generate Baud Rate for example 9600bps, we first divide Fclk freq by 12. The obtained
value is again divided by 32. Now, the obtained value is divided by desired baud rate. The
negation of obtained result is then placed in TH1 register for generation of Baud Rate.
11.0592MHZ / 12 = 921600HZ
921600HZ / 32 = 28800HZ
28800HZ / 9600 = 3
Thus, -3 (decimal value) is to be loaded in TH1 register. To obtain Hexa Decimal value add
decimal value to FFh and again add 1.
eg:- FFh 3 + 1 = FDh
The standard baud rates used for serial communication are shown in the table below. All the
baud rates are factors or multiples of the Tclk (28.8 KHz).
ECE Department
Engineering, Trikaripur
Baud Rate
2400
Tclk/12
4800
Tclk/6
9600
Tclk/3
115200
Tclk*4
14400
Tclk*5
24
College of
ALGORITHM:
To serially transmit a byte of data:1. First, TMOD reg is loaded with value of 20h (Timer 1in Mode 2 to set Baud Rate).
2. Then, TH1 is loaded with required baud rate value as calculated above.
3. SCON reg is loaded with 50h (Mode 1 serial communication).
4. TR1 is set to start timer.
5. TI is cleared.
6. The data to be transferred is placed in SBUF reg.
7. Then TI flag is monitored. If TI flag is set, then a byte of data is transmitted
successfully.
First, TMOD reg is loaded with value of 20h (Timer 1in Mode 2 to set Baud Rate).
Then, TH1 is loaded with required baud rate value as calculated above.
SCON reg is loaded with 50h (Mode 1 serial communication).
TR1 is set to start timer.
RI is cleared.
Then RI flag is monitored. If RI flag is set, then a byte of data is received serially.
The received byte is stored in SBUF reg and needs to be transferred to another
register or location to receive another byte of data.
PROGRAM:
#include<reg52.h>
void UART_Init()
{
TMOD |=0x20; //Timer1 in Mode2.
TH1=-3; // 9600 Baud rate at 11.0592MHz
SCON=0x50; // Asynchronous mode 8-bit data and 1-stop bit
TR1=1; //Turn ON the timer.
}
char UART_RxChar()
{
while(RI==0);
// Wait till the data is received
ECE Department
Engineering, Trikaripur
25
College of
while(1)
{
UART_TxString("\n\n\rEnter a new String: ");
UART_RxString(msg);
UART_TxString("\n\rEntered String: ");
UART_TxString(msg); //Transmit the received string
}
}
RESULT:
The program for transferring data serially between 8051 microcontroller and PC was
written and executed successfully.
ECE Department
Engineering, Trikaripur
26
College of
SCHEMATIC DIAGRAM:
ECE Department
Engineering, Trikaripur
27
College of
Exp No: 6
THEORY:
The term I2C is an inter integrated circuit and it is called as I squared C. I2C is a
serial computer bus, which is invented by NXP semiconductors previously it is named as
Philips semiconductors. The I2C bus is used to attach low speed peripheral integrated
circuits to microcontrollers and processors.
I2c bus uses two bidirectional open-drain lines such as SDA (serial data line) and
SCl (serial clock line) and these are pulled up with resistors. I2C bus permits a master
device to start communication with a slave device. Data is interchanged between these two
devices. Typical voltages used are +3.3V or +5V although systems with extra voltages are
allowed.
ECE Department
Engineering, Trikaripur
28
College of
PROGRAM:
#include <reg52.h>
#include "i2c.h"
#include
"lcd.h"
int main(void){
lcd_init();
printlcd(" HAI ");
lcd_command(0xc0);
printlcd(" BFORGE
");
ECE Department
Engineering, Trikaripur
29
College of
write(1,'A');
//DelayMs(10);
write(0,'B');
//DelayMs(10);
write(2,'C');
//DelayMs(10);
lcd_command(0xc0);
lcd_data(read(0));
lcd_data(read(1));
lcd_data(read(2));
while(1);
}
#include"i2c.h"
void start(void){
SDA = 1;
SCL = 1;
SDA = 0;
SCL = 0;
}
char out(char s_data){
char s_cnt=0;
while(s_cnt++ < 8){
if((s_data & 0x80)==0)SDA = 0;
else SDA = 1;
SCL = 1;
SCL = 0;
s_data <<=1;
}
SDA = 1;
SCL = 1;
SCL = 0;
return SDA;
}
char in(void){
char in_data=0;
char s_cnt=0;
SDA = 1;
while(s_cnt++ < 8){
ECE Department
Engineering, Trikaripur
30
College of
31
College of
<reg52.h>
"lcd.h"
#define
LCD_STROBE()
#define
lcd_goto(pos) lcd_write(0x80+(pos))
LCD_EN = 1;LCD_EN=0
32
College of
RESULT:
The program to read, write and validate data from a serial EEPROM was written and
executed successfully.
CIRCUIT DIAGRAM:
ECE Department
Engineering, Trikaripur
33
College of
ECE Department
Engineering, Trikaripur
34
College of
ADC INTERFACING
AIM:
To interface an ADC0804 to the 8051 microcontroller.
THEORY:
ADC0804 is an 8-bit successive approximation ADC which works with +5V dc
voltage and has a resolution of 8 bits. The device is fed with differential analog input
voltage which in turn provides output in form of digital signal which can be processed by
any processor. The conversion time of ADC0804 cannot be faster than 110 microseconds
and it has on-chip clock generator which can be used to provide clock pulse required for the
operation of this device.
The pin layout is shown in figure below and the description of each pins are then
described.
CS: - This is an active low input pin. When this pin is at LOW logic level (i.e. logic 0),
ADC0804 is ready to operate.
WR:-This is an active low input pin. A LOW-to-HIGH pulse at this pin tells the ADC to
start the conversion of applied analog input signal.
INTR: - This is an active low output pin to indicate the end of conversion.
RD: - This is an active low input pin. After the end of conversion the converted digital
signal is stored in the internal register of ADC0804 chip. Before the data is lost it is
required to read the digital data from those internal register. By sending a HIGH-to-LOW
pulse at this pin, we can read the digital data through 8-bit parallel pins ofADC0804.
ECE Department
Engineering, Trikaripur
35
College of
The suitable value of R and C used in the circuitry is 10k and 150pF respectively. But its
not any hard rule to use the same value of R and C, any value of R and C can be used which
can generate approximately 110us of conversion time.
Vin: - These (Vin+ and Vin-) are the pin where you apply differential analog input from any
sensor.
Vref/2:- This is the reference voltage pin. If this pin is left not connected then the reference
voltage will automatically become 5V. But for application where you require reference
voltage to be less then 5V, an external source of appropriate voltage should be connected to
this pin. A voltage divider circuit can be used to obtain the required reference voltage by
utilizing the same power source which microcontroller and ADC0804 are using.
AGND: - This is analog ground pin where a ground of analog input source is connected.
Similarly, in DGND which is referred to as digital ground, the ground of working voltage
source of the MCU or ADC is connected.
D0-D7:- These are 8-bit parallel data pins of ADC0804.
ALGORITHM:
1.
2.
3.
4.
PROGRAM:
ECE Department
Engineering, Trikaripur
36
College of
char ar[5];
int i,k,l,val=0;
void delay()
{
for(k=0;k<2;k++)
for(l=0;l<255;l++);
}
//Data/cmd reg
37
College of
//enable LCD
delay();
LCD_EN =0;
}
void dat(char temp)
{
LCD_RS = 1;
P0=temp;
LCD_EN =1;
delay();
LCD_EN =0;
}
void lcd_init()
{
cmd(0X30);
delay();
delay();
delay();
ECE Department
Engineering, Trikaripur
38
College of
cmd(0X38);
delay();
cmd(0X01);
//
delay();
cmd(0X0C);
//
delay();
cmd(0X06);
//
delay();
cmd(0X83);
//
delay();
void main()
{
lcd_init();
cmd(0x80);
print("ADC");
//RC3 = 0;
while(1)
ECE Department
Engineering, Trikaripur
39
College of
}
}
RESULT:
The program to interface an ADC0804 to the 8051 microcontroller was written and
executed successfully.
ECE Department
Engineering, Trikaripur
40
College of
SCHEMATIC DIAGRAM
ECE Department
Engineering, Trikaripur
41
College of
THEORY:
A Stepper Motor is a brushless, synchronous DC Motor. It has many applications in
the field of robotics and mechatronics. The total rotation of the motor is divided into steps.
The angle of a single step is known as the stepper angle of the motor. There are two types
of stepper motors Unipolar and Bipolar. Due to the ease of operation unipolar stepper
motor is commonly used. Stepper Motors can be easily interfaced with a microcontroller
using driver ICs such as L293D or ULN2003.Unipolar stepper motors can be used in three
modes namely the Wave Drive, Full Drive and Half Drive mode.
Wave Drive
In this mode only one electromagnet is energized at a time. Generated torque will be
less when compared to full drive in which two electromagnets are energized at a time but
power consumption is reduced. It has same number of steps as in the full drive. This drive
is preferred when power consumption is more important than torque. It is rarely used.
Wave Drive Stepping Sequence
Step
Full Drive
In this mode two electromagnets are energized at a time, so the torque generated
will be larger when compared to Wave Drive. This drive is commonly used than others.
Power consumption will be higher than other modes.
Full Drive Stepping Sequence
Step
ECE Department
Engineering, Trikaripur
42
College of
Half Drive
In this mode alternatively one and two electromagnets are energized, so it is a
combination of Wave and Full drives. This mode is commonly used to increase the angular
resolution of the motor but the torque will be less, about 70% at its half step position. We
can see that the angular resolution doubles when using Half Drive.
Half Drive Stepping Sequence
Step
PROGRAM:
#include<reg52.h>
int k;
void DelayMs(long d)
{
int i,j;
for(i=0;i<d;i++)
{
ECE Department
Engineering, Trikaripur
43
College of
P1=0XEF;
//
DelayMs(3);
//
P1=0XFB;
//
DelayMs(3);
//
P1=0XF7;
//
DelayMs(3);
//
P1=0XFD;
//
DelayMs(10);
//
//
}
}
RESULT:
ECE Department
Engineering, Trikaripur
44
College of
ECE Department
Engineering, Trikaripur
45
College of