You are on page 1of 84

A Laboratory Manual for

Advanced
Microcontroller
(EC16406)

Semester V

Diploma in Electronics Engineering

Government Polytechnic Mumbai


(Academically Autonomous Institute of Maharashtra Government)

49 Kherwadi, Bandra (E)

Phone: +912226474780, 4587 Fax: +912226472552 web: gpmumbai.ac.in,

Email: gpmumbai@gpmumbai.ac.in
LIST OF EXPERIMENTS AND PROGRESSIVE ASSESSMENT
ACADEMIC YEAR 20.... – 20….

Course & Code: Advanced Microcontroller Subject & Code: EC16046

Name of Candidate: Mihir P. Gharat Enrollment No: FS18EC007

Marks- Max: 50 Min: 20 Name of Faculty: V.M.Patil

Sr Title of Experiment Page Date of Date of Assessment Dated


No. No. Performance Submission Marks Sign. of
Teacher
with
Remark

1. Simulate arithmetic 26 Aug 2020


operation on arm in
assembly language.

2. Simulation of soft delay in 2 Sep 2020


assembly language.

3. LED blinking variable 16 Sep 2020


speed in ASM.

4. Configure input and 14 Oct 2020


output port in ASM.

5. Seven Segment LED 28 Oct 2020


display interface in C.

6. Realize timer peripheral 11 Nov 2020


by polling method.

7. Realize timer peripheral in 9 Dec 2020


ARM by interrupt driven
method.

8. Serial transmission and 23 Dec 2020


reception by polling
method.
9. Serial transmission and 9 Feb 2021
reception by interrupt
driven method.

10. Display alpha numeric 10 Feb 2021


character in 2X16 LCD
Display.

11. Display “Hello World” 11 Feb 2021


string on LCD of
Raspberry Pi using python
program.

12. Interface of LM 35 12 Feb 2021


temperature sensor
Government Polytechnic Mumbai
Certificate

This is to certify that Mr.Mihir P. Gharat. Enrollment No. FS18EC007,


of Fifth Semester of Diploma In Electronics Engineering has
completed the term work satisfactorily in subject AMC (EC16406) for
the academic year 2020-21 as prescribed in the curriculum.

Place: MUMBAI Enrollment No.: FS18EC007


Date: 13/02/2021 Exam. Seat No.: ………..

Subject Teacher Head of the department

principal
Experiment No-1

Aim:-Simulate arithmetic operation (Addition, Subtraction and Multiplication) on


ARM in assembly language.

Objective:

1. To write assembly program for Arithmetic operation.

2. To test / simulate the assembly language program.

Learning outcome:

1. Review the various arithmetic operation syntax.

2. Write the assembly program for arithmetic operation.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1

Theory:
Arithmetic instructions are very basic and frequently used in your ARM
programming. Here is a table that demonstrates the usage of the ARM
processor's arithmetic instructions with examples.

Instruction Mnemonic Meaning


==================================================================
=
Addition ADD R0, R1, R2 ; R0 = R1 + R2
------------------------------------------------------------------------
Addition ADDS R1, R2, R3 ; R1 = R2 + R3,
; and FLAGs are updated
------------------------------------------------------------------------
Subtraction SUB R0, R1, R2 ; R0 = R1 - R2
------------------------------------------------------------------------
Subtraction SUBS R1, R2, R3 ; R1 = R2 - R3,
; and FLAGs are updated
------------------------------------------------------------------------
SUBS R7, R6, #20 ; R7 = R6 - 20
; Sets the flags on the result
------------------------------------------------------------------------
Reverse Subtraction
RSB R4, R4, #120 ; R4 = 120 - R4
------------------------------------------------------------------------
Multiply MUL R0, R1, R2 ; R0 = R1 * R2
------------------------------------------------------------------------
UMULL R0, R4, R5, R6 ; Unsigned (R4,R0) = R5 * R6
------------------------------------------------------------------------
SMLAL R4, R5, R3, R8 ; Signed (R5,R4) =(R5, R4) +R3*R8
------------------------------------------------------------------------
Division SDIV R0, R2, R4 ; Signed divide, R0 = R2/R4
------------------------------------------------------------------------
UDIV R8, R8, R1 ; Unsigned divide, R8 = R8/R1.

Program
AREA RESET, DATA, READONLY

AREA RESET, CODE, READONLY

ENTRY

MOV RO, #12

ADD RO, RO, #4

SUB RO, RO, #4

STOP B STOP

END

AREA RESET, DATA, READONLY

AREA RESET, CODE, READONLY

ENTRY

MOV RO, #12

ADD RO, RO, #4


SUB RO, RO, #4

STOP B STOP

END

Result: We verified various arithmetic operations.


Op1=5
Op 2=4

References:
1. http://arantxa.ii.uam.es/~gdrivera/sed/docs/ARMBook.pdf
2. http://courses.cs.tamu.edu/rabi/cpsc617/resources/ARM%20Lab
%20Mannual.pdf
3. https://blueskytechi.blogspot.com/2017/02/basic-arm-lpc218-assembly-
programs.html
Questions:
1. State the types of arithmetic instructions.
2. Explain the addition instruction with example.
3. Explain the subtraction instruction with example.
4. Explain the multiplication instruction with example.
5. Explain the division instruction with example.

2 4 4 10 Sign

Experiment No-2
Aim: Simulate soft delay in assembly language.

Objective:

1. To write delay program in Keil.

2. To test / simulate the assembly program.

Learning Outcome:

1. Review of embedded C language syntax.

2. Gain experience to write embedded C program for delay loops.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1

Theory

C2148 Timer/Counter

Timer is a specific type of clock which is used to measure the time intervals. It
provides/measures the time interval by counting the input clocks. Every timer
needs a clock to work. We can provide/measure any time interval if we know the
time of one clock period.
e.g. let’s say we have 1 kHz input clock frequency for the timer unit, then,
We can calculate time of one clock period as,
Time of one clock period = 1 / clock frequency
= 1 / 1000
= 1milliSecond
i.e. 1000 clock counts provide a time interval of 1 second, and hence we can
provide 1 second delay with these 1000 clock counts.
Now, once we have the time period of one clock, we can use this time period to
generate delays that are integer multiples of it. We can also use the time period
to measure the time interval between specific events of a received signal.
 

Counter is the unit which is similar to Timers but works in a reverse manner to
the timers. It counts the external events or we can say external clock ticks. It is
mostly used to measure frequency from the counts of clock ticks.
e.g. Let’s say Counter is measuring counts of external clock ticks, and frequently
its count reaches 2000 in one second i.e. 2000 clock ticks/second.
Then, we can calculate external clock frequency as,
External clock frequency = count of clocks / one second
                                             = 2000 / 1

                                              = 2 kHz
Hence, we can measure such external clock/event frequencies using counter.
 
 Example
Let’s write a code for generating a delay of 100msec and blink LEDs using LPC2148
Timer.
PCLK = 30MHz
Hence, we will load T0PR with a value 29, so that the TC will increment after every
30 PCLK rising edges.
30MHz/30 = 1MHz, which gives 1µsec time.
To get 100msec time, we will have to load T0MR with 100000 (1 µsec * 1000 =
1msec, 1msec * 100 = 100msec. Hence, 1000 * 100 = 100000)
This will give us a delay of 100msec.
Here we are using timer interrupt MR0. On each compare match between MR0
and TC, the ISR for Timer0 will be executed where we are toggling the pin
connected to the LED.
 
ALGORITHM:

Step 1: Declare DIR register for output function.

Step 2: Set the port pin value as 1 to produce logic 1 level output.

