0% found this document useful (0 votes)
22 views56 pages

MC Lab Manual

The document outlines a series of assembly language programs for microcontrollers, including tasks such as multiplying binary numbers, summing integers, calculating factorials, and finding the largest or smallest number in an array. Each program includes specific instructions, input and output details, and memory addresses for data storage. The document serves as a laboratory guide for students in the Microcontroller and Embedded Systems course at VVIET, Mysuru.

Uploaded by

drivemaheshs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views56 pages

MC Lab Manual

The document outlines a series of assembly language programs for microcontrollers, including tasks such as multiplying binary numbers, summing integers, calculating factorials, and finding the largest or smallest number in an array. Each program includes specific instructions, input and output details, and memory addresses for data storage. The document serves as a laboratory guide for students in the Microcontroller and Embedded Systems course at VVIET, Mysuru.

Uploaded by

drivemaheshs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Microcontroller and Embedded Systems Laboratory (21CS43)

PART - A
Program 1: Write a program to multiply two 16 bit binary numbers.
AREA BINMUL,CODE,READONLY

ENTRY

MOV R1,#0X40000000; Move the address to the Register R1

LDR R2,[R1]; Load the Data which is stored in Register R1 to the Register R2

MOV R3,#0X40000004; Move the address to the Register R3

LDR R4,[R3]; Load the Data which is stored in Register R3 to the Register R4

MUL R5,R2,R4; Multiply the data which is stored in R2 and R4. Store it in R5

MOV R6,#0X40000008; Move the address to the Register R6

STR R5,[R6]; Store the resultant data to the address of Register R6

NOP

END

Input:

Enter the First 16 bit number onto 0x40000000 (Eg: AAAA)

Enter the Second 16 bit number onto 0x40000004 (Eg: BBBB)

Output:

Result can be viewed in Register R5 or on the memory location 0x40000008 (2ED8267D) in hex
decimal values.

Dr. Archana B, Department of CSE, VVIET, Page 1


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 2: Write a program to find the sum of first 10 integer numbers.


AREA SUM_INTEGERS,CODE,READONLY

ENTRY

MOV R1,#0X00000001; Move the first value to the register R0

MOV R2,#0X0000000B; Move the last value to the register R1

MOV R3,#0X00000000; Move Zero to the register R3

LOOP

ADD R3,R3,R1; Add the content of R1 with R3 and store the result back to R3

ADD R1,R1,#01; Add one to the data of R1 and store the result back to R1

CMP R1,R2; Compare R1 and R2

BNE LOOP; Repeat till R1 has the value 10

MOV R4,R3; Move the resultant data to the register to R4

MOV R5,#0X40000000; Move the address to the Register R5 to store the result

STR R4,[R5]; Store the result to the address of register R5

NOP

END

Output:

Result can be viewed in Register R4 and on the memory location 0X40000000 (37) in hex
decimal value.

Dr. Archana B, Department of CSE, VVIET, Page 2


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 3. Write a program to find factorial of a number.


AREA FACT,CODE,READONLY

ENTRY

MOV R0,#0X00000005; Store factorial number in register R0

MOV R1,R0; Move the same number in R1

LOOP

SUB R1,R1,#01; Subtract R1 with 1 and store the result back to R1

CMP R1,#01; Comparison

BEQ STOP;

MUL R2,R0,R1; Multiply R0 and R1 and store the result to R2

MOV R0,R2; Move the result to the register R0

MOV R3,#0X40000000; Move the address to the register R3 to store the result

STR R0,[R3]; Store the result on the address of R3

BNE LOOP;

STOP

NOP

END

Output:

The result can be viewed in register R0 and on the memory location 0X40000000 (78) in hex
decimal value.

Note: The factorial of 5 is 120 and hex decimal value is 78.

Dr. Archana B, Department of CSE, VVIET, Page 3


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 4: Write a program to add an array of 16 bit numbers and store the
32 bit result in internal RAM
AREA ARRAY_SUM,CODE,READONLY

ENTRY

MOV R1,#0X00000003; Initialize the counter to 3 (i.e N=4) and move that to R1

MOV R3,#0X40000000; Move the first address to the register R3

LDR R4,[R3]; Load the first 16 bit data to the register R4

LOOP

ADD R3,R3,#4; Add 4 to the address in R3 to point out to the next address

LDR R5,[R3]; Load data which is stored on the address of R3 to the register R5

ADD R4,R5; Add R4 and R5 and store that in register R4

SUB R1,R1,#01; Decrement the counter

CMP R1,#00; Compare the counter with 0 to come out of the loop

BNE LOOP

MOV R6,#0X4000001C; Move the address to register to R6 to store the result

STR R4,[R6]; Store the result to the address of R6

NOP

END

INPUT:

0X40000000 = 1111

0X40000004 = 2222

0X40000008 = 3333

0X4000000C = 4444

Dr. Archana B, Department of CSE, VVIET, Page 4


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

OUTPUT:

The result can be viewed in register R4 and on the memory location 0X4000001C (AAAA) in
hex decimal value.

Dr. Archana B, Department of CSE, VVIET, Page 5


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 5: Write a program to find the square of a number (1 to 10) using


look-up table.
AREA SQUARE, CODE, READONLY

ENTRY ; Mark first instruction to execute


START
LDR R0, = LOOKUP ; Load start address of Lookup table
LDR R1,=2; Load no whose square is to be find
MOV R1, R1, LSL #0x2; Generate address corresponding to square of given no
MOV R4,#0x40000000 ; Move the address to the register R4 to store result
ADD R0, R0, R1; Load address of element in Lookup table
LDR R3, [R0]; Get square of given no in R3
STR R3,[R4] ; Store the result to the address of register R4
NOP
NOP
JMP B JMP
;Lookup table contains Squares of nos from 0 to 10 (in hex)
LOOKUP DCD 0X00000000; SQUARE OF 0=0
DCD 0X00000001; SQUARE OF 1=1
DCD 0X00000004; SQUARE OF 2=4
DCD 0X00000009; SQUARE OF 3=9
DCD 0X00000010; SQUARE OF 4=16
DCD 0X00000019; SQUARE OF 5=25
DCD 0X00000024; SQUARE OF 6=36
DCD 0X00000031; SQUARE OF 7=49
DCD 0X00000040; SQUARE OF 8=64
DCD 0X00000051; SQUARE OF 9=81
DCD 0X00000064; SQUARE OF 10=100
END ; Mark end of file

