You are on page 1of 60

RANGANATHAN POLYTECHNIC COLLEGE

COIMBATORE.

24064-EMBEDDED SYSTEMS
LAB MANUAL

For VI Sem Diploma in Electronics And Communication Engineering

( L- Scheme )

Prepared By

K.Shanmuga Priya
Lecturer / ECE
EXP.NO:1
STUDY OF ARM PROCESSOR KIT
DATE:

AIM:

To study about memory mapping of peripherals & I/O, Timer and UART operation with SFRs in
ARM processor kit.

APPARATUS REQUIRED:

1. LPC2148 kit

2. User manual

THEORY:

ARM is a 32bit processor. It is a high performance, low power (3.3v) device works with RISC
principle.

List of peripherals:

1. 32 KB SRAM

2. 512 KB FlashRAM

3. GPIO ports (fast & slow)

4. Timers (0 & 1)

5. UART (0 & 1)

6. A/D converter (0 & 1)

7. D/A converter

8. Real time clock

9. Serial interface (I2C, SPI)


Memory and I/O mapping: (LPC2148)

It is a process of sharing 4GB capacity of LPC2148 between memories and onchip peripherals.

VPB PERIPHERAL MAP:


AHB PERIPHERAL MAP:
1. GENERAL PURPOSE I/O

LPC2148 processor has two I/O ports, port0 and port1

Port 0 P0.31 P0.0 32 I/O lines


Port 1 P1.31 P1.16 16 I/O lines

Each pin out of the Microcontroller has several functions, maximum of 4 functions. In order to use
the physical pin out for a specific function, the pin is to be configured for that function. In order to
configure, it needs 2 bits (to carry out any one of 4 functions). For this purpose, there is a register called
PINSEL register.
PINSEL0, 32 bit register is used to configure Pin outs for P0.0 to P0.15 (16 pins), since each pin
needs 2 bits.
PINSEL1 register is used to configure Pin outs for P0.16 to P0.31
PINSEL2 register is used to configure Pin outs for P1 Port, P1.16 to P1.31

After, configuring the pin as I/O line, next it is to be designated as input pin or output pin. It is done by
another register namely IODIR.
IODIR0, 32 bit register is used to designate each I/O line in Port 0. Against the particular bit, if 1 is
written, then that bit in the Port 0 is designated as Output pin. If 0 is written in the particular bit position,
then that I/O pin will act as input pin.
Similarly, IODIR1, the bits 16 to 31 is used to designate the Port1 pins either as output or as input
If the pin is configured as output pin, in order to write 1 level in that pin, IOSET register is used. In
order to write 0 level in that pin, IOCLR register is used. It is to be noted that using single register IOSET
register, it is not possible to clear the bit.

IOSET0, 32 bit register is used to write 1 in any one of the output pin of Port0
IOCLR0, 32 bit register is used to write 0 in any one of the output pin of Port0
IOSET1, 32 bit register is used to write 1 in any one of the output pin of Port1
IOCLR1, 32 bit register is used to write 1 in any one of the output pin of Port1
If the pin is configured as input pin, in order to read the data from that pin, IOPIN register is used.
IOPIN0, 32 bit register is used to read the data from any one of the I/O pins of Port0.
IOPIN1, 32 bit register is used to read the data from any one of the I/O pins of Port1.

2. TIMERS (Timer0 and Timer1) & SFR Regosters:

There are 2 nos. of 32 bit timers in this Microcontroller. Timer is basically a counter. For timer,
internal clock is given as input. Internally, PCLK, Peripheral clock is given as the input pulses.

Timer0 registers
TC0 Timer Counter Register (32 bit register). For every clock pulse, this register is incremented.
Before the clock pulse is given to TCO, the clock pulses are given to the Prescale Counter namely
PC0 32 bit register. Along with PC0, there is another register namely Prescale Register PR0 32 bit
register. The PC0 gives one output pulse for each prescale register value. For example, if the PR0 has the
value of decimal 10, then the PC0 gives one output pulse for every 10 input clock pulses. The Prescale
Counter output is given as the clock pulse to Timer Counter register TC0. In this way, 32 bit Prescale
divider is included in the timer operation.

TCR0 Timer Control Register. This register is used to reset the counter and disable/enable the
Timer Counter Register TC0.

