Sei sulla pagina 1di 83

EMBEDDED SYSTEMS AND

MICROPROCESSOR

Sardar Vallabhbhai National Institute of

Subject : Embedded Systems LAB Report

DEPARTMENT OF ELECTRICAL ENGINEERING


Sardar Vallabhbhai National Institute of Technology
SURAT-835215, GUJARAT, INDIA
April 2019

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.3 Hex Code ................................................................................................... 10


2.4 Simulated Output ....................................................................................... 10
2.5 Hardware interfaced Output ...................................................................... 10
2.6 Conclusion ................................................................................................. 11
3. LEDs shifting pattern-I ........................................................................................ 11
3.1 Aim ............................................................................................................ 11
3.2 Code ........................................................................................................... 11
3.3 Hex Code ................................................................................................... 12
3.4 Simulated Output ....................................................................................... 12
3.5 Hardware interfaced Output ...................................................................... 13
3.6 Conclusion ................................................................................................. 13
4. LEDs shifting pattern-II ....................................................................................... 14
4.1 Aim ............................................................................................................ 14
4.2 Code ........................................................................................................... 14
4.3 Hex Code ................................................................................................... 15
4.4 Simulated Output ....................................................................................... 15
4.5 Hardware interfaced Output ...................................................................... 16
4.6 Conclusion ................................................................................................. 16
5. LEDs shifting pattern-III...................................................................................... 17
5.1 Aim ............................................................................................................ 17
5.2 Code ........................................................................................................... 17
5.3 Hex Code ................................................................................................... 18
5.4 Simulated Output ....................................................................................... 18
5.5 Hardware interfaced Output ...................................................................... 19
5.6 Conclusion ................................................................................................. 19
6. LEDs shifting pattern-IV ..................................................................................... 20
6.1 Aim ............................................................................................................ 20
6.2 Code ........................................................................................................... 20
6.3 Hex Code ................................................................................................... 21
6.4 Simulated Output ....................................................................................... 21
6.5 Hardware interfaced Output ...................................................................... 22
6.6 Conclusion ................................................................................................. 22
7. Switching Patterns-I ............................................................................................. 23

2
Wednesday, 9 January 2019

7.1 Aim ............................................................................................................ 23


7.2 Code ........................................................................................................... 23
7.3 Hex Code ................................................................................................... 25
7.4 Simulated Output ....................................................................................... 25
7.5 Hardware interfaced Output ...................................................................... 28
7.6 Conclusion ................................................................................................. 29
8. Switching Patterns-II ........................................................................................... 29
8.1 Aim ............................................................................................................ 29
8.2 Code ........................................................................................................... 29
8.3 Hex Code ................................................................................................... 31
8.4 Simulated Output ....................................................................................... 32
8.5 Hardware interfaced Output ...................................................................... 32
8.6 Conclusion ................................................................................................. 33
9. Toggling LED ...................................................................................................... 33
9.1 Aim ............................................................................................................ 34
9.2 Code ........................................................................................................... 34
9.3 Hex Code ................................................................................................... 34
9.4 Simulated Output ....................................................................................... 35
9.5 Hardware interfaced Output ...................................................................... 35
9.6 Conclusion ................................................................................................. 35
10. Switching Patterns-III ....................................................................................... 36
10.1 Aim ........................................................................................................ 36
10.2 Code ....................................................................................................... 36
10.3 Hex Code ............................................................................................... 37
10.4 Simulated Output ................................................................................... 38
10.5 Hardware interfaced Output ................................................................... 38
10.6 Conclusion ............................................................................................. 38
11. PWM Generation .............................................................................................. 39
11.1 Aim ........................................................................................................ 39
11.2 Code ....................................................................................................... 39
11.3 Hex Code ............................................................................................... 40
11.4 Simulated Output ................................................................................... 40
11.5 Hardware interfaced Output ................................................................... 41

3
Wednesday, 9 January 2019

11.6 Conclusion ............................................................................................. 41


