Professional Documents
Culture Documents
M.tech I Sem ESD LAB MANUAL
M.tech I Sem ESD LAB MANUAL
The Intel 8051 is an 8-bit microcontroller which means that most available
operations are limited to 8 bits. There are 3 basic "sizes" of the 8051: Short, Standard, and
Extended. The Short and Standard chips are often available in DIP (dual in-line package)
form, but the Extended 8051 models often have a different form factor, and are not "drop-
in compatible". All these things are called 8051 because they can all be programmed using
8051 assembly language, and they all share certain features (although the different models
all have their own special features).
Some of the features that have made the 8051 popular are:
Basic Pins:
PIN 9: PIN 9 is the reset pin which is used to reset the microcontroller‟s internal registers
and ports upon starting up. (Pin should be held high for 2 machine cycles.)
PINS 18 & 19: The 8051 has a built-in oscillator amplifier hence we need to only connect
a crystal at these pins to provide clock pulses to the circuit.
PIN 40 and 20: Pins 40 and 20 are VCC and ground respectively. The 8051 chip needs
+5V 500mA to function properly, although there are lower powered versions like the
Atmel 2051 which is a scaled down version of the 8051 which runs on +3V.
PINS 29, 30 & 31: As described in the features of the 8051, this chip contains a built-in
flash memory. In order to program this we need to supply a voltage of +12V at pin 31. If
external memory is connected then PIN 31, also called EA/VPP, should be connected to
Ports:
There are 4 8-bit ports: P0, P1, P2 and P3.
PORT P1 (Pins 1 to 8): The port P1 is a general purpose input/output port which can be
used for a variety of interfacing tasks. The other ports P0, P2 and P3 have dual roles or
additional functions associated with them based upon the context of their usage.The port 1
output buffers can sink/source four TTL inputs. When 1s are written to portn1 pins are
pulled high by the internal pull-ups and can be used as inputs.
PORT P3 (Pins 10 to 17): PORT P3 acts as a normal IO port, but Port P3 has additional
functions such as, serial transmit and receive pins, 2 external interrupt pins, 2 external
counter inputs, read and write pins for memory access.
PORT P2 (pins 21 to 28): PORT P2 can also be used as a general purpose 8 bit port when
no external memory is present, but if external memory access is required then PORT P2
will act as an address bus in conjunction with PORT P0 to access external memory. PORT
P2 acts as A8-A15, as can be seen from figure.
PORT P0 (pins 32 to 39): PORT P0 can be used as a general purpose 8 bit port when no
external memory is present, but if external memory access is required then PORT P0 acts
as a multiplexed address and data bus that can be used to access external memory in
conjunction with PORT P2. P0 acts as AD0-AD7, as can be seen from figure.
PORT P10: asynchronous communication input or Serial synchronous communication
output.
Oscillator Circuits:
The 8051 requires an external oscillator circuit. The oscillator circuit usually runs
around 12MHz, although the 8051 (depending on which specific model) is capable of
running at a maximum of 40MHz. Each machine cycle in the 8051 is 12 clock cycles,
giving an effective cycle rate at 1MHz (for a 12MHz clock) to 3.33MHz (for the maximum
40MHz clock). The oscillator circuit generates the clock pulses so that all internal
operations are synchronized.
One machine cycle has 6 states. One state is 2 T-states. Therefore one machine
cycle is 12 T-states. Time to execute an instruction is found by multiplying C by 12 and
dividing product by Crystal frequency.
T=(C*12d)/crystal frequency
A and B Registers:
The A register is located in the SFR memory location 0xE0. The A register works
in a similar fashion to the AX register of x86 processors. The A register is called the
accumulator, and by default it receives the result of all arithmetic operations. The B register
is used in a similar manner, except that it can receive the extended answers from the
multiply and divide operations. When not being used for multiplication and Division, the B
register is available as an extra general-purpose register. The A and B registers can store up
to 8-bits of data each.
16. Change file type to asm source file(*.a*;*.src) and click on blinking.asm
17. Click add button and click close button
19. Click the project menu and click translate current active file
24. Select Output Tab and Click on create Hex file Check Box
25. Click ok button
27. Click on the debug menu and select start/stop debug session
32. To exit out, Click on debug menu and select start/stop debug session.
Apparatus:
1. Desktop PC
2. Keil µVision software
3. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Run button of the Debug Toolbar or choose Debug – Run to start the “Hello”
program. “Hello World” is printed to the Serial Window and the program enters into an endless
loop.
6. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
7. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
8. Test the Reset command to reset the simulated microcontroller. If the program is still running,
it halts at the first breakpoint.
9. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include <reg51.h>
#include <stdio.h>void main(void)
{
SCON=0x52; // SET SERIAL PORT TO MODE 1
TMOD=0x20; // TIMER1 MODE 2
TH1=-13; // RELOAD COUNTER FOR 2400 BAUD RATE
TR1=1; // START TIMER1
// Write your code here
while (1)
printf("Hello World\n");
RESULT: Thus the hello world program has been compiled, debugged and executed
successfully.
Aim: To write an embedded c program to copy a value from P1 to P2 of 8051 using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board.
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the Command
Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still running, it
halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include<reg51.h>
#include<string.h>
#define lcd_data P1
sbit lcd_rs = P1^2;
sbit lcd_en = P1^3;
sbit sw=P2^0;
unsigned char count=0;
void Lcd4_Decimal3(unsigned char);
void delay(unsigned int v)
{
unsigned int i,j;
for(i=0;i<=v;i++)
for(j=0;j<=1275;j++);
}
void lcdcmd(unsigned char value) // LCD COMMAND
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
}
Dept of ECE, Prasiddha College of Engineering and Technology
19
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
delay(3);
}
void msgdisplay(unsigned char b[]) // send string to lcd
{
unsigned char s,count=0;
for(s=0;b[s]!='\0';s++)
{
count++;
if(s==16)
lcdcmd(0xc0);
if(s==32)
{
lcdcmd(1);
count=0;
}
lcddata(b[s]);
}
}
void main(void)
{
lcd_init();
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("welcome to ");
Dept of ECE, Prasiddha College of Engineering and Technology
20
lcdcmd(0xc0);
msgdisplay("prasidda clg ");
delay(100);delay(100);
lcdcmd(0x01);
while(1)
{
if(sw==1)
{
count=0;
}
if(sw==0)
{
count++;
}
lcdcmd(0x80);
Lcd4_Decimal3(count);
}}
void Lcd4_Decimal3(unsigned char val)
{
unsigned int Lcd_h,Lcd_hr,Lcd_t,Lcd_o;
Lcd_h=val/100;
Lcd_hr=val%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
lcddata(Lcd_h+0x30);
lcddata(Lcd_t+0x30);
lcddata(Lcd_o+0x30);
}
RESULT: Thus the loop application to copy a value from P1 to P2 program has been compiled,
debugged and executed successfully.
Aim: To write an embedded c program for counting the number of times that a switch is pressed and
released in using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board.
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the Command
Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still running, it
halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include<reg51.h>
#include<string.h>
#define lcd_data P1
sbit lcd_rs = P1^2;
sbit lcd_en = P1^3;
sbit sw=P2^0;
unsigned char count=0;
void Lcd4_Decimal3(unsigned char);
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x0e); //cursor blinking
lcdcmd(0x06); //move the cursor to right side
lcdcmd(0x01); //clear the lcd
}
void lcddata(unsigned char value)
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(3);
lcd_en=0;
delay(3);
}
void msgdisplay(unsigned char b[]) // send string to lcd
{
unsigned char s,count=0;
for(s=0;b[s]!='\0';s++)
{
count++;
if(s==16)
lcdcmd(0xc0);
if(s==32)
{
lcdcmd(1);
count=0;
}
lcddata(b[s]);
}
}
void main(void)
{
lcd_init();
sw=1;
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("welcome to ");
lcdcmd(0xc0);
msgdisplay("prasidda clg ");
while(1)
{
if(sw==0)
{
count++;
}
lcdcmd(0x80);
Lcd4_Decimal3(count);
lcdcmd(0xc0);
msgdisplay("welcomes u ");
}}
Lcd_h=val/100;
Lcd_hr=val%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
lcddata(Lcd_h+0x30);
lcddata(Lcd_t+0x30);
lcddata(Lcd_o+0x30);
}
RESULT: Thus the counting the number of times that a switch is pressed and released program has
been compiled, debugged and executed successfully.
Aim: To write an embedded program to create a portable hardware delay using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board.
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still running,
it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include<reg51.h>
#include<string.h>
#define lcd_data P1
sbit lcd_rs = P1^2;
sbit lcd_en = P1^3;
delay(3);
}
lcd_init();
while(1)
{
lcdcmd(0x80);
msgdisplay("ECE Dept. ");
lcdcmd(0xc0);
msgdisplay("welcomes u ");
}}
RESULT: Thus to create a portable hardware delay program has been compiled, debugged and executed
successfully.
Aim: To write an embedded program to write a C program to test loop time outs using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board.
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still running,
it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include<reg51.h>
timer0_init()
{
TMOD = 0x01;
TH1 = 0x0;
TL1 = 0x0;
}
void delay(unsigned char i)
{
unsigned int j;
for(i;i>0;i--){
for(j=0;j<123;j++)
{
//do nothing as this function is to produce simple delay
}
}
}
main()
{
int timer_value = 0;
timer0_init();
TR1 = 1; //start the timer before testing a loop
delay(5); //here we assumed delay() function as loop to be tested. What ever the loop to be tested
shuld be placed instead of delay
TR1 = 0; //stop the timer
timer_value = (TH0<<8) | TLO;
/*********************************
Note: Now we have total cycles consumed by the testing_loopi.e.,Delay() function in this
program.
Dept of ECE, Prasiddha College of Engineering and Technology
28
Calculation follows:
Assume crystal frequency = 12MHZ
Timer works 1/12 of clock frequency so 12MHz/12 is 1MHZ. As a result, each clock has a period
of T=1/f i.e., T = 1/1MHz = 1us.
Timer 0 counts up each 1us resulting in delay = timer_value x 1us.
***********************************/
}
RESULT: Thus the test loop time outs program has been compiled, debugged and executed
successfully.
Aim: To write an embedded program to write a C program to test TRAFFIC LIGHT using keil µVision.
Apparatus:
1. . Desktop PC.
2. Keil µVision software.
3. 8051 target board
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still
running, it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which
will execute next, is marked with a yellow arrow. The yellow arrow moves each time
you step.
Program:
#include <reg52.h>
void msdelay(unsigned int t)
{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<1275;j++);
}
void main()
{
while(1)
{
P1=0X0F;
P2=0X00;
msdelay(250);
P1=0X00;
P2=0X0F;
msdelay(250);
}
}
RESULT: Thus the TRAFFIC LIGHT outs program has been compiled, debugged and executed
successfully.
Aim: To write an embedded program to write a C program to test LCD using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still
running, it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which
will execute next, is marked with a yellow arrow. The yellow arrow moves each time
you step.
Program:
#include<reg51.h>
#define display_port P2 //Data pins connected to port 2 on microcontroller
sbit rs = P3^2; //RS pin connected to pin 2 of port 3
sbit rw = P3^3; // RW pin connected to pin 3 of port 3
sbit e = P3^4; //E pin connected to pin 4 of port 3
sbit c3 = P1^6;
sbit c2 = P1^5;
sbit c1 = P1^4;
sbit r4 = P1^3;
sbit r3 = P1^2;
sbit r2 = P1^1;
sbit r1 = P1^0;
void main()
{
lcd_init();
while(1)
{
r1=0;
if(c1==0)
{
lcd_cmd(0X80);
lcd_data('1');
msdelay(1000);
}
if(c1==0)
{
lcd_cmd(0X80);
lcd_data('2'); msdelay(1000);
}
if(c3==0)
{
lcd_cmd(0X80);
lcd_data('3'); msdelay(1000);
}
}
RESULT: Thus the PORT to interfacing consisting of LED outs program has been compiled, debugged
and executed successfully.
Aim: To write an embedded program to write a C program to test hard ware loop time outs using keil
µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board.
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still
running, it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which will
execute next, is marked with a yellow arrow. The yellow arrow moves each time you step.
Program:
#include<reg51.h>
#include<string.h>
#define lcd_data P1
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
delay(3);
}
void main(void)
{
lcd_init();
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("welcome to ");
lcdcmd(0xc0);
msgdisplay("prasidda clg ");
delay(100);delay(100);
lcdcmd(0x01);
while(1)
{
if(sw==1)
{
count=0;
}
if(sw==0)
{
count++;
}
lcdcmd(0x80);
Lcd4_Decimal3(count);
}}
Lcd_h=val/100;
Lcd_hr=val%100;
lcddata(Lcd_h+0x30);
lcddata(Lcd_t+0x30);
lcddata(Lcd_o+0x30);
}
RESULT: Thus the test hardware loop time outs program has been compiled, debugged and executed
successfully.
Aim: To write an embedded program to write a C program to test LCD using keil µVision.
Apparatus:
1. Desktop PC.
2. Keil µVision software.
3. 8051 target board
4. Protous software
Procedure:
1. Open the keil µVision software in PC.
2. Create a new project and select the target board from the list.
3. Write the c code in the test file, compile and build it.
4. Open the Serial Window UART #1 to display the application’s output.
5. Click the Stop button to halt the program. Alternatively, press the Esc key while in the
Command Line of the Command Window.
6. Use the Insert/Remove Breakpoint command to set or clear a breakpoint.
7. Test the Reset command to reset the simulated microcontroller. If the program is still
running, it halts at the first breakpoint.
8. Single-step through the program using the Step buttons. The current instruction, which
will execute next, is marked with a yellow arrow. The yellow arrow moves each time
you step.
Program:
#include<reg51.h>
#include<string.h>
#define lcd_data P1
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
delay(3);
}
void main(void)
{
lcd_init();
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("welcome to ");
lcdcmd(0xc0);
msgdisplay("prasidda clg ");
delay(100);delay(100);
lcdcmd(0x01);
while(1)
{
if(ir==0)
{
lcdcmd(0x80);
msgdisplay("Intruder came ");
buzzer=1;
}
if(ir==1)
{
lcdcmd(0x80);
msgdisplay("no Intruder "); buzzer=0;
}
}}
Lcd_h=val/100;
Lcd_hr=val%100;
Lcd_t=Lcd_hr/10;
Lcd_o=Lcd_hr%10;
lcddata(Lcd_h+0x30);
lcddata(Lcd_t+0x30);
lcddata(Lcd_o+0x30);
RESULT: Thus the Intruder Alarm System outs program has been compiled, debugged and executed successfully.