T0MR0 Match0 Register. It is a 32 bit register. The 32 bit content entered is compared with the
content of Timer/Counter Register TC0 continuously. When the match occurs, the following functions can
be actuated.
1. If the interrupt enable bit is made 1, interrupt flag bit for MR0 is made 1 in T0IR register.
2. The Timer/Counter register can be made to reset.
3. The Timer/Counter register can be disabled.
4. In the corresponding pin MAT0.0 for MR0, output can be generated.
The first 3 functions can be actuated by writing control bits in MCR register Match Control Register.

Similar to T0MR0, there are T0MR1, T0MR2, T0MR3 match registers. They can be also used for
comparing with the contents of Timer/Counter (TC) register. On match, the above functions for the
corresponding match register can be actuated.

T0IR It is an 8 bit interrupt register. For every match, corresponding bit in this interrupt register is
set. On writing again the same bit in the Interrupt Service Routine, the corresponding bit will be cleared.

Similar to match registers, there are 4 capture registers namely T0CR0, T0CR1, T0CR2 and
T0CR3. The content of Timer/Counter (TC) register value is loaded into T0CR0, when an event on
physical pin CAP0.0, one particular physical input.

T0CCR is a 32 bit register which controls which edges of the capture inputs are used to load the
Capture registers and whether or not an interrupt is generated when a capture takes place.

In order to use the timer as counter, T0CTCR register is used. It is used to change to counter mode
and to determine in which pin, physical count input pulses is given.

3. UART Universal Asynchronous Receiver Transmitter (UART0 and UART1)

UART0 has lines TXD, RXD and Gnd lines for interfacing simple serial port.
UART1 has lines apart from the above, control lines for interfacing Modem also. Now, we are going to see
only the registers available in UART0

UART0 is used to send the byte of data serially and receive the byte of the data serially.

At the time of receiving, it receives the bits serially and assembles as parallel 8 bit data and it places
in the receiver buffer register U0RBR. It is the content of the top of the FIFO buffer registers.

At the time of transmitting, the user is supposed to place the 8 bit data in Transmit Hold Register
namely U0THR.
In serial communication, the serial data is sent in the same rate at which the receiving system also
receives. This is called baud rate (bits per second). For example, 9600 baud means 9600 bits per second.
The internal clock is divided by 16 bit no. to arrive at the required baud rate.

The Most Significant 8 bits of the divider value are stored is called U0DLM. The Least Significant
8 bits of the divider value are stored in the register called U0DLL. At the time of writing in these registers
only, DLAB bit in the U0LCR register (Line Control Register) is to be made 1.

Whenever, the U0THR register is empty, the next byte of data can be sent to send it out serially.

Similarly, whenever, a byte of data is received, it is placed in U0RBR. As soon as it happen,


interrupt may be raised to inform the user. But interrupts are to be enabled before the use. There is an
interrupt enable register namely U0IER. By writing proper bits in the register, the above events will raise
the interrupt.

There is another register U0IIR, which is used to find what are all the interrupts pending.

The register FIFO control register U0FCR is used to reset TX FIFO (Transmit First In First Out register set)
and RX FIFO (Receive First In First Out) and to enable them.

The register U0LCR, line control register is used to write serial protocol parameters namely, the word
length of the data, no. of stop bits, parity enable, parity select, Break control. The 7th bit in this register
namely DLAB is used to enter the 16 bit divisor data.

Line Status register U0LSR is the status register to know whether data has been received, data can be sent
for transmission, to find out errors.

There is another register U0TER which is used to enable the serial transmitter

4. A to D Converter

There are 2 units of A/D Converters in this controller AD0 and AD1. There are 6 channels in AD0
unit and 8 channels in AD1 unit. It is a 10 bit ADC. The maximum analog voltage that can be given as input
is 3.3V. It uses Successive Approximation techniques to convert analog input to corresponding 10 bit digital
output. It requires clock which will be less than 4 MHz.

AD0CR register is a control register in which the details of the channel to be used, clock speed
divider, switching on the ADC Section and finally start signal to start the converter.

AD0GDR is the global data register. The done bit for the latest conversion and the 10 bit digital data
are available in this register.

AD0STAT is the A/D Status register. This register contains Done and error bits for all the channels
for AD0 unit.

ADGSR is the global start register. It is used to start conversion in both A/D Converters AD0 and
AD1 simultaneously.