12. Delay using Interrupt-I...................................................................................... 42
12.1 Aim ........................................................................................................ 42
12.2 Code ....................................................................................................... 42
12.3 Hex Code ............................................................................................... 42
12.4 Simulated Output ................................................................................... 43
12.5 Hardware interfaced Output ................................................................... 43
12.6 Conclusion ............................................................................................. 43
13. Delay using Interrupt-II .................................................................................... 44
13.1 Aim ........................................................................................................ 44
13.2 Code ....................................................................................................... 44
13.3 Hex Code ............................................................................................... 44
13.4 Simulated Output ................................................................................... 45
13.5 Hardware interfaced Output ................................................................... 45
13.6 Conclusion ............................................................................................. 45
14. Delay using Interrupt-III ................................................................................... 46
14.1 Aim ........................................................................................................ 46
14.2 Code ....................................................................................................... 46
14.3 Hex Code ............................................................................................... 46
14.4 Simulated Output ................................................................................... 47
14.5 Hardware interfaced Output ................................................................... 47
14.6 Conclusion ............................................................................................. 47
15. LCD Interfacing ................................................................................................ 48
15.1 Aim ........................................................................................................ 48
15.2 Code ....................................................................................................... 48
15.3 Hex Code ............................................................................................... 49
15.5 Hardware interfaced Output ................................................................... 50
15.6 Conclusion ............................................................................................. 50
16. Auto Reload Mode- PWM Generation ............................................................. 51
16.1 Aim ........................................................................................................ 51
16.2 Code ....................................................................................................... 51
16.3 Hex Code ............................................................................................... 51
16.4 Simulated Output ................................................................................... 52

4
Wednesday, 9 January 2019

16.5 Hardware interfaced Output ................................................................... 52


16.6 Conclusion ............................................................................................. 52
17. Blinking of LED Using External Interrupt ....................................................... 53
17.1 Aim ........................................................................................................ 53
17.2 Code ....................................................................................................... 53
17.3 Hex Code ............................................................................................... 53
17.4 Simulated Output ................................................................................... 54
17.5 Hardware interfaced Output ................................................................... 54
17.6 Conclusion ............................................................................................. 54
18. ADC Interfacing................................................................................................ 55
18.1 Aim ........................................................................................................ 55
Generate a 8051 code for measuring DC voltage using ADC0808, also display the
measured voltage in LCD. ................................................................................... 55
18.2 Code ....................................................................................................... 55
18.3 Hex Code ............................................................................................... 57
18.5 Hardware interfaced Output ................................................................... 59
18.6 Conclusion ............................................................................................. 59
19. Seven Segment Display .................................................................................... 60
19.1 Aim ........................................................................................................ 60
19.2 Code ....................................................................................................... 60
19.3 Hex Code ............................................................................................... 61
19.5 Hardware interfaced Output ................................................................... 62
19.6 Conclusion ............................................................................................. 62
20. Digital Clock ..................................................................................................... 63
20.1 Aim ........................................................................................................ 63
20.2 Code ....................................................................................................... 63
20.3 Hex Code ............................................................................................... 64
20.5 Hardware interfaced Output ................................................................... 65
20.6 Conclusion ............................................................................................. 66
21. DAC Interfacing................................................................................................ 67
21.1 Aim ........................................................................................................ 67
21.2 Code ....................................................................................................... 67
21.3 Hex Code ............................................................................................... 68
21.4 Simulated Output ................................................................................... 69
5
Wednesday, 9 January 2019

21.5 Hardware interfaced Output ................................................................... 69


21.6 Conclusion ............................................................................................. 70
22. Timer 2 Auto Reload Mode .............................................................................. 71
22.1 Aim ........................................................................................................ 71
22.2 Code ....................................................................................................... 71
22.3 Hex Code ............................................................................................... 71
22.4 Simulated Output ................................................................................... 72
22.5 Hardware interfaced Output ................................................................... 73
22.6 Conclusion ............................................................................................. 73
23. Timer-2 Clock Out Mode.................................................................................. 74
23.1 Aim ........................................................................................................ 74
23.2 Code ....................................................................................................... 74
23.3 Hex Code ............................................................................................... 74
23.4 Simulated Output ................................................................................... 74
23.5 Hardware interfaced Output ................................................................... 75
23.6 Conclusion ............................................................................................. 75
24. Measurement Of Frequency.............................................................................. 76
24.1 Aim ........................................................................................................ 76
24.2 Code ....................................................................................................... 76
24.3 Hex Code ............................................................................................... 77
24.6 Conclusion ............................................................................................. 78
25. Serial Communication ...................................................................................... 79
25.1 Aim ........................................................................................................ 79
25.2 Code ....................................................................................................... 79
25.3 Hex Code ............................................................................................... 79
25.4 Simulated Output ................................................................................... 79
25.6 Conclusion ............................................................................................. 79
26. PCA Timer ........................................................................................................ 80
26.1 Aim ........................................................................................................ 80
26.2 Code ....................................................................................................... 80
26.3 Hex Code ............................................................................................... 80
26.4 Simulated Output ................................................................................... 81
26.5 Hardware interfaced Output ................................................................... 81