Step 3: Call delay routine

Step 4: Clear the port pin value as 0 to produce logic 0 level output.

PROCEDURE:

➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output:

Step-1: Open the IAR workspace.

Step-2: Go to project >> option and do the following settings:

General Options: Target >> Processor variant >> Core >> ARM7TDMI

a. Output Converter: Output >> Generate additional output: (Output format


>> Intel extended) and ( Output file >> Override default >>
project_name.hex ) b. Linker >> Linker configuration file, and
browse/provide path for the linker file as follows:

b. C:\ProgramFiles\IARSystems\Embedded Workbench
5.40\arm\config\linker\NXP\LPC2148.icf

c. After doing above setting click OK to save/ exit from the option window.

Step-3: Now execute the following:

a. Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next
step.)
b. Project >> Debug without Downloading.( Here debugging will start &
Disassembly window will open.) Open the other required window also (e.g.
Register Window) for visualizing the output. c. Project >> Make & Restart
Debugger. (Here the debugging process is ready to check the output by step by
step execution of the code).

Program:

#include <lpc214x.h>

void initClockw(void); // Setup PLL and Clock Frequency

void initTimer0(void); // Setup and INitialite Timer0

void delay_ms(unsigned int counts); // Generate delay

int main(void)

initClocks[]; //INitialite CFU and Peripheral Clocks

initTimer0[]; //INitialite Timer0

IOODIR = (i<<10); //Configure Fin P0.10 as output

while (1)

LOOSET = (1<<10); //Turn ON LED

delay_ms (1000);

LOOCLR = (1<<10); //Turn LED OFF

//return 0;

}
void initTimer0(void)

TOCTCR = 0x0; //Set Timer 0 into Mode

TOPR = 59999; //INcreament TOTC at every 60000 clock cycles

// Count begins from zero hence subtracting ;

//60000 clock cycles @60Mhr = 1mS

TOCTCR = 0X02; //Reset Timer

viod delay_ms(unsigned int counts) //Using Timer0

TOCTCR = 0X02; //Reset Timer

TOCTCR = 0x01; //Enable timer

while(TOTC < s)://wait until TC reaches the desired delay

TOCTCR = 0X00; //Disable timer

void initClocks(void)

PLLOCON = 0X01; //Enable PLL

PLLOCPG = 0X24; //Multiplier and divider setup

PLLOFEED = 0XAA; //Feed sequencer

PLLOFEED = 0XSS;

while (!(PLLOSTAT & 0X00000400)); //ie locked?


PLLOCON = 0X03; //Connect PLL after is locked

PLLPOEED = 0XAA; //Feed sequence

PLLOFEED = 0X55;

VPBDIV = 0X01; //PCLK is same as CCLK i.e.60 MHz

Result:

We observe the delay produced

We observed on the keil software


References:
1. http://www.ocfreaks.com/lpc2148-timer-tutorial/

2. https://www.exploreembedded.com/wiki/LPC2148_Timers

Questions:

1. State the content of I0PIN register for Toggling P0.6 pin.

2. Explain the significance of I0DIR register in view of delay routine.

3. Give various mode of VPBDIV register.

4. List the various timer registers.


2 4 4 10 Sign

Experiment No-3

Aim: LED blinking variable speed in ASM.

To develop and verify the interfacing LED with ARM DEVELOPMENT KIT
microcontroller using embedded c program.

Objective:

1. To write embedded C program for LED blinking in Keil.

2. To test / simulate the embedded C language program.

Learning outcome:
1. Write the LED blinking program.

2. Interface LED to ARM development kit.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1

Theory: GPIO lines of any microcontroller can be used mainly to perform two
things. One is to generate digital signal and second one is to read a digital signal.
In LPC2148 microcontroller most of port pins are multiplexed, this means they ’re
allowed to provide multiple functions. Configuring GPIO to use different function
is out of the scope of this tutorial. Just keep in mind that by default: all functional
pins i.e. Pins on PORT0 and PORT1 are set to be as GPIO so we can directly use
them in our example project.

Here we’ve listed some GPIO related registers and its functions. We need to
replace ‘x’ with the port number to get the register name. Say for example:
IOxPIN register becomes IO0PIN when used for PORT0 and IO1PIN when used for
PORT1. These all register names defined in the header file “lpc2148.h ” Register
names defined in the header file are nothing but a pointer GPIO Related Registers
In LPC2148

IOxPIN: This register can be used to read or write values directly to the pins.
Regardless of the direction set for the particular pins. It gives the current state of
GPIO pin when read.

IOxDIR: This is the GPIO direction control register. Setting a bit to ‘0’ in this
register will configure the corresponding pin to be used as input while setting it to
‘1’ will configure it as output.

IOxSET: This register can be used to drive an ‘output’ configured pin to logic 1 i.e.
HIGH. Writing zero does not have any effect and hence it can ’t be used to drive a
pin to Logic 0 i.e. LOW. For driving pins LOW IOxCLR is used which is explained as
below:

IOxCLR: This register can be used to drive an ‘output’ configured pin to logic 0 i.e.
LOW. Writing zero does not have any effect and hence it can ’t be used to drive a
pin to Logic 1. Which holds the address of actual register in LPC2148? ( ‘x ’
represent port number).

Program
#include <lpc214x.h>

int delay;

int main(void)

IOODIR = 0 xffffffff; //Configure Pin Po.10 as output

While(1)

ROOSET = Oxfffffff; //Turn ON LED

for (delay=0; delay=s; delay++);

IOODIR = 0xfffffff; //Turn LED OFF

for (delay=0delay=s; delay++);

Result:
Thus the interfacing of LED with ARM DEVELOPMENT KIT was done by using
embedded C program.
References:

1. https://www.instructables.com/id/Blinking-LED-Using-ARM7-LPC2148-
Microcontroller/

2. https://binaryupdates.com/blink-led-with-arm7-lpc2148/

3. https://electrosome.com/blinking-led-using-lpc2148-arm-microcontroller/

2 4 4 10 Sign

Experiment No-4

Aim:-Configure input output port in ASM.

Objective:

1. To write embedded C program to configure I/O port.

2. To test / simulate the assembly language program.

Learning outcome:

1. Configure I/O port in input and output Direction.

Apparatus:
Sr. No. Apparatus Range Quantity
1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1

Theory:

PINSEL0 It is a 32 bits register. It is used to select function of port 0 pins P0.0 to


P0.15. For selecting function of each port pin 2 bits are used. For GPIO function
the two bits must be 00.
PINSEL1: It is a 32 bits register. It is used to select function of port 0 pins P0.15 to
P0.31. For selecting function of each port pin 2 bits are used. For GPIO function
the two bits must be 00.
IODIR0: It is a 32 bits register. It is used to select operation of port 0 pins P0.0 to
P0.31. Writing 1 at ith location in this register makes P0.i output pin. Writing 0 at
ith location in this register makes P0.i input pin.
IOSET0: It is a 32 bits register. It is used to set state of port 0 pins 0 to 31. Writing
1 at ith location in this register makes P0.i pin high.
IOCLR0: It is a 32 bits register. It is used to set state of port 0 pins 0 to 31. Writing
1 at ith location in this register makes P0.i pin low.
IOPIN0: It is a 32 bits register. It is used to set state of port 0 pins 0 to 31. The
value written at ith location in this register controls the state of P0.i pin.
PINSEL2: It is a 32 bits register. It is used to select function of port 1 pins P1.15 to
P1.31.
IODIR1: It is a 32 bits register. It is used to select operation of port 1 pins P1.15 to
P1.31. Writing 1 at ith location in this register makes P1.i pin output pin. Writing 0
at ith location in this register makes P1.i pin input pin.
IOSET1: It is a 32 bits register. It is used to set state of port 1 pins P1.15 to P1.31.
Writing 1 at ith location in this register makes P1.i pin high.
IOCLR1: It is a 32 bits register used to set state of port 1 pins P1.15 to P1.31.
Writing 1 at ith location in this register makes P1.i pin low.
IOPIN1: It is a 32 bits register used to set state of port 1 pins P1.15 to P1.31. The
value written at ith location in this register controls the state of P1.i pin.