Dr. Archana B, Department of CSE, VVIET, Page 6


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

OUTPUT:

The result can be viewed in register R3 and on the memory location 0X40000000 in hex decimal
value. (eg: In this program 2 is loaded onto the register R1, so the output at 0X40000000 memory
location is 4)

Dr. Archana B, Department of CSE, VVIET, Page 7


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 6: Write a program to find the largest/smallest number in an array


of 32 bit numbers.
//BHI for Greater
//BLS for lesser

A. To find Largest number in an array


AREA LARGEST,CODE,READONLY
ENTRY
MOV R1, #0x00000004; Initialize the counter to 4 (i.e N=5)
MOV R2,#0x40000000; Move the first address to the register to R2
MOV R3,#0x4000001C; Move the resultant address to register R3
LDR R4,[R2]; Load the first 32 bit data to the register R4
LOOP
ADD R2,R2,#04 ; Increment the address to 4 to point to the next address
LDR R5,[R2] ; Store the next data to the register R5
CMP R4,R5 ; Compare both numbers which is stored in register R4 and R5
BHI LOOP1 ; IF THE 1st NUMBER IS > THEN GOTO LOOP1
MOV R4,R5 ; IF THE 1st NUMBER IS < THEN MOVE CONTENT R4 TO R2

LOOP1
SUB R1,R1,#01 ; Decrement the counter
CMP R1,#00 ; Compare counter to 0 to exit from LOOP
BNE LOOP
STR R4,[R3] ; Store the resultant to the address of register R3
NOP
NOP
NOP
END

Dr. Archana B, Department of CSE, VVIET, Page 8


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

INPUT:

0X40000000 = 11111111

0X40000004 = 22222222

0X40000008 = 33333333

0X4000000C = 44444444

0X40000010 = 55555555

OUTPUT:

The result can be viewed in register R4 and on the memory location 0X4000001C (55555555) in
hex decimal value.

Dr. Archana B, Department of CSE, VVIET, Page 9


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

B. To find Smallest number in an array


AREA SMALLEST,CODE,READONLY
ENTRY
MOV R1, #0x00000004; Initialize the counter to 4 (i.e N=5)
MOV R2,#0x40000000; Move the first address to the register to R2
MOV R3,#0x4000001C; Move the resultant address to register R3
LDR R4,[R2]; Load the first 32 bit data to the register R4
LOOP
ADD R2,R2,#04 ; Increment the address to 4 to point to the next address
LDR R5,[R2] ; Store the next data to the register R5
CMP R4,R5 ; Compare both numbers which is stored in register R4 and R5
BLS LOOP1 ; IF THE 1st NUMBER IS < THEN GOTO LOOP1
MOV R4,R5 ; IF THE 1st NUMBER IS > THEN MOVE CONTENT R4 TO R2

LOOP1
SUB R1,R1,#01 ; Decrement the counter
CMP R1,#00 ; Compare counter to 0 to exit from LOOP
BNE LOOP
STR R4,[R3] ; Store the resultant to the address of register R3
NOP
NOP
NOP
END

Dr. Archana B, Department of CSE, VVIET, Page 10


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

INPUT:

0X40000000 = 11111111

0X40000004 = 22222222

0X40000008 = 33333333

0X4000000C = 44444444

0X40000010 = 55555555

OUTPUT:

The result can be viewed in register R4 and on the memory location 0X4000001C (11111111) in
hex decimal value.

Dr. Archana B, Department of CSE, VVIET, Page 11


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Program 7: Write a program to arrange a series of 32 bit numbers in


ascending/descending order.
//BLT for Ascending
//BGT for Descending

A. Arrange a series of 32 bit numbers in Ascending order


AREA ASCENDING,CODE,READONLY
ENTRY
MOV R0, #0x00000004; Initialize the counter to 4 (i.e N=5)
LOOP2
MOV R1,#04 ; Initialize another counter to 4 (i.e N=5)
MOV R2,#0x40000000; Move the first address to the register to R2
LOOP1
LDR R3,[R2]; Load the first 32 bit data to the register R3
ADD R2,R2,#04 ; Increment the address to 4 to point to the next address
LDR R4,[R2] ; Store the next data to the register R4
CMP R3,R4 ; Compare two values
BLT LOOP ; IF THE 1st NUMBER IS < THEN GOTO LOOP
STR R3,[R2] ; Interchange the numbers stored in register R4 and R3
SUB R2,R2,#04 ; Decrement the address with 4 to point out to the previous value
STR R4,[R2] ; Interchange the numbers stored in register R4 and R3
ADD R2,R2,#04; After interchange then add 4 to the register R4 to point to the next Data
LOOP
SUB R1,R1,#01 ; Decrement the first counter
CMP R1,#00 ; Compare the counter with 0 to exit LOOP1
BNE LOOP1
SUB R0,R0,#01 ; Decrement the second counter
CMP R0,#00 ; Compare the counter with 0 to exit LOOP2
BNE LOOP2
NOP
END

Dr. Archana B, Department of CSE, VVIET, Page 12


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

INPUT:

0X40000000 = 22222222

0X40000004 = 11111111

0X40000008 = 55555555

0X4000000C = 44444444

0X40000010 = 33333333

OUTPUT:

The result can be viewed in the five different memory location starting from 0X40000000 to
0x40000010

0X40000000 = 11111111

0X40000004 = 22222222

0X40000008 = 33333333

0X4000000C = 44444444

0X40000010 = 55555555

Dr. Archana B, Department of CSE, VVIET, Page 13


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

B. Arrange a series of 32 bit numbers in Descending order