6
Wednesday, 9 January 2019

26.6 Conclusion ............................................................................................. 81

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);
}
}

1.3 Hex Code


:10080000E4F508F509C3E5099FE5089E500A0509C6
:09081000E50970F1050880ED22F4
:100819007590FF7F107E27120800E4F590120800FA
:0208290080EE5F
:0300000002082BC8
:0C082B00787FE4F6D8FD758109020819F9
:00000001FF

1.4 Simulated Output

1.5 Hardware interfaced Output

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. Toggling LEDs Alternatively

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);
}
}

2.3 Hex Code


:10080000E4F508F509C3E5099FE5089E500A0509C6
:09081000E50970F1050880ED22F4
:100819007590AA7F107E271208007590551208005E
:0208290080EE5F
:0300000002082BC8
:0C082B00787FE4F6D8FD758109020819F9
:00000001FF

2.4 Simulated Output

2.5 Hardware interfaced Output

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. LEDs shifting pattern-I

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);
}
}
}

3.3 Hex Code


:10082800E4F508F509C3E5099FE5089E500A05099E
:09083800E50970F1050880ED22CC
:100800007590017F107E27120828E59025E0F5906D
:100810007F107E27120828AF90EF648070EC7590EF
:08082000017F1012082880E29C
:03000000020841B2
:0C084100787FE4F6D8FD758109020800FC
:00000001FF

3.4 Simulated Output

12
Wednesday, 9 January 2019

3.5 Hardware interfaced Output

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. LEDs shifting pattern-II

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);
}
}
}

4.3 Hex Code


:10082800E4F508F509C3E5099FE5089E500A05099E
:09083800E50970F1050880ED22CC
:100800007590807F107E27120828E590C313F5901D
:100810007F107E27120828AF90EF640170EC75906E
:08082000807F1012082880E21D
:03000000020841B2
:0C084100787FE4F6D8FD758109020800FC
:00000001FF

4.4 Simulated Output

15
Wednesday, 9 January 2019

4.5 Hardware interfaced Output

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. LEDs shifting pattern-III

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);
}
}
}

5.3 Hex Code


:10082800E4F508F509C3E5099FE5089E500A05099E
:09083800E50970F1050880ED22CC
:100800007590017FE87E03120828E59025E004F545
:10081000907FE87E03120828AF90EFF470EC75909B
:08082000017FE812082880E2C4
:03000000020841B2
:0C084100787FE4F6D8FD758109020800FC
:00000001FF

5.4 Simulated Output

18
Wednesday, 9 January 2019

5.5 Hardware interfaced Output

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. LEDs shifting pattern-IV

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;
}
}
}

6.3 Hex Code


:03000000020853A0
:0C085300787FE4F6D8FD758109020800EA
:10080000759001E4F508F509AE08AF09E4FCFD7B3D
:10081000FF7AFFF9F8D312083D400A0509E509708F
:10082000E7050880E3AF90EFF47004F59080D4E51D
:0D08300090C313F59074802590F59080C65C
:10083D00EB9FF5F0EA9E42F0E99D42F0EC6480C832
:06084D0064809845F022D2
:00000001FF

6.4 Simulated Output

21
Wednesday, 9 January 2019

6.5 Hardware interfaced Output

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;
}
}

7.3 Hex Code


:030000000208C72C
:0C08C700787FE4F6D8FD75810B0208254F
:10082500E4F5A030A0031208D330A1031208DF308D
:10083500A20312086B30A30312088E30A4E5120838
:030845000080E050
:10084800E4F50AF50BAE0AAF0BE4FCFD7BFF7AFF7B
:10085800F9F8D31208B1400A050BE50B70E7050A51
:0308680080E32208
:0C08D3007590A51208487590490208486D
:0C08DF007590AA1208486390FF020848B8
:10086B00759001E4F508F509120848E59025E0F5C7
:10087B00900509E50970020508C39407E508940083
:03088B0040E62222
:10088E00759080E4F508F509120848E590C313F554
:10089E00900509E50970020508C39407E508940060
:0308AE0040E622FF
:10080000759001E4F508F509120848E59025E0F532
:100810009005900509E50970020508C39407E508ED
:05082000940040E422F9
:1008B100EB9FF5F0EA9E42F0E99D42F0EC6480C8BE
:0608C10064809845F0225E
:00000001FF

