EMBEDDED CONTROLLERS
(18EC2205)
LABORATORY MANUAL
2019-2020
Course Coordinator
Dr. [Link], Associate Professor
Course Instructors
[Link] Mantravadi, Associate Dean
[Link] Suman, Assistant Professor
Mrs. [Link], Assistant Professor
[Link], Assistant Professor
Mr. Khanal Madhav Prasad, Assistant Professor
[Link], Assistant Professor
Department of Electronics and Communication Engineering
(DST - FIST Sponsored Department)
KONERU LAKSHMAIAH EDUCATION FOUNDATION
(Deemed to be University estd, u/s, 3 of the UGC Act, 1956)
(NAAC Accredited “A++” Grated University)
Green Fields, Vaddeswaram Guntur District,
A.P., India – 522502
INTRODUCTION TO KEIL TOOL
Procedure to create a new μvision project:
Step 1: Give a double click on μvision4 icon on the desktop, it will generate a window as shown below:
Step 2: To create new project, go to project, select new μvision project.
Step 3: Select a drive where you would like to create your project.
Step 4: Create a new folder and name it with your project name.
Step 5: Open that project folder and give a name of your project executable file and save it.
Step 6: After saving, it will show some window there select your microcontroller company i.e. Atmel.
Step 7: Select your chip as AT89C52.
Step 8: After selecting chip click on OK then it will display some window asking to add STARTUP file.
Select YES.
Step 9: A target is created and startup file is added to your project target and is shown below.
Step 10: To write your project code select a new file from FILE menu bar.
Step 11: It will display some text editor, to save that file select SAVE option from FILE menu bar.
Step 12: Save file name with .c extension.
Step 13: Write the code of your project and save it.
Step 14: To add c file to target, give a right click on Source Group, choose “ADD files to Group” option.
Step 15: It will displays some window there select the file you have to add and click on ADD option.
Step 16: The file will be added to target and it is shown in the project window.
Step 17: Now give a right click on target in the project window and select “Options for Target”.
Step 18: It will show some window, in that go to output option and choose Create Hex file option by
selecting that box.
Step 19: In the same window go to Linker option and choose use memory layout from target dialog by
selecting the box, and Click OK.
Step 20: Now to compile your project Select build target option or press F7.
Step 21: In the build OUTPUT window, you can see the errors and warnings of the code. Project HEX file
will be created.
ALM 1:
Aim: To Read data from Port-1 and write that on to Port2
Software used: Keil
Program:-
#include<reg51.h>
#define LED P2
void MSDelay(unsigned int);
void main(void)
P1=0;
LED=0;
for(;;)
P1++;
MSDelay(2000);
LED=~P1;
MSDelay(2000);
void MSDelay(unsigned int itime)
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
Result:
Complement of Port1 data copied into LED(Port 2)
ALM 2:
Aim: Generate a Square waveform using Timer-1
Software used: Keil
Program:
#include<reg51.h>
#define LED P2
void T1M2Delay(void);
sbit MYBIT = P2^7;
void main(void)
while(1)
MYBIT=~MYBIT;
T1M2Delay();
void T1M2Delay(void)
TMOD=0x20;
TH1=0x00;
TR1=1;
while(TF1==0);
TR1=0;
TF1=0;
}
To see the waveform
Select Debugger button
Select the Analysis window Logic Analyzer
Select Setup Button and Add P2 variable in it, press enter it would be added
Run the File
Result:
Square wave form generated by using Timer1 mode 2,
ALM 3:
Aim: To Transfer Data through Serial Port
Software used: Keil
Program:-
#include <reg51.h>
void main(void)
TMOD=0x20;
TH1=0xFA;
SCON=0x50;
TR1=1;
while(1)
SBUF='P';
while(TI==0);
TI=0;
SBUF='&';
while(TI==0);
TI=0;
SBUF='C';
while(TI==0);
TI=0;
Result: Transfers data “P&C” through serial port
ALM 4:
Aim:- To Blink the LED using Interrupts
Software used: keil
Program:-
#include <reg51.h>
sbit SW = P1^7;
sbit IND=P1^0;
#define LED P2
void timer0(void) interrupt 1
LED=~LED;
void main()
SW=1;
TMOD = 0x02;
TH0=0xA4;
IE = 0x82;
TR0=1;
while (1)
IND=SW;
Result: Blink the LED’s which are connected in PORT2 using Timer0 Internal Interrupt