KEMBAR78
r20 - Ece - MPMC Lab Manual | PDF
0% found this document useful (0 votes)
99 views72 pages

r20 - Ece - MPMC Lab Manual

Uploaded by

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

r20 - Ece - MPMC Lab Manual

Uploaded by

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

LAKIREDDY BALI REDDY COLLEGE OF ENGINEERING

(AUTONOMOUS)
L.B.Reddy Nagar, Mylavaram – 521 230.
Affiliated to JNTUK, Kakinada & Approved by AICTE, New Delhi
NAAC Accredited with “A” grade, Accredited by NBA
Certified by ISO 9001-2008
1. Course Code : 20EC59
2. Course Title : Microprocessors & Microcontrollers Lab
3. Core / Elective : Core
4. Pre–requisite : Digital Logic Circuits
5. Year in which offered : III Year B.Tech, ECE-VI SEM

6. No. of weeks of instruction : 17


7. No. of hours per week : 3 periods

Pre requisite: Digital Logic Circuits


Course Educational Objective:
In this course student will learn about the architecture of 8086 Microprocessor, 8051 Microcontroller and
ARM, programming using assembler language, interfacing of devices for real time applications.

COURSE OUTCOMES (COs): At the end of the course, students are able to

CO 1 : Demonstrate the MASM/TASM tool for developing Assembly Language Programs.


(Understand–L2)
CO 2 : Apply the Assembly Language instructions of Processor and Controller for logical operations.
(Apply–L3)
CO 3 : Develop the ARM based interfacing systems for Real time applications. (Apply – L3)

CO4 : Adapt effective communication, presentation and report writing skills. (Apply – L3)

COURSE ARTICULATION MATRIX:

Cos PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3

CO1 1 2 3 2 2 - - - - - - - - 1 -
CO2 3 3 2 2 2 - - - - - - - - 2 -
CO3 2 3 3 3 3 - - - - - - - - 3 -

Note: 1- Slight (Low), 2 – Moderate (Medium), 3 - Substantial (High), no correlation ‘-’


Prescribed Syllabus:

List of Experiments:
Part – 1:
Programming using MASM:
1. Display, comparison and reverse the string.
2. Factorial using Procedures.
3. Sorting the signed and unsigned numbers.
4. Checking the given string for Palindrome.

Programming using 8051:


5. Arithmetic operations like Addition, Subtraction, Multiplication and Division.
6. Byte checking by using 8051
7. Addition of series of numbers
8. Checking the given numbers for Odd or Even

Part – II: Interfacing using ARM:


1. Interfacing of A/D and D/A converter
2. Interfacing of LEDs and Switches
3. Interfacing of LCD
4. Interfacing of Stepper Motors
5. Interfacing of traffic Light controller
6. Interfacing of Real Time Clock
7. Data loggers – Rollover display

Note: Minimum of 6 experiments from each part to be conducted.


10. List of equipment and soft ware tools used:
1. Computer systems :P-IV @3GHz, 256MB, 20GBHDD
2. Microprocessor 8086 trainer kits
3. Micro controller 8051 trainer kits
4. Interfacing modules : Dual DAC, Dual ADC & Stepper Motor
8251-USART, 8259-Interrupt controller,
8279 Keyboard display,
5. MASM/TASM software Tool : (open Source) :Version 5.10
6. 8086 & 8051 DEBUGGER: : (open Source) Version 2.0
7. Cathode Ray Oscilloscope :30MHz
INDEX

Ex. No DATE NAME OF THE EXPERIMENT Marks Signature

Programming using MASM:

1. Display, comparison and reverse the string.

2. Factorial using Procedures.

3. Sorting the signed and unsigned numbers.

4. Checking the given string for Palindrome.

Programming using 8051:


Arithmetic operations like Addition, Subtraction,
5.
Multiplication and Division.
6. Byte checking by using 8051

7. Addition of series of numbers

8. Checking the given numbers for Odd or Even

Part – II: Interfacing using ARM:

9. Interfacing of A/D and D/A converter

10. Interfacing of LEDs and Switches

11. Interfacing of LCD

12. Interfacing of Stepper Motors

13. Interfacing of traffic Light controller

14. Interfacing of Real Time Clock

15. Data loggers – Rollover display

Day to Day Evolution Marks Obtained

Number of Experiments Done

Average Marks Obtained


EXPT. NO : 1(a)
DISPLAY STRING ON THE MONITOR
DATE :

AIM :Write an ALP to implement Display string on the monitor.

COMPONENTS & TOOLS REQUIRED :


1 Computer system,
2 MASM / TASM SOFTWARE

PROGRAM:
DATA SEGMENT
MESSAGE DB ' COLLEGE $ '
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX ;Initialize DS register
LEA DX, MESSAGE ;EA of message will move to DX register
MOV AH, 09H ;to display a string
INT 21H ;DOS Interrupt service routine
MOV AH, 4CH ;return to DOS prompt
INT 21H
CODE ENDS ; end of code segment
END START

EXPECTED RESULTS:

COLLEGE should be displayed on the screen.

CONCLUSION:
String “COLLEGE” is displayed on the screen.
EXPT. NO : 1(b)
STRING COMPARISION
DATE :

AIM: Write an ALP to implement String comparison (Pass word checking) .


COMPONENTS & TOOLS REQUIRED:
1 Computer system,
2 MASM / TASM SOFTWARE
PROGRAM:
DATA SEGMENT
PASSWORD DB 'LBRCE'
NEWSTR DB 'LRBCE' / 'LBRCE'
CNT DB 05H
STR1 DB 'THE GIVEN STRING IS VALID$'
STR2 DB 'THE GIVEN STRING IS INVALID$'
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA, ES: DATA
START: MOV AX, DATA
MOV DS, AX
MOV ES, AX
MOV CL, CNT
LEA SI, PASSWORD
LEA DI, NEWSTR
REP CMPSB
JNZ L1
LEA DX, STR1
JMP L2
L1: LEA DX, STR2
L2: MOV AH, 09H
INT 21H
INT 3
CODE ENDS
END START

EXPECTED RESULTS:
INPUT: PSCMR
PSRCMR
OUTPUT: THE GIVEN STRING IS INVALID

INPUT: PSCMR
PSCMR
OUTPUT: THE GIVEN STKRING IS VALID

CONCLUSION:
The given two strings are compared and displayed the GIVEN STRING IS EQUAL if they are
equal.

ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS


MOV SI,2400
MOV DI,2450
MOV CX,0006
CLD
REPZ
CMPSB
MOV BX, 2500
MOV AH,00
JZ L1
MOV AH,0FF
L1 MOV [BX],AH
INT 3
EXPT. NO : 1(c)
REVERSE THE STRING
DATE :

AIM :Write an ALP to implement Reverse the string.

COMPONENTS & TOOLS REQUIRED :


2.1 Computer system,
2.2 MASM / TASM SOFTWARE

PROGRAM: -REVERSE THE STRING


DATA SEGMENT
MAX EQU 0050H
STR DB MAX DUP(?)
REV DB MAX DUP(?)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX ; Initialize DS register
MOV AH, 3FH ; DOS read from handle function
MOV BX, 0 ; Standard input handle
MOV CX, MAX ; Read up to max. number of char. to reverse
MOV DX, OFFSET STR ; Store the string here
INT 21H ; Get the string
AND AX, AX ; Were any characters read
JZ DONE ; No so done
MOV CX, AX ; Put string length in CX
PUSH CX ; Save the string length
MOV BX, OFFSET STR
MOV SI, OFFSET REV ; Reverse string
ADD SI, CX ; Point to the end of the reverse string buffer
DEC SI
RS: MOV AL, [BX] ; Get the next character
MOV [SI], AL ; Store the next character in reverse order
INC BX ; Point to next character
DEC SI ; Point to previous location in reverse buffer
LOOP RS ; move next character, if any
POP CX ; get back the string length
MOV AH, 40H ; DOS write, from handle function
MOV BX, 1 ; Standard output handle
MOV DX, OFFSET REV
INT 21H ; Print the reverse string
DONE: MOV AH, 4CH ; DOS terminate program function
INT 21H ; Terminate the program
CODE ENDS
END START

EXPECTED RESULTS:
INPUT: FIATH
OUTPUT: HTAIF

CONCLUSION:
The given string entered from keyboard is reversed and displayed on the screen.

Signature of the In – Charge: Date:


EXPT. NO : 2
FACTORIAL USING PROCEDURES
Date:

AIM :Write an ALP to implement Factorial using recursive procedure.

COMPONENTS & TOOLS REQUIRED :