7.4 Simulated Output

25
Wednesday, 23 January 2019

1)

2)

3)

26
Wednesday, 23 January 2019

4)

5)
27
Wednesday, 23 January 2019

7.5 Hardware interfaced Output

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;
}
}

8.3 Hex Code


:030000000208C72C
:0C08C700787FE4F6D8FD75810B0208254F
:10082500E4F5A030A0031208D330A1031208DF308D
:10083500A20312086B30A30312088E30A4E5120838
:030845000080E050
:10084800E4F50AF50BAE0AAF0BE4FCFD7BFF7AFF7B
:10085800F9F8D31208B1400A050BE50B70E7050A51
:0308680080E32208
:0C08D3007590A51208487590490208486D
:0C08DF007590AA1208486390FF020848B8
:10086B00759001E4F508F509120848E59025E0F5C7
:10087B00900509E50970020508C39407E508940083
:03088B0040E62222
:10088E00759080E4F508F509120848E590C313F554
:10089E00900509E50970020508C39407E508940060
:0308AE0040E622FF
:10080000759001E4F508F509120848E59025E0F532
:100810009005900509E50970020508C39407E508ED
:05082000940040E422F9

31
Wednesday, 23 January 2019

:1008B100EB9FF5F0EA9E42F0E99D42F0EC6480C8BE
:0608C10064809845F0225E
:00000001FF

8.4 Simulated Output

1)

8.5 Hardware interfaced Output

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.

(Xtal=18.432 MHz , 6 clock mode)

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();
}
}

9.3 Hex Code


:10080000E4F508F509758C87758ACED28C308DFD9C
:10081000C28DC28C0509E5097002050864644508AB
:0308200070E32260
:0B082F007589016390FF12080080F83B
:03000000020823D0
:0C082300787FE4F6D8FD75810902082FEB
:00000001FF

34
Wednesday, 30 January 2019

9.4 Simulated Output

9.5 Hardware interfaced Output

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. Switching Patterns-III

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

10.4 Simulated Output

2)

10.5 Hardware interfaced Output

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. PWM Generation

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;
}
}
}

11.3 Hex Code


:1008AB00758DFE758BCDD28E308FFDC28FC28E2291
:1008000075891075A00EAFA0EF24FC603F24FC603A
:100810005F240670F1E4F508F5091208AB0509E557
:100820000970020508C39408E508940040EC639041
:10083000FFE4F508F5091208AB0509E509700205A2
:1008400008C39402E508940040EC801F1208AB63D3
:1008500090FFE4F508F5091208AB0509E5097002F7
:100860000508C39404E508940040EC6390FF80966B
:10087000E4F508F5091208AB0509E5097002050859
:10088000C39408E508940040EC6390FFE4F508F594
:10089000091208AB0509E50970020508C3940CE5C7
:0B08A00008940040EC6390FF02080683
:030000000208BB38
:0C08BB00787FE4F6D8FD75810902080082
:00000001FF

11.4 Simulated Output

40
Wednesday, 6 February 2019

11.5 Hardware interfaced Output

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. Delay using Interrupt-I

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);
}

12.3 Hex Code


:03000B0002081CCC
:0A081C006390FF758CF4758A0032BA
:1008000075890175A882758CF4E4F58AD28C80FE16
:03000000020810E3
:0C081000787FE4F6D8FD7581090208002D
:00000001FF

42
Wednesday, 6 February 2019

12.4 Simulated Output

12.5 Hardware interfaced Output

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. Delay using Interrupt-II

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;
}

13.3 Hex Code


:0408BE00020800002C
:10088C0075891075A888758D87758BCED28EE50904
:0F089C006464450870F86390FFF508F50980EF74
:03001B000208AB2D
:1008AB00C0E00509E50970020508758D87758BCECB
:0308BB00D0E03258
:03000000020800F3
:0C080000787FE4F6D8FD758109020847F6
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008BEE47E86

44
Wednesday, 6 February 2019

:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3

13.4 Simulated Output

