Professional Documents
Culture Documents
Bhagalpur - 813210
Submitted by:
Yachit Saksham
(170102055)
Class: B.Tech. – III
Semester: V
CERTIFICATE
Date: 22/09/2019
Place: IIIT Bhagalpur
Dr. Suraj
(Assistant Professor, ECE, IIIT Bhagalpur)
Monday, 19 August 2019
Contents
1. Shifting bits from right to left keeping previous LEDs off .......... 1
1.1 Aim: -..................................................................................................................................... 1
1.2 Source Code: - ................................................................................................................. 1
1.3 Hex Code: -......................................................................................................................... 1
1.4 Simulated Output: - ..................................................................................................... 2
1.5 Conclusion: - .................................................................................................................... 2
2. Shifting bits from left to right keeping previous LEDs on ............ 2
2.1 Aim: -..................................................................................................................................... 2
2.2 Source Code: - ................................................................................................................. 2
2.3 Hex Code: -......................................................................................................................... 2
2.4 Simulated Output: - ..................................................................................................... 3
2.5 Conclusion: - .................................................................................................................... 3
3. Blinking of LEDs using keys .................................................................................... 3
3.1 Aim: -..................................................................................................................................... 4
3.2 Source Code: - ................................................................................................................. 4
3.3 Hex Code: -......................................................................................................................... 5
3.4 Simulated Output: - ..................................................................................................... 6
3.5 Conclusion: - .................................................................................................................... 7
4. Software delay using an external function .................................................. 8
4.1 Aim: -..................................................................................................................................... 8
4.2 Source Code: - ................................................................................................................. 8
4.3 Hex Code: -......................................................................................................................... 9
4.4 Simulated Output: - ..................................................................................................... 9
4.5 Conclusion: - .................................................................................................................... 9
5. Hardware delay of 1 sec ........................................................................................... 10
5.1 Aim: -................................................................................................................................... 10
5.2 Source Code: - ............................................................................................................... 10
5.3 Hex Code: -....................................................................................................................... 10
5.4 Simulated Output: - ................................................................................................... 11
5.5 Conclusion: - .................................................................................................................. 11
6. Hardware delay using LEDs blinking in a single bit of any port
12
i|Page
6.1 Aim: -................................................................................................................................... 12
6.2 Source Code: - ............................................................................................................... 12
6.3 Hex Code: -....................................................................................................................... 12
6.4 Simulated Output: - ................................................................................................... 13
6.5 Conclusion: - .................................................................................................................. 13
7. Hardware delay using interrupt ........................................................................... 14
7.1 Aim: -................................................................................................................................... 14
7.2 Source Code: - ............................................................................................................... 14
7.3 Hex Code: -....................................................................................................................... 15
7.4 Simulated Output: - ................................................................................................... 15
7.5 Hardware Output: - ...................................................................................................... 16
7.6 Conclusion: - .................................................................................................................. 16
8. Display 0 to 9 using 7 segment display ............................................................ 17
8.1 Aim: -................................................................................................................................... 17
8.2 Source Code: - ............................................................................................................... 17
8.3 Hex Code: -....................................................................................................................... 18
8.4 Conclusion: - .................................................................................................................. 19
9. LCD Interfacing ................................................................................................................... 20
9.1 Aim: -................................................................................................................................... 20
9.2 Source Code: - ............................................................................................................... 20
9.3 Hex Code: -....................................................................................................................... 21
9.4 Hardware Interfaced Output: -............................................................................ 23
9.5 Conclusion: - .................................................................................................................. 23
10. UART communication .......................................................................................................... 24
10.1 Aim: - ................................................................................................................................ 24
10.2 Source Code: - ............................................................................................................. 24
10.3 Hex Code: - .................................................................................................................... 24
10.4 Simulated Output: - ................................................................................................. 25
10.5 Conclusion: - ............................................................................................................... 25
11.Generation of PWM signals ........................................................................................... 26
11.1 Aim: - ............................................................................................................................ 26
11.2 Source Code: - ......................................................................................................... 26
11.3 Hex Code: - ................................................................................................................ 27
11.4 Simulated Output: - ............................................................................................. 27
11.5 Conclusion................................................................................................................... 29
ii | P a g e
12. Serial Communication using interrupt ............................................................... 30
12.1 Aim: - ................................................................................................................................ 30
12.2 Source Code: - ............................................................................................................. 30
12.3 Hex Code: - .................................................................................................................... 30
12.4 Simulation Output: - ............................................................................................... 31
12.5 Conclusion: - ............................................................................................................... 31
13. Generate a PWM of following duty cycle suing PCA timer .................... 32
13.1 Aim: - ................................................................................................................................ 32
13.2 Source Code: - ............................................................................................................. 32
13.3 Hex Code: - .................................................................................................................... 32
13.4 Simulated Output: - ................................................................................................. 32
13.5 Conclusion: - ............................................................................................................... 33
14. Basics of Python(loops) .............................................................................................. 34
14.1 Use of while loop ...................................................................................................... 34
14.2 Use of for loop........................................................................................................... 34
15. Basics of Python (Pandas library) ...................................................................... 37
15.1 Program: 01 .................................................................................................................... 37
15.2 Program: 02 .................................................................................................................... 37
15.3 Program: 03 .................................................................................................................... 37
16. Basics of Python (Numpy library) ........................................................................ 39
16.1 Program: 01 .................................................................................................................... 39
16.2 Program: 02 .................................................................................................................... 39
17. Basics of Python (Image Processing) ................................................................. 40
17.1 Program: 01 .................................................................................................................... 40
17.2 Program: 02 .................................................................................................................... 40
15.3 Program: 03 .................................................................................................................... 42
iii | P a g e
Figure 1 :Shifting of bits from right to left .............................................................................................. 2
Figure 2 : shifting of LED from left to right keeping previous LED on ..................................................... 3
Figure 3 : Shifting of LED from right to left and left to right respectively............................................... 6
Figure 4 : Shifting of LED from right to left and left to right respectively keeping previous LED on ...... 6
Figure 5 : Software delay of 1ms ............................................................................................................ 9
Figure 6 : Hardware delay of 1sec......................................................................................................... 11
Figure 7 : Wave showing LED blinking with hardware delay of 0.5 sec ................................................ 13
Figure 8 : Wave showing interrupt signal ............................................................................................. 15
Figure 9 : Interrupt signal in DSO .......................................................................................................... 16
Figure 10 : Hardware showing name and roll no of student ................................................................ 23
Figure 11 : Printing IIIT BHAGALPUR in UART #1 .................................................................................. 25
Figure 12 : Wave showing 80%,20% and 40% duty cycle respectively ................................................. 29
Figure 13 : Serial communication using interrupt ................................................................................ 31
Figure 14 : Wave showing 40% and 80% duty cycle using PCA timer................................................... 33
iv | P a g e
Monday, 19 August 2019
1.1 Aim: -
Write an 8051 program to toggle LEDs connected to the
port P1 from right to left, turning off the previous
LEDs.
1.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 19 August 2019 *
* *
********************************************************************
*/
#include <reg51.h>
int i,j;
void main()
{
P1=0x01; // initial state
while(1)
{
for(i=0;i<8;i++)
{
P1=P1<<1; // Shift Left
if(P1==0x80) // Reset to initial state
P1=0x01;
}
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to shift blinking of LED connected to port 1. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
1|Page
Monday, 19 August 2019
:0E08BC0040DCAF90EF648070CA75900180C57B
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008CAE47E7A
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108CE000029
:00000001FF
1.5 Conclusion: -
We Successfully got blinking LED from right to left,
turning off the previous LEDs.
2|Page
Monday, 19 August 2019
2.1 Aim: -
Write an 8051 C program to toggle LEDs connected to the
port P1, from left to right, keeping previous LEDs on.
2.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 19 August 2019 *
* *
********************************************************************
*/
#include <reg51.h>
unsigned int i;
unsigned int j;
void main()
{
while(1)
{
P1=0x80; // initial state
for(j=0;j<8;j++)
{
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to shift blinking of LED connected to port 1. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
2|Page
Monday, 19 August 2019
:1008CC0009C3E5099464E508940050B7E4F508F50C
:1008DC00090509E509700205086464450870F2050C
:0908EC0009E50970DC050880D85B
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008F5E47E4F
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108F90000FE
:00000001FF
2.5 Conclusion: -
We Successfully got blinking LED from left to right,
keeping the previous LEDs On.
3|Page
Monday, 26 August 2019
3.1 Aim: -
Write an 8051 C program to perform blinking of LEDs using
keys.
3.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 26 August 2019 *
* *
********************************************************************
*/
#include <reg51.h>
unsigned int i=0;
void delaying() // delay function
{
for(i=0;i<100;i++)
{for(i=0;i<100;i++);}
}
// specifing switches
int main()
{
P1=0x00; // initial state
P2=0X00; // initial state
while(1)
{
4|Page
Monday, 26 August 2019
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to perform user-based operations at LED %
% connected to port 1. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
5|Page
Monday, 26 August 2019
Figure 3 : Shifting of LED from right to left and left to right respectively
Figure 4 : Shifting of LED from right to left and left to right respectively keeping previous LED on
6|Page
Monday, 26 August 2019
3.5 Conclusion: -
We have successfully performed the blinking of LEDs
using keys .
7|Page
Monday, 2 September 2019
4.1 Aim: -
Write an 8051 program to perform software delay using an
external function.
4.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 2 September 2019 *
* *
********************************************************************
*/
#include <reg51.h>
void wait(int);
void main()
{
P1=0x01; // initial state
while(1)
{
P1=0x00; // all off
wait(10);
P1=0xFF; // all on
wait(10);
}
}
int i,j;
8|Page
Monday, 2 September 2019
4.5 Conclusion: -
We have successfully performed Software Delay using
external function and we got delay of 1ms.
9|Page
Monday, 2 September 2019
5.1 Aim: -
Write an 8051 program to perform hardware delay of 1 sec.
5.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 2 September 2019 *
* *
********************************************************************
*/
#include <reg51.h>
void delay();
int i;
int main()
{
while(1)
{
P1=~P1; // complement the port bits
for(i=0;i<100;i++)
{
delay(); // loop for 100times
} // produces 1 s delay
}
}
void delay()
{
TMOD=0X01; // mode 0
TH0=0xDB;
TL0=0xFF;
TR0=1; // timer start
while(TF0==0); // wait till flag is set to 1
TF0=0; // reset flag value
TR0=0; // stop timer
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to perform a hardware delay of 1 sec using an %
% external function. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
10 | P a g e
Monday, 2 September 2019
:0808BA0002080001020A00001F
:10088C006390FFE4F50AF50B1208AA050BE50B7053
:0E089C0002050AC39490E50A940140EC80E244
:1008AA00758CDCE4F58AD28C308DFDC28DC28C2227
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008BAE47E8A
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108C2000035
:00000001FF
5.5 Conclusion: -
We Successfully performed Hardware Delay using LEDs
blinking and we got delay of 1s.
11 | P a g e
Monday, 9 September 2019
6.1 Aim: -
Write an 8051 program to perform hardware delay using
LEDs blinking in a single bit of any port.
6.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 9 September 2019 *
* *
********************************************************************
*/
#include<reg51.h>
TMOD0=0x01; // timer mode 0
unsigned int i=0;
void delay();
sbit x=P1^0;
void main()
{
P1=0x00; // initial state
x=0xFF; // pin 0 of port P1 is set to 1
while(1)
{
}
}
void delay()
{
TH0=0x78;
TL0=0x01;
TR0=1; // timer start
while(TF0==0); // wait till flag is 1
TF0=0; // reset flag
TR0=0; // stop timer
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to perform a hardware delay using LED blinking %
% in a single bit of any port. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
12 | P a g e
Monday, 9 September 2019
:0C080000787FE4F6D8FD75810B020847F4
:0808BE0002080001020A00001B
:10088C00E4F590D290B290E4F50AF50B1208AE059F
:10089C000BE50B7002050AC39490E50A940140EC39
:0208AC0080E3E7
:1008AE00758C78758A01D28C308DFDC28DC28C22EA
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008BEE47E86
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108C6000031
:00000001FF
Figure 7 : Wave showing LED blinking with hardware delay of 0.5 sec
6.5 Conclusion: -
We Successfully performed Hardware Delay using using LEDs
blinking and we got delay of 1.5s.
13 | P a g e
Monday, 16 September 2019
7.1 Aim: -
Write an 8051 program to perform hardware delay using
interrupt.
x=1; i=0;
while(1)
{
if(i==8)
x=~x; // blink
if(i==10) {
x=~x; // blink
i=0;
}
}
}
void func() interrupt 1 // interrupt function
{
i++;
TH0=0xF4;
TL0=0x00;
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to perform a hardware delay using interrupt. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
14 | P a g e
Monday, 16 September 2019
15 | P a g e
Monday, 16 September 2019
7.6 Conclusion: -
We have successfully implemented Hardware Delay of 1s as
specified in mode 1 using Timer T1 interrupt.
16 | P a g e
Monday, 21 October 2019
8.1 Aim: -
Write an 8051 program to display 0 to 9 using 7 segment
display. control lines are p2.7, p2.6, p2.5. Display is
connected to p0.
17 | P a g e
Monday, 21 October 2019
}
}
void main()
{
int i;
P0=0x00;
P2=0x00;
seg=0;
while(1)
{
findseg(); // call findseg function
for(i=0;i<10;i++)
{
P0=disp[i];
delay();
}
seg++;
if(seg==4) seg=0;
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to display 0 to 9 using 7 segment LED display. %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
18 | P a g e
Monday, 21 October 2019
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0109270000CF
:00000001FF
8.4 Conclusion: -
We used four 7 segment LED display to continuously
display series of numbers from 0 to 9. We kept shifting
this series from first segment to last segment
19 | P a g e
Monday, 4 November 2019
9. LCD Interfacing
9.1 Aim: -
Interface the LCD with 8051 micro controller and display
Name and Roll number in first and second line
respectively.
9.2 Source Code: -
/*
********************************************************************
* Author: Yachit Saksham *
* Roll No.: 170102055 *
* Institute: IIIT BHAGALPUR *
* Department: ECE *
* Date: 4 November 2019 *
* *
********************************************************************
*/
#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;
// switches
sbit RS=P2^7;
sbit RW=P2^6;
sbit EN=P2^5;
void delay(unsigned int t)
{
for(i=0;i<t;i++)
{
TMOD=0X01; // timer mode 0
TH0=0XF4;
TL0=0X00;
TR0=1; // timer start
while(TF0==0); // loop till flag is set to 1
TF0=0; // reset flag
TR0=0; // stop timer
}
}
void lcd_init() // initial the LCD
{
lcd_cmd(0x38); // turn on LCD
delay(10);
lcd_cmd(0x0F); // clear display
delay(10);
lcd_cmd(0x01); // cursor glow
delay(10);
}
void lcd_cmd(char command)
{
P0=command; // input command
RS=0; // register select
RW=0; // register read/write
EN=1; // enable set
20 | P a g e
Monday, 4 November 2019
delay(10);
EN=0; // enable reset
}
void lcd_data(char disp_data)
{
P0=disp_data; // output data
RS=1;
RW=0;
EN=1;
delay(10);
EN=0;
}
void main()
{
// string to output
char name[8]= {'V','A','T','S','A','L','Y','A'};
char roll[8]= {'U','1','6','E','E','0','5','9'};
int i;
char command;
while(1)
{
lcd_init(); // initialize the LCD
lcd_cmd(0x80); // select 1st line
for(i=0;i<9;i++)
{
command=name[i]; // read 1st string
lcd_data(command); // display input string
}
lcd_cmd(0xc0); // selct 2nd line
for(i=0;i<9;i++)
{
command=roll[i]; // read 2nd string
lcd_data(command); // display input sting
}
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to display name and roll number in first and %
% second line respectively. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
21 | P a g e
Monday, 4 November 2019
:0609A5002DF8E6F518FF35
:0A09AB008F80D2A7120956C2A522C0
:1008F60078087C007D007BFF7A0979B57E007F0849
:100906001208D078107C007D007BFF7A0979BD7EC5
:10091600007F081208D01209897F801209D1E4FDF0
:10092600FC74081209A50DBD00010CED64064C709F
:10093600F07FC01209D1E4FCFDC3ED9409EC64809C
:10094600948050D274101209A50DBD00010C80E9E7
:10080000E709F608DFFA8046E709F208DFFA803EDA
:1008100088828C83E709F0A3DFFA8032E309F608C7
:10082000DFFA8078E309F208DFFA807088828C832F
:10083000E309F0A3DFFA806489828A83E0A3F608E3
:10084000DFFA805889828A83E0A3F208DFFA804CBD
:1008500080D280FA80C680D4806980F28033801094
:1008600080A680EA809A80A880DA80E280CA8033FD
:1008700089828A83ECFAE493A3C8C582C8CCC58375
:10088000CCF0A3C8C582C8CCC583CCDFE9DEE78045
:100890000D89828A83E493A3F608DFF9ECFAA9F0C4
:1008A000EDFB2289828A83ECFAE0A3C8C582C8CC1A
:1008B000C583CCF0A3C8C582C8CCC583CCDFEADE33
:1008C000E880DB89828A83E493A3F208DFF980CC95
:1008D00088F0EF60010E4E60C388F0ED2402B4048E
:1008E0000050B9F582EB2402B4040050AF23234535
:0608F00082239008507302
:00000001FF
22 | P a g e
Monday, 4 November 2019
9.5 Conclusion: -
In this experiment we have learnt how to interface an LCD
using 8051 micro controller. We use lcd_init function to
initialize LCD, lcd_cmd function to pass a command to
LCD, lcd_data function to send data to be displayed to
LCD. RS, RW & EN are control signals of LCD.
23 | P a g e
Monday, 11 November 2019
10.1 Aim: -
Write a program for UART communication.
void main()
{
TMOD=0X20; // timer mode 2
TH1=0XFD;
TCON=0X50; // start timer
TR1=1; // timer start
while(1)
{
for (i=0; i<15; i++)
{
SBUF=A[i]; // serial buffer reads string bit
while(TI==0); // loop till interrupt flag is set to 1
TI=0; // reset flag
}
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to set a UART serial communication by loading %
% data into SBUF. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
24 | P a g e
Monday, 11 November 2019
:0D08AC001870020517640F451770E580DE17
:10080C0002088CE493A3F8E493A34003F68001F26E
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008B9E47E8B
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108CA00002D
:00000001FF
10.5 Conclusion: -
We did UART Serial Communication by loading data into SBUF. We
used the baud rate of 9600 Hz and sent the data “IIIT
BHAGALPUR” at this baud rate.
25 | P a g e
Monday, 11 November 2019
26 | P a g e
Monday, 11 November 2019
}
if(c==1) // 3rd PWM
{
delay(12);
PIN3=1; // off for 6/10 halves
delay(8);
PIN3=0; // on for 4/10 halves
}
}
}
void delay(int r)
{
while(r!=0)
{TH1=0xDC;
TL1=0x03;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
r--;
}
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function file is created to generate PWM waves. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
27 | P a g e
Monday, 11 November 2019
28 | P a g e
Monday, 11 November 2019
11.5 Conclusion
Hence, we have generated PWM signal of different duty cycle on
port 1 based on switching condition of port 2 bits, results
have been shown in above figures for different case.
29 | P a g e
Monday, 18 November 2019
12.1 Aim: -
Write a program for Serial Communication using interrupt.
30 | P a g e
Monday, 18 November 2019
:0C080000787FE4F6D8FD758111020847EE
:0A08C900080853414E544F534800F5
:1008B80075892075985075A898758DFAD28ED29939
:0108C800220D
:0300230002088C44
:10088C00C0E0C0D075D000C00075100075110074A8
:10089C00082511F8E6F5993099FDC2990511E51175
:0C08AC00700205106409451070E580DD45
:10080C000208B8E493A3F8E493A34003F68001F242
:10081C0008DFF48029E493A3F85407240CC8C333ED
:10082C00C4540F4420C8834004F456800146F6DFBC
:10083C00E4800B01020408102040809008C9E47E7B
:10084C00019360BCA3FF543F30E509541FFEE493B1
:10085C00A360010ECF54C025E060A840B8E493A378
:10086C00FAE493A3F8E493A3C8C582C8CAC583CAA3
:10087C00F0A3C8C582C8CAC583CADFE9DEE780BE5B
:0108D3000024
:00000001FF
12.5 Conclusion: -
We did UART Serial Communication using interrupt by
loading data into SBUF. We used the baud rate of 9600 Hz
and sent the data “SANTOSH” at this baud rate.
31 | P a g e
Monday, 18 November 2019
while(1)
{
if(sw==0)
{
CCAP0L=0X40; // set initial same as CCAP0H
CCAP0H=0X40; // duty cycle of 40%
}
if(sw==1)
{
CCAP0L=0X99; // set same as CCAP0H
CCAP0H=0X99; // duty cycle of 80%
}
}
}
32 | P a g e
Monday, 18 November 2019
Figure 14 : Wave showing 40% and 80% duty cycle using PCA timer
13.5 Conclusion: -
We generated PWM of different duty cycle using PCA timer
for different states of switch. We programmed module 0 of
PCA timer in 8bit PWM mode.
33 | P a g e
Monday, 18 November 2019
Program : 01
table=8
while(table<=9):
print('Table of ', table)
mul=1
while(mul<=10):
print(table, ' * ', mul, ' = ', table*mul)
mul +=1
table+=1
print()
Output: -
Table of 8
8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80
Table of 9
9 * 1 = 9
9 * 2 = 18
9 * 3 = 27
9 * 4 = 36
9 * 5 = 45
9 * 6 = 54
9 * 7 = 63
9 * 8 = 72
9 * 9 = 81
9 * 10 = 90
Program : 02
Output: -
0 Stud 0 Hi
1 Stud 1 Hi
2 Stud 2 Hi
3 Stud 3 Hi
4 Stud 4 Hi
5 Stud 5 Hi
34 | P a g e
Monday, 18 November 2019
6 Stud 6 Hi
7 Stud 7 Hi
8 Stud 8 Hi
9 Stud 9 Hi
10 Stud 10 Hi
Program : 03
Output: -
Program : 04
string=input("Enter the string :")
length=len(string)
print(length)
for row in range(length):
for col in range(row+1):
print(string[col],end="")
print()
Output: -
Enter the string :IIITBhagalpur
13
I
II
III
IIIT
IIITB
IIITBh
IIITBha
IIITBhag
IIITBhaga
IIITBhagal
IIITBhagalp
IIITBhagalpu
IIITBhagalpur
35 | P a g e
Monday, 18 November 2019
Program : 05
Output: -
* * * *
* * *
* *
* *
* *
*
36 | P a g e
Monday, 18 November 2019
15.1 Program: 01
Output: -
Institute Rank
0 IIIT Bhagalpur 10
1 BCE Bhagalpur 15
2 Agri Bhagalpur 14
15.2 Program: 02
# Import pandas library
import pandas as pd
# initialize list of lists
data = [['Aman', 10], ['Rashi', 15], ['Sadik', 14]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['Name', 'Marks'])
# print dataframe.
df
Output: -
Name Marks
0 Aman 10
1 Rashi 15
2 Sadik 14
15.3 Program: 03
# Python code demonstrate creating DataFrame from dict narray / lists
By default addresses.
import pandas as pd
# intialise data of lists.
data = {'Name':['Neeraj', 'Anuranjan', 'Aakash', 'Gunjan'],
'Age':[20, 21, 19, 18]}
# Create DataFrame
df = pd.DataFrame(data)
# Print the output.
df
Output: -
Name Age
0 Neeraj 20
1 Anuranjan 21
2 Aakash 19
3 Gunjan 18
37 | P a g e
Monday, 18 November 2019
df.max()
Output: -
Name Neeraj
Age 21
dtype: object
df
Output: -
Name Age
0 Neeraj 20
1 Anuranjan 21
2 Aakash 19
3 Gunjan 18
df.head(2)
Output: -
Name Age
0 Neeraj 20
1 Anuranjan 21
df.tail(2)
Output: -
Name Age
2 Aakash 19
3 Gunjan 18
38 | P a g e
Monday, 18 November 2019
Output: -
3.988027572631836
0.9958744049072266
16.2 Program: 02
def myFibonacci(n):
if n<0:
print("Incorrect input")
# First Fibonacci number is 0
elif n==1:
return 0
# Second Fibonacci number is 1
elif n==2:
return 1
else:
return myFibonacci(n-1)+myFibonacci(n-2)
print(myFibonacci(9))
Output: -
21
39 | P a g e
Monday, 18 November 2019
Output: -
Text(0.5, 1.0, 'title of plot')
x=[1,2,3]
y=[4,5,1]
suji.plot(x,y)
Output: -
[<matplotlib.lines.Line2D at 0x20f30664a20>]
17.2 Program: 02
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import cv2
img=cv2.imread('logo.png',0)
print(img)
Output: -
[[255 255 255 ... 255 255 255]
[255 255 255 ... 255 255 255]
[255 255 255 ... 255 255 255]
...
[255 255 255 ... 255 255 255]
[255 255 255 ... 255 255 255]
[255 255 255 ... 255 255 255]]
40 | P a g e
Monday, 18 November 2019
Img
Output: -
array([[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
...,
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255],
[255, 255, 255, ..., 255, 255, 255]], dtype=uint8)
plt.imshow(img)
Output: -
<matplotlib.image.AxesImage at 0x203c705db48>
plt.imshow(img,'gray')
Output: -
<matplotlib.image.AxesImage at 0x203c721ecc8>
41 | P a g e
Monday, 18 November 2019
img.min()
Output: -
0
img.max()
Output: -
255
img.mean()
Output: -
235.23600380527603
15.3 Program: 03
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import cv2
img=cv2.imread('Suraj.jpg',0)
print(img)
Output: -
[[182 182 183 ... 181 182 182]
[182 183 184 ... 181 181 182]
[183 184 185 ... 181 181 182]
...
[ 60 61 53 ... 41 33 29]
[ 56 55 43 ... 29 26 27]
[ 72 57 48 ... 19 22 28]]
type(img)
Output: -
numpy.ndarray
img.shape
Output: -
(360, 279)
img.size
Output: -
100440
plt.imshow(img[50:300,30:200],'gray')
Output: -
<matplotlib.image.AxesImage at 0x1d8f1b95608>
42 | P a g e
Monday, 18 November 2019
plt.imshow(img,'gray')
Output: -
<matplotlib.image.AxesImage at 0x1d8f1bf45c8>
Output: -
<matplotlib.image.AxesImage at 0x1d8f1cb1f88>
plt.contour(img,[50,100])
Output: -
<matplotlib.contour.QuadContourSet at 0x1d8f1d0d5c8>
43 | P a g e
Monday, 18 November 2019
ultaImg=np.flipud(img)
plt.imshow(ultaImg,'gray')
Output: -
<matplotlib.image.AxesImage at 0x1d8f1dd3f88>
Output: -
<matplotlib.image.AxesImage at 0x1d8f1e95f88>
44 | P a g e