1. Computer system,
2. MASM / TASM SOFTWARE
THEORY:
A recursive procedure is a procedure, which calls itself. This seems simple enough, but the question
you may be thinking is, “Why would we want a procedure to call itself?” The answer is that certain
types of problems, such as choosing the next move in a computer chess program, can best be solved
with a recursive procedure. Recursive procedures are often used to work with complex data structures
called trees. We usually write recursive procedures in a high-level language such as C or Pascal,
except in those cases where we need the speed gained by writing in assembly language. However, the
assembly language example in the following sections should help you understand how recursion
works and how th stack is used by recursive and other nested procedures
ALGORITHM:
To find the factorial of a number N, the basic algorithm can be expressed very simply as
IF N = 1 THEN factorial = 1,
ELSE factorial = N x (factorial of N – 1)
The procedure to compute the factorial of N is
PROCEDURE FACTO
IF N = 1
FACTORIAL = 1
RET
ELSE
REPEAT
DECRMENT N
CALL FACTO
UNTIL N = 1
MULTIPLY (N-1)! X PREVIOUS N
RET
PROGRAM:
1. Factorial using Procedure:
DATA SEGMENT
NUMBER EQU 08
DATA ENDS

STACK_SEG SEGMENT STACK


DW 200 DUP (0)
TOP_STACK LABEL WORD
STACK_SEG ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA, SS: STACK_SEG
START: MOV AX, STACK_SEG ; Initialize SS register
MOV SS, AX
MOV SP, OFFSET TOP_STACK
SUB SP, 0004H ; Make space in stack for factorial
MOV AX, NUMBER ; Put number to AX passed on to stack
PUSH AX
CALL FACTO ; Compute factorial of a given number
ADD SP, 2
POP AX
POP DX
INT3
FACTO PROC NEAR
PUSHF ; Save flags and registers
PUSH AX
PUSH DX
PUSH BP ; Point BP to top of stack
MOV BP, SP
MOV AX, [BP+10]
CMP AX, 0001H ; If number <> 1 then proceed
JNE GO_ON ; and compute factorial
MOV WORD PTR [BP+12], 0001H ; Else load factorial of one in stack
MOV WORD PTR [BP+14], 0000H ;and return to main line
JMP EXIT
GO_ON: SUB SP, 0004H ; Move space in stack for preliminary factorial
DEC AX ; Decrement number in AX
PUSH AX
CALL FACTO ; Compute factorial of number-1
MOV BP, SP ; Point BP at top of stack
MOV AX, [BP+02] ; Last (n-1)! from stack to multiply by previous n
MUL WORD PTR [BP+16]
MOV [BP+18], AX ; Copy new factorial to stack
MOV [BP+20], DX
ADD SP, 0006H ; Point stack pointer to push together
EXIT: POP BP
POP DX
POP AX
POPF
RET
FACTO ENDP
CODE ENDS
END START
2. Factorial using general Instructions:
DATA SEGMENT

NUM DW 5

FACT DW ?

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START: MOV AX,DATA

MOV DS,AX

MOV AX,NUM

MOV CX,NUM

DEC CX

REPEAT: MUL CX

LOOP REPEAT

MOV FACT,AX
MOV AH,4CH

INT 21H

CODE ENDS

END START

EXPECTED RESULTS:

INPUT: N =5 OUTPUT: 120 DECIMAL

CONCLUSION:
Using recursive procedure, the factorial of given N number is found.

Signature of the In – Charge: Date


EXPT. NO : 3
SORTING
Date:

AIM : Write an ALP to implement sorting .

COMPONENTS & TOOLS REQUIRED :


1. Computer system,
2. MASM / TASM SOFTWARE

THEORY:
The following instructions are used for the signed and unsigned operations:

SIGNED UNSIGNED

ASCENDING ORDER JLE JBE

DESCENDING ORDER JGE JAE

PROGRAM: SORTING

DATA SEGMENT
COUNT DB 05H
NUM DB 89H, 0B4H, 94H, 02H, 0AH
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX ; Initialize DS register
MOV BL, COUNT ; Count loaded in to BL reg
DEC BL ; Decrement BL
L3: LEA SI, NUM ;
MOV CL, BL ;
L2: MOV AL, [SI] ; Move the element to AL register
INC SI ; next element
CMP AL, [SI] ; Comp. AL with the element in array pointed by SI
JLE L1
XCHG AL, [SI] ; If AL not smaller, then exchange the elements
DEC SI
MOV [SI], AL ;
INC SI
L1: DEC CL
JNZ L2
DEC BL
JNZ L3
INT 3 ; Breaking Interrupt
CODE ENDS
END START

EXPECTED RESULTS:

UNSIGNED NUMBERS:
INPUT: 2500: 05H (NUMBER OF ELEMENTS)

2501: 9A
2502: 08
2503: 93
2504: 34
2505: 01

OUTPUT: 2501: 01
2502: 08
2503: 34
2504: 93
2505: 9A

SIGNED NUMBERS:
INPUT: 2500: 05H (NUMBER OF ELEMENTS)

2501: 9A
2502: E0
2503: FF
2504: 34
2505: 01

OUTPUT: 2501: 9A
2502: E0
2503: FF
2504: 01
2505: 34

CONCLUSION:
The given numbers are sorted in Ascending order for both signed and unsigned and stored in the same
locations.

Signature of the In – Charge: Date


EXPT. NO : 4
PALINDROME
Date:

AIM : Write an ALP to find given string is palindrome or not.

COMPONENTS & TOOLS REQUIRED :


1. Computer system,
2. MASM / TASM SOFTWARE

PROGRAM:
DATA SEGMENT
M1 DB 10, 13, 'Enter the string : $'
M2 DB 10, 13, 'String is palindrome $'
M3 DB 10, 13, 'String is not palindrome $'
BUFF DB 80
DB 0
DB 80 DUP (0)
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, data
MOV DS, AX
MOV AH, 09H ; Display message M1
MOV DX, OFFSET M1
INT 21H
MOV AH, 0AH ; input the string
LEA DX, BUFF
INT 21H
LEA BX, BUFF+2
MOV CH, 00H
MOV CL, BUFF+1
MOV DI, CX
DEC dI
SAR CL, 1
MOV SI, 00H
BACK: MOV AL, [BX + DI] ; Get the right most character
MOV AH, [BX + SI] ; Get the left most character
CMP AL, AH
JNZ LAST
DEC DI
INC SI
DEC CL
JNZ BACK
MOV AH, 09H ; Display message 2
MOV DX, OFFSET M2
INT 21H
JMP TER
LAST: MOV AH, 09H
MOV DX, OFFSET M3 ; Display message 3
INT 21H
TER: MOV AH, 4CH
INT 21H
CODE ENDS
END START

EXPECTED RESULTS:

INPUT: LIRIL

OUTPUT: THE GIVEN STRING IS PALINDROME

Signature of the In – Charge: Date


EXPT. NO : 5(a)
ADDITION OF TWO 32-BIT NUMBERS
DATE:

AIM : Write 8051 program to implement Multi byte addition.

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)
THEORY: Generally 8-bits are called a byte, 16-bits are called a word, 32-bits are called a double
word. The data more than 4 bytes is called a multi byte. Here, we are adding two multi bytes which are
stored in the registers. By using the instruction ADDC, we can add byte by byte.
PROGRAM:

ADDITION OF TWO 32-BIT NUMBERS; RESULT 32-BIT

ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS


MOV A, R0
ADD A, R4
MOV R0, A
MOV A, R1
ADDC A, R5
MOV R1, A
MOV A, R2
ADDC A, R6
MOV R2, A
MOV A, R3
ADDC A, R7
MOV R3, A
HERE: LJMP HERE

EXPECTED RESULTS:

INPUT: R3, R2, R1, R0 = X


R7, R6, R5, R4 = Y
OUTPUT: R3, R2, R1, R0 = Signed Sum S = X + Y
INPUT:
INPUT OUTPUT
[R0] = 45 [R0] = 67
[R1] = 58 [R1] = 04
[R2] = 7A [R2] = B7
[R3] = 2D [R3] = 4B

[R4] = 22
[R5] = AC
[R6] = 3C
[R7] = 1E

CONCLUSION: The Multi Byte Addition is performed by using 8051 instructions.


EXPT. NO : 5 (b)
SUBTRACTION OF 2 32-BIT NUMBERS
DATE:

AIM : Write 8051 program to implement two 32-bit numbers..

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)

THEORY: Generally 8-bits are called a byte, 16-bits are called a word and 32-bits are called a double
word. The data more than 4 bytes is called a multi byte. Here, we are subtracting two multi bytes
which are stored in the registers. By using the instruction SUBB, we can subtract byte by byte.