13.5 Hardware interfaced Output

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.Delay using Interrupt-III

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;
}

14.3 Hex Code


:0408C1000208000029
:10088C0075890175A882758C87758ACED28CE5091D
:10089C00B42CFBE508B401F66390FFE4F508F50908
:0208AC0080ECDE
:03000B000208AE3A
:1008AE00C0E00509E50970020508758C87758ACECA
:0308BE00D0E03255
:03000000020800F3
:0C080000787FE4F6D8FD758109020847F6
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC

46
Wednesday, 6 February 2019

:10083C00E4800B01020408102040809008C1E47E83
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378

14.4 Simulated Output

14.5 Hardware interfaced Output

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. LCD Interfacing

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++);
}
}

15.3 Hex Code


:0F09C90048454D414E544855313645453036303E
:1008F60078087C007D007BFF7A0979C97E007F0736
:100906001208D0780F7C007D007BFF7A0979D07EB3
:10091600007F081208D01209AD7F801209E4E4F5C1
:1009260017F51874082518F8E6FF1209EE7FF47E0D
:100936000112098D7F061209E40518E518700205F3
:1009460017C39407E517940040D97FC01209E4E461
:10095600F517F518C3E5189408E517940050B77411
:100966000F2518F8E6FF1209EE7FF47E0112098DB5
:0F0976007F061209E40518E51870D9051780D51A
:0A09E4008F80C2A7120985C2A52268
:0A09EE008F80D2A7120985C2A5224E
:1009AD007F381209E41209897F0F1209E4120989AF
:0C09BD007F011209E47F0A7E0002098D10
:08098500C2A6D2A57F0A7E0084
:10098D00E4FDFCC3ED9FEC9E5015E4FBFA0BBB00A0
:0F099D00010AEB64644A70F50DBD00010C80E4A3
:0109AC002228
:030000000209D81A
:0C09D800787FE4F6D8FD7581180208F65F
:10080000E709F608DFFA8046E709F208DFFA803EDA
:1008100088828C83E709F0A3DFFA8032E309F608C7
:10082000DFFA8078E309F208DFFA807088828C832F
:10083000E309F0A3DFFA806489828A83E0A3F608E3
:10084000DFFA805889828A83E0A3F208DFFA804CBD
:1008500080D280FA80C680D4806980F28033801094
:1008600080A680EA809A80A880DA80E280CA8033FD

49
Wednesday, 13 February 2019

:1008700089828A83ECFAE493A3C8C582C8CCC58375
:10088000CCF0A3C8C582C8CCC583CCDFE9DEE78045
:100890000D89828A83E493A3F608DFF9ECFAA9F0C4
:1008A000EDFB2289828A83ECFAE0A3C8C582C8CC1A
:1008B000C583CCF0A3C8C582C8CCC583CCDFEADE33
:1008C000E880DB89828A83E493A3F208DFF980CC95
:1008D00088F0EF60010E4E60C388F0ED2402B4048E
:1008E0000050B9F582EB2402B4040050AF23234535
:0608F00082239008507302
:00000001FF

15.5 Hardware interfaced Output

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.Auto Reload Mode- PWM Generation

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;
}
}
}

void timer0_isr() interrupt 1


{
i++;
}

16.3 Hex Code


:0308AE000108003E
:10088C0075890275A882758CE1D28CAF087E00EF59
:10089C0064467002C291EF64644E70EFD291F50819
:0208AC0080E9E1
:03000B000208B236
:0308B20005083204
:03000000020800F3
:0C080000787FE4F6D8FD758108020847F7
Wednesday, 13 March 2019

:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008AEE47E96
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108B1000046
:00000001FF

16.4 Simulated Output

16.5 Hardware interfaced Output

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. Blinking of LED Using External Interrupt

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;
}
}
}

void ext_isr (void) interrupt 0


{
extflag=1;
}

17.3 Hex Code


:03000000020800F3
:0C080000787FE4F6D8FD758120020847DF
:02089E00C10097
:0F088C00D2AFD2A8D2883000FDC200B29480F75C
:0300030002089B55
:03089B00D2003256
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B010204081020408090089EE47EA6
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378

53
Wednesday, 13 March 2019

:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108A0000057
:00000001FF

17.4 Simulated Output

17.5 Hardware interfaced Output

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. ADC Interfacing

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 calculate(unsigned char u)