AREA DESCENDING,CODE,READONLY
ENTRY
MOV R0, #0x00000004; Initialize the counter to 4 (i.e N=5)
LOOP2
MOV R1,#04 ; Initialize another counter to 4 (i.e N=5)
MOV R2,#0x40000000; Move the first address to the register to R2
LOOP1
LDR R3,[R2]; Load the first 32 bit data to the register R3
ADD R2,R2,#04 ; Increment the address to 4 to point to the next address
LDR R4,[R2] ; Store the next data to the register R4
CMP R3,R4 ; Compare two values
BGT LOOP ; IF THE 1st NUMBER IS > THEN GOTO LOOP2
STR R3,[R2] ; Interchange the numbers stored in register R4 and R3
SUB R2,R2,#04 ; Decrement the address with 4 to point out to the previous value
STR R4,[R2] ; Interchange the numbers stored in register R4 and R3
ADD R2,R2,#04; After interchange then add 4 to the register R4 to point to the next Data
LOOP
SUB R1,R1,#01 ; Decrement the first counter
CMP R1,#00 ; Compare the counter with 0 to exit LOOP1
BNE LOOP1
SUB R0,R0,#01 ; Decrement the second counter
CMP R0,#00 ; Compare the counter with 0 to exit LOOP2
BNE LOOP2
NOP
END

Dr. Archana B, Department of CSE, VVIET, Page 14


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

INPUT:

0X40000000 = 22222222

0X40000004 = 11111111

0X40000008 = 55555555

0X4000000C = 44444444

0X40000010 = 33333333

OUTPUT:

The result can be viewed in the five different memory location starting from 0X40000000 to
0x40000010

0X40000000 = 55555555

0X40000004 = 44444444

0X40000008 = 33333333

0X4000000C = 22222222

0X40000010 = 11111111

Dr. Archana B, Department of CSE, VVIET, Page 15


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

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
LDR R6, =VALUE ; LOADS THE ADDRESS OF VALUE

LOOP MOV R1, #32 ; 32 BITS COUNTER


LDR R0, [R6], #4 ; GET THE 32 BIT VALUE

LOOP0 MOVS R0, R0, ROR #1 ; RIGHT SHIFT TO CHECK CARRY BIT (1's/0's)
BHI ONES
; IF CARRY BIT IS 1 GOTO ONES BRANCH OTHERWISE NEXT

ZEROS ADD R3, R3, #1


; IF CARRY BIT IS 0 THEN INCREMENT THE COUNTER BY 1(R3)
B LOOP1 ; BRANCH TO LOOP1

ONES ADD R2, R2, #1


; IF CARRY BIT IS 1 THEN INCREMENT THE COUNTER BY 1(R2)

LOOP1 SUBS R1, R1, #1 ; COUNTER VALUE DECREMENTED BY 1


BNE LOOP0 ; IF NOT EQUAL GOTO TO LOOP0 CHECKS 32BIT

Dr. Archana B, Department of CSE, VVIET, Page 16


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

SUBS R7, R7, #1 ; COUNTER VALUE DECREMENTED BY 1


CMP R7, #0 ; COMPARE COUNTER R7 TO 0
BNE LOOP ; IF NOT EQUAL GOTO TO LOOP
NOP
NOP
NOP
JMP B JMP

VALUE DCD 0X11111111, 0XAA55AA55 ; TWO VALUES IN AN ARRAY

END ; Mark end of file

Output:

Result can be viewed in hex decimal values on register R2 and R3.

• Number of 0’s in R3 is 0X00000028 (40 Zeros)


• Number of 1’s in R2 is 0X00000018 (24 Ones)

Dr. Archana B, Department of CSE, VVIET, Page 17


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PART – B
Creating a C project in Keil

1. Open the Keil IDE by clicking on its icon on the desktop.


2. From the Project menu Choose New μVision Project
3. Select a drive where you would like to create your project .Create a new folder and Name
it FirstProject. Type the name FirstProject for the project and click Save. Open that
project folder and give a name of your project executable file and save it.
4. In the Data base tree, choose the vendor and then the chip you want to use and then click
OK. For example, if you want to use the LPC2148, click on the ARM/NXP and then on
the LPC2148 and then press OK.
5. After selecting chip click on OK then it will display some window asking to add STARTUP
file. Click the Yes button when add the startup file to the project pop up window is
displayed. A target is created.
6. To write your project code select a new file from FILE menu bar or Make a new file by
clicking on the New Icon. Press Ctrl+S to save the new file. (You can also save the file by
choosing Save from the File menu.).Name the file as program1.asm and save it in the
FirstProject directory.
7. Type the program in the file
8. Add the program1.asm file to the project. To do so: a. Right click on Source Group 1 and
choose Add Files to Group. Then go to the FirstProject directory and choose
Program1.asm, press Add and then Close. The file will be added to target and it shows in
the project window.

Building

1. Now give a right click on target in the project window and select “Options for Target”.
2. It will show a window, in that go to output option and choose Create Hex file option by
selecting that box. In the same window go to Linker option and choose Use Memory Layout
from Target Dialog by selecting the box, and click OK.
3. To compile your project go to Project select Build Target option or press F7.
Dr. Archana B, Department of CSE, VVIET, Page 18
Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

4. In the build Output window you can see the errors and warnings in your code. And here
Your project Hex file will be created.

LPC2148 C Programming
• LPC2148 has 2 ports viz. Port 0 and Port 1. Each port can be used as I/P or O/P. Port 0 has
0-31 pins and Port1 has 16-31 pins.
• Port 0 is a 32 bit wide I/O port (i.e. it can be used for max 32 pins where each pin refers
to a corresponding bit) and has dedicated direction bits for each of the pins present in the
port. 28 out of the 32 pins can be used as bi-directional I/O (digital) pins. Pins P0.24, P0.26
& P0.27 are unavailable for use and Pin P0.30 can be used as output pin only. In port0,
P0.24, P0.26, P0.27 are not physically available means you can‟t find them on chip but still
you can write values to them. & P0.31 is available for digital output only.
• Port 1 is also a 32 bit wide I/0 port but Pins 0 to 15 i.e P1.0 – P1.15 are unavailable for use
and this port too has a dedicated direction bit for each of the usable pins. In port1, P1.0 to
P1.15 is not available physically. Only P1.16 to P1.31 is available. So out of 64 pins 45
pins are covered by port0 & port1.
• Each Port can be used as GPIO (general purpose I/p and O/p) or As SFR (Special Function).