PROGRAM:
SUBTRACTION OF TWO 32-BIT NUMBERS; RESULT 32-BIT
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
CLR C
MOV A, R0
SUBB A, R4
MOV R0, A
MOV A, R1
SUBB A, R5
MOV R1, A
MOV A, R2
SUBB A, R6
MOV R2, A
MOV A, R3
SUBB A, R7
MOV R3, A
HERE: LJMP HERE

EXPECTED RESULTS:

INPUT: R3, R2, R1, R0 = X


R7, R6, R5, R4 = Y

OUTPUT: R3, R2, R1, R0 = Signed Difference D = X – Y

INPUT OUTPUT
[R0] = 45 [R0] = 23
[R1] = 58 [R1] = AC
[R2] = 7A [R2] = 3D
[R3] = 2D [R3] = 0F

[R4] = 22
[R5] = AC
[R6] = 3C
[R7] = 1E

CONCLUSION: The Multi Byte Addition is performed by using 8051 instructions.


EXPT. NO : 5 (c)
MULTIPLICATION
DATE:

AIM :Write 8051 program to implement Multiplication.

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)
THEORY:
After multiplication, if it is 16 bit multiplication, the result will be stored in A and B registers and if
it is 8 bit multiplication, the result will be stored in A register.
PROGRAM:
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DPTR, #9001
MOVX A, @DPTR
MOV 0F0, A
MOV DPTR, #9000
MOVX A, @DPTR
MUL AB
MOV DPTR, #9002
MOVX @DPTR, A
INC DPTR
MOV A, 0F0
MOVX @DPTR, A
LJMP 0

EXPECTED RESULTS:
INPUT OUTPUT
[9000] = FF [9002] = 01
[9003] = FE
[9001] = FF
CONCLUSION: The Multiplication of two numbers is performed by using 8051 instructions.
EXPT. NO : 5(d) (d)
DIVISION
DATE:

AIM : Write 8051 program to implement division operation.


COMPONENTS & TOOLS REQUIRED :
1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)
THEORY:
After Division, the Quotient be stored in A and the Reminder will be stored in B register.
PROGRAM:
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DPTR, 9001
MOVX A, @DPTR
MOV 0F0, A
DEC 82
MOVX A, @DPTR
DIV AB
INC DPTR
INC DPTR
MOVX @DPTR, A
INC DPTR
MOV A, F0
MOVX @DPTR, A
HERE: LJMP HERE
EXPECTED RESULTS:
INPUT OUTPUT
[9000] = 19 [9002] = 05
[9003] = 00
[9001] = 05
CONCLUSION: The Division of two numbers is performed by using 8051 instructions.

Signature of the In – Charge: Date


EXPT. NO : 6
BYTE CHECKING
DATE:

AIM : Write 8051 program to implement Byte Checking..

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)
THEORY: In the given byte checking the 5th bit is '1' or '0'. If the 5th bit is '1' 00 should be stored in
8901H data memory or if it is '0' FF should be stored in 8901H data memory.
PROGRAM:
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DPTR, #8900
MOVX A, @DPTR
INC DPTR
RLC A
RLC A
RLC A
JC LOOP
MOV A, #FF
MOVX @DPTR, A
LJMP 0
LOOP: MOV A, #00
MOVX @DPTR, A
LJMP 0
EXPECTED RESULTS:

INPUT OUTPUT
[8900] = 35 [8901] = 00
INPUT OUTPUT
[8900] = 15 [8901] = FF
CONCLUSION: The multi Byte addition is performed by using 8051 instructions.

Signature of the In – Charge: Date


EXPT. NO : 7
ADDITION OF SERIES OF NUMBERS
DATE:

AIM : Write 8051 program to find the sum of the elements in an Array.

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)

THEORY:
To add the numbers of an 8-bit array, the array length being the first element in the array and store the
result in memory. The numbers are stored in consecutive locations in memory. Addition has to be
performed for the number of times decided by the length of the array. Since the sum may exceed 8-
bits, it is necessary to monitor the carry flag status. Indexed addressing employing the 16-bit Base
register DPTR is used in this program.

EXAMPLE:
The array starts at 4201. The address location 4200 contains the number of elements in that array. The
result is to be stored at 4500 and 4501.

Sample Data:
INPUT OUTPUT
[4200] = 03 (count) [4500] = 00 (MSB)
[4501] = 06 (LSB)
[4201] = 01
[4202] = 02
[4203] = 03

ALGORITHM:
i. Enter the below op codes and data from 4100 and 4200 respectively
ii. Execute the program
iii. Check for result at 4500 and 4501
iv. Change data at 4200 and check for results
PROGRAM:
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DPTR, #4200
MOVX A, @DPTR
MOV R0, A
MOV B, #00
MOV R1, B
ADD: CLR C
INC DPTR
MOVX A, @DPTR
ADD A, B
MOV B, A
JNC NC
INC R1
NC: DJNZ R0, ADD
MOV DPTR, #4500
MOV A, R1
MOVX @DPTR, A
INC DPTR
MOV A, B
MOVX @DPTR, A
HLT: SJMP HLT
EXPECTED RESULTS:
INPUT OUTPUT
[4200] = 03 (count) [4500] = 00 (MSB)
[4201] = 01 [4501] = 06 (LSB)
[4202] = 02
[4203] = 03
CONCLUSION:
The Sum of elements in an array is performed by using 8051 instructions.

Signature of the In – Charge: Date


EXPT. NO : 8
CHECKING THE GIVEN NUMBERS FOR ODD OR EVEN
DATE:

AIM : Write 8051 program to find the sum of the elements in an Array.

COMPONENTS & TOOLS REQUIRED :


1. Microcontroller 8031/51 Trainer Kit,
2. Power supply (5V, 3A)

THEORY:
To add the numbers of an 8-bit array, the array length being the first element in the array and store the
result in memory. The numbers are stored in consecutive locations in memory. Addition has to be
performed for the number of times decided by the length of the array. Since the sum may exceed 8-
bits, it is necessary to monitor the carry flag status. Indexed addressing employing the 16-bit Base
register DPTR is used in this program.

EXAMPLE:
The array starts at 4201. The address location 4200 contains the number of elements in that array. The
result is to be stored at 4500 and 4501.

Sample Data:
INPUT OUTPUT
[4200] = 03 (count) [4500] = 00 (MSB)
[4501] = 06 (LSB)
[4201] = 01
[4202] = 02
[4203] = 03

ALGORITHM:
i. Enter the below op codes and data from 4100 and 4200 respectively
ii. Execute the program
iii. Check for result at 4500 and 4501
iv. Change data at 4200 and check for results
PROGRAM:
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
EXPECTED RESULTS:
INPUT OUTPUT
[4200] = 03 (count) [4500] = 00 (MSB)
[4201] = 01 [4501] = 06 (LSB)
[4202] = 02
[4203] = 03
CONCLUSION:
The Sum of elements in an array is performed by using 8051 instructions.

Signature of the In – Charge: Date


EXPT. NO: 9
INTERFACING OF A/D AND D/A CONVERTER
DATE:
AIM:
To write and execute the program for A/D and D/A converter with ARM7 (LPC2148)
processor.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 ARM Processor 1
2 RS232/USB Connector 1
3 10-bit ADC 1

4 Power Supply (5V, DC) 1

THEORY:
Analog to Digital Converter(ADC) is used to convert analog signal into digital form. LPC2148 has
two inbuilt 10-bit ADC i.e. ADC0 & ADC1.
 ADC0 has 6 channels &ADC1 has 8 channels.
 Hence, we can connect 6 distinct types of input analog signals to ADC0 and 8 distinct types of
input analog signals to ADC1.
 ADCs in LPC2148 use Successive Approximation technique to convert analog signal into
digital form.
 This Successive Approximation process requires a clock less than or equal to 4.5 MHz. We can
adjust this clock using clock divider settings.
 Both ADCs in LCP2148 convert analog signals in the range of 0V to VREF (typically 3V; not
to exceed VDDA voltage level).

ARM LPC4128 ADC Pins:

AD0.1:4, AD0.6:7 & AD1.7:0 (Analog Inputs)

These are Analog input pins of ADC. If ADC is used, signal level on analog pins must not be above
the level of VDDA; otherwise, ADC readings will be invalid. If ADC is not used, then the pins can be
used as 5V tolerant digital I/O pins.

VREF (Voltage Reference)

Provide Voltage Reference for ADC.

VDDA& VSSA (Analog Power and Ground)