Program
#include <lpc214x.h>
int delay;
int main(void)
{
PINSEL0 =0x00000000; //GPIO
IO0DIR = 0x000000f0; //Configure Pin P0 as Output

while(l)
{
IOPIN0= IOPIN0^0x000000f0;
for (delay=0); delay<=5; delay++);

}
}

Result:
Thus I/O port configuration of ARM processor has done successfully.
References:

2 4 4 10 Sign
Experiment No-5

Aim:-Seven Segment LED display interface in C.

Objective:

1. To write embedded C program for seven segment display.

2. To simulate / interface the seven segment display.

Learning outcome:

1. Develop embedded C program for seven segment display.

2. Interface the seven segment display to ARM Development Kit.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1

Theory: A seven segment display is the most basic electronic display device that
can display digits from 0-9. The most common configuration has an array of eight
LEDs arranged in a special pattern to display these digits. They are laid out as a
squared-off figure ‘8’.
Interfacing Seven Segment Display
Fig. 1 shows how to interface the seven segments with microcontroller. A seven
segment is generally available in ten pin package. While eight pins correspond to
the eight LEDs, the remaining two pins (at middle) are common and internally
shorted. These segments come in two configurations, namely, Common cathode
(CC) and Common anode (CA).
We now want to display a four digit number in LPC2148 Advanced Development
Board by using seven segment displays. The seven segment display is connected
with LPC2138 controller.
Pin Assignment
P0.0-a
P0.1-b
P0.2-c
P0.3-d
P0.4-e
P0.5-f
P0.6-g
Program
#include <lpc2114x.h>
int delay;
int i;
unsigned char a[ ]=[0x3f,0x06,0x5b,0xif,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
int main(void)
{
PINSEL0 =0x00000000; //GPIO
IOODIR = 0xffffffff; //Configure Pin P0 as Output

while(l)
{
For(i-0;1<-9;1++)
{
IO0SET = a(i); // TURN ON LED
for (delay-0; delay<-5; delay++);
IO0CLR = a(I);. //TURN LED OFF
For (delay-0; delay<-5; delay++);
}
}
}
Result:
Thus seven segment interfacing with ARM DEVELOPMENT KIT processor has been
done successfully.
References:
1. LPC 214x User manual (UM10139).
2. https://circuitdigest.com/microcontroller-projects/interfacing-7-segment-
display-with-arm7-lpc2148-development-board
3. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright.

2 4 4 10 Sign
Experiment No-6

AIM: To write a program for realizing the timer peripheral in ARM by polling
method and verify the output using LPC2148 kit.
Objective:

1. To write embedded C program for timer peripheral.

2. To simulate / configure the timer peripheral.

Learning outcome:

1. Develop the embedded C program for timer peripheral.

2. Verify the operation of timer peripheral using polling method.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:
Timer is a specific type of clock which is used to measure the time intervals. It
provides/measures the time interval by counting the input clocks. Every timer
needs a clock to work. We can provide/measure any time interval if we know the
time of one clock period.
e.g. let’s say we have 1 kHz input clock frequency for the timer unit, then,
We can calculate time of one clock period as,
Time of one clock period = 1 / clock frequency
= 1 / 1000
= 1milliSecond
i.e. 1000 clock counts provide a time interval of 1 second, and hence we can
provide 1 second delay with these 1000 clock counts.

There are many applications for which we can use these timers and counters in
real world.
 
LPC2148 Timer& Counter
LPC2148 has two 32-bit timers/counters: Timer0/Counter0 & Timer1/Counter1.
LPC2148 Timer has input of peripheral clock (PCLK) or an external clock. It counts
the clock from either of these clock sources for its operation.
 LPC2148 Timer/Counter can generate an interrupt signal at specified time
value.
 LPC2148 has match registers that contain count value which is continuously
compared with the value of the Timer register. When the value in the Timer
register matches the value in the match register, specific action (timer
reset, or timer stop, or generate an interrupt) is taken.

 For information about LPC2148 compare and match operation refer Timer


Compare Mode.

 Also, LPC2148 has capture registers which can be used to capture the timer
value on a specific external event on capture pins. For information about
LPC2148 capture operation refer Input Capture Mode. 
 Here, we will see how to use timer 0 registers to configure the timer 0.
Timer 1 can be used in a similar manner by using its corresponding
registers.

 Let’s see the various registers of timer 0.

Timer0 Registers
1. T0IR (Timer0 Interrupt Register)
 It is an 8-bit read-write register.
 Consists of 4 bits for match register interrupts and 4 bits for compare
register interrupts.

 If interrupt is generated, then the corresponding bit in this register will be


high, otherwise it will be low.

 Writing a 1 to any bit of this register will reset that interrupt. Writing a 0
has no effect.

 T0IR (Timer0 Interrupt Register)

2.  T0TCR (Timer0 Timer Control Register)


 It is an 8-bit read-write register.
 It is used to control the operation of the timer counter.

T0TCR (Timer0 Timer Control Register)

 Bit 0 – Counter Enable


0 = Counters are disabled
1 = Timer counter and Prescale counter are enabled for counting
 Bit 1 – Counter Reset
0 = Counter not reset
1 = Timer counter and Prescale counter are synchronously reset on next
positive edge of PCLK

 
3.  T0CTCR (Timer0 Counter Control Register)
 It is an 8-bit read-write register.

T0CTCR (Timer0 Counter Control Register)


 Used to select between timer counter mode.
 When in counter mode, it is used to select the pin and edges for counting.

 Bits 1:0 – Counter/Timer Mode


This field selects which rising edges of PCLK can increment Timer ’s Prescale
Counter (PC), or clear PC and increment Timer Counter (TC).
00 = Timer Mode: Every rising edge of PCLK
01 = Counter Mode: TC is incremented on rising edge on the capture input
selected by Bits 3:2.
10 = Counter Mode: TC is incremented on falling edge on the capture input
selected by Bits 3:2
01 = Counter Mode: TC is incremented on both edges on the capture input
selected by Bits 3:2

 Bits 3:2 – Count Input Select


When bits 1:0 in this register are not 00, these bits select which capture pin
is sampled for clocking.
00 = CAP0.0
01 = CAP0.1
10 = CAP0.2
11 = CAP0.3

 Note : If counter mode is selected for a certain capture (CAP) input, then
the corresponding 3 bits in the T0CCR register must be programmed as
000. Capture and/or interrupt can be selected for other CAP inputs.

 
1.    T0TC (Timer0 Timer Counter)
·      It is a 32-bit timer counter.
·      It is incremented when the Prescale Counter (PC) reaches its maximum value
held by Prescaler Register (PR).
Note : When TC overflow occurs, it does not generate any overflow interrupt.
Alternatively, we can use match register to detect overflow event if needed.
 
4.  T0PR (Timer0 Prescale Register)
 It is a 32-bit register.
 It holds the maximum value of the Prescale Counter.

 
5.  T0PC (Timer0 Prescale Counter Register)
 It is a 32-bit register.
 It controls the division of PCLK by some constant value before it is applied
to the Timer Counter.

 It is incremented on every PCLK.

 When it reaches the value in Prescale Register, the Timer Counter is


incremented and Prescale Counter is reset on next PCLK.

 
6.  T0MR0-T0MR3 (Timer0 Match Registers)
 These are 32-bit registers.
 The values stored in these registers are continuously compared with the
Timer Counter value.

 When the two values are equal, the timer can be reset or stop or an
interrupt may be generated.  The T0MCR controls what action should be
taken on a match.

 
7.  T0MCR (Timer0 Match Control Register)
 It is a 16-bit register.
 It controls what action is to be taken on a match between the Match
Registers and Timer Counter.
T0MCR (Timer0 Match Control Register)
 Bit 0 – MR0I (Match register 0 interrupt)
0 = This interrupt is disabled
1 = Interrupt on MR0. An interrupt is generated when MR0 matches the
value in TC (Timer Counter)
 Bit 1 – MR0R (Match register 0 reset)
0 = This feature is disabled
1 = Reset on MR0. The TC (Timer Counter) will be reset if MR0 matches it

 Bit 2 – MR0S (Match register 0 stop)


0 = This feature is disabled
1 = Stop on MR0. The TC (Timer Counter) and PC (Prescale Counter) is
stopped and Counter Enable bit in T0TCR is set to 0 if MR0 matches TC

 MR1, MR2 and MR3 bits function in the same manner as MR0 bits.

ALGORITHM:
Step 1: Start
Step 2: Initialize timer registers.
Step 3: Set the prescale register and match register values.
Step 4: Enable the Timer operation.
Step 5: Output will be displayed in LPC2148 kit.
Step 6: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S.
a. Output Converter: Output >> Generate additional output: (Output format >>
Intel extended) and (Output file >> Override default >> project_name.hex)
b.Linker >> Linker configurations file,and browse/provide path for the linker file
as
follows:C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linke
r\NXP\LPC2148.icf
c. After doing above setting click OK to save/ exit from the option window. Step-3:
Now execute the following:EXP
a. Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next
step.)
Step 4: Flash the program in LPC2148 kit.
Step 5: Verify the output using LEDs.