Registers used for GPIO C programming.

1. IOPINx (x=port number): To read the status of the PIN. GPIO Port Pin value registers. This
register can be used to Read or Write values directly to the pins. Regardless of the direction set for
the particular pins it gives the current start of the GPIO pin when read. The current state of the
GPIO configured port pins can always be read from this register, regardless of pin direction.

2. IODIRx: To set the direction of the PIN (INPUT or OUTPUT). This is the GPIO direction
control register. Setting a bit to 0 in this register will configure the corresponding pin to be used
as an Input while setting it to 1 will configure it as Output. To set the direction of any Port as I/P
or O/P we have to SET and CLR a Register named as IODIR. This register individually controls
the direction of each port pin.

Dr. Archana B, Department of CSE, VVIET, Page 19


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

When we are giving INPUT to the pin then some output should be produced from the
microcontroller, so the pin should be OUTPUT pin.

|= ---set as o/p pin

When we are accepting request from the pin then it should be INPUT.

&=~ ---set as i/p

Example:

IODIR0&=~0x00000000; // it means port 0 will act as i/p

IO1DIR |= 0x000000ff; // it means lower 8 bit of port 1 will act as o/p

3. IOSETx: GPIO Port Output Set registers. This register can be used to drive an „output‟
configured pin to Logic 1 i.e HIGH. Writing Zero does NOT have any effect and hence it cannot
be used to drive a pin to Logic 0 i.e LOW. This register controls the state of output pins in
conjunction with the IOCLR register. Writing ones produces highs at the corresponding port pins.
Writing zeroes has no effect.

Example:

IOSET0=0x00000001; //it means 0th bit of Port 0 will be set

4. IOCLR0: This register can be used to drive an „output‟ configured pin to Logic 0 i.e LOW.
Writing Zero does NOT have any effect and hence it cannot be used to drive a pin to Logic 1.
GPIO Port Output Clear registers. This Register controls the state of output pins. Writing ones
produces lows at the corresponding port pins and clears the corresponding bits in the IOSET
register.

5. PINSELx: It will select the particular function of a PIN.

PINSEL0: Applicable for P0.0 to P0.15

PINSEL1: Applicable for P0.16 to P0.31

PINSEL2: Applicable for P1.16 to P1.31

Dr. Archana B, Department of CSE, VVIET, Page 20


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

• IOPIN Register is used to get the status of the pins.


• IODIR Register is used to set the direction of the pins, when set to 1 means output and
when 0 means input. IOSET Register is used to set the GPIO pins. IOCLR Register is used
to clear the GPIO pins.

Note:- When IOSET = 1 it will set the particular pin, but it doesn't means that to clear the pin you
will use IOSET = 0 or IOCLR = 0, this is different in case of ARM, to set the pin we have to use
IOSET=1 and to clear we have to use IOCLR=1.

Dr. Archana B, Department of CSE, VVIET, Page 21


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

LPC2148 PIN CONFIGURATION:

Dr. Archana B, Department of CSE, VVIET, Page 22


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 9: Display “Hello World” message using Internal UART.


#include <lpc214x.h>

void uart_interrupt(void) irq;

unsigned char temp;

unsigned char rx_flag=0,tx_flag=0;

int main(void)

PINSEL0=0X0000005; //select TXD0 and RXD0 lines


0
0 IODIR1 = 0X00ff0000;//define as o/p
lines

U0LCR = 0X00000083; //enable baud rate divisor loading


and

U0DLM = 0X00; //select the data format

U0DLL = 0x13; //select baud rate 9600 bps

U0LCR = 0X00000003;

U0IER = 0X03; //select Transmit and Recieve


interrupt

VICVectAddr0 = (unsigned long)uart_interrupt;//UART 0 INTERRUPT

VICVectCntl0 = 0x20|6; // Assign the VIC channel uart-0 to interrupt priority 0

VICIntEnable = 0x00000040; // Enable the uart-0 interrupt

rx_flag = 0x00;

tx_flag = 0x00;

Dr. Archana B, Department of CSE, VVIET, Page 23


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

while(1)

while(rx_flag == 0x00); //wait for receive flag to set

rx_flag = 0x00; //clear the flag

while(tx_flag == 0x00); //wait for transmit flag to set

tx_flag = 0x00; //clear the flag

// Do this forever

void uart_interrupt(void) irq

temp = U0IIR;

temp = temp & 0x06;

if(temp == 0x02)

tx_flag = 0xff;

VICVectAddr=0;

else if(temp == 0x04)

U0THR = U0RBR;

Dr. Archana B, Department of CSE, VVIET, Page 24


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

rx_flag = 0xff;

VICVectAddr=0;

Dr. Archana B, Department of CSE, VVIET, Page 25


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 10: Interface and Control a DC Motor.


DC motor converts electrical energy in the form of Direct Current into mechanical energy. In case
of a dc motor, the mechanical energy produced is in the form of rotational movement of the motor
shaft. The direction of rotation of the shaft of the motor can be reversed by reversing the direction
of Direct Current through the motor.
The motor can be rotated at a certain speed by applying a fixed voltage to it. If the voltage varies,
the speed of the motor varies.The DC Motor can also be interfaced to the board by connecting it
to the Reliamate RM4. The direction of the rotation can be changed through software. Port lines
used for DC motor are P0.8 and P0.11.

PROGRAM:

#include <LPC214x.H>
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++); //1275 * int * times
}

int main()
{
IODIR0| = 0x00000900; //setting both the pins p0.8 and p0.11 to high making them as o/p pins

while(1) // Loop Continue


{
IOSET0 = 0x00000100; //setting pin to high state rotating Anti- clockwise
delay(5000);
IOCLR0=0x00000900; //setting pin to low state (no rotation)
delay(5000);

Dr. Archana B, Department of CSE, VVIET, Page 26


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

IOSET0 = 0x00000900; //setting pin to high state rotating clockwise


delay(5000);
IOCLR0=0x00000900; //setting pin to low state (no rotation)
delay(5000);
}
}