These are the power and ground pins for ADC. These should be same as VDD & VSS.
Let’s see the ADC registers which are used to control and monitors the ADC operation.

Here, we will see ADC0 registers and their configurations. ADC1 has similar registers and can be
configured in a similar manner.

ADC0 Registers Configuration

1. AD0CR (ADC0 Control Register)

 AD0CR is a 32-bit register.


 This register must be written to select the operating mode before A/D conversion can occur.
 It is used for selecting channel of ADC, clock frequency for ADC, number of clocks or number
of bits in result, start of conversion and few other parameters.

AD0CR (ADC0 Control Register)


 Bits 7:0 – SEL
These bits select ADC0 channel as analog input. In software-controlled mode, only one of
these bits should be 1.e.g. bit 7 (10000000) selects AD0.7 channel as analog input.
 Bits 15:8 – CLKDIV
The APB(ARM Peripheral Bus)clock is divided by this value plus one, to produce the clock
for ADC.
This clock should be less than or equal to 4.5MHz.
 Bit 16 – BURST
0 = Conversions are software controlled and require 11 clocks
1 = In Burst mode ADC does repeated conversions at the rate selected by the CLKS field for
the analog inputs selected by SEL field. It can be terminated by clearing this bit, but the
conversion that is in progress will be completed.
When Burst = 1, the START bits must be 000, otherwise the conversions will not start.
 Bits 19:17 – CLKS
Selects the number of clocks used for each conversion in burst mode and the number of bits of
accuracy of Result bits of AD0DR.
e.g. 000 uses 11 clocks for each conversion and provide 10 bits of result in
corresponding ADDR register.
000 = 11 clocks / 10 bits
001 = 10 clocks / 9 bits
010 = 9 clocks / 8 bits
011 = 8 clocks / 7 bits
100 = 7 clocks / 6 bits
101 = 6 clocks / 5 bits
110 = 5 clocks / 4 bits
111 = 4 clocks / 3 bits
 Bit 20 – RESERVED
 Bit 21 – PDN
0 = ADC is in Power Down mode
1 = ADC is operational
 Bit 23:22 – RESERVED
 Bit 26:24 – START
When BURST bit is 0, these bits control whether and when A/D conversion is started
000 = No start (Should be used when clearing PDN to 0)
001 = Start conversion now
010 = Start conversion when edge selected by bit 27 of this register occurs on
CAP0.2/MAT0.2 pin
011= Start conversion when edge selected by bit 27 of this register occurs on CAP0.0/MAT0.0
pin
100 = Start conversion when edge selected by bit 27 of this register occurs on MAT0.1 pin
101 = Start conversion when edge selected by bit 27 of this register occurs on MAT0.3 pin
110 = Start conversion when edge selected by bit 27 of this register occurs on MAT1.0 pin
111 = Start conversion when edge selected by bit 27 of this register occurs on MAT1.1 pin
 Bit 27 – EDGE
This bit is significant only when the Start field contains 010-111. In these cases,
0 = Start conversion on a rising edge on the selected CAP/MAT signal
1 = Start conversion on a falling edge on the selected CAP/MAT signal
 Bit 31:28 – RESERVED

2. AD0GDR (ADC0 Global Data Register)

 AD0GDR is a 32-bit register.


 This register contains the ADC’s DONE bit and the result of the most recent A/D conversion.

A
D0GDR (ADC0 Global Data Register)
 Bit 5:0 – RESERVED
 Bits 15:6 – RESULT
When DONE bit is set to 1, this field contains 10-bit ADC result that has a value in the range
of 0 (less than or equal to VSSA) to 1023 (greater than or equal to VREF).
 Bit 23:16 – RESERVED
 Bits 26:24 – CHN
These bits contain the channel from which ADC value is read.
e.g. 000 identifies that the RESULT field contains ADC value of channel 0.
 Bit 29:27 – RESERVED
 Bit 30 – Overrun
This bit is set to 1 in burst mode if the result of one or more conversions is lost and overwritten
before the conversion that produced the result in the RESULT bits.
This bit is cleared by reading this register.
 Bit 31 – DONE
This bit is set to 1 when an A/D conversion completes. It is cleared when this register is read
and when the AD0CR is written.
If AD0CR is written while a conversion is still in progress, this bit is set and new conversion is
started.

3. ADGSR (A/D Global Start Register)

 ADGSR is a 32-bit register.


 Software can write to this register to simultaneously start conversions on both ADC.

A
DGSR (A/D Global Start Register)
 BURST (Bit 16), START (Bit <26:24>) & EDGE (Bit 27)
These bits have same function as in the individual ADC control registers i.e. AD0CR &
AD1CR. Only difference is that we can use these function for both ADC commonly from this
register.

4. AD0STAT (ADC0 Status Register)

 AD0STAT is a 32-bit register.


 It allows checking of status of all the A/D channels simultaneously.

AD0STAT (ADC0 Status Register)


 Bit 7:0 – DONE7:DONE0
These bits reflect the DONE status flag from the result registers for A/D channel 7 - channel 0.
 Bit 15:8 – OVERRUN7:OVERRUN0
These bits reflect the OVERRUN status flag from the result registers for A/D channel 7 -
channel 0.
 Bit 16 – ADINT
This bit is 1 when any of the individual A/D channel DONE flags is asserted and enables ADC
interrupt if any of interrupt is enabled in AD0INTEN register.
 Bit 31:17 – RESERVED

5. AD0INTEN (ADC0 Interrupt Enable)

 AD0INTEN is a 32-bit register.


 It allows control over which channels generate an interrupt when conversion is completed.

AD0INTEN (ADC0 Interrupt Enable)


 Bit 0 – ADINTEN0
0 = Completion of a A/D conversion on ADC channel 0 will not generate an interrupt
1 = Completion of a conversion on ADC channel 0 will generate an interrupt
 Remaining ADINTEN bits have similar description as given for ADINTEN0.
 Bit 8 – ADGINTEN
0 = Only the individual ADC channels enabled by ADINTEN7:0 will generate interrupts
1 = Only the global DONE flag in A/D Data Register is enabled to generate an interrupt

6. AD0DR0-AD0DR7 (ADC0 Data Registers)

 These are 32-bit registers.


 They hold the result when A/D conversion is completed.
 They also include flags that indicate when a conversion has been completed and when a
conversion overrun has occurred.

A
D0 Data Registers Structure
 Bit 5:0 – RESERVED
 Bits 15:6 – RESULT
When DONE bit is set to 1, this field contains 10-bit ADC result that has a value in the range
of 0 (less than or equal to VSSA) to 1023 (greater than or equal to VREF).
 Bit 29:16 – RESERVED
 Bit 30 – Overrun
This bit is set to 1 in burst mode if the result of one or more conversions is lost and overwritten
before the conversion that produced the result in the RESULT bits.
This bit is cleared by reading this register.
 Bit 31 – DONE
This bit is set to 1 when an A/D conversion completes. It is cleared when this register is read.

PROCEDURE
1. Create a New project, Go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project Create New Project Select Device
for Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a program on the editor window and save as “Main.c”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files”.
8. Open Flash magic and select the device LPC2148 in ARM 7 category, COM
port will be COM 3, baud rate 9600, interface None [ISP], Oscillator frequency
12.0 MHz and click on erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware Kit and click on start then device
will start to program
11. Finally can be see the finished indication and values in SPJ Terminal and
Reset the device into running mode.

Steps for Analog to Digital Conversion

1. Configure the ADxCR (ADC Control Register) according to the need of application.
2. Start ADC conversion by writing appropriate value to START bits in ADxCR. (Example,
writing 001 to START bits of the register 26:24, conversion is started immediately).
3. Monitor the DONE bit (bit number 31) of the corresponding ADxDRy (ADC Data Register)
till it changes from 0 to 1. This signals completion of conversion. We can also monitor DONE
bit of ADGSR or the DONE bit corresponding to the ADC channel in the ADCxSTAT
register.
4. Read the ADC result from the corresponding ADC Data Register.
ADxDRy. E.g. AD0DR1 contains ADC result of channel 1 of ADC0.

Read Analog Voltage using LPC2148


Let’s write a program to convert input voltage signal on AD0.1 (P0.28) into digital signal. We will
convert the digital value to equivalent voltage value and display it on an LCD. We can compare this
voltage with actual voltage measured on a digital multimeter.
A/D converter INTERFACING:

CIRCUIT DIAGRAM:

PROGRAM:
#include <lpc214x.h>
#include <stdint.h>
#include "LCD-16x2-8bit.h"
#include <stdio.h>
#include <string.h>