AD0INTEN is A/D Interrupt Enable register. This register contain enable bits that allow the DONE
flag of each A/D Channel to raise common A/D interrupt.
EXP.NO:2
SIMULATION OFARITHMETIC OPERATION ON ARM IN
DATE: ASSEMBLY.

There are eight ADDR0, ADDR1, ADDR2, ADDR3, ADDR4, ADDR5, ADDR6 and ADDR7 Data
register. This register contains the result of the most recent conversion completed in the respective channel

RESULT:

Thus the memory mapping of peripherals & I/O, Timer and UART operation with SFRs in ARM
processor kit was studied.

AIM:

To write and simulate the assembly language program for addition, subtraction and multiplication.

APPARATUS REQUIRED:

1. PC

ALGORITHM:

Step 1: Load the first value in register.

Step 2: Load the second value in another register.

Step 3: By using proper instruction arithmetic operation is performed and the result
stored in destination register.

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 "Arithmetic" workspace.


Step-2: Go to project >> option and do the following settings:
General Options: Target >> Processor variant >> Core >> ARM7TDMI S.
Output Converter: Output >> Generate additional output : ( Output format >> Intel
extended ) and ( Output file >> Override default >> project_name.hex )
Linker >> Linker configuration file, and browse/provide path for the linker file as follows :
C:\Program Files\IAR Systems\Embedded Workbench
5.40\arm\config\linker\NXP\LPC2148.icf
After doing above setting click OK to save/ exit from the option window.
Step-3: Now execute the following:
Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next step.)

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.
Project >> Make & Restart Debugger. (Here the debugging process is ready to check the
output by step by step execution of the code).

PROGRAM:

#include <NXP/iolpc2148.h>

NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32

__iar_program_start

B main

SECTION .text : CODE (2)


CODE32

/*-------- Explanation of the code is given, you are recommended to follow this. ---*/

main NOP
LDR R0,=0X5 // Operend-1 ( 11111111 in hexadecimal ) stored in R0 .
LDR R1,=0XA // Operend-2 ( 11111111 in hexadecimal ) stored in R1 .

ADD R8,R1,R0 // Addition result is stored in register R8.


// Logic : R8 = R0 + R1

SUB R9,R1,R0 // Subtraction result is stored in register R9.


// Logic : R9 = R1 + R0

MUL R10, R1,R0 /* For less than 32-bit result.*/


// Logic : R9 = R1 * R0

/* R0 : 32-bit Operend-1 &


/* R1 : 32-bit Operend-2
/* R1*R0 : 32-bit (maximum) Output result.*/

/* Result is stored in 32-bit register. ( R10 )*/

UMULL R11,R12,R1,R0 /* For more than 32-bit result.*/


/* R0 : 32-bit Operend-1 &
/* R1 : 32-bit Operend-2
/* R1*R0 : 64-bit (maximum) Output result.*/

/* To store the multiplication result 64-bits are needed.


Here,
Two 32-bit registers are used to store the multiplication result.

R11 : It stores the LSB of the multiplication result. &


R12 : It stores the MSB of the multiplication result.*/

stop B stop // Halt the program.

END
EXP.NO:3
SIMULATION OF SOFT DELAY IN ASSEMBLY.
DATE:

RESULT:

Arithmetic Operation (Addition, Subtraction, and Multiplication) on ARM in assembly was written
& output is verified by checking the output register window in debugging without downloading mode.

AIM:

To write and simulate the assembly language program for soft delay.

APPARATUS REQUIRED:

1. PC

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 S.
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:
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 <nxp\iolpc2148.h>

NAME This_is_an_Assembly_Code. // Any name

PUBLIC __iar_program_start

SECTION .intvec : CODE (2)

CODE32

__iar_program_start

B main

SECTION .text : CODE (2)

CODE32

//----------- Delay Subroutine -------------------

delay

LDR R0,=1000 // 32-bit delay1 value

Loop1: LDR R1,=400 // 32-bit delay2 value

Loop2: SUBS R1,R1,#1 /* So total Delay = 32+32 = 46 bit delay routine */

BNE Loop2
SUBS R0,R0,#1

BNE Loop1

MOV PC,LR // return statement

//----------- Pointer goes to Main function -------------------

main

NOP //To Select the p1.16-p1.23 as gpio lines

LDR R0,=PINSEL2