{
h=2500/255;
b=u*h;
v[0]=b/1000+0x30;
d=b%1000;
v[2]=d/100+0x30;
f=d%100;
v[3]=f/10+0x30;
e=f%10;
v[4]=e+0x30;
disp_lcd();
}

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);
}
}
}

void delay(unsigned int t)

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);
}

void lcd_cmd(unsigned char command)


{
display_port=command;
RS=0;
RW=0;
EN=1;
delay(1);
EN=0;
}

void lcd_data(unsigned char display_data)


{
display_port=display_data;
RS=1;
RW=0;
EN=1;
delay(1);
EN=0;
}

18.3 Hex Code


:070AB200564F4C544147452B
:0B0A9300120A75120A75120A1380F88F
:100A75007590FFC2B1C2B4C2B3D2B27F017E00028B
:020A85000A6500
:100A1300C2B5C2B6C2B7D2B1D2B4120A61C2B1C2B0
:100A2300B420B2FDD2B3120A61859008120A61C2E2
:060A3300B3AF080209BB8D
:1009BB00750F09EF850FF0A4F509FB7A007C037D19
:1009CB00E8FF7E001208F6EF2430F5117C037DE87A
:1009DB00AF037E001208F68D0BE50B75F0648424D3
:1009EB0030F513E50B75F0648485F00DE50D75F0AE
:1009FB000A842430F514E50D75F00A8485F00CE5B6
:080A0B000C2430F51502094B23
:10094B0078167C007D007BFF7A0A79B27E007F07E8
:10095B001208D07F80120A9EE4F510C3E5109407AD
:10096B0074809480501574162510F8E6FF120AA8AF
:10097B007FF47E01120A65051080E07FC0120A9E8B
:10098B00E4F510AF107E00C3EF9405748094805093

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.5 Hardware interfaced Output

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. Seven Segment Display

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;
}

19.3 Hex Code


:0308AE000108003E
:10088C0075890275A882758CE1D28CAF087E00EF59
:10089C0064467002C291EF64644E70EFD291F50819
:0208AC0080E9E1
:03000B000208B236
:0308B20005083204
:03000000020800F3
:0C080000787FE4F6D8FD758108020847F7
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008AEE47E96
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108B1000046
:00000001FF

61
Wednesday, 20 March 2019

19.5 Hardware interfaced Output

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. Digital Clock

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()
{

// Hex values corresponding to digits 0 to 9


//int c;

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;
}
}

20.3 Hex Code


:0300000002088E65
:0C088E00787FE4F6D8FD7581240208D5BF
:10097C00010A00020800000A0B3F065B4F666D7D02
:03098C00077F6F73

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

20.5 Hardware interfaced Output

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. DAC Interfacing

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;
}
}
}

21.3 Hex Code


:0F094A000D0880C0DAFFFEC08040110011408010
:06092B00D2B07F0A7E003D
:10093100E4F517F518C3E5189FE5179E500A051849
:09094100E51870F1051780ED22A4
:1008000075A00EAFA0EF24FC602A24FC60672406CC
:1008100070F1E4F515F516D3E51694FFE51594008F
:1008200050E112092B851690C2B00516E51670E747
:10083000051580E3E4F515F51612092B851690C20F
:10084000B00516E51670020515D394FFE515940062
:1008500040E77515007516FFD3E5169400E515946D
:100860000040A012092B851690C2B0E5161516702F
:10087000E7151580E3E4F515F516C3E516940DE5C7
:10088000159400400302080312092B74082516F87A
:0F089000E6F590C2B00516E51670DF051580DBA2
:0300000002089F54
:0C089F00787FE4F6D8FD7581180208E6A9
:1008AB00020800E493A3F8E493A34003F68001F25B
:1008BB0008DFF48029E493A3F85407240CC8C3334E
:1008CB00C4540F4420C8834004F456800146F6DF1D
:1008DB00E4800B010204081020408090094AE47E5A
:1008EB00019360BCA3FF543F30E509541FFEE49312
:1008FB00A360010ECF54C025E060A840B8E493A3D9
:10090B00FAE493A3F8E493A3C8C582C8CAC583CA03
:10091B00F0A3C8C582C8CAC583CADFE9DEE780BEBB
:01095900009D
:00000001FF

68
Wednesday, 27 March 2019

21.4 Simulated Output

21.5 Hardware interfaced Output

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. Timer 2 Auto Reload Mode

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);
}