int main(void)
{
uint32_t result;
float voltage;
char volt[18];
LCD_Init();
PINSEL1 = 0x01000000; /* P0.28 as AD0.1 */
AD0CR = 0x00200402; /* ADC operational, 10-bits, 11 clocks for conversion */
while(1)
{
AD0CR = AD0CR | (1<<24); /* Start Conversion */
while ( !(AD0DR1 & 0x80000000) ); /* Wait till DONE */
result = AD0DR1;
result = (result>>6);
result = (result & 0x000003FF);
voltage = ( (result/1023.0) * 3.3 ); /* Convert ADC value to equivalent voltage */
LCD_Command(0x80);
sprintf(volt, "Voltage=%.2f V ", voltage);
LCD_String(volt);
memset(volt, 0, 18);
}
}

Conclusion:

Signature of the In – Charge: Date


EXPT. NO: 10
INTERFACING OF LEDS & SWITCHES
DATE:
AIM:
To write and execute the program for LED & Flashing Led’s with ARM7 (LPC2148)
processor.
HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 ARM Processor 1
2 RS232/USB Connector 1
3 LED Module 1
4 Power Supply (5V, DC) 1

5 Proteus ISIS Software 1

PROCEDURE:

1. Create a New project, Go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project Create New Project Select Device for
Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a program on the editor window and save as “Main.c”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files”.
8. Open Flash magic and select the device LPC2148 in ARM 7 category, COM port
will be COM 3, baud rate 9600, interface None [ISP], Oscillator frequency 12.0
MHz and click on erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware Kit and click on start then device will
start to program
11. Finally can be see the finished indication and values in SPJ Terminal and Reset
the device into running mode.
LED INTERFACING:

CIRCUIT DIAGRAM:

PROGRAM:

To blink LEDS with some delay:


#include<lpc21xx.h>
#define LEDS 0xFFFFFFFF
void delay(unsigned int val);
int main()
{
IODIR1 = LEDS;
IOCLR1 = LEDS;
while(1)
{
IOSET1 = LEDS;
delay(100);
IOCLR1 = LEDS;
delay(100);
}
}
void delay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<val;i++)
for(j=0;j<25000;j++);
}
Conclusion:

Signature of the In – Charge: Date:

VIVA QUESTIONS
FLASHING OF LEDS
1. What is seven segment displays?
2. What are the different configurations of LED?
3. What is the function of GPIO?
4. What are the Pins which are used to connect LEDs?
5. How to identify 'Polarity' of LED?
6. Differentiate LED from LCD.
7. What is a use of Jumper?
8. How many numbers of LEDs present in Primer board?
9. Where LEDs are used?
10. What is the use of flash magic software?
11. Which port is used in ARM 7 processor kit?
12. Which diode suffers an avalanche breakdown?
13. What happens if the junction temperature of LED is increased?
14. What is an anti collision rate light?
15. What is fail-safe conditions.
EXPT. NO: 11
INTERFACING OF LCD
DATE:

AIM:
To write and execute the program for LCD with ARM7 (LPC2148) processor.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 ARM Processor 1
2 RS232/USB Connector 1
3 LCD Module 1
4 Power Supply (5V, DC) 1

5 Proteus ISIS Software 1

THEORY:

Liquid Crystal Display (LCD) is widely used in various electronics’ applications. It is


commonly used in various systems to show different status and parameters. LCD16x2
has 2 lines with 16 characters in each line. Each character is made up of 5x8 (column x
row) pixel matrix.

LCD16x2 Pin Description:

First two pins of LCD16x2 are used for ground and supply (+5 V).
Pin 3 - VEE pin
This pin is used for adjusting the contrast of the display. Voltage on this pin defines
contrast on display, lower the voltage, higher the contrast. We can connect 4.7 k pot
for contrast adjustment or simply connect this pin to ground to get maximum contrast.

Pin 4 –RS: Register Select pin


RS = 0: Data on the D0 to D7 pins is considered as a command.
RS = 1: Data on the D0 to D7 pins is considered as data to display on LCD16x2.
Pin 5 – RW: Read / Write pin
RW = 0: Write data to the LCD
RW = 1: Read data from the LCD
Pin 6 –E: Enable
This pin is used to latch the data present on the data pins D0 to D7. High to low
pulse with a minimum width of 450 ns is required to latch the data to the display.
Pins 7:14 - DATA pins D0 to D7
Data pins are used to send data/command to the LCD16x2 as parallel 8 data bits.
Pin 15:16 - LED + and LED -
Liquid Crystal Displays don’t have their own light like seven segment displays.
Therefore, the module has a backlight LED. Supply to this LED is provided through
these pins.

PROCEDURE:

1. Create a New project, Go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project Create New Project Select Device
for Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a program on the editor window and save as “Main.c”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files”.
8. Open Flash magic and select the device LPC2148 in ARM 7 category, COM port
will be COM 3, baud rate 9600, interface None [ISP], Oscillator frequency 12.0
MHz and click on erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware Kit and click on start then device will
start to program
11. Finally can be see the finished indication and values in SPJ Terminal and
Reset the device into running mode.
INTERFACING LCD:

CIRCUIT
DIAGRAM:

PROGRAM:

#include<lpc21xx.h>
#define LCD_DATA 0xFF<<16
#define RS 1<<24
#define RW 1<<25
#define EN 1<<26
#define LCD (LCD_DATA | RS | RW | EN)
void lcd_init(void);
void lcd_cmd(char ch);
void lcd_data(char ch);
void lcd_str(char str[16]);
void delay(unsigned int val);
int main()
{
IODIR1 = LCD;
IOCLR1 = LCD;
lcd_init();
while(1)
{
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_str("WELCOME TO LBRCE ");
lcd_cmd(0xC5);
lcd_str("ECE DEPARTMENT");
delay(200);
}
}
void lcd_init(void)
{
lcd_cmd(0x38);
lcd_cmd(0x0E);
lcd_cmd(0x0C);
lcd_cmd(0x01);
lcd_cmd(0x80);
}
void lcd_cmd(char ch)
{
IOCLR1=LCD_DATA;
IOSET1=ch<<16;
IOCLR1=RS;
IOCLR1=RW;
IOSET1=EN;
delay(10);
IOCLR1=EN;
}
void lcd_data(char ch)
{
IOCLR1=LCD_DATA;
IOSET1=ch<<16;
IOSET1=RS;
IOCLR1=RW;
IOSET1=EN;
delay(10);
IOCLR1=EN;
}
void lcd_str(char str[16])
{
int k;
for(k=0;k<16;k++)
{
if(str[k]=='\0')
break;
lcd_data(str[k]);
delay(10);
}
}
void delay(unsigned int val)
{
unsigned int i,j;
for(i=0;i<val;i++)
for(j=0;j<25000;j++);
}

LCD LAYOUT:

80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F

C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF

RESULT:

Signature of the In – Charge: Date:

VIVA Questions
1. How many rows and columns are present in a 16 x 2 alphanumeric LCD?
2. How many data lines are there in a 16 x 2 alphanumeric LCD?
3. Which pin of the LCD is used for adjusting its contrast?
4. Which command of an LCD is used to shift the entire display to the right?
5. Which command is used to select the 2 lines and 5 x 7 matrix of an LCD?
6. What changes are to be made to send data to an LCD?
7. For reading operation from an LCD what changes in the software are introduced?
8. Which instruction is used to select the first row first column of an LCD?
EXPT. NO: 12
INTERFACING OF STEPPER MOTOR
DATE:

AIM: To write and execute the program for Stepper Motor with ARM7 (LPC2148) processor.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity


1 ARM Processor 1
2 RS232/USB Connector 1
3 Stepper Motor Module 1
4 Power Supply (5V, DC) 1

Proteus ISIS Software 1

THEORY:
Stepper motor is a brushless DC motor that divides the full rotation angle of 360° into
number of equal steps. The motor is rotated by applying a certain sequence of control
signals. The speed of rotation can be changed by changing the rate at which the control
signals are applied. Various stepper motors with different step angles and torque ratings
are available in the market. Microcontroller can be used to apply different control
signals to the motor to make it rotate according to the need of the application.
Working Principle of Stepper Motor
Current flowing through winding creates magnetic North and South pole on coil. If we
wrap our right-hand fingers around coil in the direction of current flowing through the
coil, then the thumb direction indicates the magnetic North Pole.
Step Angle
Step angle is the minimum angle that stepper motor will cover within one move/step.
Number of steps required to complete one rotation depends upon step angle. E.g. If step
angle is of 45° then 8 steps are required to complete one rotation as shown in figure
below.
Stepper motors are classified depending upon construction and winding arrangement.
 Depending upon winding arrangement