MOV R1,#0X00000000

STR R1,[R0]

//To Set the p1.16-p1.23 as output

LDR R0,=IO1DIR

MOV R1,#0Xff000000

STR R1,[R0]

led_glow:

//To Set high on port lines p1.16-p1.23

LDR R0,=IO1PIN

MOV R1,#0Xff000000

STR R1,[R0]

BL delay

//To Set low on port lines p1.16-p1.23

LDR R0,=IO1PIN

MOV R1,#0X00000000

STR R1,[R0]

BL delay

B led_glow

stop B stop // Halt


EXP.NO:4
LED BLINKING VARIABLE SPEED IN ASM
DATE:

END

RESULT:

Thus the assembly language program for soft delay was written and the output was simulated and
verified.

AIM:

To write an assembly language program for blinking LED with variable speed.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

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 S.
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:
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.)

Step 4: Flash the program in LPC2148 kit.

Step 5: Verify the output using onboard LEDs.

PROGRAM:

#include <nxp\iolpc2148.h>

NAME This_is_an_Assembly_Code. // Any name

PUBLIC __iar_program_start

SECTION .intvec : CODE (2)

CODE32

__iar_program_start

B main

SECTION .text : CODE (2)

CODE32

//----------- Delay Subroutine -------------------

delay

LDR R0,=1000 // 32-bit delay1 value


Loop1: LDR R1,=400 // 32-bit delay2 value

Loop2: SUBS R1,R1,#1 /* So total Delay = 32+32 = 46 bit delay routine */

BNE Loop2

SUBS R0,R0,#1

BNE Loop1

MOV PC,LR // return statement

//----------- Pointer goes to Main function -------------------

main

NOP //To Select the p1.16-p1.23 as gpio lines

LDR R0,=PINSEL2

MOV R1,#0X00000000

STR R1,[R0]

//To Set the p1.16-p1.23 as output

LDR R0,=IO1DIR

MOV R1,#0Xff000000

STR R1,[R0]

led_glow:

//To Set high on port lines p1.16-p1.23

LDR R0,=IO1PIN

MOV R1,#0Xff000000

STR R1,[R0]

BL delay

//To Set low on port lines p1.16-p1.23

LDR R0,=IO1PIN

MOV R1,#0X00000000

STR R1,[R0]

BL delay
EXP.NO:5
REALIZATION OF INPUT AND OUTPUT PORT IN ASM
DATE:

B led_glow

stop B stop // Halt

END

RESULT:

Thus the assembly language program for LED blinking with variable speed was written and the
output was verified using LEDs.

AIM:

To write an assembly language program so as to realize the input and output port in LPC2148 kit.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

ALGORITHM:

Step 1: Declare DIR register for input & output function.

Step 2: Set the port pin value in port 0 & corresponding output can be found in port 1.
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 configuration file, and browse/provide path for the linker file as follows:
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.)

Step 4: Flash the program in LPC2148 kit.

Step 5: Verify the output using onboard LEDs.

PROGRAM:

#include <nxp\iolpc2148.h>

NAME LED_SWITCH // Any name

PUBLIC __iar_program_start

SECTION .intvec : CODE (2)

CODE32

__iar_program_start

B main

SECTION .text : CODE (2)

CODE32
//----------- Delay Subroutine -------------------

delay:

LDR R0,=0Xf // delay value

LOOP:

SUBS R0,R0,#1

BNE LOOP

MOV PC,LR // return statement

//----------- Main function starts here -------------------

main: NOP

LDR R0,=PINSEL1

MOV R1,#0X00000000 // Configure the port as GPIO.

STR R1,[R0]

LDR R0,=PINSEL2

MOV R1,#0X00000000 // Configure the port as GPIO .

STR R1,[R0]

LDR R0,=IO1DIR

MOV R1,#0Xff000000 //To Set the p0.24-p0.31 as output ( LED )

STR R1,[R0]

LDR R0,=IO0DIR

MOV R1,#0X00000000 //To Set the p0.16-p1.23 as input ( SWITCH )

STR R1,[R0]

GLOW_LED

LDR R0,=IO0PIN // READ the SWITCHs address in R0

LDR R1,[R0] // Move the read value from R0 to R1

LSL R1,R1,#8 // Shift the value 8-bit left