Result: When connecting DC Motor to the microcontroller interface then motor head will first
rotate anti-clockwise and then it will rotate in clockwise.

Dr. Archana B, Department of CSE, VVIET, Page 27


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 11: Interface a Stepper motor and rotate it in clockwise and anti-
clockwise direction.
A stepper motor is a brush less, synchronous electric motor that converts digital pulses into
mechanical shaft rotation. Every revolution of the stepper motor is divided into a discretenumber
of steps, and the motor must be sent a separate pulse for each step. It demonstrates the principle of
stepper motor interfacing with ARM LPC2148 microcontroller. It finds great application in field
of microcontrollers such as robotics. Unipolar Motor is the most popular stepper motor among
electronics hobbyist because of its ease of operation and availability.
The Stepper motor can be interfaced to the board by connecting it into the Power Mate PM1. The
rotating direction of the stepper motor can be changed through software. Port lines used for Stepper
motor are P0.12 to P0.15. (4 Pins)

PROGRAM:

#include<LPC214x.h>
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++); //1275 * int * times
}
void main()
{
int s;
IODIR0 |= 0x0000f000; //setting all four pins p0.12 to p0.15 to high making them as o/p pins
IOCLR0 = 0x0000f000;

for(s=0;s<60;s++) // clockwise rotation (For each iteration motor will rotate 1 cycle clockwise)
{
IOCLR0=0x0000f000; // for anticlockwise send 8,4,2,1 instead of 1,2,4,8

Dr. Archana B, Department of CSE, VVIET, Page 28


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

IOSET0=0x00001000; // setting P0.12 pin to high to rotate motor 90 degree


delay(100);
IOCLR0=0x0000f000;
IOSET0=0x00002000; // setting P0.13 pin to high to rotate motor 180 degree
delay(100);
IOCLR0=0x0000f000;
IOSET0=0x00004000; // setting P0.14 pin to high to rotate motor 270 degree
delay(100);
IOCLR0=0x0000f000;
IOSET0=0x00008000; //setting P0.15 pin to high to rotate motor 360 degree
delay(100);
}
for(s=0;s<60;s++) // anticlockwise rotation (For each iteration motor will rotate 1 cycle anticlockwise)
{
IOCLR0=0x000f000; //for clockwise send 1,2,4,8 instead of 8,4,2,1
IOSET0=0x00008000; //setting P0.15 pin to high to rotate motor 90 degree
delay(100);
IOCLR0=0x0000f000;
IOSET0=0x00004000; // setting P0.14 pin to high to rotate motor 180 degree
delay(100);
IOCLR0=0x0000f000;
IOSET0=0x00002000; // setting P0.13 pin to high to rotate motor 270 degree
delay(100);
IOCLR0=0x000f000;
IOSET0=0x00001000; // setting P0.12 pin to high to rotate motor 360 degree
delay(100);
}
}

Result: When connecting Stepper Motor to the microcontroller interface then motor head will
first rotate clockwise and then it will rotate in anti-clockwise.

Dr. Archana B, Department of CSE, VVIET, Page 29


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

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

unsigned int data_lcd=0;


unsigned int adc_value=0,temp_adc=0,temp1,temp2;
float temp;
char var[15],var1[15];
char *ptr,arr[]= "ADC O/P= ";
char *ptr1,dis[]="A I/P = ";

#define vol 3.3 //Reference voltage


#define fullscale 0x3ff //10 bit adc

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;
temp1 = 0x80; //Display starting address of first line 1 th pos
lcd_com();
delay(800);

while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;

Dr. Archana B, Department of CSE, VVIET, Page 30


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

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

while(((temp_adc = AD0GDR) &0x80000000) == 0x00000000); //to check the


interrupt bit

adc_value = AD0GDR; //reading the ADC value


adc_value >>=6;
adc_value &= 0x000003ff;
temp = ((float)adc_value * (float)vol)/(float)fullscale;
sprintf(var1,"%4.2fV",temp);
sprintf(var,"%3x",adc_value);

temp1 = 0x89;
lcd_com();
delay(1200);
ptr = var1;

while(*ptr!='\0')
{
temp1=*ptr;
lcd_data();
ptr++;

temp1 = 0xc9;
lcd_com();

Dr. Archana B, Department of CSE, VVIET, Page 31


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

delay(1200);

Dr. Archana B, Department of CSE, VVIET, Page 32


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

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

Dr. Archana B, Department of CSE, VVIET, Page 33


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

Dr. Archana B, Department of CSE, VVIET, Page 34


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

void lcd_com(void)
{
temp2= temp1 & 0xf0;
wr_cn();
temp2 = temp1 & 0x0f;
temp2 = temp2 << 4;
wr_cn();
delay(500);
}

// command nibble o/p routine


void wr_cn(void) // write command reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp2; // Assign the value to the PORT lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}

// data nibble o/p routine


void wr_dn(void)
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp2; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}

// data o/p routine which also outputs high nibble first


// and lower nibble next
void lcd_data(void)
{
temp2 = temp1 & 0xf0;
wr_dn();
temp2= temp1 & 0x0f;
temp2= temp2 << 4;
wr_dn();
delay(100);
}

void delay(unsigned int r1)

Dr. Archana B, Department of CSE, VVIET, Page 35


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

{
unsigned int r;
for(r=0;r<r1;r++);
}
void clr_disp(void)
{
temp1 = 0x01;
lcd_com();
delay(500);
}

Dr. Archana B, Department of CSE, VVIET, Page 36


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 13: Interface a DAC and generate Triangular and Square


waveforms.

Triangular Wave:

#include <lpc214x.h>
#include <Stdio.h>

int main ()
{
unsigned long int temp=0x00000000;
unsigned int i=0;

PINSEL1 = 0X00080000; //AOUT pin is selected(P0.25)

while(1)
{
// output 0 to FFC
for(i=0; i!=0x3ff; i++)
{
temp = i;
temp = temp << 6;
DACR = temp;
}

// output FF to 1
for(i=0x3ff; i!=0; i--)
{
temp=i;
temp = temp << 6;
DACR = temp;
}
}//End of while(1)
}//End of main()