- Unipolar Stepper Motor
- Bipolar Stepper Motor
 Depending upon construction
- Permanent Magnet Stepper Motor
- Variable Reluctance Stepper Motor
- Hybrid Stepper Motor
Stepper motor rotates in steps and for continuous or limited angle rotation we need to
provide sequential steps. Mostly there are two step sequences used to rotate Stepper
Motor as shown in below figure i.e.
 Full Step Sequence
Here motor moves through its basic step angle. At a time two coils are excited.

 Half Step Sequence


Here motor moves half of its basic step angle.
Half step can be achieve by exciting both current and next coil.

Full step sequence

Step A B C D

1 1 0 0 1
2 1 1 0 0

3 0 1 1 0

4 0 0 1 1

PROCEDURE

1. Create a New project, Go to “Project” and close the current project “Close Project”.
2. Next Go to the Project New μvision Project Create New Project Select Device for Target.
3. Select the data base NXP LPC2148.
4. Add Startup file and Next go to “File” and click “New”.
5. Write a program on the editor window and save as “Main.c”.
6. Add this source file to Group and click on “Build Target” or F7.
7. Create a Hex file from “Project” menu and click on “Rebuild all target Files”.
8. Open Flash magic and select the device LPC2148 in ARM 7 category, COM port will
be COM 3, baud rate 9600, interface None [ISP], Oscillator frequency 12.0 MHz and
click on erase of flash code Rd plot.
9. Next browse the path of hex file and select the file.
10. After selecting ISP mode on the Hardware Kit and click on start then device will start
to program
11. Finally can be see the finished indication and values in SPJ Terminal and Reset the
device into running mode.
STEPPER MOTOR: (FORWARD ROTATION)
CIRCUIT DIAGRAM:

PROGRAM:
#include<lpc21xx.h>
#define smotor 0xFFFFFFFF
void delay(unsigned int val);

int main()
{
IODIR0 = smotor;
IODIR1 = smotor;
IOCLR0 = smotor;
IOCLR1 = smotor;

while(1)
{
IOSET0 = 0xFFFFFF1F;
delay(100);
IOCLR0 = 0xFFFFFF1F;

IOSET0 = 0xFFFFFF2F;
delay(100);
IOCLR0 = 0xFFFFFF2F;

IOSET0 = 0xFFFFFF4F;
delay(100);
IOCLR0 = 0xFFFFFF4F;

IOSET0 = 0xFFFFFF8F;
delay(100);
IOCLR0 = 0xFFFFFF8F;
}
}

void delay(unsigned int val)


{
unsigned int
i,j;
for(i=0;i<val;
i++)
for(j=0;j<25000;j++);
}

RESULT:

Signature of the In – Charge: Date

VIVA Questions
1) Define GPIO.
2) What is the function of ULN2803?
3) How LPC2148 control stepper motor?
4) Which I/O port lines used to rotate stepper motor?
5) How stepper motor reacts for each pulse it receives?
6) What is serial communication?
7) What is parallel communication?
8) What is stepper motor & why it is named so?
9) How can be step angle is calculated?
10) What are the advantages and disadvantages of parallel communication?
11) What does instruction-pipelining mean?
12) What is the power supply required for ARM processor?
13) What is a unit for torque?
14) What is RPM rating for a DC motor?
15) What device that is used to obtain an accurate position control of rotating shafts in terms of
steps?
EXPT. NO: 13
P a g e | 54
IMPLEMENTATION OF
TRAFFIC LIGHT CONTROLLER DATE:

AIM:

Create a Keil u vision protect to display 8-Bit LED of LPC 2148 board with traffic light
control using timer with delay by configure timer 0 peripheral of LPC2148.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity

1 ARM Processor 1
2 RS232/USB Connector 1
3 LED Module 1
4 Power Supply (5V, DC) 1

5 ADC Module 1

6 CRO (Or) DSO 1

THEORY:

Traffic Light Control:

Traffic lights, which may also be known as stoplights, traffic lamps, traffic signals, signal
lights, robots or semaphore, are signaling devices positioned at road intersections, pedestrian
crossings and other locations to control competing flows of traffic.
About the colors of Traffic Light Control:

Traffic lights alternate the right of way of road users by displaying lights of a standard color
(red, yellow/amber, and green), using a universal color code (and a precise sequence to enable
comprehension by those who are color blind).

In the typical sequence of colored lights:


 Illumination of the green light allows traffic to proceed in the direction denoted,
 Illumination of the yellow/amber light denoting, if safe to do so, prepare to stop
short of the intersection, and
 Illumination of the red signal prohibits any traffic from proceeding.

Usually, the red light contains some orange in its hue, and the green light contains some blue,
for the benefit of people with red-green color blindness, and “green” lights in many areas are
in fact blue lenses on a yellow light (which together appear green).

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 55

Interfacing Traffic Light with LPC2148:


The Traffic light controller section consists of 12 Nos. point leds are arranged by 4Lanes
in LPC2148 Development Board. Each lane has Go(Green), Listen(Yellow) and
Stop(Red) LED is being placed.
Pin Assignment with LPC2148

PROCEDURE:

1. Read the User Manual of NXP LPC21xx and study the Fast GPIO Peripheral hardware.
2. Launch Keil uVision and create a new uVision project file
3. Target the NXP LPC2148 Microcontroller and add Initializing code as a part of project
4. Set the Target 1 Project options
5. Examine the startup code ‘startup.s’ added as a part of the project.
6. Create an New C Source File and add it as a part of the project.
7. Write a software program to drive the 8bit LEDs on LPC 21xx platform.
8. Compile the Software Program and correct if any errors and again build the target.
9. Connect LPC21xx Target platform board to Host machine.
10. Launch Flash Magic and setup the options.
11. Download the .hex file to Flash Magic tool and Program it.

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 56

PROGRAM:
#include<lpc21xx.h>
void Delay(int); //Delay Routine
void SupDelay(int); //Delay Routine
void main()
{
PINSEL2 = 0x00000000; // P0.0 TO P1.31 as GPIO
IODIR0 = 0xFFFFFFF0; // p0.4 TO P1.31 Configured as Output port.
while(1)
{
//1
IOSET0=0x00044400;
Delay(100);
IOCLR0=0x00044400;

IOSET0=0x00022200;
SupDelay(20);
IOCLR0=0x00022200;

IOSET0=0x00011100;
Delay(100);
IOCLR0=0x00011100;

//2
IOSET0=0x00040440;
Delay(100);
IOCLR0=0x00040440;

IOSET0=0x00020220;
SupDelay(20);
IOCLR0=0x00020220;
IOSET0=0x00010110;
Delay(100);
IOCLR0=0x00010110;

//3
IOSET0=0x00044040;
Delay(100);
IOCLR0=0x00044040;

IOSET0=0x00022020;
SupDelay(20);
IOCLR0=0x00022020;
IOSET0=0x00011010;
Delay(100);
IOCLR0=0x00011010;

//4
IOSET0=0x00004440;
Delay(100);
IOCLR0=0x00004440;

IOSET0=0x00002220;
SupDelay(20);
IOCLR0=0x00002220;
IOSET0=0x00001110;
Delay(100);
IOCLR0=0x00001110;
}
}

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 57

void Delay(int n)
{
int p,q;
for(p=0;p<n;p++)
for(q=0;q<0xFFFF;q++);
}
void SupDelay(int n)
{
int p,q;
for(p=0;p<n;p++)
{
for(q=0;q<0xFFFF;q++);
for(q=0;q<0xFFFF;q++);
}
}

RESULT:

Signature of the In – Charge: Date:

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 58
EXPT. NO : 14
INTERFACING OF REAL TIME CLOCK
DATE :

AIM: Create a Keil u vision protect to interface Real Time Clock using LPC 2148 with built in timer.

HARDWARE & SOFTWARE TOOLS REQUIRED:

S.No Hardware & Software Requirements Quantity

1 ARM Processor 1
2 RS232/USB Connector 1
3 LED Module 1
4 Power Supply (5V, DC) 1

5 ADC Module 1

6 CRO (Or) DSO 1

THEORY:

Real Time Clock (RTC) is a time counter that counts real time continuously.

 We can get present time details using RTC. It gives us time as well as date information.
 RTC is clocked by separate 32.768KHz oscillator to continuously keep track of current time.
 RTC is powered either by main system power or separately by battery backup in absence of main
system power.
 Since RTC needs to be running continuously, it should be provided with battery backup in case of
main system power failure. Otherwise, it can lose present time information.
 We can easily program the RTC with the current date and time information in the case of loss