PROGRAM:
#include<nxp\iolpc2148.h>
unsigned int timer_delay = 1000 ;
void timer_init()
{
VPBDIV = 1;
T0PR = 12000*timer_delay ;
T0MR0 = 1;
T0MCR = 2;
T0TCR = 1;
}

int main(void)
{
IO1DIR = 0xFF000000;
timer_init();
while(1)
{
if( T0TC==0 )
{
IO1PIN = 0xF0000000;
while(T0TC==0);
}
else
IO1PIN = 0x0F000000;

}
}
RESULT: Thus the program for realizing the Timer peripheral in ARM by polling
method was written and the output was verified using LPC2148 kit.

References:

1. LPC 214x User manual (UM10139)


2. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-timercounter
2 4 4 10 Sign

Experiment No-7

AIM: To write a program for realizing the timer peripheral in ARM by interrupt
driven method and verify the output using LPC2148 kit.
Objective:
1. To write embedded C program for timer peripheral.

2. To simulate / configure the timer peripheral.

Learning outcome:

1. Write embedded C program for timer peripheral.

2. Verify the operation of timer peripheral using interrupt driven method.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:

LPC2148 Timer& Counter


LPC2148 has two 32-bit timers/counters: Timer0/Counter0 & Timer1/Counter1.
LPC2148 Timer has input of peripheral clock (PCLK) or an external clock. It counts
the clock from either of these clock sources for its operation.
 LPC2148 Timer/Counter can generate an interrupt signal at specified time
value.
 LPC2148 has match registers that contain count value which is continuously
compared with the value of the Timer register. When the value in the Timer
register matches the value in the match register, specific action (timer
reset, or timer stop, or generate an interrupt) is taken.

 For information about LPC2148 compare and match operation refer Timer


Compare Mode.

 Also, LPC2148 has capture registers which can be used to capture the timer
value on a specific external event on capture pins. For information about
LPC2148 capture operation refer Input Capture Mode. 
 Here, we will see how to use timer 0 registers to configure the timer 0.
Timer 1 can be used in a similar manner by using its corresponding
registers.

 Let’s see the various registers of timer 0.

Timer0 Registers
2. T0IR (Timer0 Interrupt Register)

 It is an 8-bit read-write register.


 Consists of 4 bits for match register interrupts and 4 bits for compare
register interrupts.

 If interrupt is generated, then the corresponding bit in this register will be


high, otherwise it will be low.

 Writing a 1 to any bit of this register will reset that interrupt. Writing a 0
has no effect.

 T0IR (Timer0 Interrupt Register)

2.  T0TCR (Timer0 Timer Control Register)


 It is an 8-bit read-write register.
 It is used to control the operation of the timer counter.

T0TCR (Timer0 Timer Control Register)


 Bit 0 – Counter Enable
0 = Counters are disabled
1 = Timer counter and Prescale counter are enabled for counting
 Bit 1 – Counter Reset
0 = Counter not reset
1 = Timer counter and Prescale counter are synchronously reset on next
positive edge of PCLK

 
3.  T0CTCR (Timer0 Counter Control Register)

 It is an 8-bit read-write register.

T0CTCR (Timer0 Counter Control Register)


 Used to select between timer counter mode.
 When in counter mode, it is used to select the pin and edges for counting.

 Bits 1:0 – Counter/Timer Mode


This field selects which rising edges of PCLK can increment Timer ’s Prescale
Counter (PC), or clear PC and increment Timer Counter (TC).
00 = Timer Mode: Every rising edge of PCLK
01 = Counter Mode: TC is incremented on rising edge on the capture input
selected by Bits 3:2.
10 = Counter Mode: TC is incremented on falling edge on the capture input
selected by Bits 3:2
01 = Counter Mode: TC is incremented on both edges on the capture input
selected by Bits 3:2

 Bits 3:2 – Count Input Select


When bits 1:0 in this register are not 00, these bits select which capture pin
is sampled for clocking.
00 = CAP0.0
01 = CAP0.1
10 = CAP0.2
11 = CAP0.3

 Note : If counter mode is selected for a certain capture (CAP) input, then
the corresponding 3 bits in the T0CCR register must be programmed as
000. Capture and/or interrupt can be selected for other CAP inputs.

 
1.    T0TC (Timer0 Timer Counter)
·      It is a 32-bit timer counter.
·      It is incremented when the Prescale Counter (PC) reaches its maximum value
held by Prescaler Register (PR).
Note : When TC overflow occurs, it does not generate any overflow interrupt.
Alternatively, we can use match register to detect overflow event if needed.
 
4.  T0PR (Timer0 Prescale Register)
 It is a 32-bit register.
 It holds the maximum value of the Prescale Counter.

 
5.  T0PC (Timer0 Prescale Counter Register)
 It is a 32-bit register.
 It controls the division of PCLK by some constant value before it is applied
to the Timer Counter.

 It is incremented on every PCLK.

 When it reaches the value in Prescale Register, the Timer Counter is


incremented and Prescale Counter is reset on next PCLK.

 
6.  T0MR0-T0MR3 (Timer0 Match Registers)
 These are 32-bit registers.
 The values stored in these registers are continuously compared with the
Timer Counter value.

 When the two values are equal, the timer can be reset or stop or an
interrupt may be generated.  The T0MCR controls what action should be
taken on a match.

 
7.  T0MCR (Timer0 Match Control Register)
 It is a 16-bit register.
 It controls what action is to be taken on a match between the Match
Registers and Timer Counter.