Square Wave:

#include <lpc214x.h>
#include <Stdio.h>

unsigned int count;

int main()
{

Dr. Archana B, Department of CSE, VVIET, Page 37


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PINSEL1 = 0X00080000; //AOUT pin is selected(P0.25)

while(1)
{
DACR = 0x00000000;
for(count=0;count<1000;count++);
DACR = 0x0000ffc0;
for(count=0;count<1000;count++);
}
} //end of main()

Dr. Archana B, Department of CSE, VVIET, Page 38


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 14: Interface a 4x4 keyboard and display the key code on an
LCD.

#include<lpc21xx.h>
#include<stdio.h>

/******* FUNCTION PROTOTYPE*******/

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

unsigned long int scan_code[16]= {0x00EE0000,0x00ED0000,0x00EB0000,0x00E70000,


0x00DE0000,0x00DD0000,0x00DB0000,0x00D70000,
0x00BE0000,0x00BD0000,0x00BB0000,0x00B70000,
0x007E0000,0x007D0000,0x007B0000,0x00770000};

unsigned char ASCII_CODE[16]= {'0','1','2','3',


'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};

unsigned char row,col;

unsigned char temp,flag,i,result,temp1;


unsigned int r,r1;
unsigned long int var,var1,var2,res1,temp2,temp3,temp4;
unsigned char *ptr,disp[] = "4X4 KEYPAD";
unsigned char disp0[] = "KEYPAD TESTING";
unsigned char disp1[] = "KEY = ";
int main()
{
// ARMLIB_enableIRQ();
init_port(); //port intialisation
delay(3200); //delay
lcd_init(); //lcd intialisation

Dr. Archana B, Department of CSE, VVIET, Page 39


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

delay(3200); //delay
clr_disp(); //clear display
delay(500); //delay

//........LCD DISPLAY TEST. ....... //


ptr = disp;
temp1 = 0x81; // Display starting address
lcd_com();
delay(800);

while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data();
ptr ++;
}

//........KEYPAD Working ........ //


while(1)
{
get_key();
display();
}

} //end of main()

void get_key(void) //get the key from the keyboard


{
unsigned int i;
flag = 0x00;
IO1PIN=0x000f0000;
while(1)
{
for(row=0X00;row<0X04;row++) //Writing one for col's
{
if( row == 0X00)
{
temp3=0x00700000;
}
else if(row == 0X01)
{
temp3=0x00B00000;
}
else if(row == 0X02)
{
temp3=0x00D00000;

Dr. Archana B, Department of CSE, VVIET, Page 40


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

}
else if(row == 0X03)
{
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

if(temp2 != 0x000F0000) // store the value in res1


{
flag = 0xff;
res1 = temp2;
t = (temp3 & 0x00F00000); //Verfying Row Write
res1 = res1 | t; //final scan value is stored in res1
}
else

Dr. Archana B, Department of CSE, VVIET, Page 41


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

{
flag = 0x00;
}
}
} // 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();
}

void lcd_init (void)


{
temp = 0x30;
wr_cn();
delay(3200);

temp = 0x30;
wr_cn();
delay(3200);

temp = 0x30;

Dr. Archana B, Department of CSE, VVIET, Page 42


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

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

// load a command for display on, cursor on and blinking off


temp1 = 0x0C;
lcd_com();
delay(800);

// command for cursor increment after data dump


temp1 = 0x06;
lcd_com();
delay(800);

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 wr_dn(void) ////write data reg


{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);

Dr. Archana B, Department of CSE, VVIET, Page 43


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

IO0CLR = 0x00000008;
}

void lcd_com(void)
{
temp = temp1 & 0xf0;
wr_cn();
temp = temp1 & 0x0f;
temp = temp << 4;
wr_cn();
delay(500);
}

void wr_cn(void) //write command reg


{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008;
}

void clr_disp(void)
{
// command to clear lcd display
temp1 = 0x01;
lcd_com();
delay(500);
}

void delay(unsigned int r1)


{
for(r=0;r<r1;r++);
}

void init_port()
{
IO0DIR = 0x000000FC; //configure o/p lines for lcd
IO1DIR = 0XFFF0FFFF;
}

Dr. Archana B, Department of CSE, VVIET, Page 44


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 15: Demonstrate the use of an external interrupt to toggle an


LED On/Off.

The external interrupts are the interrupts received from the (external) devices interfaced with the
microcontroller. By using P0.3 port line we are generating external interrupt (EINT1).Short JP12,
when we press the switch SW12 the port line goes low & the external interrupt occurs at port line
P0.16. The microcontroller gets interrupts in whatever it is doing and jumps to the vector table to perform
the interrupt service routine.

#include<lpc214x.h>
void Extint1_Isr(void) irq; //declaration of ISR
unsigned char int_flag, flag;

void main()
{
IODIR1 |= 0X02000000; //P1.25 int led
IOSET1 = 0X02000000;
PINSEL0=0X000000c0; //P0.3 EINT1
EXTMODE =0x01; //edge i.e falling edge trigger and active low
EXTPOLAR= 0X00;
VICVectAddr0 = (unsigned long) Extint1_Isr; //Assign the EINT0 ISR function
VICVectCntl0 = 0x20 | 15; //Assign the VIC channel EINT1 to interrupt priority 0
VICIntEnable |= 0x00008000; //Enable the EINT1 interrupt

while(1) //waiting for interrupt to occur


{
if(int_flag == 0x01)
{
if(flag == 0)
{
IO1CLR = 0X02000000;

Dr. Archana B, Department of CSE, VVIET, Page 45


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

flag = 1;
}
else if(flag == 1)
{
IO1SET = 0x02000000;
flag = 0;
}
int_flag = 0x00;
}
}
}

void Extint1_Isr(void) irq //whenever there is a low edge on EINT0


{
EXTINT = 0x02; //clear the interrupt
int_flag = 0x01;
VICVectAddr=0; //Acknowledge Interrupt
}

Result: After dumping the code to the microcontroller when we press the interrupt switch the
LED will go off and again if we press the same switch the LED will gets on, which indicates that
the interrupt is servicing.

Dr. Archana B, Department of CSE, VVIET, Page 46


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

PROGRAM 16: Display the Hex digits 0 to F on a 7-segment LED interface,


with an appropriate delay in between

Seven segment display (SSD), or seven-segment indicator, is a form of electronic


display device for displaying decimal numerals that is an alternative to the morecomplex dot
matrix displays. seven segment display consists of seven LEDs (hence its name) arranged in a
rectangular fashion as shown.

There are four multiplexed 7-segment displays TL543 (U8 - U11) on the board. Each display has
8-inputs SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G and DP. The port lines
P0.28 to P0.31 are used to select one of the 4 digits as shown in the table below. The port lines
P0.16 to P0.23 are used as segment lines for the EIGHT digits.

PROGRAM:

#include<LPC214x.h>
void delay(unsigned int x)
{
unsigned int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++);
}