time and date information due to power failure.
 But this is not a feasible solution in real time systems once they are deployed into the market,
where there are many time constraints on the tasks and timely decision making is important. In
such cases, the RTC must not fail. This makes battery backup of utmost importance.

LPC2148 has an inbuilt RTC. LPC2148RTC can be clocked by a separate 32.768 KHz oscillator or by a
programmable prescale divider based on the APB clock.

 It maintains a calendar and clock and provides seconds, minutes, hours, month, year, day of week,
day of month and day of year.
 It has power supply pin that can be connected to a battery or to the main 3.3V.
 It uses little power in power down mode.
 And most important, it has Alarm functionality.

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 59

ARM LPC2148 RTC Pins:


RTCX1 & RTCX1 (RTC Crystal Pins)
These pins are used to connect RTC external crystal. Generally, 32.768 kHz crystal oscillator is
connected to these pins.
VBAT (RTC Power pin)
Power to the RTC unit is given through this pin. Either it will be from main system power or from battery
backup mechanism.
Now, let’s see RTC Registers that are used to set and control RTC operations.
RTC Registers Configuration:
1. ILR (Interrupt Location Register)

 It is an 8-bit register.
 It specifies which blocks are generating an interrupt.

ILR
(Interrupt Location Register)

 Bit 0 – RTCCIF
When this bit is 1, it means that the counter increment interrupt block generated an interrupt.
Writing a 1 to this bit clears the counter increment interrupt. Writing a 0 has no effect.
 Bit 1 – RTCALF
When this bit is 1, it means that the alarm registers generated an interrupt.
Writing a 1 to this bit clears the alarm interrupt. Writing a 0 has no effect.

2. CTCR (Clock Tick Counter Register)

 It is a 16-bit register.
 It is a read only register.

CTCR (Clock Tick Counter Register)

 It can be reset through the Clock Control Register (CCR).


 It consists of the bits of the clock divide counter.
 Bits 14:1 – Clock Tick Counter
Prior to the seconds counter, the CTC counts 32,768 clocks per second. Due to RTC Prescalar,
these 32,768 time increments may not all be of the same duration.

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 60

3. CCR (Clock Control Register)

 It is an 8-bit register.
 It controls the operation of the clock divide circuit.

CCR (Clock Control Register)

 Bit 0 – CLKEEN (Clock Enable)


0 = Timer counters are disabled. They should be initialized in this condition.
1 = Timer counters are enabled
 Bit 1 – CTRST (CTC Reset)
When 1, elements in CTC (Clock Tick Counter) are reset. The elements remain reset until this bit
is changed to 0.
 Bit 3:2 – CTTEST (Test Enable)
These bits should always be 0 during normal operation.
 Bit 4 – CLKSRC
0 = CTC takes clock from Prescalar
1 = CTC takes clock from 32.768 kHz oscillator

4. CIIR (Counter Increment Interrupt Register)

 It is an 8-bit register.

CIIR (Counter Increment Interrupt Register)

 It provides the option to generate an interrupt every time a counter is incremented.


 This interrupt remains valid until it is cleared by writing a 1 to RTCCIF bit in ILR.
 Bit 0 – IMSEC
When 1, an increment of the Seconds value generates an interrupt.
 Bit 1 – IMMIN
When 1, an increment of the Minutes value generates an interrupt.
 Bit 2 – IMHOUR
When 1, an increment of the Hours value generates an interrupt.
 Bit 3 – IMDOM
When 1, an increment of the Day of Month value generates an interrupt.

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 61

 Bit 4 – IMDOW
When 1, an increment of the Day of Week value generates an interrupt.
 Bit 5 – IMDOY
When 1, an increment of the Day of Year value generates an interrupt.
 Bit 6 – IMMON
When 1, an increment of the Month value generates an interrupt.
 Bit 7 – IMYEAR
When 1, an increment of the Year value generates an interrupt.

5. AMR (Alarm Mask Register)

 It is an 8-bit register.

A
MR (Alarm Mask Register)

 It allows user to mask any of the alarm registers.


 Writing a 1 to any bit in this register masks the corresponding register.
 For alarm function, every non-masked alarm register must match the corresponding time counter
for an interrupt to be generated.
 The interrupt is generated only when the counter comparison first changes from no match to
match.
 The interrupt is removed by writing 1 to the RTCALF bit in ILR.
 If all the bits in this register are set, then the alarm is disabled.
 Bit 0 – AMRSEC
When 1, the Seconds value is not compared for alarm.
 Bit 1 – AMRMIN
When 1, the Minutes value is not compared for alarm.
 Bit 2 – AMRHOUR
When 1, the Hours value is not compared for alarm.
 Bit 3 – AMRDOM
When 1, the Day of Month value is not compared for alarm.
 Bit 4 – AMRDOW
When 1, the Day of Week value is not compared for alarm.
 Bit 5 – AMRDOY
When 1, the Day of Year value is not compared for alarm.
 Bit 6 – AMRMON
When 1, the Month value is not compared for alarm.

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 62

 Bit 7 – AMRYEAR
When 1, the Year value is not compared for alarm.

6. Consolidated Time Registers

 The 3 consolidated time registers together provide an alternative to reading the values of 8 time
counter registers.
 These are read only registers.
 These are 32-bit registers.

a) CTIME0 (Consolidated Time Register 0)

CTI
ME0 (Consolidated Time Register 0)

 Bits 5:0 – Seconds


Seconds value in the range of 0 to 59.
 Bits 13:8 – Minutes
Minutes value in the range of 0 to 59.
 Bits 20:16 – Hours
Hours value in the range of 0 to 23.
 Bits 26:24 – Day of Week
Day of Week value in the range of 0 to 6.

b) CTIME1 (Consolidated Time Register 1)

CTIME1 (Consolidated Time Register 1)

 Bits 4:0 – Day of Month


Day of Month value in the range of 1 to 28, 29, 30 or 31 (depending on the month and whether it
is a leap year).
 Bits 11:8 – Month
Month value in the range of 1 to 12.
 Bits 27:16 – Year
Year value in the range of 0 to 4095.

c) CTIME2 (Consolidated Time Register 2)

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 63

CTIME2 (Consolidated Time Register 2)

 Bits 11:0 – Day of Year


Day of Year value in the range of 1 to 365 (366 for leap years).

7. Time Counter Group

 It consists of 8 counters.
 These can be read/write.
 They are given in the table below.

Name Size Description

SEC 6 Seconds value in the range of 0 to 59

MIN 6 Minutes value in the range of 0 to 59

HOUR 5 Hours value in the range of 0 to 23

Day of Month value in the range of 1 to 28, 29,


DOM 5 30 or 31 (depending on month and whether it is a
leap year)

DOW 3 Day of Week value in the range of 0 to 6