MOV R2,#0XFF000000
EXP.NO:6
SIMPLE LED BLINKING WITH VARIABLE SPEED IN C
DATE:

AND R2,R2,R1 // Make unused bits = 0

LDR R0,=IO1PIN // STORE LEDs address to R0

STR R2,[R0] // Store the switches value at LED address

BL delay // After some delay

B GLOW_LED // Repeat the same forever

stop B stop // Halt

END

RESULT:

Thus the assembly language program realizing the input and output port in LPC2148 kit was written
and the output was verified.

AIM:

To write an assembly language program for blinking LED with variable speed in C.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.


ALGORITHM:

Step 1: Start

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 S.
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:
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.)

Step 4: Flash the program in LPC2148 kit.

Step 5: Verify the output using onboard LEDs.

PROGRAM:

#include<nxp/iolpc2148.h>

void delay_ms() //delay routine

int i;

for(i=0;i<60000;i++);

}
void main()

IO1DIR = 0xff000000;

while(1)

IO1SET=0xff00f000 ;

delay_ms();

IO1CLR=0xff00f000 ;

delay_ms();

RESULT:

Thus the C language program for LED blinking with variable speed was written and the output was

EXP.NO:7
SEVENSEGMENT LED DISPLAY INTERFACE IN C
DATE:

verified using LEDs.

AIM:

To write a program in Embedded C for 7 segment LED display and verify the output using LPC2148
kit.
APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

ALGORITHM:

Step 1: Start

Step 2: Data is given in serial manner through shift register.

Step 3: Call delay routine for one second of each display.

Step 4: Output will be displayed in 7 segment display.

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\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.)

Step 4: Flash the program in LPC2148 kit.

Step 5: Verify the output using onboard 7 segment LEDs.


PROGRAM:

#include <nxp\iolpc2148.h>

#define counter_delay 0x4ffff // Counter Delay (1 second approx. )

void delay(unsigned int k)

for(int i=0;i<k;i++);

}
void i2c_config(void)

PINSEL0|=0X00000050;

I2C0CONCLR=0X6C;

I2C0CONSET=0X40;

I2C0SCLH=70;

I2C0SCLL=50;

void i2c_write(char address,char data)

I2C0CONSET=0X20;

delay(50);

while(I2C0STAT!=0x08);

I2C0CONCLR=0X28;

// To send a slave address

I2C0DAT=address;

delay(50);

while(I2C0STAT!=0x18);

I2C0CONCLR=0x08;

//Data has been written to appropriate address

I2C0DAT=data;

delay(50);

while(I2C0STAT!=0x28);

//stop condition

I2C0CONSET=0X10;

I2C0CONCLR=0x08;
delay(50);

void counter(int limit)