void timer2_ISR() interrupt 5


{
TF2=0;
i++;
if(i==2)
{
LED=0;
}
if(i==10)
{
i=0;
LED=1;
}
}

22.3 Hex Code


:0308D40001080018
:1008B900D2AFD2ADE4F5C9F5C875CDFE75CCCD750D
:0B08C900CBFE75CACDD2CAD29280FED1
:03002B0002088C3C

71
Wednesday, 30 March 2019

:10088C00C0E0C0D075D000C006C007C2CF0508AF0D
:10089C00087E00EF64027002C292EF640A4E70048C
:0D08AC00F508D292D007D006D0D0D0E032AF
:03000000020800F3
:0C080000787FE4F6D8FD758108020847F7
:10080C000208B9E493A3F8E493A34003F68001F241
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008D4E47E70
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108D7000020
:00000001FF

22.4 Simulated Output

72
Wednesday, 30 March 2019

22.5 Hardware interfaced Output

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. Timer-2 Clock Out Mode

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);
}

23.3 Hex Code


:10080000E4F5C875C90275CDDCF5CC75CBDCF5CA4D
:04081000D2CA80FECA
:03000000020814DF
:0C081400787FE4F6D8FD7581070208002B
:00000001FF

23.4 Simulated Output

74
Wednesday, 30 March 2019

23.5 Hardware interfaced Output

23.6 Conclusion
We generated Clock of 1 kHz frequency using Timer T2 in Clock out mode.

75
Wednesday, 3 April 2019

24. Measurement Of Frequency

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);
}
}
}

void t2_isr() interrupt 5


{
if (TF2==1)
{

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;
}
}
}

void calculate (unsigned int rc,unsigned int cnt1c,unsigned int cnt2c)


{
t_cnt=rc*(0xffff)+cnt2c-cnt1c;
f=(float)(18432000/(6*t_cnt));
}

24.3 Hex Code


:0300000002092CC6
:0C092C00787FE4F6D8FD75812002097385
:070AEB00011000C100C10170
:1009B800D2AFD2ADE4F5C975C809F5CDF5CCD2CA28
:1009C80030001AC20085CB0885CA0AE508FE7C00FB
:1009D800E4250AFFEC3E900004F0A3EFF03001E0BC
:1009E800C20185CB0985CA0BE509FE7C00E4250B0D
:1009F800FFEC3E900006F0FAA3EFF0FB900002E057
:0F0A0800FEA3E0FFA3E0FCA3E0FD120AA880B16B
:03002B00020A17AF
:100A1700C0E0C083C082C0D075D000C006C0073018
:100A2700CF12C2CF900003E004F07024900002E0E0
:100A370004F0801C30CE19C2CEAF107E00EF7006D6
:100A4700D2000510800AEF64014E7004D201C2CAB9
:0D0A5700D007D006D0D0D082D083D0E032BE
:100AA8008D828C837CFF7DFF12083EEF2BFFEE3A90
:100AB800CFC39582CF9583FE900000F0A3EFF07C22
:100AC800007D0612083EAB07AA06E4F9F8FF7E404F
:100AD8007D190C120A64EC1208008F0F8E0E8D0D12
:030AE8008C0C2251
:1008000075F020800E75F010800575F0087D007E73
:10081000007F003392D530D503120850EC334010DE
:10082000EF33FFEE33FEED33FDEC33FCD5F0ED227C
:0E083000E5F0247EA2D513CC92E7CDCEFF22B8
:100938000209B8E493A3F8E493A34003F68001F214
:1009480008DFF48029E493A3F85407240CC8C333C0
:10095800C4540F4420C8834004F456800146F6DF8F

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. Serial Communication

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.3 Hex Code


:03000000020815DE
:0C081500787FE4F6D8FD7581070208002A
:10080000758920759850758DFDD28E7599563099E1
:05081000FDC29980F615
:00000001FF

25.4 Simulated Output

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. PCA Timer

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;
}
}
}

26.3 Hex Code


:1008000075D90275DA42E4F5F9F5E9D2DE30A108CE
:100810007508998508FA80F520A1F275083F8508CA
:03082000FA80EA71
:03000000020823D0
:0C082300787FE4F6D8FD7581080208001B
:00000001FF

80
Wednesday, 10 April 2019

26.4 Simulated Output

26.5 Hardware interfaced Output

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

Potrebbero piacerti anche