r20 - Ece - MPMC Lab Manual
r20 - Ece - MPMC Lab Manual
(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
COURSE OUTCOMES (COs): At the end of the course, students are able to
CO4 : Adapt effective communication, presentation and report writing skills. (Apply – L3)
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 -
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.
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:
CONCLUSION:
String “COLLEGE” is displayed on the screen.
EXPT. NO : 1(b)
STRING COMPARISION
DATE :
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.
EXPECTED RESULTS:
INPUT: FIATH
OUTPUT: HTAIF
CONCLUSION:
The given string entered from keyboard is reversed and displayed on the screen.
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
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:
CONCLUSION:
Using recursive procedure, the factorial of given N number is found.
THEORY:
The following instructions are used for the signed and unsigned operations:
SIGNED UNSIGNED
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.
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
EXPECTED RESULTS:
[R4] = 22
[R5] = AC
[R6] = 3C
[R7] = 1E
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 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
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:
INPUT OUTPUT
[8900] = 35 [8901] = 00
INPUT OUTPUT
[8900] = 15 [8901] = FF
CONCLUSION: The multi Byte addition is performed by using 8051 instructions.
AIM : Write 8051 program to find the sum of the elements in an Array.
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.
AIM : Write 8051 program to find the sum of the elements in an Array.
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.
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).
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.
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.
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.
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.
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.
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.
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:
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:
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.
THEORY:
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.
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:
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.
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.
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;
}
}
RESULT:
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.
1 ARM Processor 1
2 RS232/USB Connector 1
3 LED Module 1
4 Power Supply (5V, DC) 1
5 ADC Module 1
THEORY:
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).
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).
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.
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;
}
}
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:
AIM: Create a Keil u vision protect to interface Real Time Clock using LPC 2148 with built in timer.
1 ARM Processor 1
2 RS232/USB Connector 1
3 LED Module 1
4 Power Supply (5V, DC) 1
5 ADC Module 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.
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.
It is a 16-bit register.
It is a read only register.
It is an 8-bit register.
It controls the operation of the clock divide circuit.
It is an 8-bit register.
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.
It is an 8-bit register.
A
MR (Alarm Mask Register)
Bit 7 – AMRYEAR
When 1, the Year value is not compared for alarm.
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.
CTI
ME0 (Consolidated Time Register 0)
It consists of 8 counters.
These can be read/write.
They are given in the table below.
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.
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)
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;
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 */
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:
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
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
LOOK – UP TABLE:
1200 0C 9F 4A 0B
1204 99 29 28 8F
1208 08 09 88 38
120C 6C 1A 68 E8
EXPECTED RESULTS:
CONCLUSION:
The interfacing of 8279 keyboard-display is implemented.