Dr. Archana B, Department of CSE, VVIET, Page 47


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

void main()
{
IODIR0 |= 0xF0FF0000;
while(1)
{
IOCLR0=0xF0FF0000;
IOSET0=0xF03F0000; // Code to print 0
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0060000; // Code to print 1
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF05B0000; // Code to print 2
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF04F0000; // Code to print 3
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0660000; // Code to print 4
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF06D0000; // Code to print 5
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF07D0000; // Code to print 6
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0070000; // Code to print 7
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF07F0000; // Code to print 8

Dr. Archana B, Department of CSE, VVIET, Page 48


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0670000; // Code to print 9
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0770000; // Code to print A
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF07C0000; // Code to print b
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0390000; // Code to print C
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF05E0000; // Code to print d
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0790000; // Code to print E
delay(5000);
IOCLR0=0xF0FF0000;
IOSET0=0xF0710000; // Code to print F
delay(5000);
}
}

Result: After dumping the code to the microcontroller when we switch on ALL four seven
segments the HEX digits from 0 to F will be displayed.

Dr. Archana B, Department of CSE, VVIET, Page 49


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

VIVA QUESTIONS
1. What do you mean by Embedded System? Give examples.
An embedded system is a computer system, made from a combination of hardware and
software, that is used to perform a specific task. It may or not be programmable, depending
on the application. Examples of embedded systems include washing machines, printers,
automobiles, cameras, industrial machines and more.
2. Why are embedded Systems useful?
Since the embedded system is dedicated to specific tasks, design engineers can optimize
it to reduce the size and cost of the product and increase the reliability and performance.
Some embedded systems are mass-produced, benefiting from economies of scale.
3. What are the segments of Embedded System?
Memory Segment and Data Segment.
4. What is Embedded Controller?
An embedded controller is a microcontroller in computers that handles various system
tasks that the operating system does not handle.
5. What is Microcontroller?
A microcontroller is a computer present in a single integrated circuit which is dedicated
to perform one task and execute one specific application.

It contains memory, programmable input/output peripherals as well a processor.


Microcontrollers are mostly designed for embedded applications and are heavily used in
automatically controlled electronic devices such as cellphones, cameras, microwave ovens,
washing machines, etc.

6. List out the differences between Microcontroller and Microprocessor.

Microprocessor is an IC which has only the CPU inside them i.e. only the processing
powers such as Intel’s Pentium 1,2,3,4, core 2 duo, i3, i5 etc. These microprocessors don’t
have RAM, ROM, and other peripheral on the chip. A system designer has to add them
externally to make them functional. Application of microprocessor includes Desktop PC’s,
Laptops, notepads etc.

Dr. Archana B, Department of CSE, VVIET, Page 50


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

But this is not the case with Microcontrollers. Microcontroller has a CPU, in addition with
a fixed amount of RAM, ROM and other peripherals all embedded on a single chip. At
times it is also termed as a mini computer or a computer on a single chip. Today different
manufacturers produce microcontrollers with a wide range of features available in different
versions. Some manufacturers are ATMEL, Microchip, TI, Freescale, Philips, Motorola etc.
7. How are Microcontrollers more suitable than Microprocessor for Real Time
Applications?
Microcontroller is a mini computer it contains processor, memory , io ports etc, all are
integrated in a single chip. Microcontrollers are used in specific task applications as it has
limited memory and peripherals. Examples: pic, Atmel, avr etc. Microcontroller is cheaper
than microprocessor.
8. Differentiate between Program Memory and Data Memory.
Data memory = where you place your variables. You can read and write values.

Program memory = where the application is stored. Some chips allows parts of the program
memory to be modified in blocks (segments), but you can't store variables in the program
memory. It is normally possible to store constants - i.e. initialized variables that you do not
change - in the program memory.

9. What are registers in microcontroller?

A register is a small place in a CPU that can store small amounts of the data used for
performing various operations such as addition and multiplication and loads the resulting
data on the main memory.

10. What is the program counter?

The program counter, commonly called the instruction pointer in Intel x86 and Itanium
microprocessors, and sometimes called the instruction address register, the instruction
counter, or just part of the instruction sequencer, is a processor register that indicates where
a computer is in its program sequence.

Dr. Archana B, Department of CSE, VVIET, Page 51


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

11. What is a stack pointer (SP)?

A stack pointer is a small register that stores the address of the last program request in
a stack. A stack is a specialized buffer which stores data from the top down. As new
requests come in, they "push down" the older ones.

12. Explain the Immediate Addressing Mode.

In this mode data is present in address field of instruction .Designed like one address
instruction format.

13. Explain the Register Addressing Mode.

In register addressing the operand is placed in one of 8 bit or 16 bit or 32 bit general purpose
registers. The data is in the register that is specified by the instruction.

14. Explain the Direct Addressing Mode.