Day of Year value in the range of 1 to 365 (366


DOY 9
for leap years 0

MONTH 4 Month value in the range of 1 to 12

YEAR 12 Year value in the range of 0 to 4095


8. Alarm Register Group

 It consists of 8 counters.
 The values in these registers are compared with the timer counters.
 If all unmasked alarm registers match their corresponding time counters, then an interrupt is
generated.
 These registers are given in the table below.

Name Size Description

ALSEC 6 Alarm value for Seconds

ALMIN 6 Alarm value for Minutes

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 64

ALHOUR 5 Alarm value for Hours

ALDOM 5 Alarm value for Day of Month

ALDOW 3 Alarm value for Day of Week

ALDOY 9 Alarm value for Day of Year

ALMON 4 Alarm value for Month

ALYEAR 12 Alarm value for Year

9. PREINT (Prescaler Integer Register)

 When PCLK acts as the clock source for RTC, then, this prescaler allows generation of 32.768
kHz reference clock from any PCLK greater than 65.536 kHz (2 * 32.768).
 This allows RTC to run at proper rate irrespective of the PCLK.
 PREINT is the integer portion of the prescale value.
 PREINT = int (PCLK/32768) – 1
 PREINT must be greater than or equal to 1.

PR
EINT (Prescaler Integer Register)

 Bits 12:0 – Prescale Integer


Contains the integer value of the RTC prescaler.

10. PREFRAC (Prescaler Fraction Register)

 This is the fractional part of the prescale value.


 PREFRAC = PCLK – ((PREINT+1) * 32768)

PREFRAC (Prescaler Fraction Register)

 Bits 14:0 - Prescale Fraction


Contains the fraction value of the RTC prescaler.

Let’s take example for prescale register values


For PCLK = 15 MHz

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 65

PREINT = int (15000000/32768) – 1 = 457 – 1 = 456 (0x1C8)


PREFRAC = 15000000 – ((456+1) * 32768) = 15000000 – 14974976 = 25024 (0x61C0)
PROGRAM:
#include <lpc214x.h>
#include <stdint.h>
#include <stdio.h>
#include "UART0.h"
uint8_t alarm, flag;
__irq void RTC_ISR(void)
{
if (ILR & 0x01)
{
flag = 1;
ILR = ILR | 0x01;
}
if (ILR & 0x02)
{
alarm = 1;
ILR = ILR | 0x02;
}
VICVectAddr = 0;
}

typedef struct
{
uint8_t seconds;
uint8_t minutes;
uint8_t hours;
uint8_t day_of_month;
uint8_t day_of_week;
uint16_t day_of_year;
uint8_t month;
uint16_t year;
}RTC_Time;

void RTC_Set_Time( RTC_Time Set_Time)


{
SEC = Set_Time.seconds;
MIN = Set_Time.minutes;
HOUR = Set_Time.hours;
DOM = Set_Time.day_of_month;
DOW = Set_Time.day_of_week;
DOY = Set_Time.day_of_year;
MONTH = Set_Time.month;
YEAR = Set_Time.year;
}

void RTC_Set_Alarm_Time( RTC_Time Alarm_Time)


{
ALSEC = Alarm_Time.seconds;
ALMIN = Alarm_Time.minutes;

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 66

ALHOUR = Alarm_Time.hours;
ALDOM = Alarm_Time.day_of_month;
ALDOW = Alarm_Time.day_of_week;
ALDOY = Alarm_Time.day_of_year;
ALMON = Alarm_Time.month;
ALYEAR = Alarm_Time.year;
}

RTC_Time RTC_Get_Time(void)
{
RTC_Time time;
time.seconds = SEC;
time.minutes = MIN;
time.hours = HOUR;
time.day_of_month = DOM;
time.day_of_week = DOW;
time.day_of_year = DOY;
time.month = MONTH;
time.year = YEAR;
return time;
}

int main(void)
{
/* Setting Time + Alarm */
RTC_Time set_time, alarm_time, current_time;
char timestr[30], datestr[30];
alarm = 0;
flag = 0;
IO0DIR = 0x00000010; /* P0.4 as output pin for LED */
UART0_init();
ILR = 0x0; /* No RTC interrupts */
CCR = 0x02; /* Reset Clock Tick Counter */
CCR = 0x00;
CIIR = 0x00; /* No interrupts */
AMR = 0x00; /* Alarm registers not masked */
PREINT = 0x01C8; /* For 15MHz Fpclk, PREINT value */
PREFRAC = 0x61C0; /* For 15MHz Fpclk, PREFRAC value */
VICVectAddr0 = (unsigned) RTC_ISR;
VICVectCntl0 = 0x0000002D;
VICIntEnable = 0x00002000;
VICIntSelect = 0x00000000;
set_time.seconds = 00;
set_time.minutes = 25;
set_time.hours = 11;
set_time.day_of_month = 6;
set_time.day_of_week = 5;
set_time.day_of_year = 279;
set_time.month = 10;
set_time.year = 2017;
RTC_Set_Time(set_time);
CIIR = 0x01; /* Seconds value increment interrupt */

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 67

alarm_time.seconds = 15;
alarm_time.minutes = 25;
alarm_time.hours = 11;
alarm_time.day_of_month = 6;
alarm_time.day_of_week = 5;
alarm_time.day_of_year = 279;
alarm_time.month = 10;
alarm_time.year = 2017;
RTC_Set_Alarm_Time(alarm_time);
CCR = 0x01; /* Clock Enable */
ILR = 0x03; /* RTC interrupts enabled */
IO0CLR = 0x00000010;
/* Only RTC Read */
while(1)
{
if(alarm == 1)
{
current_time = RTC_Get_Time();
sprintf(timestr,"Alarm!!!: %d:%d:%d \r\
n",current_time.hours,current_time.minutes,current_time.seconds);
UART0_SendString(timestr);
uint8_t i;
for(i=0;i<10;i++)
{
IO0SET = 0x00000010;
delay_ms(300);
IO0CLR = 0x00000010;
delay_ms(300);
}
alarm = 0;
}
if (flag == 1)
{
current_time = RTC_Get_Time();
sprintf(timestr,"Time: %d:%d:%d
",current_time.hours,current_time.minutes,current_time.seconds);
sprintf(datestr,"Date: %d/%d/%d \r\
n",current_time.day_of_month,current_time.month,current_time.year);
UART0_SendString(timestr);
UART0_SendString(datestr);
flag = 0;
}
}
}

CONCLUSION:

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 68

Signature of the In – Charge: Date:

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 69
EXPT. NO : 15
DATA LOGGERS – ROLLOVER DISPLAY
DATE :

AIM : Write 8086 program to interface 8279 key board display.

COMPONENTS & TOOLS REQUIRED :


1 Microprocessor 8086 Trainer Kit,
2 Power supply (5V, 3A)
3 8279 key board display interfacing module
4 Flat ribbon cable

THEORY:
ROLLING DISPLAY
Display/Keyboard mode set word and clear word take care of basic initialization of 8279.
However, before sending codes to the display RAM, a write display RAM control word should be sent.
Then, write the data to be displayed, to the data register. Then, the data is fetched from address and is
displayed in the first digit of the display. The next data is displayed in the second digit of the display,
since in the command word for ‘write display RAM’ the Auto increment flag is set. A time delay is
given between successive digits for a lively display.
N – KEY ROLLOVER
With N-key rollover each key depression is treated independently from all others. When a key is
depressed, the debounce circuit waits 2 keyboard scans and then checks to see if the key is still down. If
it is, the key is entered into the FIFO. Any number of keys can be depressed and another can be
recognized and entered according to the order the keyboard scan found them
Any number of keys can be pressed and all will be entered There is no constraint that all keys
should be released before a depressed key is to be recognized.
ROLLING DISPLAY ( " ECE IS GOOD ")
a

f b
g
e c
. dp

SEGMENT d c b A dp g f e
LETTER 'E' 0 1 1 0 1 0 0 0

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 70

HEX CODE 6 8

PROGRAM:
ROLLING DISPLAY (DISPLAY MESSAGE IS “ECE IS GOOD”
ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
1000 ST: MOV SI, 1200 ; Set pointer = 1200H
1004 MOV CX, 000F ; Initialize counter
1008 MOV AL, 10
100B OUT C2, AL ; Set mode and display
100D MOV AL, CC ; Clear display
1010 OUT C2, AL
1012 MOV AL, 90 ; Write display
1015 OUT C2, AL
1017 NXT: MOV AL, [SI]
1019 OUT C0, AL
101B CALL DLY
101E INC SI ; Increment the pointer
LOOP NXT
1021 JMP ST ; Repeat

1500 DLY: MOV DX, 0A0FF ; Delay sub routine


1504 L1: DEC DX
1505 JNZ L1:
1507 RET
LOOK – UP TABLE:

1200 FF FF FF FF DB ; Display message


1204 68 6C 68 FF DB ECE
1208 9F 29 FF 28 DB IS
120C 0C 0C 1A FF DB GOOD

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 71

TO INITIALIZE 8279 IN N-KEY ROLLOVER:


ADDR OPCODE LABEL MNEMONICS OPERANDS COMMENTS
1000 MOV CX, 0008
1004 MOV AL, 02
1007 OUT C2, AL ; Set mode and display
1009 MOV AL, 0CC ; Clear display
100C OUT C2, AL
100E MOV AL, 90 ; Write display
1011 OUT C2, AL
1013 MOV AL, 0FF ; Clear the display RAM
1016 REP: OUT C0, AL
1018 LOOP REP
101A L1: IN AL, C2 ; L1 for the pressing of a key
101C TEST AL, 07
101F JZ L1
1021 MOV AL, 40 ; Set to read FIFO RAM
1024 OUT C2, AL
1026 IN AL, C0
102B MOV BL, AL
102D MOV BH, 12
1030 MOV AL, [BX]
1032 OUT C0, AL
1034 JMP L1

LOOK – UP TABLE:
1200 0C 9F 4A 0B
1204 99 29 28 8F
1208 08 09 88 38
120C 6C 1A 68 E8

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230


P a g e | 72

EXPECTED RESULTS:

INPUT: ECE IS GOOD


OUTPUT: ECE IS GOOD is roll over on display.

CONCLUSION:
The interfacing of 8279 keyboard-display is implemented.

Signature of the In – Charge: Date:

Lakireddy Bali Reddy College of Engineering, L. B. Nagar., Mylavaram – 521 230

You might also like