Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MICROPROCESSOR
CERTIFICATE
This is to certify that Mr./Miss Your Name bearing Institute Roll No.
U16EE0xx has satisfactorily completed the course in Embedded Systems and
Microcontroller (EExxx) during the year 2018-19.
Contents
Contents .................................................................................................................... 2
1. BLINKING LEDs .................................................................................................. 7
1.1 Aim .............................................................................................................. 7
1.2 Code ............................................................................................................. 7
1.3 Hex Code ..................................................................................................... 8
1.4 Simulated Output ......................................................................................... 8
1.5 Hardware interfaced Output ........................................................................ 8
1.6 Conclusion ................................................................................................... 9
2. Toggling LEDs Alternatively ................................................................................ 9
2.1 Aim .............................................................................................................. 9
2.2 Code ............................................................................................................. 9
Wednesday, 9 January 2019
2
Wednesday, 9 January 2019
3
Wednesday, 9 January 2019
4
Wednesday, 9 January 2019
6
Wednesday, 9 January 2019
1. BLINKING LEDs
1.1 Aim
Blink the LEDs connected to the port P1, using software delay.
1.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <stdio.h>
#include <reg51.h>
unsigned int i;
void delay(int x)
{
for(i=0;i<x;i++);
}
void main()
7
Wednesday, 9 January 2019
{
while(1)
{
P1=0xFF;
delay(10000);
P1=0x00;
delay(10000);
}
}
8
Wednesday, 9 January 2019
1.6 Conclusion
We used for loop to generate the required amount of time delay for
blinking all the LEDs. And to do this task continuously, we used while loop
with condition which is always true.
2.1 Aim
Toggle the alternate LEDs connected to Port P1, using software delay.
2.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<stdio.h>
#include<reg51.h>
unsigned int i;
void delay(int x)
{
for(i=0;i<x;i++);
}
void main()
9
Wednesday, 9 January 2019
{
while(1)
{
P1=0xAA;
delay(10000);
P1=0x55;
delay(10000);
}
}
10
Wednesday, 9 January 2019
2.6 Conclusion
We used for loop to generate the required amount of time delay for
blinking the alternate LEDs. And to do this task continuously, we used
while loop with condition which is always true.
3.1 Aim
Shift the blinking of LED, that connected to the port P1 from left to right, keeping
previous LED OFF.
3.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay(int x)
{
for(i=0;i<x;i++);
11
Wednesday, 9 January 2019
void main()
{
P1=0x01;
delay(10000);
while(1)
{
P1=P1<<1;
delay(10000);
if(P1==0x80)
{
P1=0x01;
delay(10000);
}
}
}
12
Wednesday, 9 January 2019
3.6 Conclusion
We used for loop to generate the required amount of time delay to
shift the blinking of the LEDs. We used << command to shift the status of
LEDs connected to port P1 in the left direction. And to do this task
continuously, we used while loop with condition which is always true.
13
Wednesday, 9 January 2019
4.1 Aim
Shift the blinking of LED, that connected to the port P1 from left to right, keeping
previous LED OFF.
4.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay(int x)
{
for(i=0;i<x;i++);
}
void main()
{
P1=0x80;
delay(10000);
14
Wednesday, 9 January 2019
while(1)
{
P1=P1>>1;
delay(10000);
if(P1==0x01)
{
P1=0x80;
delay(10000);
}
}
}
15
Wednesday, 9 January 2019
4.6 Conclusion
We used for loop to generate the required amount of time delay to
shift the blinking of the LEDs. We used >> command to shift the status of
LEDs connected to port P1 in the right direction. And to do this task
continuously, we used while loop with condition which is always true.
16
Wednesday, 9 January 2019
5.1 Aim
Shift the blinking of LED, that connected to the port P1 from right to left, keeping
previous LED ON.
5.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay(int x)
{
for(i=0;i<x;i++);
}
void main()
{
P1=0x01;
17
Wednesday, 9 January 2019
delay(1000);
while(1)
{
P1=(P1<<1)+1;
delay(1000);
if(P1==0xff)
{
P1=0x01;
delay(1000);
}
}
}
18
Wednesday, 9 January 2019
5.6 Conclusion
We used for loop to generate the required amount of time delay to
shift the blinking of the LEDs. We used << command to shift the status of
LEDs connected to port P1 in the left direction, and then we added 0x01 to
get the desired pattern. And to do this task continuously, we used while
loop with condition which is always true.
19
Wednesday, 9 January 2019
6.1 Aim
Shift the blinking of LED, that connected to the port P1 from left to right, keeping
previous LED ON.
6.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void main()
{
P1=0x01;
while(1)
{
for(i=0;i<65535;i++);
if(P1==0xFF)
20
Wednesday, 9 January 2019
{
P1=0x01;
}
else
{
P1=P1>>1;
P1=P1+0x80;
}
}
}
21
Wednesday, 9 January 2019
6.6 Conclusion
We used for loop to generate the required amount of time delay to shift the
blinking of the LEDs. We used >> command to shift the status of LEDs
connected to port P1 in the right direction, and then we added 0x80 to get
the desired pattern. And to do this task continuously, we used while loop
with condition which is always true.
22
Wednesday, 9 January 2019
7. Switching Patterns-I
7.1 Aim
Implement the pattern from 1 to 5, using Switch keys connected to port P2
7.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
void delay(void);
unsigned int i;
unsigned int j;
sbit down=P2^0;
sbit right=P2^1;
sbit center=P2^2;
sbit left=P2^3;
sbit up=P2^4;
void first(void);
void second(void);
23
Wednesday, 23 January 2019
void third(void);
void forth(void);
void fifth(void);
void main()
{
P2=0X00;
while(1)
{
if(down==1)
{
first();
}
if(right==1)
{
second();
}
if(center==1)
{
third();
}
if(left==1)
{
forth();
}
if(up==1)
{
fifth();
}
}
}
void delay()
{
for(j=0;j<65535;j++);
}
void first ()
{
P1=0x00;
delay();
P1=0xFF;
delay();
}
void second ()
{
P1=0xAA;
delay();
P1=~P1;
delay();
}
void third ()
{
P1=0x01;
for(i=0;i<7;i++)
{
delay();
P1=P1*2;
}
24
Wednesday, 23 January 2019
void forth ()
{
P1=0x80;
for(i=0;i<7;i++)
{
delay();
P1=P1>>1;
}
}
void fifth ()
{
P1=0x01;
for(i=0;i<7;i++)
{
delay();
P1=P1<<1;
P1=P1+1;
}
}
25
Wednesday, 23 January 2019
1)
2)
3)
26
Wednesday, 23 January 2019
4)
5)
27
Wednesday, 23 January 2019
28
Wednesday, 23 January 2019
7.6 Conclusion
We made different functions for each pattern so that whenever this
key is pressed, its corresponding function gets called and executes the
specific task to get the desired pattern for that particular key press. We
used for loop to generate time delay between two status of the LED. And
to do this task continuously, we used while loop with condition which is
always true.
8. Switching Patterns-II
8.1 Aim
Implement the patterns from 1 to 5 using switch keys connected to the port P2 in real
time.
8.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
void delay(void);
29
Wednesday, 23 January 2019
unsigned int i;
unsigned int j;
sbit down=P2^0;
sbit right=P2^1;
sbit center=P2^2;
sbit left=P2^3;
sbit up=P2^4;
void first(void);
void second(void);
void third(void);
void forth(void);
void fifth(void);
void main()
{
P2=0X00;
while(1)
{
if(down==1)
{
first();
}
if(right==1)
{
second();
}
if(center==1)
{
third();
}
if(left==1)
{
forth();
}
if(up==1)
{
fifth();
}
}
}
void delay()
{
for(j=0;j<65535;j++);
}
void first ()
{
P1=0x00;
delay();
P1=0xFF;
delay();
}
void second ()
{
P1=0xAA;
delay();
P1=~P1;
delay();
}
30
Wednesday, 23 January 2019
void third ()
{
P1=0x01;
for(i=0;i<7;i++)
{
delay();
P1=P1*2;
}
}
void forth ()
{
P1=0x80;
for(i=0;i<7;i++)
{
delay();
P1=P1>>1;
}
}
void fifth ()
{
P1=0x01;
for(i=0;i<7;i++)
{
delay();
P1=P1<<1;
P1=P1+1;
}
}
31
Wednesday, 23 January 2019
:1008B100EB9FF5F0EA9E42F0E99D42F0EC6480C8BE
:0608C10064809845F0225E
:00000001FF
1)
32
Wednesday, 23 January 2019
8.6 Conclusion
To implement the required various pattern in real time (Hardware
Kit), we burned the hex code to the microcontroller kit through SST
software and after pressing the RESET button, we were able to observe
the corresponding pattern for its designed key press.
9. Toggling LED
33
Wednesday, 30 January 2019
9.1 Aim
Blink the LED connected to port 1 with a delay of 1 sec using timer 0 in mode 1.
9.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay()
{
for(i=0;i<100;i++)
{
TH0=0x87;
TL0=0xCE;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}
void main()
{
TMOD=0x01;
while(1)
{
P1=~P1;
delay();
}
}
34
Wednesday, 30 January 2019
9.6 Conclusion
We used timer 0 in mode 1 to generate the time delay of 1 sec for
blinking all the LEDs. And to do this task continuously, we used while loop
with condition which is always true.
35
Wednesday, 6 February 2019
10.1 Aim
Implement the pattern from 1 to 6, using Switch keys connected to port P2.(using
Hardware delay)
10.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<stdio.h>
#include<reg51.h>
unsigned int i;
sbit down=P2^0;
sbit right=P2^1;
sbit center=P2^2;
sbit left=P2^3;
sbit up=P2^4;
void delay()
{
for(i=0;i<50;i++)
{
TH0=0x88;
TL0=0x00;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
}
void main()
{
TMOD=0x01;
P2=0x00;
while(1)
{
if(down==1)
{
P1=0xAA;
delay();
P1=0x55;
delay();
}
else if(right==1)
{
if(P1==0x00||P1==0x80)
{
P1=0x01;
delay();
}
P1=P1<<1;
36
Wednesday, 6 February 2019
delay();
}
else if(center==1)
{
if(P1==0x01||P1==0x00)
{
P1=0x80;
delay();
}
P1=P1>>1;
delay();
}
else if(left==1)
{
P1=(P1<<1)+1;
delay();
if(P1==0xff)
{
P1=0x01;
delay();
}
}
else if(up==1)
{
P1=(P1>>1)+0x80;
delay();
if(P1==0xff)
{
P1=0x80;
delay();
}
}
}
}
10.3 Hex Code
:10088500E4F508F509758C88E4F58AD28C308DFD80
:10089500C28DC28C0509E509700205086432450858
:0308A50070E322DB
:10080000758901E4F5A030A00B7590AA12088575D2
:100810009055805030A11AAF90EF6007AF90EF6411
:10082000807006759001120885E59025E0F59080AE
:100830003330A21AAF90EF64016005AF90EF7006FD
:10084000759080120885E590C313F590801630A34B
:1008500018E59025E004F590120885AF90EFF4704C
:10086000A5759001120885809D30A49AE590C31368
:100870002480F590120885AF90EFF4708975908010
:050880001208858081D3
:030000000208A84B
:0C08A800787FE4F6D8FD75810902080095
:00000001FF
37
Wednesday, 6 February 2019
2)
10.6 Conclusion
We made different functions for each pattern so that whenever this
key is pressed, its corresponding function gets called and executes the
specific task to get the desired pattern for that particular key press. We used
timer 0 in mode 1 to generate time delay of 1 second between two statuses
of the LED. And to do this task continuously, we used while loop with
condition which is always true.
38
Wednesday, 6 February 2019
11.1 Aim
Generate PWM signal as mentioned below, using timer 1 in mode 1(polling method)
a)When P2.1=1, Generate PWM signal of frequency 1 KHz and duty cycle=80%
b)When P2.2=1, Generate PWM signal of frequency 2 KHz and duty cycle=20%
c)When P2.3=1, Generate PWM signal of frequency 500 Hz and duty cycle=40%
(Xtal=18.432 MHz , 6 clock mode)
11.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay()
{
TH1=0xFE;
TL1=0xCD;
TR1=1;
while(TF1==0);
TF1=0;
TR1=0;
}
void main()
{
TMOD=0x10;
P2=0x0E;
while(1)
{
switch(P2)
{
case 2:
for(i=0;i<8;i++)
delay();
P1=~P1;
for(i=0;i<2;i++)
delay();
P1=~P1;
break;
case 4:
delay();
P1=~P1;
for(i=0;i<4;i++)
delay();
P1=~P1;
break;
case 8:
for(i=0;i<8;i++)
39
Wednesday, 6 February 2019
delay();
P1=~P1;
for(i=0;i<12;i++)
delay();
P1=~P1;
break;
}
}
}
40
Wednesday, 6 February 2019
11.6 Conclusion
We used timer 1 in mode 1 to generate the required PWM.Here we
moniter port P2.0 and generate the PWM required according to the input.
And to do this task continuously, we used while loop with condition which
is always true.
41
Wednesday, 6 February 2019
12.1 Aim
Generate a delay of 1ms using timer 0 interrupt in mode 1.
12.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i;
void delay() interrupt 1
{
P1=~P1;
TH0=0xF4;
TL0=0x00;
}
void main()
{
TMOD=0x01;
IE=0x82;
TH0=0xF4;
TL0=0x00;
TR0=1;
while(1);
}
42
Wednesday, 6 February 2019
12.6 Conclusion
We used timer 0 interrupt in mode 1 to generate the time delay of 1
msec .To check the delay we are blinking the LEDs. And to do this task
continuously, we used while loop with condition which is always true.
43
Wednesday, 6 February 2019
13.1 Aim
Generate a delay of 1s using timer 1 interrupt in mode 1.
13.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i=0;
void main()
{
TMOD=0x10;
IE=0x88;
TH1=0x87;
TL1=0xCE;
TR1=1;
while(1)
{
if(i==100)
{
P1=~P1;
i=0;
}
}
}
void delay() interrupt 3
{
i++;
TH1=0x87;
TL1=0xCE;
}
44
Wednesday, 6 February 2019
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
13.6 Conclusion
We used timer 1 interrupt in mode 1 to generate the time delay of 1
sec .To check the delay we are blinking the LEDs. And to do this task
continuously, we used while loop with condition which is always true.
45
Wednesday, 6 February 2019
14.1 Aim
Generate a delay of 3s using timer 0 interrupt in mode 1.
14.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
unsigned int i=0;
void main()
{
TMOD=0x01;
IE=0x82;
TH0=0x87;
TL0=0xCE;
TR0=1;
while(1)
{
if(i==300)
{
P1=~P1;
i=0;
}
}
}
void delay() interrupt 1
{
i++;
TH0=0x87;
TL0=0xCE;
}
46
Wednesday, 6 February 2019
:10083C00E4800B01020408102040809008C1E47E83
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
14.6 Conclusion
We used timer 0 interrupt in mode 1 to generate the time delay of
3 sec .To check the delay we are blinking the LEDs. And to do this task
continuously, we used while loop with condition which is always true.
47
Wednesday, 13 February 2019
15.1 Aim
Interface the LCD with 8051 micro controller and display your Name and Roll number
in first and second line respectively.
15.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<reg51.h>
void lcd_init(void);
void lcd_cmd(unsigned char command);
void lcd_data(unsigned char disp_data);
void delay(unsigned int t);
unsigned int i;
sbit RS=P2^7;
sbit RW=P2^6;
sbit e=P2^5;
void main()
{
unsigned char a[7]="HEMANTH";
unsigned char b[8]="U16EE060";
while(1)
{
lcd_init();
lcd_cmd(0x80);
for(i=0;i<7;i++)
{
lcd_data(a[i]);
delay(500);
lcd_cmd(0x06);
}
lcd_cmd(0xc0);
for(i=0;i<8;i++)
{
lcd_data(b[i]);
delay(500);
lcd_cmd(0x06);
}
}
}
void lcd_cmd(unsigned char command)
{
P0=command;
RS=0;
RW=0;
e=1;
delay(10);
e=0;
}
void lcd_data(unsigned char disp_data)
48
Wednesday, 13 February 2019
{
P0=disp_data;
RS=1;
RW=0;
e=1;
delay(10);
e=0;
}
void lcd_init()
{
lcd_cmd(0x38);
delay(10);
lcd_cmd(0x0F);
delay(10);
lcd_cmd(0x01);
delay(10);
}
void delay(unsigned int t)
{
unsigned int j,k;
for(k=0;k<t;k++)
{
for(j=0;j<100;j++);
}
}
49
Wednesday, 13 February 2019
:1008700089828A83ECFAE493A3C8C582C8CCC58375
:10088000CCF0A3C8C582C8CCC583CCDFE9DEE78045
:100890000D89828A83E493A3F608DFF9ECFAA9F0C4
:1008A000EDFB2289828A83ECFAE0A3C8C582C8CC1A
:1008B000C583CCF0A3C8C582C8CCC583CCDFEADE33
:1008C000E880DB89828A83E493A3F208DFF980CC95
:1008D00088F0EF60010E4E60C388F0ED2402B4048E
:1008E0000050B9F582EB2402B4040050AF23234535
:0608F00082239008507302
:00000001FF
15.6 Conclusion
In this experiment we have learnt how to interface an LCD using
8051 controller. We use init function to initialize LCD, cmd function to
pass a command to LCD, data function to send data to be displayed to LCD.
RS, RW & e are control signals of LCD.
50
Wednesday,13 March 2019
16.1 Aim
Generate a PWM of 1KHz and 70 pecentage duty cycle at P1,using timer 0 in Auto
reload mode(Use timer in interrupt mode).
16.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
sbit LED=P1^1;
unsigned char i=0;
void main()
{
TMOD=0x02;
IE=0x82;
TH0=0xE1;
TR0=1;
while(1)
{
if(i==70)
{
LED=0;
}
if(i==100)
{
LED=1;
i=0;
}
}
}
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008AEE47E96
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108B1000046
:00000001FF
16.6 Conclusion
We used timer 0 in auto reload mode (interrupt mode) to generate
the PWM of 70 percentage duty cycle
52
Wednesday, 13 March 2019
17.1 Aim
Blink the LED connected to port 1.4 when an external signal is received by 8051
controller(use concept of external interrupt).
17.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
bit extflag=0;
sbit led=P1^4;
void main ()
{
EA=1;
EX0=1;
IT0=1;
while(1)
{
if(extflag==1)
{
extflag=0;
led=~led;
}
}
}
53
Wednesday, 13 March 2019
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108A0000057
:00000001FF
17.6 Conclusion
We toggled the LED whenever negative edge of external interrupt is
coming. For that we set the flag in external interrupt ISR and took the
toggling action in while loop.
54
Wednesday , 13 March 2019
18.1 Aim
Generate a 8051 code for measuring DC voltage using ADC0808, also display the
measured voltage in LCD.
18.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
#include <intrins.h>
#define display_port P0
sbit ALE=P3^1;
sbit EOC=P3^2;
sbit OE=P3^3;
sbit SOC=P3^4;
sbit CS_A=P3^5;
sbit CS_B=P3^6;
sbit CS_C=P3^7;
unsigned char a,b,c,d,e,f,g,h,i,v[5];
void ADC_INI(void);
void ADC_READ(void);
void calculate(unsigned char u);
sbit RS=P2^7;
sbit RW=P2^6;
sbit EN=P2^5;
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void lcd_init();
void disp_lcd();
void delay(unsigned int);
void main()
{
ADC_INI();
while(1)
{
ADC_INI();
ADC_READ();
}
}
void ADC_INI()
{
P1=0xFF;
ALE=0;
SOC=0;
OE=0;
EOC=1;
delay(1);
}
68
Wednesday, 13 March 2019
void ADC_READ()
{
CS_A=0;
CS_B=0;
CS_C=0;
ALE=1;
SOC=1;
delay(1);
ALE=0;
SOC=0;
while(EOC==1);
OE=1;
delay(1);
a=P1;
delay(1);
OE=0;
calculate(a);
}
void disp_lcd()
{
unsigned char z[7]="VOLTAGE";
void lcd_init();
lcd_cmd(0x80);
for(i=0;i<7;i++)
{
lcd_data(z[i]);
delay(500);
}
lcd_cmd(0xc0);
for(i=0;i<5;i++)
{
if(i==1)
{
lcd_data('.');
delay(500);
}
else
{
lcd_data(v[i]);
delay(500);
}
}
}
56
Wednesday, 13 March 2019
{
for(c=0;c<t;c++);
}
void lcd_init()
{
lcd_cmd(0x38);
delay(10);
lcd_cmd(0x0F);
delay(10);
lcd_cmd(0x01);
delay(10);
}
57
Wednesday, 13 March 2019
:10099B001EEF640170047F2E800774112510F8E69A
:0F09AB00FF120AA87FF47E01120A65051080D49E
:0109BA00221A
:080A5D00C2A6D2A57F017E00B4
:100A6500E4F50AC3E50A9FE49E5004050A80F422D2
:100A39007F38120A9E7F0A7E00120A657F0F120A0A
:100A49009E7F0A7E00120A657F01120A9E7F0A7E36
:040A590000020A6528
:0A0A9E008F80C2A7120A5DC2A522D4
:0A0AA8008F80D2A7120A5DC2A522BA
:03000000020A876A
:0C0A8700787FE4F6D8FD75811C020A930C
:10080000E709F608DFFA8046E709F208DFFA803EDA
:1008100088828C83E709F0A3DFFA8032E309F608C7
:10082000DFFA8078E309F208DFFA807088828C832F
:10083000E309F0A3DFFA806489828A83E0A3F608E3
:10084000DFFA805889828A83E0A3F208DFFA804CBD
:1008500080D280FA80C680D4806980F28033801094
:1008600080A680EA809A80A880DA80E280CA8033FD
:1008700089828A83ECFAE493A3C8C582C8CCC58375
:10088000CCF0A3C8C582C8CCC583CCDFE9DEE78045
:100890000D89828A83E493A3F608DFF9ECFAA9F0C4
:1008A000EDFB2289828A83ECFAE0A3C8C582C8CC1A
:1008B000C583CCF0A3C8C582C8CCC583CCDFEADE33
:1008C000E880DB89828A83E493A3F208DFF980CC95
:1008D00088F0EF60010E4E60C388F0ED2402B4048E
:1008E0000050B9F582EB2402B4040050AF23234535
:0608F00082239008507302
:1008F600BC000BBE0029EF8DF084FFADF022E4CCE6
:10090600F875F008EF2FFFEE33FEEC33FCEE9DECAE
:10091600984005FCEE9DFE0FD5F0E9E4CEFD22EDF4
:10092600F8F5F0EE8420D21CFEADF075F008EF2F3E
:10093600FFED33FD4007985006D5F0F222C398FD2F
:050946000FD5F0EA22CC
:00000001FF
58
Wednesday, 13 March 2019
18.6 Conclusion
We measured the level of DC voltage and displayed it on LCD. Through
potentiometer arrangement, we varied the level of DC voltage. Then we gave this
variable DC voltage to ADC and manipulated the output of ADC to display.
59
Wednesday , 20 March 2019
19.1 Aim
Write a program to display 0 to 9 using seven segment display.
19.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
sbit x=P2^7;
sbit y=P2^6;
sbit z=P2^5;
void delay(void);
unsigned int i,j,seg=0;
void main()
{
unsigned char
disp[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
while(1)
{
k:
if(seg==0)
{
x=0;
y=0;
z=0;
}
if(seg==1)
{
x=0;
y=0;
z=1;
}
if(seg==2)
{
x=0;
y=1;
z=0;
}
if(seg==3)
{
x=0;
y=1;
z=1;
}
if(seg==4)
{
68
Wednesday, 20 March 2019
seg=0;
goto k;
}
for(i=0;i<10;i++)
{
P0=disp[i];
for(j=0;j<1000;j++)
{delay();}
}
seg++;
}
}
void delay(void)
{
TMOD=0x01;
TL0=0xFB;
TH0=0xF3;
TR0=1;
while(TF0==0);
TF0=0;
TR0=0;
}
61
Wednesday, 20 March 2019
19.6 Conclusion
We used four 7 segment LED displays to continuously display series
of numbers from 0 to 9. We kept shifting this series from first segment to
last segment.
62
Wednesday, 20 March 2019
20.1 Aim
Write a program for real time digital clock using seven segment display.
20.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
int i,j;
unsigned char dig_disp=0;
int min2;
int min1;
int sec2;
int sec1;
sbit led =P2^7;
sbit led1=P2^6;
sbit led2=P2^5;
int x,y;
int seg=0;
void timer_delay(void);
char num[]={0x3F, 0x06, 0x5B, 0x4F, 0x66,0X6D ,0x7D, 0x07, 0x7F, 0x6F};
void main()
{
while(1)
{
min2=min1=sec2=sec1=0;
for(min2=0;min2<6;min2++)
{
for(min1=0;min1<10;min1++)
{
for(sec2=0;sec2<6;sec2++)
{
for(sec1=0;sec1<10;sec1++)
{
for(i=0;i<1000;i++)
{
timer_delay();
}
}
}
}
}
63
Wednesday, 20 March 2019
}
}
void timer_delay(void)
{
TMOD=0X01;
TH0=0XF3;
TL0=0XFB;
TR0=1;
while(TF0==0)
{
;
}
TR0=0;
TF0=0;
dig_disp++;
dig_disp=dig_disp%4;
switch(dig_disp)
{
case 0:
P0=num[sec1];
led=0;
led1=1;
led2=1;
break;
case 1:
P0= num[sec2];
led=0;
led1=1;
led2=0;
break;
case 2:
P0= num[min1];
led=0;
led1=0;
led2=1;
break;
case 3:
P0=num[min2];
led=0;
led1=0;
led2=0;
break;
}
}
64
Wednesday, 20 March 2019
:10080000E4F519F51AF51BF51CF51DF51EF521F596
:1008100022F521F522E4F51DF51EE4F51BF51CE497
:10082000F519F51AE4F515F51612091A0516E51667
:1008300070020515C394E8E5156480948340EA05C9
:100840001AE51A70020519C3940AE51964809480A8
:1008500040D2051CE51C7002051BC39406E51B6411
:1008600080948040BA051EE51E7002051DC3940ADF
:10087000E51D6480948040A20522E52270020521D6
:0E088000C39406E52164809480408A0208003B
:10091A00758901758CF3758AFBD28C308DFDC28C7A
:10092A00C28D050A530A03E50A14601914602514D6
:10093A0060312403703B740B251AF8E6F580C2A7D0
:10094A00D2A6D2A522740B251CF8E6F580C2A7D23E
:10095A00A6C2A522740B251EF8E6F580C2A7C2A678
:10096A00D2A522740B2522F8E6F580C2A7C2A6C238
:02097A00A522B4
:10089A00020800E493A3F8E493A34003F68001F26C
:1008AA0008DFF48029E493A3F85407240CC8C3335F
:1008BA00C4540F4420C8834004F456800146F6DF2E
:1008CA00E4800B010204081020408090097CE47E39
:1008DA00019360BCA3FF543F30E509541FFEE49323
:1008EA00A360010ECF54C025E060A840B8E493A3EA
:1008FA00FAE493A3F8E493A3C8C582C8CAC583CA15
:10090A00F0A3C8C582C8CAC583CADFE9DEE780BECC
:01098F000067
:00000001FF
65
Wednesday, 20 March 2019
20.6 Conclusion
We made digital clock by using four 7 segment LED displays. We
displayed Seconds on the last 2 displays and Minutes on the first 2
displays.
66
Wednesday,27 March 2019
21.1 Aim
Write a program to monitor the state of switch connected to port 2 and generate
following waveform using DAC.
When P2.1=1, Generate ramp waveform.
When P2.2=1, Generate triangle waveform.
When P2.3=1, Generate sinusoidal waveform.
21.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
#include <intrins.h>
sbit DAC_WR = P3^0;
unsigned int i;
unsigned int j;
unsigned char
arr[13]={0x80,0xC0,0xDA,0xFF,0xFE,0xC0,0x80,0x40,0x11,0x00,0x11,0x40,
0x80};
void delay(unsigned int t)
{
for(j=0;j<t;j++);
}
void main()
{
P2=0x0E;
while(1)
{
switch(P2)
{
case 2:
for(i=0;i<=255;i++)
{
DAC_WR=1;
delay(10);
P1=i;
DAC_WR=0;
}
break;
case 4:
for(i=0;i<=255;i++)
{
DAC_WR=1;
delay(10);
P1=i;
DAC_WR=0;
68
Wednesday, 27 March 2019
}
for(i=255;i>0;i--)
{
DAC_WR=1;
delay(10);
P1=i;
DAC_WR=0;
}
break;
case 8:
for(i=0;i<13;i++)
{
DAC_WR=1;
delay(10);
P1=arr[i];
DAC_WR=0;
}
break;
}
}
}
68
Wednesday, 27 March 2019
69
Wednesday, 27 March 2019
21.6 Conclusion
We generated Ramp Wave, Triangular Wave and Sinusoidal Wave using DAC
for different conditions of Switch.
70
Wednesday, 30 March 2019
22.1 Aim
Write a program to generate PWM wave of 1KHz and 20 percentage duty cycle using
Timer T2 in auto reload mode.
22.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <p89v51rd2.h>
sbit LED=P1^2;
unsigned char i=0;
void main()
{
EA=1;
ET2=1;
T2MOD=0x00;
T2CON=0x00;
TH2=0xFE;
TL2=0xCD;
RCAP2H=0xFE;
RCAP2L=0xCD;
TR2=1;
LED=1;
while(1);
}
71
Wednesday, 30 March 2019
:10088C00C0E0C0D075D000C006C007C2CF0508AF0D
:10089C00087E00EF64027002C292EF640A4E70048C
:0D08AC00F508D292D007D006D0D0D0E032AF
:03000000020800F3
:0C080000787FE4F6D8FD758108020847F7
:10080C000208B9E493A3F8E493A34003F68001F241
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008D4E47E70
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108D7000020
:00000001FF
72
Wednesday, 30 March 2019
22.6 Conclusion
We generated PWM of 1 kHz frequency 20 percentage duty cycle using Timer
T2 in 16 bit Auto Reload Mode in Interrupt Mode.
73
Wednesday, 30 March 2019
23.1 Aim
Write a program to generate clock of 1KHz using timer T2(Timer 2 in clock out mode).
23.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <p89v51rd2.h>
void main()
{
T2CON=0x00;
T2MOD=0x02;
TH2=0xDC;
TL2=0x00;
RCAP2H=0xDC;
RCAP2L=0x00;
TR2=1;
while(1);
}
74
Wednesday, 30 March 2019
23.6 Conclusion
We generated Clock of 1 kHz frequency using Timer T2 in Clock out mode.
75
Wednesday, 3 April 2019
24.1 Aim
WRITE A PROGRAM TO MEASURE UNKNOWN SIGNAL FREQUENCY USING
TIMER T2 IN CAPTURE MODE.
24.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include<p89v51rd2.h>
unsigned char h1,l1,h2,l2,x=0x00;
unsigned int xdata cnt1,cnt2,r,t_cnt;
float f;
bit flag1=0,flag2=0;
void calculate(unsigned int,unsigned int,unsigned int);
void main(void)
{
EA=1;
ET2=1;
T2MOD=0X00;
T2CON=0x09;
TH2=0x00;
TL2=0x00;
TR2=1;
while(1)
{
if(flag1==1)
{
flag1=0;
h1=RCAP2H;
l1=RCAP2L;
cnt1=(h1<<8)+l1;
}
if(flag2==1)
{
flag2=0;
h2=RCAP2H;
l2=RCAP2L;
cnt2=(h2<<8)+l2;
calculate(r,cnt1,cnt2);
}
}
}
76
Wednesday, 3 April 2019
TF2=0;
r++;
}
else if(EXF2==1)
{
EXF2=0;
if(x==0)
{
flag1=1;
x++;
}
else if (x==1)
{
flag2=1;
TR2=0;
}
}
}
77
Wednesday, 3 April 2019
:10096800E4800B0102040810204080900AEBE47E2A
:10097800019360BCA3FF543F30E509541FFEE49384
:10098800A360010ECF54C025E060A840B8E493A34B
:10099800FAE493A3F8E493A3C8C582C8CAC583CA76
:1009A800F0A3C8C582C8CAC583CADFE9DEE780BE2E
:010AF2000003
:10083E00EF8DF0A4A8F0CF8CF0A428CE8DF0A42ECE
:02084E00FE2288
:100A6400C2D5E830E70FB2D5E4C39BFBE49AFAE4BD
:100A740099F9E498F8EC30E717B2D5120A9A1208FB
:100A84009AE4C39BFBE49AFAE499F9E498F88003A6
:100A940012089A30D50DE4C39FFFE49EFEE49DFD49
:040AA400E49CFC22B0
:0E085000C3E49FFFE49EFEE49DFDE49CFC22B9
:10085E0075F008758200EF2FFFEE33FECD33CDCC51
:10086E0033CCC58233C5829BED9AEC99E5829840D4
:10087E000CF582EE9BFEED9AFDEC99FC0FD5F0D6B1
:10088E00E4CEFBE4CDFAE4CCF9A88222B800C1B9DB
:10089E000059BA002DEC8BF084CFCECDFCE5F0CB19
:1008AE00F97818EF2FFFEE33FEED33FDEC33FCEB52
:1008BE0033FB10D703994004EB99FB0FD8E5E4F90D
:1008CE00FA227818EF2FFFEE33FEED33FDEC33FCFA
:1008DE00C933C910D7059BE99A4007EC9BFCE99AEE
:1008EE00F90FD8E0E4C9FAE4CCFB2275F010EF2F33
:1008FE00FFEE33FEED33FDCC33CCC833C810D70733
:10090E009BEC9AE899400AED9BFDEC9AFCE899F86D
:0E091E000FD5F0DAE4CDFBE4CCFAE4C8F92200
:00000001FF
24.6 Conclusion
We measured the frequency of unknown signal using timer T2 in
capture mode. We captured the two counts for one-time period of the
waveform and calculated the frequency and displayed it on LCD.
78
Wednesday, 10 April 2019
25.1 Aim
Write a program for UART communication.
25.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <reg51.h>
void main ()
{
TMOD=0x20;
SCON=0x50;
TH1=0xfd;
TR1=1;
while(1)
{
SBUF='V';
while(TI==0);
TI=0;
}
}
25.6 Conclusion
We did UART Serial Communication by loading data into SBUF. We used the
baud rate of 9600 Hz and sent the data ‘V’ at this baud rate.
79
Wednesday, 10 April 2019
26.1 Aim
Write a program to generate a PWM of following duty cycle using PCA timer.
When P2.1=1, Generate a PWM of duty cycle of 40 percentage
When P2.1=0, Generate a PWM of duty cycle of 75 percentage
26.2 Code
**********************************************************
* // Institute: SVNIT *
* // File Name: MICRO CONTROLLER AND EMBEDDED SYSTEMS *
* // Author: Jevin, Vatsalya, Hemanth *
* // Date: 14/03/2019 *
* // ADM.No:- U16EE056,59,60 *
**********************************************************
#include <p89v51rd2.h>
sbit SW=P2^1;
unsigned char duty_cnt;
void main()
{
CMOD=0x02;
CCAPM0=0x42;
CH=0;
CL=0;
CR=1;
while(1)
{
if(SW==1)
{
duty_cnt=256*(1-0.4);
CCAP0H=duty_cnt;
}
else if(SW==0)
{
duty_cnt=0xff*(1-0.75);
CCAP0H=duty_cnt;
}
}
}
80
Wednesday, 10 April 2019
26.6 Conclusion
We generated PWM of different duty cycle using PCA timer for different states
of switch. We programmed module 0 of PCA timer in 8 bit PWM mode.
81