The operand’s offset is given in the instruction as an 8 bit or 16 bit or 32 bit displacement
element. In this addressing mode the 32 bit effective address of the data is the part of the
instruction.
15. Explain the Indirect Addressing Mode.
Indirect addressing mode uses instructions that include the address of a value thatpoints
to the effective address of the operand. The instructions point to either a registeror a
memory location, and the location would contain the effective address of the operand in
memory.
16. What is difference between microprocessor and microcontroller?
The microprocessor has no ROM, RAM and no I/O ports on the chip itself.
Whereas the microcontroller has a CPU in addition to a fixed amount of RAM,ROM, I/O
ports and a timer all on a single chip.
17. What Is The Difference Between Harvard Architecture And Von Neumann
Architecture?
The name Harvard Architecture comes from the Harvard Mark. The most obvious
characteristic of the Harvard Architecture is that it has physically separate signals and
storage for code and data memory. It is possible to access program memory and data

Dr. Archana B, Department of CSE, VVIET, Page 52


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

memory simultaneously. Typically, code (or program) memory is read-only and data
memory is read-write. Therefore, it is impossible for program contents to be modified by
the program itself.
The von Neumann Architecture is named after the mathematician and early computer
scientist John von Neumann. Von Neumann machines have shared signals and memory for
code and data. Thus, the program can be easily modified by itself since it is stored in read-
write memory.
18. List some of the 8051 microcontroller manufacturers?
Intel
Philips
Infineon
Maxim/Dallas semiconductor
Atmel
19. What are the various types of memories used in microcontroller/microprocessor?
ROM - Read Only Memory
RAM - Random Access Memory
PROM - Programmable Read Only Memory
EPROM - Erasable Programmable Read Only Memory
EEROM - Electrically Erasable Programmable Read Only Memory
20. What is Firmware?
Firmware: The software that is stored permanently in ROM, PROM or EPROM is called
firmware.
21. What is cache memory?
Cache memory is small high speed memory. It is used for temporary storage of data &
information between main memory and CPU (central processing unit).
What is the processor used by ARM7?
ARM7 is a group 32-bit RISC ARM processor cores licensed by ARM Holdings for
microcontroller use.

Dr. Archana B, Department of CSE, VVIET, Page 53


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

22. How many registers are there in ARM7?


ARM7TDMI has 37 registers(31 GPR and 6 SPR). All these designs use a Von Neumann
architecture, thus the few versions comprising a cache do not separate data and instruction
caches.
23. What are t, d, m, I stands for in ARM7TDMI?
The ARM7TDMI(ARM7 + 16 bit Thumb + JTAG Debug + fast Multiplier + enhanced
ICE) processor implements the ARM4 instruction set.
24. What is Assembly level language?
An assembly language is a low-level programming language for microprocessors. It
implements a symbolic representation of the binary machine codes and other constants
needed to program a particular CPU architecture. This representation is usually defined
by the hardware manufacturer, and is based on mnemonics that symbolize processing steps
(instructions), processor registers, memory locations, and other language features.
25. What are Mnemonics?
Mnemonics are instructions or commands to perform a particular operation
given by user to microprocessor
Ex: MOV ADD SUB MUL
26. Which LCD display is present in LPC 2148 Development Board?
On-board two line LCD Display (2*16) with jumper selection option to disable LCD
when not required.
27. Who is the founder of LPC2148 board?
ARM LPC2148 is ARM7TDMI-S core board microcontroller that uses 16/32-Bit 64
pin(LQFP) microcontroller No.LPC2148 from Philips(NXP).
28. Which IDE is supported by LPC2148 board?
Using Real view compiler the keil uVersion 4 is used. Whereas, AVR studio 4 is used for
ATmega128 microcontroller. And code block is used for c programming.
29. What does ARM7TDMI controller comprise of?
LPC 2148 Pro Development Board is a powerful development platform based on
LPC2148 ARM7TDMI micro controller with 512k on-chip memory.

Dr. Archana B, Department of CSE, VVIET, Page 54


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

30. What is UART?


A UART is a Univeral Asynchronous Receiver and Transmitter – it is an electronic circuit
which handles communication over an asynchronous serial interface .
31. What rate can define the timing in the UART?
The timing is defined by the baud rate in which both the transmitter and receiver are
used. The baud rate is supplied by the counter or an external timer called baud rate
generator which generates a clock signal.
32. What is Stepper Motor?
A stepper motor is a brushless, synchronous electric motor that converts digital pulses into
mechanical shaft rotation. Every revolution of the stepper motor is divided into a discrete
number of steps, and the motor must be sent a separate pulse for each step.
33. What is an LED? What are it uses?
Light Emitting Diodes (LED) is the most commonly used components, usually for
displaying pins digital states. Typical uses of LEDs include alarm devices, timers and
confirmation of user input such as a mouse click or keystroke.
34. Which are the different stepping modes of a stepper motor?
1. Wave step
2. Full step
3. Half step
4. Micro stepping
35. 7-Segment Display Segments for all Numbers:

35. How many LEDs are used in 7 segment display?


There are 7 LEDs used in a 7 segment display. 7 segment displays are used for displaying
decimal numerals which are comparatively convenient to dot matrix displays.

Dr. Archana B, Department of CSE, VVIET, Page 55


Mysuru
Microcontroller and Embedded Systems Laboratory (21CS43)

36. What is DP in 7 segment display?


The segments of a 7-segment display are referred to by the letters A to G, where the
optional decimal point (an "eighth segment", referred to as DP) is used for the display of
non-integer numbers.
37. What is an Embedded system? Explain.
An embedded system can be thought of as a computer hardware system having software
embedded in it. An embedded system can be an independent system or it can be a part of
a large system. An embedded system is a microcontroller or microprocessor based system
which is designed to perform a specific task. For example, a fire alarm is an embedded
system; it will sense only smoke.
An embedded system has three components −
1. It has hardware.
2. It has application software.
3. It has Real Time Operating system (RTOS) that supervises the application software
and provide mechanism to let the processor run a process as per scheduling by following a
plan to control the latencies. RTOS defines the way the system works. It sets the rules
during the execution of application program. A small scale embedded system may not have
RTOS.

Dr. Archana B, Department of CSE, VVIET, Page 56


Mysuru

You might also like