T0MCR (Timer0 Match Control Register)


 Bit 0 – MR0I (Match register 0 interrupt)
0 = This interrupt is disabled
1 = Interrupt on MR0. An interrupt is generated when MR0 matches the
value in TC (Timer Counter)
 Bit 1 – MR0R (Match register 0 reset)
0 = This feature is disabled
1 = Reset on MR0. The TC (Timer Counter) will be reset if MR0 matches it

 Bit 2 – MR0S (Match register 0 stop)


0 = This feature is disabled
1 = Stop on MR0. The TC (Timer Counter) and PC (Prescale Counter) is
stopped and Counter Enable bit in T0TCR is set to 0 if MR0 matches TC

 MR1, MR2 and MR3 bits function in the same manner as MR0 bits.

ALGORITHM:
Step 1: Start
Step 2: Initialize VIC registers [enable reg, address reg, and control reg]
Step 3: Initialize timer registers.
Step 4: Set the presale register and match register values.
Step 5: Call interrupt service routine.
Step 6: Output will be displayed in LPC2148 kit.
Step 7: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S.
a. Output Converter: Output >> Generate additional output: (Output format
>> Intel extended) and ( Output file >> Override default >>
project_name.hex )
b. Linker >> Linker configurations file, and browse/provide path for the linker
file as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NX
P\LPC2148.icfc. After doing above setting click OK to save/ exit from the option
window.
Step-3: Now execute the following: a. Project >> Rebuild all (if you get 0 errors
& 0 warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit. Step 5: Verify the output using LEDs.

PROGRAM:
#include<nxp\iolpc2148.h>
unsigned int timer_delay = 1000 ;
void Timer0_Init(void);
__irq void T0ISR(void);
int main(void)
{
VPBDIV = 0x01;
IO1DIR = 0xFF000000;
Timer0_Init();
while(1)
{
IO1PIN = 0x55000000; // LED glow in this pattern (0x55)in default ( when no
interrupt )

}
}
void Timer0_Init(void)
{
T0PR = 12000*timer delay;
T0MR0 = 1;
T0MCR = 3;
T0TCR = 1;
VICIntEnable = 0x10;
VICVectAddr4 = (unsigned) T0ISR;
VICVectCntl4 = 0x20 | 4;
}
__irq void T0ISR(void)
{
long int regVal;
regVal = T0IR;
IO1PIN ^= 0xFF000000;
T0IR = regVal;
VICVectAddr = 0x0;
}
RESULT: Thus the program for realizing the Timer peripheral in ARM by interrupt
driven method was written and the output was verified using LPC2148 kit.
References:

1. LPC 214x User manual (UM10139)


2. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-timercounter

2 4 4 10 Sign
Experiment No-8

Aim: To write a program for serial transmission and reception of a character in C


by polling method and verify the output.
Objective:

1. To write embedded C program for Serial transmission and reception using


polling method.

2. To simulate / configure the Serial transmission and reception.


Learning outcome:

1. Develop the embedded C program for serial communication.

2. Verify the operation of Serial transmission and reception using polling


method.

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:

UART (Universal Asynchronous Receiver/Transmitter) is a serial communication


protocol in which data is transferred serially bit by bit at a time. Asynchronous
serial communication is widely used for byte oriented transmission. In
Asynchronous serial communication, a byte of data is transferred at a time.
UART serial communication protocol uses a defined frame structure for their data
bytes. Frame structure in Asynchronous communication consists:
 START bit: It is a bit with which indicates that serial communication has
started and it is always low.
 Data bits packet: Data bits can be packets of 5 to 9 bits. Normally we use 8
bit data packet, which is always sent after the START bit.

STOP bit: This usually is one or two bits in length. It is sent after data bits packet
to indicate the end of frame. Stop bit is always logic high.