unsigned char data[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

unsigned char i=0,j=0,k=0,l=0;

int cnt;

for(cnt=0;cnt<=limit;cnt++) // loop to run the counter

i2c_write(0x46,data[i]); // writing data to 1st digit (LSB)

i2c_write(0x44,data[j]); // writing data to 2nd digit

i2c_write(0x42,data[k]); // writing data to 3rd digit

i2c_write(0x40,data[l]); // writing data to 4th digit (MSB)

delay(counter_delay); // Counter Delay ( 1 second approx. )

i++; // Incrementing unit digit if its count value is < 9

if(i==10) // Making unit digit =0 if it reaches to 10.

{ i=0;

j++; // Incrementing tens digit if its count value is < 9

if(j==10) // Making tens digit =0 if it reaches to 10.

{ j=0;

k++; // Incrementing hundreds digit if its count value is < 9

if(k==10) // Making hundreds digit =0 if it reaches to 10.

{k=0;

l++; // Incrementing thousand digit if its count value is < 9

if(l==10) // Making thousand digit =0 if it reaches to 10.


{ i=0;

j=0;

k=0; // Making all digits =0 if count is over.

l=0;

void main(void)

unsigned char i,address[6]={0x40,0x42, 0x44, 0x46, 0x48, 0x4A};

i2c_config(); // confugring I2C for 7 segment driver .

for(i=0;i<6;i++) {i2c_write(address[i],0x00);} // making all 7 segment blank.

counter(110); // counting upto cunnting limit.

} // Here counting limit is 110.

RESULT:

Thus the program in Embedded C for 7 segment LED display was written and the output was verified using

EXP.NO:8 SEVENSEGMENT LED DISPLAY USING ASM DELAY


LPC2148 kit.
DATE:

AIM:

To write a program for 7 segment LED display in Embedded C by using ASM delay and verify the
output using LPC2148 kit.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

ALGORITHM:

Step 1: Start

Step 2: Data is given in serial manner through shift register.

Step 3: Call delay routine for one second of each display.

Step 4: Output will be displayed in 7 segment display.

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: project >> option>>add files (asmdelay.s)
Step-3: Go to project >> option and do the following settings:
General Options: Target >> Processor variant >> Core >> ARM7TDMI S.
C, C++ compiler>> code>>ARM
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\Embedded Workbench 5.40\arm\config\linker\NXP\LPC2148.icf
c. After doing above setting click OK to save/ exit from the option window.
d. Copy asm delay.s file and then paste it inside the created folder.
Step-4: Now execute the following:
a. Project >> Rebuild all (if you get 0 errors & 0 warnings then only got to next step.)
Step 5: Flash the program in LPC2148 kit.
Step 6: Verify the output using onboard 7 segment LEDs.
PROGRAM:

#include<nxp/iolpc2148.h>
extern void delay(void); // Definition of this function is available in

// " asm_delay.s " so you must add this file with the project.

void i2c_config(void)

PINSEL0|=0X00000050; // To select the Port pins p0.2 and p0.3 as i2c configurable

I2C0CONCLR=0X6C; // To clear all bits in the i2c0 register

I2C0CONSET=0X40; // To enable the i2c

I2C0SCLH=70;

I2C0SCLL=50; // To set clock rate as 100 KHZ

void i2c_write(char address,char data)

I2C0CONSET=0X20;

while(I2C0STAT!=0x08);

I2C0CONCLR=0X28;

// To send a slave address

I2C0DAT=address;

while(I2C0STAT!=0x18);

I2C0CONCLR=0x08;

//Data has been written to appropriate address

I2C0DAT=data;

while(I2C0STAT!=0x28);

//stop condition

I2C0CONSET=0X10;

I2C0CONCLR=0x08 ;}

void counter(int limit)

{
unsigned char data[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

unsigned char i=0,j=0,k=0,l=0;

int cnt;

for(cnt=0;cnt<=limit;cnt++) // loop to run the counter

i2c_write(0x46,data[i]); // writing data to 1st digit (LSB)

i2c_write(0x44,data[j]); // writing data to 2nd digit

i2c_write(0x42,data[k]); // writing data to 3rd digit

i2c_write(0x40,data[l]); // writing data to 4th digit (MSB)

delay(); // Counter Delay ( 1 second approx. from asm_delay.s )

i++; // Incrementing unit digit if its count value is < 9

if(i==10) // Making unit digit =0 if it reaches to 10.

{ i=0;

j++; // Incrementing tens digit if its count value is < 9

if(j==10) // Making tens digit =0 if it reaches to 10.

{ j=0;

k++; // Incrementing hundreds digit if its count value is < 9

if(k==10) // Making hundreds digit =0 if it reaches to 10.

{k=0;

l++; // Incrementing thousand digit if its count value is < 9

if(l==10) // Making thousand digit =0 if it reaches to 10.

{ i=0;

j=0;

k=0; // Making all digits =0 if count is over.

l=0;

}
}

//----------- Main function starts here -------------------

void main(void)

unsigned char i,address[6]={0x40,0x42, 0x44, 0x46, 0x48, 0x4A};

i2c_config(); // confugring I2C for 7 segment driver .

for(i=0;i<6;i++) {i2c_write(address[i],0x00);} // making all 7 segment blank.

counter(110); // counting upto cunnting limit.

// Here counting limit is 110.

Program: 2 asm-delay.s

#include <nxp\iolpc2148.h>

NAME This_is_delay_function. // Any name

EXTERN rand

PUBLIC delay // Declaration of symbol to be exported

SECTION .text: CODE (2) // to main function

CODE32

//----------- Delay Subroutine -------------------

delay

LDR R0,=400000 // Delay value for 1 Second.

LOOP:

SUBS R0,R0,#1
BNE LOOP

MOV PC,LR // return statement

//----------- Pointer goes to Main function -------------------

stop B stop // Halt

END
RESULT:

Thus the program for 7 segment LED display in Embedded C by using ASM delay was written and the output

EXP.NO:9
REALIZING TIMER PERIPHERAL BY POLLING METHOD
DATE:

was verified using LPC2148 kit.

AIM:

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

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

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\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.)
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.

EXP.NO:10 REALIZING TIMER PERIPHERAL IN ARM BY INTERRUPT


DATE: DRIVEN METHOD

AIM:

To write a program for realizing the timer peripheral in ARM by interrupt driven method and verify
the output using LPC2148 kit.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

ALGORITHM:

Step 1: Start

Step 2: Initialize VIC registers [enable reg,address reg,control reg]

Step 3: Initialize timer registers.

Step 4: Set the prescale 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\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.)
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.

EXP.NO:11 SERIAL TRANSMISSION AND RECEPTION BY POLLING


DATE: METHOD

AIM:

To write a program for serial transmission and reception of a character in C by polling method and
verify the output.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

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\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.)
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.

EXP.NO:12 SERIAL TRANSMISSION AND RECEPTION BY INTERRUPT


DATE: METHOD

AIM:

To write a program for serial transmission and reception of a character in C by interrupt method and
verify the output.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

ALGORITHM:

Step 1: Start

Step 2: Initialize UART registers.

Step 3: Initialize VIC registers [enable reg,address reg,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\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.)

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.

EXP.NO:13 DISPLAYING ALPHA NUMERIC CHARACTERS IN 2X16 LCD


DATE: DISPLAY

AIM:

To write a program for displaying the alpha numeric characters in 2x16 LCD display and verify the
output using LPC2148 kit.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.


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: Display 2 messages in LCD display.

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\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.)
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

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)

unsigned char alphabets[16]= {"Embedded Systems"};

unsigned char numbers[16]= {" 04/02/2014 "};

unsigned char i=0,j=0,line1=0x80,line2=0xC0;

IO0DIR = 0x00000F00;

IO1DIR = 0x00FF0000;

IO0CLR = RW;

lcd_initialize();

for(j=0;j<1;j++)

for(i=0;i<16;i++)

send_cmd(line1+i); delay();

send_data(alphabets[i]); delay();

for(i=0;i<16;i++)

send_cmd(line2+i); delay();

send_data(numbers[i]); delay();

}
}

