RV Institute of Technology and Management
RV Institute of Technology and Management
RV Institute of Technology and Management
IV Semester
2018 Scheme
Prepared By:
Dr. Asha S Manek,
Assistant Professor,
Department of Computer Science and Engineering
RVITM, Bengaluru - 560076
Email: [email protected]
Dr. A. Ajina,
Assistant Professor,
Department of Information Science and Engineering
RVITM, Bengaluru - 560076
Email: [email protected]
RV Institute of Technology & Management®
Institute Vision
Strive to impart quality technical education with global competence and societal
commitment, leading to breakthrough innovations.
Department Vision
To be at the frontier of Computer Science and Engineering with a focus on innovation
and industry needs and to produce global professionals contributing to society.
Department Mission
• To impart world-class education in Computer Science and Engineering through
contemporary pedagogical practices.
• To inculcate quality research leading to innovation through latest tools and various
technical forums.
• To impart technical skills and domain knowledge focusing on emerging areas to
produce industry-ready graduates and entrepreneurs
• To impart knowledge to students in interdisciplinary areas that extend the scope of
computer science for the benefit of society.
Program Educational Objectives (graduates are expected to perform and achieve during
the first few years after graduation.)
PEO 1: Impart strong foundation in solving hardware & software engineering problems and
adapt to the changes in technology through continuous-learning.
PEO 2: Inculcate innovation in new technologies and systems in their key domains thus
encouraging them to pursue higher education and research.
PEO 3: Disseminate their knowledge in advance areas of Computer science to become
industry ready graduates or entrepreneurs.
PEO 4: Exhibit professional ethics & values, effective communication and team work with a
multidisciplinary approach to meet the needs of the society.
Program Specific Objectives (students should be able to do at the time of graduation.)
PSO 1: Analyse the core concepts by Computer Science Engineering for building intensive
systems to improve efficiency with different algorithms and tools.
PSO 2: Able to use professional, managerial and interdisciplinary skills in identifying the
research gaps to develop cost effective and innovative solutions leading to
automation.
Introduction to ARM7
Step 1: After opening Keil uV4, Go to Project tab and click on close project
Step 2: After Creating project now Select your device model. Example.NXP-LPC2148
Step 3: so now your project is created and Message window will appear to add start up file of
your Device click on Yes so it will be added to your project folder
Step 4: Now go to File and create new file and save it with .C extension if you will write program
in C language or save with .asm for assembly language.
Step 5: Now write your program and save it again. You can try example given at end of this
tutorial.
Step 6: After that on left you see project window [if it’s not there….go to View tab and click on
project window]
Click output tab here & check create Hex file if you want to generate hex file
Step 7: Now Expand target and you will see source group
Step 9: you can see Status of your program in Build Output window
[If it’s not there go to view and click on Build output window]
PROGRAMS
PART-A
Conduct the following experiments by writing program using
ARM7TDMI/LPC2148 using an evaluation board/simulator and the required
software tool.
END
execute START
R0
BEQ STOP
Program 4: Write a program to add an array of 16-bit numbers and store the
32-bit result in internal RAM.
AREA ADDITION, CODE, READONLY
ENTRY ; Mark first instruction to
execute START
MOV R5, #6 ; INTIALISE COUNTER TO 6(i.e.
N=6)
MOV R0, #0 ; INTIALISE SUM TO ZERO
LDR R1, =VALUE1 ; LOADS THE ADDRESS OF FIRST
VALUE LOOP
CMP R5, #0
JMP B JMP
VALUE1 DCW 0X1111, 0X2222, 0X3333, 0XAAAA, 0XBBBB, 0XCCCC
START
found
NOP
back B back ; Lookup table contains Squares of nos from 0 to 10 (in hex)
START
LOOP1
NOP
back B back ; ARRAY OF 32-BIT NUMBERS (N=7) VALUE1
DCD 0X44444444 ;
DCD 0X22222222 ;
DCD 0X11111111 ;
DCD 0X33333333 ;
DCD 0XAAAAAAAA ;
DCD 0X88888888 ;
DCD 0X99999999 ;
execute START
LOOP0
LOOP2
SUBS R5, R5, #1 ; DECREMENT COUNTER CMP
R5, #0 ; COMPARE COUNTER TO 0
CVALUE
DCD 0X44444444
DCD 0X11111111
DCD 0X33333333
DCD 0X22222222
AREA DATA1, DATA, READWRITE;
DCD 0X00000000
END ; Mark end of file
Program 8: Write a program to count the number of ones and zeros in two
consecutive memory locations.
AREA ONEZERO, CODE, READONLY
ENTRY ;Mark first instruction
to execute START
MOV R2, #0 ; COUNTER FOR ONES
MOV R3, #0 ; COUNTER FOR ZEROS
MOV R7, #2 ; COUNTER TO GET TWO WORDS
OTHERWISE NEXT
ZEROS ADD R3, R3, #1 ; IF CARRY BIT IS 0 THEN INCREMENT THE COUNTER BY 1(R3)
PART –B
int main ()
{
while (1)
{
uart_init();
ptr = arr;
while (*ptr! ='\0')
{
U0THR=*ptr++;
while (! (U0LSR & 0x40) == 0x40);
for (delay=0; delay<=600; delay++);
}
for (delay=0; delay<=60000; delay++);
}
}
void uart_init(void)
{
PINSEL0=0X0000005; //select TXD0 and RXD0
lines U0LCR = 0X00000083; //enable baud rate divisor
loading U0DLM = 0X00; //select the data format
U0DLL = 0x13; //select baud rate 9600
bps U0LCR = 0X00000003;
}
#include<lpc214x.h>
void clock_wise(void);
void
anti_clock_wise(void);
unsigned int j=0;
int main ()
{
IO0DIR= 0X00000900;
IO0SET= 0X00000100; //P0.8 should always high.
while (1)
{
clock_wise();
for(j=0;j<400000;j++); //delay
anti_clock_wise();
for(j=0;j<400000;j++); //delay
//End of while (1)
}
} //End of Main
void clock_wise(void)
{
IO0CLR = 0x00000900; //stop motor and also turn off relay
for (j=0; j<10000; j++); //small delay to allow motor to turn
off IO0SET = 0X00000900; //Selecting the P0.11 line for
clockwise
}
void anti_clock_wise(void)
{
IO0CLR = 0X00000900; //stop motor and also turn off relay for
(j=0; j<10000; j++); //small delay to allow motor to turn off
IO0SET = 0X00000100; //not selecting the P0.11 line for Anti clockwise
}
Program 11: Interface a Stepper motor and rotate it in clockwise and anti-
clockwise direction.
Note: Stepper motor is connected to port pins P0.12 to P0.15.
#include <LPC21xx.H>
void clock_wise(void);
void
anti_clock_wise(void);
unsigned long int var1, var2;
unsigned int i=0, j=0, k=0;
int main(void)
{
PINSEL0 = 0x00FFFFFF; //P0.12 to P0.15
GPIo IO0DIR = 0x0000F000; //P0.12 to P0.15 output
while (1)
{
for (j=0; j<50; j++)
clock_wise();
for (k=0; k<65000; k++);
for (j=0; j<50; j++)
anti_clock_wise();
} // End of main
void clock_wise(void)
{
var1 = 0x00000800; //For
Clockwise for (i=0; i<=3; i++) // for A B C
D Stepping
{
var1 = var1<<1; //For
Clockwise IO0PIN = var1;
for (k=0; k<3000; k++); //for step speed variation
}
}
void anti_clock_wise(void)
{
var1 = 0x00010000; //For Anticlockwise
for (i=0; i<=3; i++) // for A B C D
Stepping
{
var1 = var1>>1; //For Anticlockwise
IO0PIN = var1;
for (k=0; k<3000; k++); //for step speed variation
}
}
Result: Stepper Motor rotates 3600 in Clockwise and after a small delay rotates in
3600 in anticlockwise direction.
Program 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 = 0X00040000; //AD0.4 pin is selected (P0.25)
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;
while (*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
ptr1 = arr;
temp1 = 0xC0; //Display starting address of second
line 4 th pos
lcd_com();
delay (800);
while(*ptr1!='\0')
{
temp1 = *ptr1;
lcd_data();
ptr1 ++;
}
//infinite loop
while (1)
{
//CONTROL register for ADC
AD0CR = 0x01200010; //command register for
ADC-AD0.4
temp1 = 0x89;
lcd_com();
delay (1200);
ptr = var1;
while (*ptr!='\0')
{
temp1=*ptr;
lcd_data();
ptr++;
}
temp1 = 0xc9;
lcd_com();
delay(1200);
ptr1 = var;
while (*ptr1!='\0')
{
temp1=*ptr1;
lcd_data();
ptr1++;
}
} // end of while (1)
} //end of main ()
//lcd initialization
void lcd_init()
{
temp2=0x30;
wr_cn();
delay (800);
temp2=0x30;
wr_cn();
delay(800);
temp2=0x30;
wr_cn();
delay (800);
temp2=0x20;
wr_cn();
delay (800);
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);
}
Result: Analog values given by Potentiometer (POT) is converted to digital value and
displayed on LCD.
Program 13: Interface a DAC and generate Triangular and Square waveforms.
Note: 8 bit DAC 0800 is connected to port pins P0.16 to P0.23.
Square wave:
#include <lpc21xx.h>
unsigned int var;
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;
var= 0x00000000;
delay();
IO0PIN = 0x00FF0000;
var= 0x00FF0000;
delay();
}
}
void delay(void)
{
unsigned int i=0;
for(i=0;i<=950;i++);
}
Result: Square wave can be observed on CRO and also on Logic Analyzer.
Triangular Wave:
#include <LPC21xx.h>
unsigned long int temp=0x00000000;
int main ()
{
unsigned int i=0;
PINSEL0 = 0x00000000 ; // Configure P0.0 to P0.15 as
GPIO PINSEL1 = 0x00000000 ; // Configure P0.16 to P0.31 as
GPIO IO0DIR=0x00FF0000;
while(1)
{
for(i=0;i!=0xFF;i++)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
for(i=0xFF; i!=0;i--)
{
temp=i;
temp = temp << 16;
IO0PIN=temp;
}
}
}
Result: Triangular wave can be observed on CRO and also on Logic Analyzer.
Program 14: Interface a 4X4 keyboard and display the key code on an LCD.
/*Program to demonstrate keyboard operation
Takes a key from key board and displays it on LCD screen*/
#include<lpc21xx.h>
#include<stdio.h>
void lcd_init(void);
void clr_disp(void);
void lcd_com(void);
void lcd_data(void);
void wr_cn(void);
void wr_dn(void);
void scan(void);
void get_key(void);
void display(void);
void delay(unsigned int);
void init_port(void);
delay(500); //delay
while (*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
//........KEYPAD Working.........//
while (1)
{
get_key ();
display ();
}
} //end of main()
temp3=0x00E00000;
}
var1 = temp3;
IO1PIN = var1; // each time var1 value is put to port1
IO1CLR =~var1; // Once again Conforming (clearing all other bits)
scan ();
delay (100); //delay
if (flag == 0xff)
break;
} // end of for
if (flag == 0xff)
break;
} // end of while
for (i=0;i<16;i++)
{
if (scan_code[i] == res1) //equate the scan_code with res1
{
result = ASCII_CODE[i]; //same position value of ascii code
break; //is assigned to result
}
}
}// end of get_key();
void scan(void)
{
unsigned long int t;
temp2 = IO1PIN; // status of port1
temp2 = temp2 & 0x000F0000; // Verifying column key
if(temp2 != 0x000F0000) // Check for Key Press or Not
{
delay (1000); //delay(100)//give debounce delay check again
temp2 = IO1PIN;
temp2 = temp2 & 0x000F0000; //changed condition is same
} // end of scan()
void display(void)
{
ptr = disp0;
temp1 = 0x80; // Display starting address of first line
lcd_com();
while (*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}
ptr = disp1;
temp1 = 0xC0; // Display starting address of second line
lcd_com();
while (*ptr!='\0')
{
temp1 = *ptr;
lcd_data ();
ptr ++;
}
temp1 = 0xC6; //display address for key value
lcd_com();
temp1 = result;
lcd_data();
}
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x30;
wr_cn();
delay(3200);
temp = 0x20;
wr_cn();
delay(3200);
// load command for lcd function setting with lcd in 4 bit mode,
// 2 line and 5x7 matrix display
temp = 0x28;
lcd_com();
delay(3200);
temp1 = 0x80;
lcd_com();
delay (800);
}
void lcd_data(void)
{
temp = temp1 & 0xf0;
wr_dn();
temp= temp1 & 0x0f;
temp= temp << 4;
wr_dn();
delay(100);
}
void lcd_com(void)
{
temp = temp1 & 0xf0;
wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}
void clr_disp(void)
{
// command to clear lcd display
temp1 = 0x01;
lcd_com();
delay(500);
}
void init_port()
{
IO0DIR = 0x000000FC; //configure o/p lines for lcd
IO1DIR = 0XFFF0FFFF;
}
Result: out of 16 keys, one of the key is pressed and values assigned to that key is displayed
on LCD.
#include<lpc214x.h>
void Extint0_Isr(void) irq; //declaration of ISR
unsigned char int_flag = 0, flag = 0;
int main(void){
IO1DIR = 0X02000000;
IO1SET = 0X02000000;
PINSEL1 =0X00000001; //Setup P0.16 to alternate function EINT0
EXTMODE =0x01; //edge i.e falling edge trigger and active low
EXTPOLAR= 0X00;
VICVectAddr0 = (unsigned long) Extint0_Isr; //Assign the EINT0 ISR function
VICVectCntl0 = 0x20 | 14; //Assign the VIC channel EINT0 to interrupt priority 0
VICIntEnable |= 0x00004000; //Enable the EINT0 interrupt
while (1) //waiting for interrupt to occur
{
if(int_flag == 0x01)
{
if(flag == 0)
{
IO1CLR = 0X02000000;
flag = 1;
}
else if(flag == 1)
{
IO1SET = 0x02000000;
flag = 0;
}
int_flag = 0x00;
}
}
}
void Extint0_Isr(void) irq
{ //whenever there is a low level on
EINT0 EXTINT |= 0x01; //Clear interrupt
int_flag = 0x01;
VICVectAddr = 0; //Acknowledge Interrupt
}
Result: LED connected to port pin P0.25 toggle when external interrupt occurs.
Program 16: Display the Hex digits 0 to F on a 7-segment LED interface, with
an appropriate delay in between.
Note: Seven segment LEDS are connected to port pins P0.16 to P0.23 and select lines of 4 seven
segment LEDS are connected to port pins P0.28 to P0.31.
#include <LPC21xx.h>
unsigned int delay, count=0, Switchcount=0;
unsigned int Disp[16]={0x003F0000, 0x00060000, 0x005B0000, 0x004F0000,
0x00660000,0x006D0000, 0x007D0000, 0x00070000, 0x007F0000, 0x006F0000,
0x00770000, 0x007C0000, 0x00390000, 0x005E0000, 0x00790000, 0x00710000
};
while (1)
{
IO0SET = ALLDISP; IO0CLR = 0x00FF0000;
for (delay=0;delay<100;delay++);
IO0SET = Disp[Switchcount]; // display the values 0 to F one after the other
for(delay=0;delay<1000000;delay++);
Switchcount++;
if (Switchcount == 16) // after F go back to 0
{
Switchcount = 0;
}
}
}
Result: Numbers 0000, 1111, 2222, …….FFFF is displayed on Seven segment display with
a delay in between.
VIVA QUESTIONS
Program to toggle 8 LED’s which are connected to Port pins P0.16 to P0.23.
#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)
{
IO0CLR = 0x00FF0000;
delay();
IO0SET = 0x00FF0000;
delay();
}
}
void delay(void)
{
unsigned int i=0,x=0;
for(i=0;i<=95000;i++)
{
for(x=0;x<1000;x++);
}
Result: Eight LED’s toggle (on and off with delay in between) continuously.
#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 = 0x00000200 ;
IO0SET = 0x00000200;
delay();
IO0CLR = 0x00000200;
}
void delay(void)
{
unsigned int i=0,x=0;
for(i=0;i<=95000;i++)
{
for(x=0;x<1000;x++);
}
count = 0;
int main(void)
{
unsigned int value=0;
while(1)
{
for(count = 0; count < 2000; count++)
{
value = 1023;
DACR = (value<<6);
}
}
}