Algorithm:
Step 1: Start
Step 2: Initialize UART registers.
Step 3: Transmit the characters through serial port.
Step 4: Receive the characters through serial port.
Step 4: Output will be displayed in monitor.
Step 5: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace.
Step-2: Go to project >> option and do the following settings:
General Options: Target >> Processor variant >> Core >> ARM7TDMI S. a. Output
Converter: Output >> Generate additional output: (Output format >> Intel
extended) and ( Output file >> Override default >> project_name.hex )
b.Linker >> Linker configurations file, and browse/provide path for the linker file
as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NXP\L
PC2148.icf
c. After doing above setting click OK to save/ exit from the option window.
Step-3: Now execute the following: a. Project >> Rebuild all (if you get 0 errors &
0 warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit.
➢ Open the Hyper Terminal window as shown below : (Start >> All Programs >>
Accessories >> Communications>> Hyper Terminal) Enter any arbitrary name,
select the correct COM Port and do the following settings: • Bits per second :
9600, Data bits : 8, Parity : None, Stop bit : 1, Flow Control : None ➢ Now
observe the texts/message in hyper terminal, it should display “Enter the Data:
“now press any key on the computer keyboard, you should see the corresponding
letters in the Hyper Terminal. ➢ i.e. When you will press the key the
corresponding data will be received by the LPC2148 board and the same will be
transmitted back by the LPC2148 board to the Hyper Terminal.
Step 5: Verify the output in monitor.
Program:
#include<nxp/iolpc2148.h>
#define f 12000000 // PCLKFREQ ( controller frequency )
void serial_Init(void) // Function to initialise the serial port
{
unsigned int baudrate ;
PINSEL0=0X00000005;
VPBDIV=0X01;
baudrate = (f/(9600*16)); // Baudrate setting (9600 bps)
U0LCR=0X80;
U0DLL = baudrate & 0X00FF;
U0DLM=( baudrate >>8) & 0X00FF;
U0LCR=0X03;
}
char serialrx(void) // Function to receive the data serially
{
unsigned char rxdata;
while(!(U0LSR&0x01));
rxdata=U0RBR;
return rxdata;
}
void serialtx(char txdata) // Function to transmit the data serially
{
while(!(U0LSR&0x20));
U0RBR=txdata;
}
void main()
{
unsigned char msg[]="\r\nEnter the Data : ";
unsigned int i,rxdata;

serial_Init(); // Initialise the serial port


while(1)
{

for(i=0;msg[i]!='\0';i++)
{ serialtx(msg[i]); } // Transmits the enter message to hyperterminal (PC)

rxdata = serialrx(); // Receives the data entered through computer keyboard.

serialtx(rxdata); // Transmits the received character to hyperterminal (PC)

}
}
Result: Thus the program for serial transmission and reception of a character in C
by polling method was written and the output was verified.
References:
1. LPC 214x User manual (UM10139)
2. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-uart0

2 4 4 10 Sign
Experiment No-9

Aim: To write a program for serial transmission and reception of a character in C


by interrupt method and verify the output.
Objective:

1. To write embedded C program for Serial transmission and reception using


interrupt method.

2. To simulate / configure the Serial transmission and reception.

Learning outcome:

1. Develop embedded C program for serial communication.

2. Verify the operation of Serial transmission and reception using

Interrupt method.

Apparatus:
Sr. No. Apparatus Range Quantity
1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:
LPC2148 has two inbuilt UARTs available i.e. UART0&UART1. So, we can connect
two UART enabled devices (GSM module, GPS module, Bluetooth module etc.)
with LPC2148 at a time.
UART0 and UART1 are identical other than the fact that UART1 has modem
interface included.

UART0 Registers
1.  U0RBR (UART0 Receive Buffer Register)
 It is an 8-bit read only register.
 This register contains the received data.

 It contains the “oldest” received byte in the receive FIFO.

 If the character received is less than 8 bits, the unused MSBs are padded
with zeroes.

 The Divisor Latch Access Bit (DLAB) in U0LCR must be zero in order to
access the U0RBR. (DLAB = 0)

2.  U0THR (UART0 Transmit Holding Register)


 It is an 8-bit write only register.
 Data to be transmitted is written to this register.

 It contains the “newest” received byte in the transmit FIFO.

 The Divisor Latch Access Bit (DLAB) in U0LCR must be zero in order to
access theU0THR.  (DLAB = 0)

3. U0DLL and U0DLM (UART0 Divisor Latch Registers)


 U0DLL is the Divisor Latch LSB.

 U0DLM is the Divisor Latch MSB.

 These are 8-bit read-write registers.

 UART0 Divisor Latch holds the value by which the PCLK(Peripheral Clock)
will be divided. This value must be 1/16 times the desired baud rate.

 A 0x0000 value is treated like a 0x0001 value as division by zero is not


allowed.

 The Divisor Latch Access Bit (DLAB) in U0LCR must be one in order to access
the UART0 Divisor Latches. (DLAB = 1)

4. U0FDR (UART0 Fractional Divider Register)

 It is a 32-bit read write register.

 It decides the clock pre-scalar for baud rate generation.

 If fractional divider is active (i.e. DIVADDVAL>0) and DLM = 0, DLL must be


greater than 3.

 If DIVADDVAL is 0, the fractional baudrate generator will not impact the


UART0 baudrate.

 Reset value of DIVADDVAL is 0.

 MULVAL must be greater than or equal to 1 for UART0 to operate properly,


regardless of whether the fractional baudrate generator is used or not.

 Reset value of MULVAL is 1.

 The formula for UART0 baudrate is given below


 MULVAL and DIVADDVAL should have values in the range of 0 to 15. If this
is not ensured, the output of the fractional divider is undefined.
 The value of the U0FDR should not be modified while
transmitting/receiving data. This may result in corruption of data.

5. U0IER (UART0 Interrupt Enable Register)


 It is a 32-bit read-write register.

 It is used to enable UART0 interrupt sources.

 DLAB should be zero (DLAB = 0).

 Bit 0 - RBR Interrupt Enable. It also controls the Character Receive Time-
Out interrupt.
0 = Disable Receive Data Available interrupt
1 = Enable Receive Data Available interrupt
 Bit 1 - THRE Interrupt Enable
0 = Disable THRE interrupt
1 = Enable THRE interrupt

 Bit 2 - RX Line Interrupt Enable


0 = Disable UART0 RX line status interrupts
1 = EnableUART0 RX line status interrupts

 Bit 8 - ABEO Interrupt Enable


0 = Disable auto-baud time-out interrupt
1 = Enable auto-baud time-out interrupt
 Bit 9 - ABTO Interrupt Enable
0 = Disable end of auto-baud interrupt
1 = Enable the end of auto-baud interrupt

 
6.  U0IIR (UART0 Interrupt Identification Register)
 It is a 32-bit read only register.

 It provides a status code that denotes the priority and source of a pending
interrupt.
 It must be read before exiting the Interrupt Service Routine to clear the
interrupt.

 Bit 0 - Interrupt Pending


0 = At least one interrupt is pending
1 = No interrupts pending

 Bit 3:1 - Interrupt Identification


Identifies an interrupt corresponding to theUART0 Rx FIFO.
011 = Receive Line Status (RLS) Interrupt
010 = Receive Data Available (RDA) Interrupt
110 = Character Time-out Indicator (CTI) Interrupt
001 = THRE Interrupt

 Bit 7:6 - FIFO Enable These bits are equivalent to FIFO enable bit in FIFO
Control Register,
0 = If FIFOs are disabled
1 = FIFOs are enabled

 Bit 8 - ABEO Interrupt


If interrupt is enabled,
0 = No ABEO interrupt
1 = Auto-baud has finished successfully
 Bit 9 - ABTO Interrupt
If interrupt is enabled,
0 = No ABTO interrupt
1 = Auto-baud has timed out

 
7.  U0LCR (UART0 Line Control Register)
 It is an 8-bit read-write register.
 It determines the format of the data character that is to be transmitted or
received.

 Bit 1:0 - Word Length Select


00 = 5-bit character length
01 = 6-bit character length
10 = 7-bit character length
11 = 8-bit character length
 Bit 2 -  Number of Stop Bits
0 = 1 stop bit
1 = 2 stop bits

 Bit 3 - Parity Enable


0 = Disable parity generation and checking
1 = Enable parity generation and checking

 Bit 5:4 - Parity Select


00 = Odd Parity
01 = Even Parity
10 = Forced “1” Stick Parity
11 = Forced “0” Stick Parity
 Bit 6 - Break Control
0= Disable break transmission
1 = Enable break transmission

 Bit 7 - Divisor Latch Access Bit (DLAB)


0 = Disable access to Divisor Latches
1 = Enable access to Divisor Latches

 8.  U0LSR (UART0 Line Status Register)


 It is an 8-bit read only register.

 It provides status information on UART0 RX and TX blocks.

 Bit 0 - Receiver Data Ready


0 = U0RBR is empty
1 = U0RBR contains valid data

 Bit 1 - Overrun Error


0 = Overrun error status inactive
1 = Overrun error status active
This bit is cleared when U0LSR is read.

 Bit 2 - Parity Error


0 = Parity error status inactive
1 = Parity error status active
This bit is cleared when U0LSR is read.

 Bit 3 - Framing Error


0 = Framing error status inactive
1 = Framing error status active
This bit is cleared when U0LSR is read.

 Bit 4 - Break Interrupt


0 = Break interrupt status inactive
1 = Break interrupt status active
This bit is cleared when U0LSR is read.

 Bit 5 - Transmitter Holding Register Empty


0 = U0THR has valid data
1 = U0THR empty

 Bit 6 - Transmitter Empty


0 = U0THR and/or U0TSR contains valid data
1 = U0THR and U0TSR empty

 Bit 7 - Error in RX FIFO (RXFE)


0 = U0RBR contains no UART0 RX errors
1 = U0RBR contains at least one UART0 RX error
This bit is cleared when U0LSR is read.

9.  U0TER (UART0 Transmit Enable Register)

 It is an 8-bit read-write register.

 The U0TER enables implementation of software flow control. When


TXEn=1, UART0 transmitter will keep sending data as long as they are
available. As soon as TXEn becomes 0, UART0 transmission will stop.
 Software implementing software-handshaking can clear this bit when it
receives an XOFF character (DC3). Software can set this bit again when it
receives an XON (DC1) character.

 Bit 7 : TXEN
0 = Transmission disabled
1 = Transmission enabled

 If this bit is cleared to 0 while a character is being sent, the transmission of


that character is completed, but no further characters are sent until this bit
is set again.
ALGORITHM:
Step 1: Start
Step 2: Initialize UART registers.
Step 3: Initialize VIC registers [enable reg, address reg and control reg]
Step 4: Transmit the characters through serial port.
Step 5: Receive the characters through serial port.
Step 6: Call interrupt service routine.
Step 7: Output will be displayed in monitor.
Step 8: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S. a. Output Converter: Output >> Generate additional output:
(Output format >> Intel extended) and (Output file >> Override default >>
project_name.hex)
b. Linker >> Linker configurations file, and browse/provide path for the linker file
as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NXP\L
PC2148.icf
c. After doing above setting click OK to save/ exit from the option window.
Step-3: Now execute the following: a. Project >> Rebuild all (if you get 0 errors &
0 warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit.
➢ Open the Hyper Terminal window as shown below : (Start >> All Programs >>
Accessories >> Communications>> Hyper Terminal) Enter any arbitrary name,
select the correct COM Port and do the following settings: • Bits per second :
9600, Data bits : 8, Parity : None, Stop bit : 1, Flow Control : None ➢ Now
observe the texts/message in hyper terminal, it should display “Enter the Data:
“now press any key on the computer keyboard, you should see the corresponding
letters in the Hyper Terminal. ➢ i.e. When you will press the key the
corresponding data will be received by the LPC2148 board and the same will be
transmitted back by the LPC2148 board to the Hyper Terminal.
Step 5: Verify the output in monitor.

PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h> // Header Files
#include <stdio.h>
/*--------------------- User-defined Function Declaration -------------------------*/
void UART0_ISR(); // UART-0 Interrupt Service Routine function
declaration
void UART0_init(); // UART-0 Initialisation function declaration
void feed (void); // PLL-FEED function declaration
void serialtx(char txdata); // UART-0 Serial Transmitter function declaration
/*--------------------- Main Function Starts Here -------------------------*/
void main(void)
{
unsigned char msg[]="\r\n UART0 Interrupt Program. ";
PINSEL2 = 0X00000000; // ( Optional )
IO1DIR = 0xff000000; // data bits configuration as I/O
UART0_init(); // UART0 Initialisation Function
__enable_interrupt(); // Global interrupt enable

for(int i=0;msg[i]!='\0';i++)
{ serialtx(msg[i]); } // Transmits the enter message to hyperterminal (PC)
while(1)
{
IO1PIN = 0x55000000;
}
}
// void main() End .
/*--------------------- Function Definition -------------------------*/
void UART0_ISR() // Interrupt Serice routine for TIMER0 interrupt.
{
int temp,buf;
__disable_interrupt(); // Global interrupt disable.
IO1PIN = 0xAA000000; // LED glow in this pattern (0xAA)when there is an
interrupt.
for(int i = 0; i < 10000; ++i) // few ms Delay

temp = U0IIR; // Checking the Interrupt Identification Register


temp =( temp>>1 )& 0x07; // Filtering the useful bits.
if (temp==2) // If interrupt is invoked
{
while (U0LSR & 0x01)
{
buf=U0RBR; // Receiving the data from RxD pin (
from the key-board.)
serialtx(buf); // Sending the data to TxD pin.( to
the serial window.)
}
}
__enable_interrupt(); // Global interrupt enable
VICVectAddr = 0; // Clear interrupt in VIC to return in the main function.
}
void UART0_init() // UART0 and Interrupt initialisation for TIMER0 interrupt.
{
PLLCON_bit.PLLC = PLLCON_bit.PLLE = 0; // Disable and disconnect PLL
feed(); // PLL feed sequence
VPBDIV_bit.VPBDIV = 0; /* Init Peripherial divider Pckl = Clk/4 */
/*------- UART0 Setting -------------*/
PINSEL0=0X00000005; // Selecting/configuring the pins as RxD & TxD.
VPBDIV=0X01; // Making Pclk = Xclk.
int baudrate = (12000000/(9600*16)); // Baudrate setting (9600 bps)
U0LCR=0X80;
U0DLL = baudrate & 0X00FF;
U0DLM=( baudrate >>8) & 0X00FF;
U0LCR=0X03;
U0IER = 0x01; //* Enable UART0 interrupt
/*------- Vector Interrupt Setting -------------*/
VICIntSelect = 0; // Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICProtection = 0; // VIC registers can be accessed in User or
privileged mode
VICVectAddr = 0; // Clear interrupt
VICProtection = 0; // Accesss VIC in USR | PROTECT
VICIntSelect &= ~(1<<VIC_UART0); // Timer 0 intrpt is an IRQ
(VIC_TIMER0 = 4)
VICVectAddr0 = (unsigned int)&UART0_ISR; // Install ISR in VIC addr slot 0
VICVectCntl0 = 0x20 | VIC_UART0; // IRQ type, TIMER 0 int enabled
VICIntEnable |= (1<<VIC_UART0); // Turn on Timer0 Interrupt
}
void feed (void) // PLL FEED Function.
{
PLLFEED=0xAA;
PLLFEED=0x55;
}
void serialtx(char txdata) // Function to transmit the data serially
{
while(!(U0LSR&0x20)); // Checking the Line Status Register ( i.e. Tx flag )
U0RBR=txdata; // Transmitting the data byte.
}