RESULT:

Thus the program for displaying the alpha numeric characters in 2x16 LCD display was written and the output

was verified.

EXP.NO:14 CONVERTING HEXA DECIMAL TO DECIMAL AND DISPLAY IN


DATE: LCD DISPLAY

AIM:

To write a program for converting the hexadecimal value to decimal value and also display the same
in LCD display.

APPARATUS REQUIRED:

1. PC

2. LPC2148 Kit
3. Serial port cable & power cable.

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: Do the conversion process.

Step 6: Display the values in LCD display.

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\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.)
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

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;

char *display = "Decimal value = ";

IO0DIR = 0x00000F00;

IO1DIR = 0x00FF0000;

IO0CLR = RW;

lcd_initialize();

num = 0xFF;

d1 = num % 10;

num = num / 10;

d2 = num % 10;

num = num / 10;

d3 = num;

send_cmd(0x80); delay();

for(i=0;i<=15; i++)

send_data(display[i]);

send_cmd (0xc0); delay();

send_data(d3+48); delay();

send_data(d2+48); delay();

send_data(d1+48); delay();

while(1)

}
}

RESULT:

Thus the program for hexadecimal to decimal conversion was written and the output was verified.

EXP.NO:15 ACCESSING INTERNAL ADC OF THE ARM PROCESSOR AND TO


DATE: DISPLAY IN LCD

AIM:

To write a program for accessing the ADC value from ARM processor and also display the same in
LCD display.

APPARATUS REQUIRED:
1. PC

2. LPC2148 Kit

3. Serial port cable & power cable.

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\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.)
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();

}}
RESULT:

Thus the program for accessing the ADC value from ARM processor was written and the output was verified
in LCD display.
869; RANGANATHAN POLYTECHNIC COLLEGE

COIMBATORE

24064-EMBEDDED SYSTEMS PRACTICAL

(For VI sem Electronics and Communication Engineering)

(L Scheme)

K.SHANMUGA PRIYA, B.E., .,

LECTURER/ECE

RANGANATHAN POLYTECHNIC COLLEGE

COIMBATORE.

You might also like