Microcontroller Lab Manual - SCEM - 11
Microcontroller Lab Manual - SCEM - 11
Microcontroller Lab Manual - SCEM - 11
SAHYADRI
COLLEGE OF ENGINEERING & MANAGEMENT,
MANGALURU
PREFACE
Microcontrollers and Embedded System Laboratory is designed for Information Science & Engineering
students, Sahyadri College of Engineering and Management, Mangaluru.
The lab experiments enhance the learning curve for the students and give them hands-on Experience on
the different interfacing devices that were discussed in the theory classes.
The manual contains the prescribed experiments for easy & quick understanding of the students. The
authors have gathered materials from Books, Journals and Web resources.
The student should be able to analyze and develop programs based on input conditions or expected
output requirements. We hope that, this practical manual will be helpful for the students of Information
Science & Engineering for understanding the subject from the point of view of applied aspects.
There is always scope for improvement in the manual. We would appreciate to receive valuable
suggestions from readers and users for future use.
This Laboratory manual is based on the syllabus provided by VTU under the subject code 18CSL48.
ACKNOWLEDGMENTS
We are highly indebted to Dr. Shamanth Rai. Associate Professor & H.O.D. Department of
Information Science &Engineering for providing us the opportunity to prepare this manual as well as for
his guidance and constant supervision.
We would like to express our special gratitude and thanks to Dr. Srinivas Rao Kunte, Principal
Sahyadri College of Engineering & Management, Mangaluru.
We are also thankful to Dr. D. L. Prabhakara, Director Sahyadri Group of Institutions, and
Dr. Manjunath Bhandary, Chairman, Sahyadri Group of Institutions.
We are also thankful to Mr. Praveen T Damale for proof reading and constant support in the
Laboratories.
We are thankful to the students and colleagues for their support and encouragement.
List of Experiments
Expt.N Objective of the Page
o. Experiment No
PART – A
11. Interface a Stepper motor and rotate it in clockwise and anti- 17-18
clockwise direction.
12. Determine Digital output for a given Analog input using Internal 19-22
ADC of ARM controller.
13. Interface a DAC and generate Triangular and Square waveforms. 23
14. Interface a 4x4 keyboard and display the key code on an LCD. 24-28
1. Remove footwear and keep it in the rack before entering the lab.
2. Make entry in the Log Book as soon as you enter the Laboratory.
3. All the students should sit according to their roll numbers starting from their left to right.
4. All the students are supposed to enter the Equipment number in the logbook.
5. Do not change the place of Laboratory Equipment on which you are working.
6. Strictly observe the instructions given by the Professor/Lab Instructor.
7. The Laboratory Record Book should have following details:
(a) Date of the Experiment
(b) Aim
(c) Apparatus & Components Required
(d) Programs with Comments
(e) Algorithm Steps
(f) Results
8. Before starting Laboratory work follow all written and verbal instructions carefully. If you do not
understand a direction or part of a procedure, CLARIFY YOUR CONCERN WITH THE
INSTRUCTOR BEFORE PROCEEDING WITH THE ACTIVITY
9. Protect yourself from getting electric shock.
10. Break-down of equipment must be reported to the Instructor.
11. After the completion of the experiment should return the components to the respective lab
instructors.
12. Before leaving the lab, should check whether they have switch off the power supplies and keep
their chairs properly.
Institute Vision
To be a premier institution in Technology and Management by fostering excellence in education,
innovation, incubation and values to inspire and empower the young minds.
Institute Mission
M1: Creating an academic ambience to impart holistic education focusing on individual growth, integrity,
ethical values and social responsibility.
M2: Develop skill based learning through industry-institution interaction to enhance competency and
promote entrepreneurship.
M3: Fostering innovation and creativity through competitive environment with state-of-the-art
infrastructure.
Department Vision
Department Mission
M1: Creating competitive ambience to enhance the innovative and experiential learning process through
state-of the art infrastructure
M2: Grooming young minds through industry-institute interactions to solve societal issues and inculcate
affinity towards research and entrepreneurship.
M3: Promoting team work and leadership qualities through inter-disciplinary activities in diversified areas
of information science and engineering
PEO1: Possess theoretical and practical knowledge to identify, scrutinize, formulate and solve challenging
problems related to dynamically evolving information science.
PEO2: Inculcate core competency, professionalism, teamwork, and ethics to cater industrial needs and to
solve societal problems.
PEO3: Engage in Lifelong learning and stay intact to the transformation in technologies and pursue
research.
Programme Specific Outcomes
PSO1: Exhibit competency and skills in distributed computing, information security, cyber security, data
analytics and machine learning
PSO2: Able to provide sustainable solution to implement and validate information science projects.
Course Outcomes
CO-PO-PSOs Mapping:
Programme Specific
Program Outcomes (PO)
CO Outcome (PSO)
No.
1 2 3 4 5 6 7 8 9 10 11 12 1 2
C219.1 3 3 3 2 2 3 2 2 1 1
C219.2 3 3 3 2 2 3 2 2 1 1
C219.3 3 3 3 2 2 3 2 2 1 1
C219.4 3 3 3 2 2 3 2 2 1 1
C219.5 3 3 3 2 2 3 2 2 1 1
4. Write a program to add an array of 16 bit numbers and store the 32 bit result in internal RAM
START
NOP
NOP
NOP
START
MOV R5,#6 ; INTIALISE COUNTER TO 6(i.e. N=7)
LDR R1,=VALUE1 ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LOOP
LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
CMP R2,R4 ; COMPARE NUMBERS
BHI LOOP1 ; IF THE FIRST NUMBER IS > THEN GOTO LOOP1
NOP
NOP
NOP
VALUE1
DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;
START
LOOP2
NOP
NOP
NOP
8. Write a program to count the number of ones and zeros in two consecutive memory locations
START
NOP
NOP
NOP
VALUE DCD 0X11111111, 0XAA55AA55; TWO VALUES IN AN ARRAY
PART –B
Conduct the following experiments on an ARM7TDMI/LPC2148 evaluation board using Evaluation
version of Embedded 'C' & Keil Uvision-4 tool/compiler.
#include <lpc214x.h>
int main(void)
{
PINSEL0=0X0000005; //select TXD0 and RXD0 lines
rx_flag = 0x00;
tx_flag = 0x00;
while(1)
{
while(rx_flag == 0x00); //wait for receive flag to set
rx_flag = 0x00; //clear the flag
U0THR = temp1 ;
#include<lpc214x.h>
void clock_wise(void);
void anti_clock_wise(void);
unsigned int j=0;
int main()
{
PINSEL2 = 0XFFFFFFF0;
//IO1CLR = 0X0000ff00;
IO1DIR= 0X00030000; //p1.16 and p1.17 are selected as outputs.
IO1SET= 0X00010000; //P1.16 should always high.
while(1)
{
clock_wise();
for(j=0;j<500000;j++); //delay
anti_clock_wise();
for(j=0;j<500000;j++); //delay
} //End of while(1)
} //End of Main
void clock_wise(void)
{
IO1CLR = 0x00030000; //stop motor and also turn off relay
for(j=0;j<500000;j++);//small delay to allow motor to turn off
IO1SET = 0X00030000;
//Selecting the P1.17 line for clockwise and turn on motor
}
11. Interface a Stepper motor and rotate it in clockwise and anti-clockwise direction
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
while(1)
{
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
IO1SET = var1 ;
}
}
12.Determine Digital output for a given Analog input using Internal ADC of ARM controller.
#include <lpc214x.h>
#include <Stdio.h>
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
int main()
{
PINSEL1 = 0X04000000; //AD0.4 pin is selected
IO0DIR = 0x000000FC; //configure o/p lines for lcd
delay(3200);
lcd_init(); //LCD initialization
delay(3200);
clr_disp(); //clear display
delay(3200); //delay
ptr = dis;
temp1 = 0x80; //Display starting address of 1st line on LCD
lcd_com();
delay(800);
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
ptr1 = arr;
while(*ptr1!='\0')
{
temp1 = *ptr1;
lcd_data();
ptr1 ++;
}
if(fst_flag)
{
fst_flag = 0x00;
for(i=0;i<8;i++)
{
adc[i] = adc_value;
adc1[i] = temp;
}
}
else
{
n=7;
for(i=n;i>0;i--)
{
adc[i] = adc[i-1];
adc1[n] = adc1[n-1];
n = n-1;
}
adc[0] = adc_value;
adc1[0] = temp;
} temp=0;
adc_value=0;
for(i=0;i<8;i++)
{
sprintf(var1,"%4.2fV",temp);
sprintf(var,"%3x",adc_value);
temp1 = 0x89;
lcd_com();
delay(1200);
ptr1 = var1;
while(*ptr1!='\0')
{
temp1=*ptr1;
lcd_data();
ptr1++;
}
temp1 = 0xc9;
lcd_com();
delay(1200);
ptr1 = var;
while(*ptr1!='\0')
{
temp1=*ptr1;
lcd_data();
ptr1++;
}
} // end of while(1)
} //end of main()
temp2=0x30;
wr_cn();
delay(800);
temp2=0x30;
wr_cn();
delay(800);
temp2=0x20;
temp1 = 0x28;
lcd_com();
delay(800);
temp1 = 0x0c;
lcd_com();
delay(800);
temp1 = 0x06;
lcd_com();
delay(800);
temp1 = 0x80;
lcd_com();
delay(800);
}
void lcd_com(void)
{
temp2= temp1 & 0xf0;
wr_cn();
temp2 = temp1 & 0x0f;
temp2 = temp2 << 4;
wr_cn();
delay(500);
}
#include <lpc21xx.h>
void delay(void);
int main ()
{
PINSEL0 = 0x00000000 ; // Configure P0.0 to P0.15 as
GPIO
PINSEL1 = 0x00000000 ; // Configure P0.16 to P0.31 as
GPIO
IO0DIR = 0x00FF0000 ;
while(1)
{
IO0PIN = 0x00000000;
delay();
IO0PIN = 0x00FF0000;
delay();
}
}
void delay(void)
{
unsigned int i=0;
#include<lpc21xx.h>
#include<stdio.h>
void scan(void);
void get_key(void);
void display(void);
void delay(unsigned int);
void init_port(void);
void lcd_init(void);
void clr_disp(void);
void lcd_com(void); // LCD routines
void lcd_data(void);
void wr_cn(void);
void wr_dn(void);
ptr = disp0;
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
ptr = disp1;
temp1 = 0xC0; // Display starting address of 2nd line on LCD
lcd_com();
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
while(1)
{
get_key();
display();
}
} //end of main()
while(1)
{
for(row=0X00;row<0X04;row++) //Writing one for col's
{
if( row == 0X00)
{
temp3=0x00000E00;
}
else if(row == 0X01)
{
temp3=0x00000D00;
}
else if(row == 0X02)
{
temp3=0x00000B00;
var1 = temp3;
IO0PIN = var1; // each time var1 value is put to port1
IO0CLR =~var1; // Once again Confirming (clearing all other bits)
scan();
delay(100); //delay
if(flag == 0xff)
break;
if(flag == 0xff)
break;
} // end of while
for(k=0;k<16;k++)
{
if(scan_code[k] == res1) //equate the scan_code with res1
{
result = ASCII_CODE[k]; //same position value of ascii code
break; //is assigned to result
}
}
}// end of get_key();
void scan(void)
{
unsigned long int t;
temp2 = IO0PIN; // status of port1
temp2 = temp2 & 0x0000F000; // Verifying column key
if(temp2 != 0x0000F000) // Check for Key Press or Not
{
delay(3000); //delay(100)//give debounce delay check again
temp2 = IO0PIN; //IO0
temp2 = temp2 & 0x0000F000; //changed condition is same
void display(void)
{
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x20;
wr_cn();
delay(3200);
temp = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
lcd_com(); // 2 line and 5x7 matrix display
delay(3200);
temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
delay(800);
temp1 = 0x80;
lcd_com();
delay(800);
}
void lcd_data(void)
void lcd_com(void)
{
temp = temp1 & 0xf0;
wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}
void clr_disp(void)
{
temp1 = 0x01; // command to clear lcd display
lcd_com();
delay(500);
}
IO0DIR = 0x00000FFC; //Configured LCD Lines and Rows as O/P(P0.8-P0.11) and Columns
as I/P(P0.12-P0.15)
#include <LPC21xx.h>
void EINT0_Init(void);
void Extint0_Isr(void) irq;
while(1)
{
if(int_flg == 0xFF) //check interrupt occur or not
{
int_flg = 0x00;
if(flag == 0x00)
{ // when flag is '0x00' ON the LED
IO1SET = 0x02000000;
flag = 0xFF;
}
else
{ // when flag is
'0xFF' OFF the LED
IO1CLR = 0X02000000;
flag = 0x00;
}
}
}
}
void EINT0_Init(void)
{
IO1DIR |= 0X02000000; // P1.25 for LED indication
PINSEL1 &= ~0x00000003;
PINSEL1 |= 0X00000001; // Setup P0.16 to alternate function
EINT0
16. Display the Hex digits 0 to F on a 7-segment LED interface, with an appropriate delay in between
#include <LPC21XX.h>
unsigned int delay,j;
unsigned int Switchcount=0;
unsigned int Disp[16]={0x003F0000, 0x00060000, 0x005B0000, 0x004F0000,
0x00660000,0x006D0000,0x007D0000, 0x00070000, 0x007F0000, 0x006F0000,
0x00770000,0x007C0000,0x00390000, 0x005E0000, 0x00790000, 0x00710000 };
while(1)
{
IO0CLR = 0x00FF0000; // clear the data lines to 7-segment displays
IO0SET = Disp[Switchcount]; // get the 7-segment display value from the array
for(j=0;j<20;j++)
for(delay=0;delay<30000;delay++); // 1s delay
Switchcount++;
if(Switchcount == 0x10) // 0 to F has been displayed go back to 0
{
Switchcount = 0;
IO0CLR = 0x00FF0000;
}
}
}