Result: Thus the program for serial transmission and reception of a character in C
by polling method was written and the output was verified.
References:
1. LPC 214x User manual (UM10139)
2. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright
3. https://www.electronicwings.com/arm7/lpc2148-uart0

2 4 4 10 Sign

Experiment No-10
Aim: To write a program for accessing the ADC data from ARM processor and also
display the same in LCD display.
Objective:

To write embedded C program for accessing the ADC data from ARM Processor.

To configure the ADC.

Interface LCD to ARM processor.

Display the ADC value to LCD display.

Learning outcome:

Develop embedded C program for accessing ADC data from ARM

processor.

Configure ADC and send the data to LCD displays

Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:
In this experiment we display 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
millimeter.

ALGORITHM:
Step 1: Start
Step 2: Initialize LCD
Step 3: Send command signals [RS=0, R/W=0, En=1].
Step 4: Send data signals [RS=1, R/W=0, En=1].
Step 5: Set the control register value for clock frequency and bits.
Step 6: Set the control register value for Conversion start.
Step 7: Stop.
PROCEDURE:
➢ Compile, Debug & Simulate the above code in IAR, and see the output in
register view window. ➢ Follow to Steps given below to see/verify the output :
Step-1: Open the IAR workspace. Step-2: Go to project >> option and do the
following settings: General Options: Target >> Processor variant >> Core >>
ARM7TDMI S. a. Output Converter: Output >> Generate additional output:
(Output format >> Intel extended) and (Output file >> Override default >>
project_name.hex)
b.Linker >> Linker configurations file, and browse/provide path for the linker file
as follows:
C:\ProgramFiles\IARSystems\EmbeddedWorkbench5.40\arm\config\linker\NXP\
LPC2148.icf
c.After doing above setting click OK to save/ exit from the option window. Step-3:
Now execute the following: a. Project >> Rebuild all (if you get 0 errors & 0
warnings then only got to next step.)
Step 4: Flash the program in LPC2148 kit. Step 5: Verify the output using LCD.
PROGRAM:
#include<nxp\iolpc2148.h>
#define EN 0x800
#define RW 0X200
#define RS 0x100
#define DONE 0x80000000
#define START 0x01000000
#define PRESET 0x00230600

void delay(void)
{
unsigned int i;
for(i=0;i<0x1fff;i++);
}

void EN_Pulse(void)
{
IO0SET = EN ;
delay();
IO0CLR = EN ;
}

void send_cmd( int addr )


{
IO1PIN = addr<<16;
IO0CLR = RS; EN_Pulse();
}
void send_data( int data )
{
IO1PIN = data<<16;
IO0SET = RS; EN_Pulse();
}
void lcd_initialize(void)
{
send_cmd(0X38); delay();
send_cmd(0X0F); delay();
send_cmd(0X01); delay();
send_cmd(0X06); delay();
send_cmd(0X80); delay();

int main(void)
{
int num,i,d1,d2,d3,d4;
unsigned long Val;

char *display = "Digital value = ";


PINSEL1 = 0x01 << 24;
IO0DIR = 0x00000F00;
IO1DIR = 0x00FF0000;

IO0CLR = RW;
AD0CR = PRESET | 0x02;
AD0CR |= START;

lcd_initialize();

send_cmd(0x80); delay();
for(i=0;i<=15; i++)
{
send_data(display[i]);
}
while(1)
{
do
{
Val = AD0GDR;
}

while ((Val & DONE) == 0);


Val = ((AD0GDR >> 6) & 0x3FF);
num = Val;
d1 = num % 10;
num = num / 10;
d2 = num % 10;
num = num / 10;
d3 = num % 10;
num = num / 10;
d4 = num;
send_cmd (0xc0); delay();
send_data(d4+48); delay();
send_data(d3+48); delay();
send_data(d2+48); delay();
send_data(d1+48); delay();
}}
OR

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

Result: Thus the program for accessing the ADC value from ARM processor was
written and the output was verified in LCD display.
References:
1. https://www.electronicwings.com/arm7/lpc2148-adc-analog-to-digital-
converter
2. LPC 214x User manual (UM10139)
3. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright

2 4 4 10 Sign
Experiment No-11
AIM: Display “Hello World” string on LCD of Raspberry Pi using python program.

Objective:
1. To write python program for display string on LCD of Raspberry Pi.

2. Test and simulate the python program.

Learning outcome:

1. Develop python program to display the string on LCD.

2. Verify the operation of program on Raspberry Pi.

Apparatus:

Sr. No. Apparatus Specifications Quantity


1. Raspberry Pi board - 1

2. LCD Display - 1
3. Serial port cable - 1

Theory:
In 4 bit mode, each byte of data is sent to the LCD in two sets of 4 bits, one after
the other, in what are known as the upper bits and lower bits. Although 8 bit
mode transfers data about twice as fast as 4 bit mode, it takes a longer time for
the LCD driver to process each byte than it takes to transmit the byte.

Procedure:

1. We can download WiringPi using Git. Your Pi may have Git already installed (if
so skip this step), but if not, enter this at the command prompt:

sudo apt-get install git-core


 Note: If you get an error installing Git, run sudo apt-get update and try it again.

2. Now download WiringPi by entering this at the command prompt:

git clone git://git.drogon.net/wiringPi


3. Enter this to change directories:
cd wiringPi
4. Run the installation script with:

./build
5. Test the installation by entering:

gpio -v
Followed by:

gpio readall

Program:

#include <wiringPi.h>
#include <lcd.h>

//USE WIRINGPI PIN NUMBERS


#define LCD_RS 25 //Register select pin
#define LCD_E 24 //Enable Pin
#define LCD_D0 29 //Data pin D0
#define LCD_D1 28 //Data pin D1
#define LCD_D2 27 //Data pin D2
#define LCD_D3 26 //Data pin D3
#define LCD_D4 23 //Data pin D4
#define LCD_D5 22 //Data pin D5
#define LCD_D6 21 //Data pin D6
#define LCD_D7 14 //Data pin D7

int main()
{
int lcd;
wiringPiSetup();
lcd = lcdInit (2, 16, 8, LCD_RS, LCD_E, LCD_D0, LCD_D1, LCD_D2, LCD_D3, LCD_D4,
LCD_D5, LCD_D6, LCD_D7);

lcdPuts(lcd, "Hello, world!");


}

Result:
The String of character is displayed on LCD screen.
References:
1. https://www.digikey.in/en/maker/blogs/2018/how-to-connect-a-
raspberry-pi-to-a-16-x-2-lcd-display
2. LPC 214x User manual (UM10139)
3. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright

2 4 4 10 Sign

Experiment No-12
AIM: Interface of LM 35 temperature sensor.
Objective:

1. To write embedded C program for interface the temperature sensor LM 35.

2. Test and simulate the embedded C Program.

Learning outcome:

1. Develop embedded C program for LM35 interfacing.

2. Verify the operation of program on ARM development Kit.


Apparatus:

Sr. No. Apparatus Range Quantity


1. ARM Development Kit LPC2148 1

2. Keil µVision3 IDE - 1


3. Serial port cable - 1

Theory:
The LM35 is an integrated circuit sensor that can be used to measure
temperature with an electrical output proportional to the temperature (in degree
centigrade).The LM35 device has an advantage over linear temperature sensors
calibrated in Kelvin, as the user is not required to subtract a large constant
voltage from the output to obtain convenient Centigrade scaling.

Its measurement range is from -55°C to 150°C having typical accuracy(s) of 0.25°C
at room temperature and 0.75°C for full range. LM35 also supports a wide range
of supply voltage from 4V to 30V and is available in 4 different packages viz. TO-
CAN, TO-92, SOIC and TO-220.

Program
#include<lpc214x.h>
#include<stdio.h>
#define adc_sel 27 //for pinsel
#define clkdiv 8
#define ch0 0
#define burst_mode 16
#define pdn 21
#define start 24
#define done 31
#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 12
#define en 13
#define TEMP_PIN (1<<29) //P0.29 as Input to Temperature Sensor
#define TEMP_PIN_DIR (1<<26) //Bit 27:26 of PINSEL1 register
#define _PDN_BIT 1<<21
#define _ADCR_START_MASK 7<<24
#define _ADCR_SEL_MASK 0x000000FF
#define _ADC0_START 1<<24
void delay(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<5000;j++);
}
void cmnd()
{
lcdportclr=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<13);
cmnd();
lcdportclr = ((ch&0xf0)<<13);
lcdport = (((ch<<4)&0xf0)<<13);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
 
void daten()
{
lcdport=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
 
void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<13);
daten();
lcdportclr = ((ch&0xf0)<<13);

lcdport = (((ch<<4)&0xf0)<<13);
daten();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
 
void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
 
void io_init()
{
PINSEL0=0X000;
IODIR0=0xffffff;
}
void Adc0Init(unsigned char clk)
{
PCONP |= 0x00001000;//Power on the A/D converter 0
//configure the A/D control register of A/D 0  
AD0CR =((unsigned long)(clk+1)<<8 ) | _PDN_BIT ;
}
unsigned int Adc0Read(unsigned char channel)
{
static unsigned val;
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK);  //stop the A/D
converter by masking the
     //sta
rt bits and channel selection bit    
AD0CR |=((unsigned long)(1)<<channel);   //Select the A/D
channel
AD0CR |=_ADC0_START;
while(!(AD0GDR & (0x80000000)));     //Wait for the
conversion to get over
  //by
monitoring the 28th bit of A/D data register
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK);  //Stop the
conversion by masking the start bits
 
val = AD0GDR;
val = ((val>>6 & 0x03FF));   //Extract A/D result
return(val);
}
int main()
{
float temperature=0.0;
char result[5];
PINSEL1 |= TEMP_PIN_DIR; //Bit 27:26 of PINSEL1 register
IODIR0 &= ~(TEMP_PIN); //Select the AD0.3 of P0.28 as Input

io_init();
lcd_init();
lcdcmd(0x84);
lcdstring("Temperature");
Adc0Init(10);

while(1)
{

temperature = (((float)Adc0Read(2)/1023.0)*3.3*100);
lcdcmd(0xc5);
sprintf(result,"%f",temperature);
lcdstring(result);
lcddata(0xDF); //for degree character
lcddata('C');
        delay(100);

}
}

Result: The LM 35 temperature sensor is interfaced with ARM processor recorded


temperature is displayed on LCD.
References:
1. https://www.pantechsolutions.net/blog/interface-lm35-sensor-with-
lpc2148-arm7/
2. LPC 214x User manual (UM10139)
3. ARM System Developer’s Guide – Designing and Optimizing System
Software- Andrew Sloss, Dominic Symes, Chris Wright

2 4 4 10 Sign

You might also like