0% found this document useful (0 votes)
328 views92 pages

Embedded Systems For ECE

The document describes the structure and features of the LPC2148 ARM processor. It contains information on the ARM7TDMI-S CPU, flash memory size ranging from 32kB to 512kB, and interfaces enabling 32-bit code execution at 60MHz. Key features include USB, ADC, DAC, timers, GPIO pins, and low power modes. The document also provides details on the pin functions, port registers used for configuration, and a block diagram of the architectural overview.

Uploaded by

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

Embedded Systems For ECE

The document describes the structure and features of the LPC2148 ARM processor. It contains information on the ARM7TDMI-S CPU, flash memory size ranging from 32kB to 512kB, and interfaces enabling 32-bit code execution at 60MHz. Key features include USB, ADC, DAC, timers, GPIO pins, and low power modes. The document also provides details on the pin functions, port registers used for configuration, and a block diagram of the architectural overview.

Uploaded by

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

Sundar Sripada V.S.

312216106111

Ex. No.:
Date:
STUDY OF ARM PROCESSOR
AIM:
To study LPC2148 ARM (Advanced RISC Machines) Processor and understand &
describe it’s structure.

THEORY:
The LPC2141/42/44/46/48 microcontrollers are based on a 16-bit/32- bit ARM7TDMI-S CPU
with real-time emulation and embedded trace support, that combine the microcontroller with
embedded high-speed flash memory ranging from 32 kB to 512 kB. A 128-bit wide memory
interface and a unique accelerator architecture enable 32-bit code execution at the maximum
clock rate. For critical code size applications, the alternative 16-bit Thumb mode reduces code by
more than 30 % with minimal performance penalty. Due to their tiny size and low power
consumption, LPC2141/42/44/46/48 are ideal for applications where miniaturization is a key
requirement, such as access control and point-ofsale. Serial communications interfaces ranging
from a USB 2.0 Full-speed device, multiple UARTs, SPI, SSP to I2C-bus and on-chip SRAM of
8 kB up to 40 kB, make these devices very well suited for communication gateways and protocol
converters, soft modems, voice recognition and low end imaging, providing both large buffer size
and high processing power. Various 32-bit timers, single or dual 10-bit ADC(s), 10-bit DAC,
PWM channels and 45 fast GPIO lines with up to nine edge or level sensitive external interrupt
pins make these microcontrollers suitable for industrial control and medical systems.

FEATURES:
• 16-bit/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

• 8 kB to 40 kB of on-chip static RAM and 32 kB to 512 kB of on-chip flash memory.

• 128-bit wide interface/accelerator enables high-speed 60 MHz operation.

• In-System Programming/In-Application Programming (ISP/IAP) via onchip boot loader


software. Single flash sector or full chip erase in 400 ms and programming of 256 B in 1
ms.
Sundar Sripada V.S.
312216106111

• Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with the on-
chip Real Monitor software and high-speed tracing of instruction execution.
• USB 2.0 Full-speed compliant device controller with 2 kB of endpoint RAM.

• In addition, the LPC2146/48 provides 8 kB of on-chip RAM accessible to USB by DMA.

• One or two (LPC2141/42 vs. LPC2144/46/48) 10-bit ADCs provide a total of 6/14 analog
inputs, with conversion times as low as 2.44 micro sec per channel.
• Single 10-bit DAC provides variable analog output (LPC2142/44/46/48 only).

• Two 32-bit timers/external event counters (with four capture and four compare channels
each), PWM unit (six outputs) and watchdog.
• Low power Real-Time Clock (RTC) with independent power and 32 kHz clock input.

• Multiple serial interfaces including two UARTs (16C550), two Fast I2Cbus (400 kbit/s),

• SPI and SSP with buffering and variable data length capabilities.

• Vectored Interrupt Controller (VIC) with configurable priorities and vector addresses.

• Up to 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.

• Up to 21 external interrupt pins available.

• 60 MHz maximum CPU clock available from programmable on-chip PLL with settling
time of 100 micro s.
• On-chip integrated oscillator operates with an external crystal from 1 MHz to 25 MHz.

• Power saving modes include Idle and Power-down.

• Individual enable/disable of peripheral functions as well as peripheral clock scaling for


additional power optimization.
• Processor wake-up from Power-down mode via external interrupt or BOD.

• Single power supply chip with POR and BOD circuits:

• CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O pads.
Sundar Sripada V.S.
312216106111

PIN DETAILS:

PIN DESCRIPTION:
Input/Output Ports (GPIO of LPC2148):
Port Pins Type Description
General purpose
P0.0-P0.31 P1.16-P1.31 Input/output input/output. The number of
GPIOs actually available
depends on the use of
alternate functions.

PORT 0 is a 32-bit I/O port with individual direction controls for each bit. Total of 28 pins of the
Port 0 can be used as a general purpose bi-directional digital I/Os while P0.31 provides digital
output functions only. The operation of port 0 pins depends upon the pin function selected via the
pin connectblock. Pins P0.24, P0.26 and P0.27 are not available.

PORT 1 is a 32-bit bi-directional I/O port with individual direction controls


for each bit. The operation of port 1 pins depends upon the pin function selected via the pin
connect block. Pins 0 through 15 of port 1 are not available.
PORT0 and PORT1 are controlled via two groups of registers explained below.
Sundar Sripada V.S.
312216106111

IOPIN is GPIO Port Pin value register. The Current State of the GPIO configured port pins can
always be read from this register, regardless of pin direction.

IODIR is GPIO Port Direction control register. This register individually Controls the direction
of each Port Pin.

IOCLR is GPIO Port Output Clear registers. This register controls the state of output pins.
Writing ones produces lows at the corresponding port pins and clears the corresponding bits in
the IOSET register. Writing zeroes has no effect.

IOSET is GPIO Port Output Set registers. This register controls the state of output pins in
conjunction with the IOCLR register. Writing ones produces highs at the corresponding port pins.
Writing zeroes has no effect.
These are the set of register used to configure I/O Pins. Now let’s move to individual registers in
deep.

Registers for C Programming:


IOSEL0
Port 0 has 32 pins (P0.0 to P0.31). Each pin can have multiple functions. On RESET, all pins are
configured as GPIO pins. However we can re-configure using the registers IOSEL0 and IOSEL1.
IOSEL0 is used to select function of P0.0 to P0.15. Each pin has up to 4 functions so 2 bits/pin in
IOSEL0 is provided for selecting function.
00 Function 0 (default function = GPIO)
01 Function 1
10 Function 2
11 Function 3

IOSEL1
IOSEL1 is used to select function of Pins P0.16 to P0.31IOSEL2
IOSEL2 is used to select function of Pins P1.16 to P1.31
Sundar Sripada V.S.
312216106111

IO0DIR
IO0DIR is used to configure pins of Port 0-P0 as input or output pins.

1 = Output Pin, 0 = Input Pin

PIN DETAILS:
Sundar Sripada V.S.
312216106111
Sundar Sripada V.S.
312216106111

BLOCK DIAGRAM:

FUNCTIONAL DETAILS
Architectural overview
The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers high performance
and very low power consumption. The ARM architecture is based on Reduced Instruction Set
Computer (RISC) principles, and the instruction set and related decode mechanism are much
simpler than those of microprogrammed Complex Instruction Set Computers (CISC). This
simplicity results in a high instruction throughput and impressive real-time interrupt response
from a small and cost-effective processor core. Pipeline techniques are employed so that all parts
of the processing and memory systems can operate continuously. Typically, while one instruction
is being executed, its
successor is being decoded, and a third instruction is being fetched from memory. The
ARM7TDMI-S processor also employs a unique architectural strategy known as Thumb, which
makes it ideally suited to high-volume applications with memory restrictions, or applications
Sundar Sripada V.S.
312216106111

where code density is an issue. The key idea behind Thumb is that of a super-reduced instruction
set. Essentially, the ARM7TDMI-S processor has two instruction sets:
• The standard 32-bit ARM set.
• A 16-bit Thumb set.
The Thumb set’s 16-bit instruction length allows it to approach twice the density of standard
ARM code while retaining most of the ARM’s performance advantage over a traditional 16-bit
processor using 16-bit registers. This is possible because Thumb code operates on the same 32-bit
register set as ARM code. Thumb code is able to provide up to 65 % of the code size of ARM,
and 160 % of the performance of an equivalent ARM processor connected to a 16-bit memory
system. The particular flash implementation in the LPC2141/42/44/46/48 allows for full speed
execution also in ARM mode. It is recommended to program performance critical and short code
sections (such as interrupt service routines and DSP algorithms) in ARM mode. The impact on
the overall code size will be minimal but the speed can be increased by 30 % over Thumb mode.

On-chip flash program memory


The LPC2141/42/44/46/48 incorporate a 32 kB, 64 kB, 128 kB, 256 kB and 512 kB flash
memory system respectively. This memory may be used for both code and data
storage.Programming of the flash memory may be accomplished in several ways. It may be
programmed In System via the serial port. The application program may also erase and/or
program the flash while the application is running, allowing a great degree of flexibility for data
storage field firmware upgrades, etc. Due to the architectural solution chosen for an on-chip boot
loader, flash memory available for user’s code on LPC2141/42/44/46/48 is 32 kB, 64 kB, 128 kB,
256 kB and 500 kB respectively. The LPC2141/42/44/46/48 flash memory provides a minimum
of 100000 erase/write cycles and 20 years of data-retention

On-chip static RAM


On-chip static RAM may be used for code and/or data storage. The SRAM may be accessed as 8-
bit, 16-bit, and 32-bit. The LPC2141, LPC2142/44 and LPC2146/48 provide 8 kB, 16 kB and 32
kB of static RAM respectively.In case of LPC2146/48 only, an 8 kB SRAM block intended to be
utilized mainly by the USB can also be used as a general purpose RAM for data storage and code
storage and execution.
Sundar Sripada V.S.
312216106111

Memory map
The LPC2141/42/44/46/48 memory map incorporates several distinct regions. In addition, the
CPU interrupt vectors may be remapped to allow them to reside in either flash memory (the
default) or on-chip static RAM.

Introduction Keil MCB2140


The Keil MCB2140 Evaluation Board allows you to generate and test application programs for
the NXP LPC2100 microcontroller family. With this hands-on process, you can determine the
hardware and software requirements for current and future product development. The MCB2140
Evaluation Board ships with an LPC214x device that is a superset of several other device variants
Sundar Sripada V.S.
312216106111

of the NXP LPC2100 microcontroller series. The MCB2140 Board contains all hardware
components required in a single-chip LPC2100 system.The MCB2140 kit includes:
• The MCB2140 Evaluation Board.
• A μVision IDE Quick Start Guide.

RESULT:
Thus, the LPC2148 and its components were studied.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
ANALOG TO DIGITAL CONVERSION
AIM:
To perform analog to digital conversion using the internal ADC converter in LPC2148
ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Power Supply
3. Multimeter
4. Keil µvision IDE
5. Flash Magic

THEORY:
Analog to Digital Converter (ADC) is used to convert analog signal/voltage into its equivalent
digital number so that microcontroller can process that numbers and make it human readable. The
ADC characterized by resolution. The resolution of ADC indicates the number of digital values.
Let’s take example: In LPC2148 microcontroller we have in-built 10-bit ADC. So for 10-bit ADC
resolution is 10-bit and maximum value will be 210 = 1024 . This means our digital value or
discrete level lies between 0 to 1023. There is one more term important to understand while
dealing with ADC and it is step size. Step size is the minimum change in input voltage which can
be resolved by ADC. The concept of step size is closely associated with the resolution of ADC.
The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive approximation analog to
digital converter.
Sundar Sripada V.S.
312216106111

PSEUDO CODE:
• Set the CPU and the peripheral clocks at 60MHz .
• Initialize serial communication with pins P0.0 as TxD and P0.1 as RxD.
• Select port 0 pin P0.28 as output (ADC0.1).
• ADC Conversion
◦ Initialize the ADC control register (AD0CR)
◦ Check end of conversion for the AD0GDR register where the digital value is stored.
◦ Copy the contents of AD0GDR register to a variable
◦ Perform right shift on the variable to get 10 bit digital value
◦ Display the 10 bit digital value
• Perform an infinite loop of the above step.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configured to select
The main control register
1. AD0CR 0x01200302 AD0.1 and clock for
for AD0
ADC
The global data register for
Configured to check
2. AD0GDR the corresponding ADC 0x80000000
the end of conversion
module
The required function can
Configured to set
3. PINSEL1 be selected by configuring 0x01000000
PORT0 pins
the PINSEL register

PROGRAM CODE:
#include<lpc214x.h>
#include<serial.h>
#include<stdio.h>
char string[]="Hello World \n";
char newline[] = "\n\r\n";
Sundar Sripada V.S.
312216106111

char adcreading[16];
void ADC_init(void)
{
PINSEL1 = 0X01000000; // P0.28, AD0.1
}
unsigned int ADC_getadcreading()
{
unsigned int adcdata;
AD0CR= 0x01200302; // Select AD0.1, Select clock for ADC, Start of conversion
while(!((adcdata= AD0GDR) &(0x80000000))){} // Check end of conversion (Done bit)
and //read result
return((adcdata>>6)& 0x3ff); // Return 10 bit result
}
int main(void)
{
unsigned int delay, adc;
initClocks(); // Set CCLK=60Mhz and PCLK=60Mhz
initUART0();
ADC_init();
Send_String(string);
while(1){
adc=ADC_getadcreading();
sprintf(adcreading,"ADC0 CH1= %u" , adc);
Send_String(adcreading);
Send_String(newline);
for(delay=0;delay<10000000;delay++){}
}
Sundar Sripada V.S.
312216106111

TABULATION:

Analog Voltage Digital Value Digital Value


(volts) (binary)
0.01 1 0000000001
0.15 51 0000110011
0.5 143 0010001111
0.75 227 0011100011
1.28 377 0101111001
1.62 488 0111101000
1.83 564 1000110100
2.4 704 1011000000
2.7 836 1011000100
3.08 967 1111000111
3.41 1023 1111111111

OUTPUT:

RESULT:
Thus, the analog to digital conversion was done using the internal ADC converter of the
LPC2148 ARM processor and the output was verified.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
STUDY OF INTERRUPT BASED SYSTEM DESIGN IN LPC2148 ARM
PROCESSOR
AIM:
To study the working of interrupts in LPC2148 ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Power Supply
3. Keil µvision IDE
4. Flash Magic

THEORY:
The interrupts in LPC2148 microcontroller are categorized as Fast Interrupt Request (FIQ),
Vectored Interrupt Request (IRQ) and Non – Vectored Interrupt Request. All the interrupts in
LPC214x have a programmable settings i.e. the priorities of the Interrupts can be dynamically set.
Of the three categories, the FIQ requests have the highest priority, Vectored IRQ requests have
the medium priority and non – vectored IRQ requests have the least priority. So, each Vectored
IRQ has its own unique ISR address. Out of the possible 32 interrupt requests, 16 interrupt
requests can be defined as Vectored IRQ. In this 16 slots, any of the 22 interrupts that are
available in LPC2148 can be assigned. In the 16 Vectored IRQ slots, slot 0 has the highest
priority while slot 16 has the least priority.For handling Non – Vectored IRQ requests, a special
register called “VICDefVectAddr” is available in LPC2148.

PSEUDO CODE:
• Initialise PWM
◦ Select PWM4 output for Pin0.8
◦ Set 1 micro-second resolution, 10ms period duration, 0.5ms -pulse duration i.e width
(Brigtness level).
◦ Reset PWMTC on PWMMR0 match
Sundar Sripada V.S.
312216106111

◦ Update MR0 and MR4


◦ Enable PWM output
◦ Reset PWM TC &amp; PR
◦ Enable counters and PWM Mode
• Initialize clock to Setup PLL and Clock Frequency
• Perform an infinite loop.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed
Used to enable the interrupts that
Configured to
1 VICIntEnable can later contribute to either FIQ 0x00008000
enable ENT1
or IRQ
Configured to
Used to assign slots to different
2 VICVectCnt 0x000002F use VIC0 for
interrupt sources
ENT1 interrupt
Configured to
Contains the address of the
set interrupt
3 VICVectAddr interrupt service routine for the 0x00800000
vector address
highest priority
in VIC0

PROGRAM CODE:
#include <LPC214X.H>
#include <stdio.h>
void delay(){
unsigned long i=0;
for(i=0;i<=400000;i++);
}
void ExternalIRQ(void){
unsigned long n=0;
while(1){
for(n=0x00010000;n<=0x00800000;n<<=1){
IOSET1=n; delay();
Sundar Sripada V.S.
312216106111

IOCLR1=0x00FF0000;
}
for(n=0x00800000;n>=0x00010000;n>>=1){
IOSET1=n; delay();
IOCLR1=0x00FF0000;
}}
}
int main(){
IODIR1=0x00FF0000;
PINSEL0=0x20000000;
VICVectAddr0=(unsigned long) ExternalIRQ;
VICVectCntl0=0x0000002F;
VICIntEnable=0x00008000;
while(1) {IOCLR1=0x00FF0000;}
}

OUTPUT:

RESULT:
Thus, interrupts servicing logic was implemented and output was verified using LPC2148
evaluation board.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
LCD INTERFACE
AIM:
To perform LCD interfacing with LPC2148 ARM processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. LCD interface kit
3. Power Supply
4. RS 232 serial cable
5. Keil µvision IDE
6. Flash Magic

THEORY:
Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as
for debugging purpose. A liquid crystal display (LCD) is a flat panel display that uses the light
modulating properties of liquid crystals (LCs). LCD Modules can present textual information to
user.16×2 LCD is named so because; it has 16 Columns and 2 Rows. There are a lot of
combinations available like, 8×1, 8×2, 10×2, 16×1, etc. but the most used one is the 16×2 LCD.
So, it will have (16×2=32) 32 characters in total and each character will be made of 5×8 Pixel
Dots. Now, we know that each character has (5×8=40) 40 Pixels and for 32 Characters we will
have (32×40) 1280 Pixels. Further, the LCD should also be instructed about the Position of the
Pixels. Hence it will be a hectic task to handle everything with the help of MCU, hence an
Interface IC like HD44780is used, which is mounted on the backside of the LCD Module itself.

PSEUDO CODE:
• Configure the output pins.
◦ Initialize the LCD module by issuing a series of commands.
◦ Set up the serial cable with the baud rate and frame format.
◦ Enter the characters to be displayed.
Sundar Sripada V.S.
312216106111

• Make an infinite loop to perform LCD display.


◦ Obtain the message to be dispayed.
◦ Issue appropriate commands to the LCD.
◦ Give the required delay.
◦ Display the output on the LCD.

CONFIGURATION REGISTERS:

Configuration Configuration
S.no Functionality Value loaded
Register- Name Performed

Configure the
This register individually
GPIO0 and
1. IOxDIR controls the direction of 0x007FB0FC
GPIO1 as O/P
each port pin
ports
Configured the
2. IOxSET Output Set Register 1 values of output
pins as high
Configured the
3. IOxCLR Output clear Register 0x003F8000 values of output
pins to low
Configured to set
4. U1LCR Line Control Register 0x83
DLAB to low
Configure the
5. U1THR Transmit Hold Register 0xd register to store
the data

PROGRAM CODE:
/* Interface program for LCD Interface for MCB2140 board */
#include <LPC21xx.H>
//#include <stdio.h>
#define CR
0xd
unsigned char mess[] = {'I','S',' ','T','Y','P','E','D',0x00};
unsigned char disp1[] = {'W','A','I','T','I','N','G',' ','F','O','R',' ','K','E','Y',0x00};
/*Function to dislay a character on the Console (Hyperterminal)*/
Sundar Sripada V.S.
312216106111

int putchar(int ch)


{
if(ch == '\n')
{
while(!(U1LSR & 0x20));
U1THR = CR;
}
while(!(U1LSR & 0x20));
return (U1THR = ch);
}
/*Function to send a string to Console (Hyperterminal) */
void sendstr(char *p)
{
while(*p)
{
putchar(*p++);
}
}
/* Function to read a character from Keyboard through Serial Port */
int getchar (void) {
while (!(U1LSR & 0x01));
return (U1RBR);
}
void delay(unsigned int x)
{
unsigned int i,j;
for(i = 0; i < 10; i ++)
{
for(j = 0; j < x; j ++)
{}
}
}
Sundar Sripada V.S.
312216106111

void delay1()
{
unsigned int i,j;
for(i = 0; i < 0x50; i ++)
{
for(j = 0; j < 0x4fb; j ++)
{}
}
}
/* Function to display the character entered from the keyboard */
void Disp_Key(unsigned long c)
{
unsigned int x;
unsigned long l;
l = c << 16;
IOCLR1 = 0x00FF0000;
IOSET1 = l;
IOCLR0 = 0x003F8000;
*/
IOSET0 = 0xfa << 15;
IOCLR0 = 0x003F8000;
IOSET0 = 0xf9 << 15;
IOCLR0 = 0x003F8000;
IOSET0 = 0xfd << 15;
IOCLR0 = 0x003F8000;
IOSET0 = 0xf9 << 15;
IOCLR0 = 0x003F8000;
x = 0x50;
delay(x);
}
/* E R/W* RS
/* 0 1
Sundar Sripada V.S.
312216106111

/* 0 0 1 */
/* 1 0
/* 0 0 1 */
0 */
1 */
/* Function to issue the series of commands to the LCD module */
void Command_Write(unsigned long com_word)
{
unsigned int x;
IOCLR1 = 0x00FF0000;
IOSET1 = com_word;
through GPIO1 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xfb << 15;
IOCLR0 = 0x003F8000;
IOSET0 = 0xf8 << 15;
IOCLR0 = 0x003F8000;
IOSET0 = 0xfc << 15;
/* Send commands to the LCD
/* E
/* 0 R/W* RS */
1 1 */
/* 0 0 0 */
/* 1 0 0 */
IOCLR0 = 0x003F8000;
IOSET0 = 0xf8 << 15;
IOCLR0 = 0x003F8000;
x = 0x50;
delay(x);
/* 0 0 0 */
}
/* Function to read characters from a string and displaying the same
Sundar Sripada V.S.
312216106111

by calling the Disp_key fucntion */


void Disp_String1(void)
{
int i;
i = 0;
while(disp1[i] != 0x00)
{
Disp_Key(disp1[i]);
i ++;
}
}
/* Function to initialize the LCD module */
void LCD_init(void)
{
int j;
unsigned long command;
j = 0x9f;
/* Delay given for the
voltage rise from 0V to 5V */
delay(j);
command = 0x38 << 16;
/* Issue software reset for the
LCD module */
Command_Write(command);
j = 0x13F;
delay(j);
command = 0x38 << 16;
/* Function set 8-bit, 1 line 5*7
font */
Command_Write(command);
command = 0x0c << 16;
on, cursor off, */
Sundar Sripada V.S.
312216106111

Command_Write(command);
command = 0x01 << 16;
Command_Write(command);
}
void Disp_Message(void)
{
int i;
i = 0;
/* Display on off control. Diplay
/* blink off */
/* Clear the LCD display */
while(mess[i] != 0x00)
{
Disp_Key(mess[i]);
i ++;
}
}
int main()
{
unsigned long com_word;
unsigned char x;
unsigned char c;
/* Enable RxD1 and TxD1 */
PINSEL0 = 0x00050000;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000004;
IODIR0 = 0x007FB0FC;
/* Configure the GPIO0 and
GPIO1 as O/P ports */
IODIR1 = 0x00FF0000;
U1LCR = 0x83;
U1DLL = 97;
Sundar Sripada V.S.
312216106111

/* 8 bits, no Parity, 1 Stop bit


*/
*/
/* 9600 Baud Rate @ 15MHz VPB Clock
U1LCR = 0x03;
/* Initialize LCD module */
LCD_init();
com_word = 0x80 << 16;
Command_Write(com_word);
delay1();
delay1();
Disp_String1();
/* Displays the "WAITING
FOR KEY" message on LCD */
sendstr("\nEnter any key to clear the display : ");
c = getchar();
com_word = 0x01 << 16;
Command_Write(com_word);
com_word = 0x80 << 16;
Command_Write(com_word);
/* Clears the LCD Display */
/* Bring the cursor to the home location */
while(1)
{
sendstr("\nEnter Key : ");
c = getchar();
Disp_Key(c);
delay1();
com_word = 0xc0 << 16;
/* Enter the key to be displayed on the display */
/* Displays the key entered */
Command_Write(com_word);
Sundar Sripada V.S.
312216106111

Disp_Message();
message on LCD */
com_word = 0x02 << 16;
Command_Write(com_word);
x = 10;
delay(x);
}
}

OUTPUT:

RESULT:
Thus, LCD interfacing with LPC2148 ARM processor was performed.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
SERIAL INTERFACE
AIM:
To perform serial communication in LPC2148 ARM Processor through the UART module
and display the text.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Power Supply
3. Keil µvision IDE
4. Flash Magic

THEORY:
UART (Universal Asynchronous Receiver Transmitter) is one of the basic interfaces which
provides a cost effective, simple and reliable communication between one controller to another
controller or between a controller and PC. It is a widely used serial communication protocol in
embedded system based applications. Almost all microcontrollers have built-in on-chip UART
support. LPC2148 ARM7 core supports two UART in it, UART0 and UART1. UART0 can be
used as general purpose UART and also can support ISP Programming through it, whereas
UART1 has additional modem support.

PSEUDO CODE:
• Baud Rate = 9600 baud (with PCLK=60Mhz)
• Data Length = 8 bits
• No Parity Bit
• and 1 Stop Bit
• Clock frequencies are set initially. A string is passed into the serial printing function.
• Required pins are selected and baud rate is set to 9600.
• We wait will THR is empty and then pass the data into it for writing.
Sundar Sripada V.S.
312216106111

• Now the string is serially communicated character by character with the help of a pointer
variable and is written onto the console repeatedly.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configured to
UART0 baud rate generator determine the
1. U0DLM 0x00000001
divider register baud rates of
conversion
Configured to
UART0 baud rate generator determine the
2. U0DLL 0x00000110
divider register baud rates of
conversion
Configured to 8
The value or settings in this
bits, no Parity, 1
3. U0LCR register configure the UART0 0x83000000
Stop bit |
block
DLAB set to 1
Configured to
The required function can be
select TxD for
4. PINSEL0 selected by configuring the 0x50000000
P0.0 and RxD
PINSEL register
for P0.1

PROGRAM CODE:
#include <lpc214x.h>
void initClocks(void);
void initUART0(void);
void U0Write(char data);
void Send_String(char* StringPtr);
char String[]="Hello from BINARYUPDATES.COM !!! \n\r\n";
unsigned int delay;
int main(void){
initClocks(); // Set CCLK=60Mhz and PCLK=60Mhz
initUART0();
while(1){
Send_String(String); //Pass the string to the USART_putstring function and sends it over the
//serial
Sundar Sripada V.S.
312216106111

for(delay=0; delay<500000; delay++); // delay


}}
void initUART0(void)
{
PINSEL0 = 0x5; /* Select TxD for P0.0 and RxD for P0.1 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit | DLAB set to 1 */
U0DLL = 110;
U0DLM = 1;
U0FDR = 0xF1; /* MULVAL=15(bits - 7:4) , DIVADDVAL=0(bits - 3:0)*/
U0LCR &= 0x0F; // Set DLAB=0 to lock MULVAL and DIVADDVAL
//BaudRate is now ~9600 and we are ready for UART communication!
}
void U0Write(char data){
while (!(U0LSR & (1<<5))); // wait till the THR is empty
// now we can write to the Tx FIFO
U0THR = data;
}
void initClocks(void){
PLL0CON = 0x01; //Enable PLL
PLL0CFG = 0x24; //Multiplier and divider setup
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
while(!(PLL0STAT & 0x00000400)); //is locked?
PLL0CON = 0x03; //Connect PLL after PLL is locked
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x01; // PCLK is same as CCLK i.e.60 MHz
}
void Send_String(char* StringPtr){
while(*StringPtr != 0x00){
U0Write(*StringPtr);
StringPtr++;}
Sundar Sripada V.S.
312216106111

OUTPUT:

RESULT:
Thus, serial communication is performed in LPC2148 ARM 7 processor through the
UART module and a text is displayed.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
STEPPER MOTOR INTERFACE
AIM:
To interface a stepper motor with LPC2148 ARM processor

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Stepper Motor interface module
3. Power Supply
4. Keil µvision IDE
5. Flash Magic

THEORY:
A stepper motor, also known as step motor or stepping motor, is a brushless DC electric motor
that divides a full rotation into a number of equal steps. The motor's position can then be
commanded to move and hold at one of these steps without any position sensor for feedback (an
open-loop controller), as long as the motor is carefully sized to the application in respect to
torque and speed.

PSEUDO CODE:
• Set the direction of pins 16-32 (Port 1) as output using IODIR register.
• Store the values (corresponding to the coils which has to be excited) in an array.
• Using a for loop drive the pins high first corresponding to the array values.
• Call a delay function before clearing the pins.
• For anti-clockwise rotation, begin from the last element of the array.
Sundar Sripada V.S.
312216106111

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configured to
1. IOxDIR GPIO direction control register 0xffff0000 set P.0-P.31 as
output pins
Configured the
Used to drive an ‘output’
2. IOxSET 0x10000000 values of output
configured pin to Logic 1
pins as high
This register can be used to drive Configured the
3. IOxCLR an ‘output’ configured pin to 0x10000000 values of output
Logic 0 pins to low
The required function can be
Configured to
4. PINSEL selected by configuring the 0x00000000
set PORT0 pins
PINSEL register

PROGRAM CODE:
#include<lpc21xx.h>
#include<stdio.h>
int values[]={0x01,0x02,0x04,0x08};
void delay()
{
int i=0;
for(i=0;i<0x3ff0;i++);
}
int main()
{
int i=0;
int count=0;
PINSEL2=0x00000000;
IODIR1=0xffff0000;
while(1)
{
for(count=0;count<=0x400;count++)
Sundar Sripada V.S.
312216106111

for(i=0;i<4;i++)
{IOSET1=values[i]<<16;
delay();
IOCLR1=values[i]<<16;
delay();}//clockwise
for(count=0;count<=0x400;count++)
for(i=3;i>=0;i--)
{IOSET1=values[i]<<16;
delay();
IOCLR1=values[i]<<16;
delay();}//anti-clockwise
}//while
return 0;
}

OUTPUT:

RESULT:
Thus, stepper motor was interfaced with LPC2148 evaluation board and the output was
verified.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
TRAFFIC LIGHT CONTROL
AIM:
To interface traffic light controller with LPC2148 ARM Processor and simulate various
traffic light control scenarios.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Traffic light controller
3. Power Supply
4. Keil µvision IDE
5. Flash Magic

THEORY:
The traffic light controller is a module which resembles the system present in the roads to
simulate traffic control. It has signalling devices ie LED’s at road intersections and pedestrian
crossings. It has four directions- North, South, East, West. It has 28 LED’s in total. Each direction
has 7 LED’s. Two of those are used for pedestrian crossing and the other five are used for normal
traffic. It uses the standard colours for traffic control- Red, Amber, Green.

CONFIGURATION REGISTERS:

Configuration
S. Configuration
Register Functionality Value loaded
No performed
Name
Configured to
1. IOxDIR GPIO direction control register 0xffff0000 set P.0-P.31 as
output pins
Configured the
Used to drive an ‘output’ values of
2. IOxSET 0x10000000
configured pin to Logic 1 output pins as
high
Configured the
This register can be used to drive
values of
3. IOxCLR an ‘output’ configured pin to 0x10000000
output pins to
Logic 0
low
Sundar Sripada V.S.
312216106111

The required function can be Configured to


4. PINSEL selected by configuring the 0x00000000 set PORT0
PINSEL register pins

PROGRAM CODE:
#include <stdio.h>
#include <LPC21XX.H>
unsigned char arr[30] = {0x10,0x81,0x7A,0x44,0x44,0xF0,
0x08,0x11,0xE5,0x44,0x44,0xF0,
0x81,0x10,0xDA,0x44,0x44,0xF0,
0x11,0x08,0xB5,0x44,0x44,0xF0,
0x88,0x88,0x00,0x44,0x44,0xF0
},i,j;
long temp,temp1;
void call(){
unsigned long x = 0,y = 0;
IOSET1 = arr[i ++] << 16;
temp = arr[i ++] << 15;
IOSET0 = temp;
temp1 = arr[i ++] << 2;
x = temp1;
x &= 0x00000F00;
x <<= 4;
y = temp1;
y &= 0x000000FF;
temp1 = x + y;
IOSET0 = temp1;}
void delay(void){
int m = 0,n = 0;
for(m = 0; m <= 1400; m ++){
for (n = 0; n <= 1400; n ++){ }
}}
Sundar Sripada V.S.
312216106111

void main(){
PINSEL0 = 0x00000000;
PINSEL1 = 0x0000000;
PINSEL2 = 0x00000004;
IODIR0 = 0x007FB0FC;
IODIR1 = 0x00FF0000;
while(1){
i = 0;
for(j = 0; j < 10; j++){
call();
delay();
IOCLR1 = 0x00FF0000;
IOCLR0 = 0x007FB0FC;
i ++;
if(i == 0xFF)
i = 0;
}}}

OUTPUT:

RESULT:
Thus, traffic light controller was interfaced with LPC2148 ARM Processor and traffic
light control was implemented for different scenarios.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
DAC INTERFACE
AIM:
To perform DAC interface with LPC2148 Arm Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. DAC interface
3. RS232 cable
4. Power Supply
5. CRO
6. Keil µvision IDE
7. Flash Magic

THEORY:
A digital-to-analog converter (DAC, D/A, D2A, or D-to-A) is a system that converts a digital
signal into an analog signal. An analog-to-digital converter (ADC) performs the reverse function.
There are several DAC architectures; the suitability of a DAC for a particular application is
determined by figures of merit including: resolution, maximum sampling frequency and others.
Digital-to-analog conversion can degrade a signal, so a DAC should be specified that has
insignificant errors in terms of the application. DACs are commonly used in music players to
convert digital data streams into analog audio signals. They are also used in televisions and
mobile phones to convert digital video data into analog video signals which connect to the screen
drivers to display monochrome or color images. These two applications use DACs at opposite
ends of the frequency/resolution trade-off. The audio DAC is a low-frequency, high-resolution
type while the video DAC is a high-frequency low-to medium-resolution type.

PSEUDO CODE:
• To display square and sawtooth wave,
• Configure the outputpins.
• Set the gpiopins.
Sundar Sripada V.S.
312216106111

• Initialize the serialinterface.


• To obtain square wave, Run an infinite loop:
◦ Send high on output.
◦ Give a delay.
◦ Send low onoutput.
◦ Give a delay.
• To display sine wave,
◦ Load the analog values of sine wave using lookup table into one variable
◦ Configure the gpio and output pins.
◦ Get the lookup table value via IOPIN1 register with some delay.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
no Register-Name performed
Port 1 is
Pin Select Register: It is used
selected for use
1. PINSEL2 for selecting the set of pins to 0x00000004
and it controls
be used
P1.16 – P1.31
Produce high
Output Set Register: It is used level output
2. IOSET1 for setting the value for a 0x00ff0000 (logic 1) at port1
group of pins pins (P1.16-
P1.23)
Produce low
Output Clear Register: It is level output
3. IOCLR1 used for clearing the value in 0x00ff0000 (logic 0) at port1
a group of pins pins (P1.16-
P1.23).
It configures
port1 pins
Direction Control Register: It
(P1.16
4. IODIR1 is used in assigning a pin as 0x00ff0000
-P1.23) as
input/output.
output lines.
Sundar Sripada V.S.
312216106111

PROGRAM CODE:

To display a square waveform:


#include <lpc21xx.h> /*preprocessor directive*/
void delay() /*Definition of delay function*/
{
unsigned int i;
for(i = 0; i <= 10000; i ++);
}
int main()
{
PINSEL2 = 0x00000004; /*Configure the (p1.16-p1.23) lines as gpio signals*/
IODIR1 = 0x00ff0000; /*Configure the gpio1 (p1.16-p1.23) as output lines*/
while(1)
{
IOSET1 =0x00ff0000; /*Output 0xff to gpio1 and 0x00 followed with delay*/
delay();
IOCLR1 = 0x00ff0000;
delay();
}
}

To display sawtooth waveform:


#include <lpc21xx.h> /*preprocessor directive*/
void delay() /*Definition of delay function*/
{
unsigned int i;
for(i = 0; i <= 100; i ++);
}
int main()
{
int i;
Sundar Sripada V.S.
312216106111

PINSEL2 = 0x00000004; /*Configure the (p1.16-p1.23) lines as gpio signals*/


IODIR1 = 0x00ff0000; /*Configure the gpio1 (p1.16-p1.23) as output lines*/
while(1)
{
for(i=0;i<=0x00ff0000;i=i+0x00010000)
{
IOSET1 = i; /*Output 0xff to gpio1 and 0x00 followed with delay*/
delay();
IOCLR1 = i;
delay();
} }}

To display a sine waveform:


/*Sine wave generation using Lookuptable by KRM on 09AUG2016*/

#include <lpc21xx.h> /*preprocessor directive*/


unsigned char a[256]={
0x40,0x42,0x43,0x45,0x46,0x48,0x49,0x4b,
0x4c,0x4e,0x50,0x51,0x53,0x54,0x56,0x57,
0x58,0x5a,0x5b,0x5d,0x5e,0x60,0x61,0x62,
0x64,0x65,0x66,0x67,0x69,0x6a,0x6b,0x6c,
0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
0x75,0x76,0x77,0x78,0x78,0x79,0x7a,0x7b,
0x7b,0x7c,0x7c,0x7d,0x7d,0x7e,0x7e,0x7e,
0x7f,0x7f,0x7f,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x7f,0x7f,
0x7f,0x7e,0x7e,0x7e,0x7d,0x7d,0x7c,0x7c,
0x7b,0x7b,0x7a,0x79,0x78,0x78,0x77,0x76,
0x75,0x74,0x73,0x72,0x71,0x70,0x6f,0x6e,
0x6d,0x6c,0x6b,0x6a,0x69,0x67,0x66,0x65,
0x64,0x62,0x61,0x60,0x5e,0x5d,0x5b,0x5a,
0x58,0x57,0x56,0x54,0x53,0x51,0x50,0x4e,
Sundar Sripada V.S.
312216106111

0x4c,0x4b,0x49,0x48,0x46,0x45,0x43,0x42,
0x40,0x3e,0x3d,0x3b,0x3a,0x38,0x37,0x35,
0x34,0x32,0x30,0x2f,0x2d,0x2c,0x2a,0x29,
0x28,0x26,0x25,0x23,0x22,0x20,0x1f,0x1e,
0x1c,0x1b,0x1a,0x19,0x17,0x16,0x15,0x14,
0x13,0x12,0x11,0x10,0xf,0xe,0xd,0xc,
0xb,0xa,0x9,0x8,0x8,0x7,0x6,0x5,
0x5,0x4,0x4,0x3,0x3,0x2,0x2,0x2,
0x1,0x1,0x1,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x1,
0x1,0x2,0x2,0x2,0x3,0x3,0x4,0x4,
0x5,0x5,0x6,0x7,0x8,0x8,0x9,0xa,
0xb,0xc,0xd,0xe,0xf,0x10,0x11,0x12,
0x13,0x14,0x15,0x16,0x17,0x19,0x1a,0x1b,
0x1c,0x1e,0x1f,0x20,0x22,0x23,0x25,0x26,
0x28,0x29,0x2a,0x2c,0x2d,0x2f,0x30,0x32,
0x34,0x35,0x37,0x38,0x3a,0x3b,0x3d,0x3e};
unsigned int i;
void delay() /*Definition of delay function*/
{
unsigned int i;
for(i = 0; i <= 10000; i ++);
}

int main()
{
PINSEL2 = 0x00000004; /*Configure the (p1.16-p1.23) lines as gpio signals*/
IODIR1 = 0x00ff0000; /*Configure the gpio1 (p1.16-p1.23) as output lines*/
while(1)
{
for(i = 0; i <= 0x0FF; i ++)
IOPIN1 = a[i] << 15; /*Output SINE WAVE SAMPLES*/
Sundar Sripada V.S.
312216106111

}
}

OUTPUT:
Experimental Setup:

Square Waveform:
Sundar Sripada V.S.
312216106111

Sawtooth Waveform:

Sine Waveform:

RESULT:
Thus, the Digital to Analog Conversion was done using the DAC interface module & LPC2148
ARM processor and the output was verified.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
PULSE WIDTH MODULATION
AIM:
To generate pulse width modulated signals with various duty cycles and also visualise the
same with the LEDs using LPC2148 ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Power Supply
3. CRO
4. Keil µvision IDE
5. Flash Magic

THEORY:
Pulse width modulation (PWM), or pulse-duration modulation (PDM), is a method of reducing
the average power delivered by an electrical signal, by effectively chopping it up into discrete
parts. The average value of voltage (and current) fed to the load is controlled by turning the
switch between supply and load on and off at a fast rate. The longer the switch is on compared to
the off periods, the higher the total power supplied to the load. Along with MPPT maximum
power point tracking, it is one of the primary methods of reducing the output of solar panels to
that which can be utilized by a battery. PWM is particularly suited for running inertial loads such
as motors, which are not as easily affected by this discrete switching, because they have inertia to
react slow. The PWM switching frequency has to be high enough not to affect the load, which is
to say that the resultant waveform perceived by the load must be as smooth as possible.

PSEUDO CODE:
• Initialise PWM
◦ Select PWM4 output for Pin0.8
◦ Set 1 micro-second resolution, 10ms period duration, 0.5ms - pulse duration i.e width
(Brigtness level).
◦ Reset PWMTC on PWMMR0 match
Sundar Sripada V.S.
312216106111

◦ Update MR0 and MR4


◦ Enable PWM output
◦ Reset PWM TC &amp; PR
◦ Enable counters and PWM Mode
• Initialize clock to Setup PLL and Clock Frequency
• Perform an infinite loop.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configured for
2500
25% duty cycle
Match Registers: These registers
holds the Match value(PWM
Duty) for corresponding PWM Configured for
1. PWMMR4 5000
channels PWM 4 50% duty cycle

Configured for
7500
75% duty cycle
Load Enable Register: Enables Update Latch
2 PWMLER use of new PWM values once the 0 x4 Enable bit for
match occurs. PWMMR4
Select Single
0 x0
PWM Control Register: PWM Edge PWM
Control Register. Enables PWM
3 PWMPCR outputs and selects PWM channel
types as either single edge or
double edge controlled. Enable PWM
0 xC
output
Clock Cycle=60
then PR=59 i.e.
Prescaler Register: This is used to
(60-1). We get
4 PWMPR specify the Prescaler value for 0x1
resolution of
incrementing the PWMTC
exact 1 micro
second.
Match Register: This register
10ms period
5 PWMMR0 hold the max cycle 10000
duration
Time(Ton+Toff).
6 PWMMCR Setup the PWM Match Control 0 x1 Reset PWMTC
Register to cause a counter reset on PWMMR0
Sundar Sripada V.S.
312216106111

when the match register occurs match


Reset PWM TC
Timer Control Register: The 0 x1
& PR
PWMTCR is used to control the
7 PWMTCR
Timer Counter (0x0)|(0x3)
Enable counters
functions(enable/disable/reset).
and PWM Mode
PLL0CON (PLL Control
Register) contains the PLL Enable PLL
Enable bit (bit 0), and the PLL 0 x01
Connect bit (bit 1)
8 PLL0CON
Connect PLL
after PLL is
0x03 locked

PLL0CFG (PLL Configuration


Register) contains the PLL Multiplier and
9 PLL0CFG 0 x24
Multiplier (MSEL) and PLL divider setup
Divider (PSEL) values.
PLL0FEED (PLL Feed Register)
contains the 8-bit value last
written to this register. To set the
0xAA
clock configuration, this register Feed Sequence
10 PLL0FEED
must be stored with consecutive
values of 0xAA and 0x55, while
the PLLE and PLLC bits are
0 x55
enabled.
PINSEL0 is used to configure Select PWM4
11 PINSEL0 (0 x10)|(0 x11)
PORT0 pins P0.0 to P0.15. output for Pin0.8
12 This is GPIO Port Pin value
register. The Current State of the (0 x10) / (0 Check
GPIO configured port pins can x11)/ (0 x12)/ P1.16/P1.17/
IO1PIN
always be read from this register, (0 x13) P1.18/
regardless of pin direction. P1.19

PROGRAM CODE:
#include <lpc214x.h>
void initPWM(void); // Initialize PWM
void initClocks(void); // Setup PLL and Clock Frequency
int main(void)
{
initClocks(); //Initialize CPU and Peripheral Clocks @ 60Mhz
initPWM(); //Initialize PWM
Sundar Sripada V.S.
312216106111

//Also by default all pins are configured as Inputs after MCU Reset.
while(1){
if(!((IO1PIN) & (1<<16)) ) // Check P1.16
{ PWMMR4 = 2500; //T-ON=25% , Hence 25% Bright
PWMLER = (1<<4); //Update Latch Enable bit for PWMMR4
}
else if( !((IO1PIN) & (1<<17)) ) // Check P1.17
{ PWMMR4 = 5000; //50% Bright
PWMLER = (1<<4);
}
else if( !((IO1PIN) & (1<<18)) ) // Check P1.18
{ PWMMR4 = 7500; //75% Bright
PWMLER = (1<<4);
}
else if( !((IO1PIN) & (1<<19)) ) // Check P1.19
{
PWMMR4 = 10000; //100% Bright
PWMLER = (1<<4); }
} //
return 0; //
}
void initPWM(void){
PINSEL0 = (PINSEL0 & ~(1 << 16)) | (1 << 17); // Select PWM4 output for Pin0.8 //
PWMPCR = 0x0; //Select Single Edge PWM - by default its single Edged so this line
//can be removed
PWMPR = 60-1; // 1 micro-second resolution
PWMMR0 = 10000; // 10ms period duration
PWMMR4 = 5000; // 0.5ms - pulse duration i.e width (Brigtness level)
PWMMCR = (1<<1); // Reset PWMTC on PWMMR0 match
PWMLER = (1<<0)|(1<<4); // update MR0 and MR4
PWMPCR = (1<<12); // enable PWM output
PWMTCR = (1<<1) ; //Reset PWM TC & PR
Sundar Sripada V.S.
312216106111

//Now , the final moment - enable everything


PWMTCR = (1<<0) | (1<<3); // enable counters and PWM Mode
//PWM Generation goes active now - LED must be 25% Bright after boot!!
//Now you can get the PWM output at Pin P0.8!
}
void initClocks(void){
PLL0CON = 0x01; //Enable PLL
PLL0CFG = 0x24; //Multiplier and divider setup
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
while(!(PLL0STAT & 0x00000400)); //is locked?
PLL0CON = 0x03; //Connect PLL after PLL is locked
PLL0FEED = 0xAA; //Feed sequence
PLL0FEED = 0x55;
VPBDIV = 0x01; // PCLK is same as CCLK i.e.60 MHz
}

OUTPUT:

RESULT:
Thus, various pulse width modulated signals are generated with different duty cycles
using PWM module in LPC2148.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
KEYBOARD INTERFACE
AIM:
To interface a keyboard with the LPC2148 ARM processor and display the keys entered
through serial port.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Keyboard module
3. Power Supply
4. Keil µvision IDE
5. Flash Magic

THEORY:
ARM, previously Advanced RISC Machine, originally Acorn RISC Machine, is a family
of reduced instruction set computing (RISC) architectures for computer processors, configured
for various environments. The Arm CPU architecture allows developers to write software and
firmware that conforms to the Arm specifications, secure in the knowledge that any Arm-based
processor will execute it in the same way. This is the foundation of the portability and
compatibility promise, underlying the Arm ecosystem. LPC2148 microcontroller is based on a
16-bit/32-bit ARM7TDMI-S CPU. The board contains two UARTs, LEDs, keypads, an ADC
input and LCD Display to create a stand-alone versatile test platform. This controller is small in
size, low on power consumption and has large number of features which make it useful in
embedded applications. Keyboard is used as an input device to read the key pressed by the user
and to process it. The rows are connected to an output port and the columns are connected to an
input port. To detect a pressed key, the microcontroller grounds all rows by providing 0 to the
output latch, and then it reads the columns.

PSEUDO CODE:
1. Initialize the serial interface
• Enable RXD1 and TXD.
Sundar Sripada V.S.
312216106111

• Set baud rate to 9600.


• Assign 8 data bits and 1 stop bits to the line control register.
2. Send the character to UART.
3. Write data to the scanlines.
4. Read from the readlines connected to P0.
5. If the key is pressed, return index of key pressed. Else, increment the index.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configures the ADC


1 0x0121000
ADCR ADC Control Register into the required
. 8
settings
Getting the data
ADC Channel Data
2 ADDR from the ADC
Register
channel
Port0 is configured as
3 PINSEL0 Output port 0x05
output.
0x83,0x83 Initialises start,
4 U0LCR Line control register
&0x0f stop bits, length
Baud rate divider
5 U0DLL 110 Baud rate generators
registers
6 U0DLM Upper 4 bits 1 Baud rate generators
Pre-scale
7 U0FDR Fractional dividerregister 0xF1
multiplication value
8 PLL0CON PLL control register 0x01, 0x03 Enable PLL
0xAA,0x5 Multiplier and divider
9 PLL0FEED PLL feed register
5 setup
1
PLL0CFG PLL configure register 0x24 Feed sequence
0
1
VPBDIV PCLK configure 0x01 PCLK = CCLK
1

PROGRAM CODE:
#include <LPC214X.H>
#define CR 0x0d
void delay(void){
unsigned long i;
for(i=0;i<=62000;i++);
Sundar Sripada V.S.
312216106111

}
void init_serial (void){
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}
int putkey(int ch){
if(ch == '\n'){
while(!(U1LSR & 0x20));
U1THR = CR;
}
while(!(U1LSR & 0x20));
return (U1THR = ch);
}
void sendhex (int hex){
if (hex > 9)
putkey('A' + (hex - 10));
else
putkey('0' + hex);
}
void sendstr(unsigned char *p){
while(*p){
putkey(*p++);
}
}
unsigned char KeyScan(){
unsigned char j,indx;
unsigned long i,s=0x00;
while(1){
indx = 0x00;
for(i=0x00000004;i<=0x00000010;i<<=1){
Sundar Sripada V.S.
312216106111

IOCLR0 = 0x0000001C; //clear P0.28


IOSET0 = i;
delay();
s = 0x00FF0000 & IOPIN1;
s >>= 16;
if(s > 0){
for(j=0; j<=7; j++){ // Check for 8 lines
s >>=1;
if(s==0){
while(( 0x00FF0000 & IOPIN1)!= 0x00);
return(indx+j);
}}}
indx += 8; }}}
int main(){
unsigned char temp = 0,key;
PINSEL2 = PINSEL2 & 0xFFFFFFF7; // P1.25-P1.16 is GPIO
IODIR1 = 0x00000000;
IODIR0 = 0x0000001C; // Set Pin P0.28 as output
init_serial();
sendstr("\n Demonstration program for Key Board Interface");
sendstr("\n Press any key from Interface");
while(1){
key = KeyScan();
sendstr("\n The Key pressed is : ");
temp = (key & 0xf0) >> 4;
sendhex(temp);
sendhex(key & 0x0f);
}}
Sundar Sripada V.S.
312216106111

OUTPUT:
Output on the terminal:

Keyboard module connected to LPC2148 board

RESULT:
Thus, the keyboard was interfaced with LPC2148 ARM Processor and the output was
observed.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
SEVEN SEGMENT DISPLAY
AIM:
To interface the Seven Segment display board with an LPC2148 ARM Processor and to
display specified words.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Seven segment display board
3. Power Supply
4. Keil µvision IDE
5. Flash Magic

THEORY:
A seven-segment display (SSD), or seven-segment indicator, is a form of electronic display
device for displaying decimal numerals that is an alternative to the more complex dot matrix
displays. Seven-segment displays are widely used in digital clocks, electronic meters, basic
calculators, and other electronic devices that display numerical information. The seven elements
of the display can be lit in different combinations to represent the Arabic numerals. Often the
seven segments are arranged in an oblique (slanted) arrangement, which aids readability. In most
applications, the seven segments are of nearly uniform shape and size, though in the case of
adding machines, the vertical segments are longer and more oddly shaped at the ends in an effort
to further enhance readability.

PSEUDO CODE:
• Set the characters in hex to display in the lcd in an array
• Write a delay function
• Set the IODIR and PINSEL registers to the required settings
• The first loop is to display 5 sets of characters
• The second loop is to display each character in a set
Sundar Sripada V.S.
312216106111

• The third loop is to display each segment in a single character


• Send the clock signal through P0.2

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Configured to
1. IOxDIR GPIO direction control register 0x00008004 set PORT0 as
output pins
Configured the
Used to drive an ‘output’ values of
2. IOxSET 0x00008000
configured pin to Logic 1 output pins as
high
Configured the
This register can be used to
values of
3. IOxCLR drive an ‘output’ configured 0x00008000
output pins to
pin to Logic 0
low
The required function can be Configured to
4. PINSEL selected by configuring the 0x00000000 set PORT0
PINSEL register pins

PROGRAM CODE:
#include<stdio.h>
#include<LPC21xx.H>
char port[20] =
{0xff,0xff,0xff,0xff,0xcf,0xce,0x88,0x89,0x92,0xbf,0xcf,0xc8,0xcf,0xce,0x88,0x89,0xc6,0xbf,0
xcf,0xc8},i;
void delay()
{
long x,y;
for(x=0;x<=90000;x++);
}
void main()
{
int d,b,j,m,i=0,x;
Sundar Sripada V.S.
312216106111

unsigned char k;
PINSEL0=0x00000000;
IODIR0=0x00008004;
delay();
delay();
delay();
do{
i=0;
for(d=0;d<5;d++)
{
for(b=0;b<4;b++)
{
k=port[i++];
for(j=0;j<8;j++)
{
m=k;
NAME: MOHAMMED ABRAAR A
REG NO: 312215106059
k=k&0x80;
{
if(k==00)
IOCLR0|=0x00008000;
else
IOSET0|=0x00008000;
}
IOSET0|=0x00000004;
IOCLR0|=0x00000004;
k=m;
k<<=1;
}}
for(x=0;x<=40;x++)
{
Sundar Sripada V.S.
312216106111

delay();
}}}
while(1);
}
OUTPUT:

RESULT:
Thus, seven segment display board was interfaced with an LPC2148 ARM Processor and
the specified words were displayed.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
TEMPERATURE SENSOR INTERFACE
AIM:
To measure the temperature of the room by interfacing temperature sensor with LPC2148
ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Temperature sensor interface
3. RS232 cable
4. Power Supply
5. Keil µvision IDE
6. Flash Magic

THEORY:
A temperature sensor is a device, usually an RTD (resistance temperature detector) or a
thermocouple, that collects the data about temperature from a particular source and converts the
data into understandable form for a device or an observer. Temperature sensors are used in many
applications like HV and AC system environmental controls, food processing units, medical
devices, chemical handling and automotive under the hood monitoring and controlling systems,
etc. The most common type of temperature sensor is a thermometer, which is used to measure
temperature of solids, liquids and gases.

PSEUDO CODE:
• Configure the outputpins.
• SetthedirectioncontrolandpinselectregistersInitializetheADCandLCD interface.
• Run an infinite loop.
◦ Read the ADC.
◦ Check for LCD busy.
◦ If not, write commands to the LCD.
Sundar Sripada V.S.
312216106111

◦ Display the temperature.

CONFIGURATION REGISTERS:

Configuration
S. Configuration
Register- Functionality Value loaded
No performed
Name
Configures the
1. ADCR ADC Control Register 0x01210008 ADC into the
required settings
Getting the data
ADC Channel
2 ADDR from the ADC
Data Register
channel
Port0 is configured
3 PINSEL0 Output port 0x05
as output.
0x83,0x83&0x0 Initialises start,
4 U0LCR Line control register
f stop bits, length
Baud rate
5 U0DLL divider 110 Baud rate generators
registers
6 U0DLM Upper 4 bits 1 Baud rate generators
Fractional Pre-scale
7 U0FDR 0xF1
dividerregister multiplication value
8 PLL0CON PLL control register 0x01, 0x03 Enable PLL
Multiplier and
9 PLL0FEED PLL feed register 0xAA,0x55
divider setup
10 PLL0CFG PLL configure register 0x24 Feed sequence
11 VPBDIV PCLK configure 0x01 PCLK = CCL

PROGRAM CODE:
#include<LPC214X.h> //preprocessordirective
#defineLCD_RS1<<24 //macros definition #define
LCD_RW1<<16
#define LCD_EN 1<<17 #define LCD_DATA 0xFF<<16 #define LCD_STS 1<<23

/*ADC Signal Declaration*/ #define AD0_3 1<<28


#define CLK_DIV 1<<8
#define PDN1<<21
#define SOC1<<24
#define BURST 1<<16
Sundar Sripada V.S.
312216106111

#define DONE 1<<31

intmain(void); //Function Declaration voidlcdini(void);


void lsts(void);
void lcdctl(unsigned char val1); void lputc(unsigned char lcr); void put_s(char *str);
void lputval(unsigned int lbuf);
unsigned int adc_read(unsigned char channel); void adc_init(void);
void delay(unsigned int k);

/*Main Program*/ int main(void) { unsigned int tp1;


IODIR0 = LCD_RW | LCD_EN; IODIR1 = LCD_RS;
PINSEL0 = 0; PINSEL1 = 0 | AD0_3;
IOCLR0 = LCD_EN; IOCLR1 = LCD_RS; IOSET0 = LCD_RW;
delay(1000); lcdini(); adc_init(); do
{ lsts(); lcdctl(2); lsts();
put_s("Temperature="); tp1 = adc_read(3); lputval(tp1);
lputc('c');
}
while(1); return 0;
}

void lcdini()
{ lcdctl(0x38); delay(5); lcdctl(0x38); delay(5); lcdctl(0x38); lsts(); lcdctl(0x38); lsts();
lcdctl(0x04); lsts(); lcdctl(0x01); lsts(); lcdctl(0x06); lsts(); lcdctl(0x0c);
}

/*Check the LCD status for busy*/ void lsts()


{ unsigned long int tp1;
IOCLR1 = LCD_RS;
IOSET0 = LCD_RW;

do {
IOSET0 = LCD_EN;
Sundar Sripada V.S.
312216106111

tp1 = IOPIN1 & LCD_STS; IOCLR0 = LCD_EN;

} while(tp1);
IOCLR0=LCD_EN;
IOCLR0=LCD_RW;
}

void lcdctl(unsigned char val1)


{ unsigned long int dat;
dat = ((unsigned long int)val1)<<16; IODIR1 = LCD_RS | LCD_DATA;

/*Write command to control register*/ IOCLR1 = LCD_RS;


IOCLR0 = LCD_RW;

IOCLR1 = LCD_DATA;
IOSET1 = dat;

IOSET0 = LCD_EN;
IOCLR0 = LCD_EN; IOSET0 = LCD_RW; IODIR1 = LCD_RS;
}

/*Displays a character in LCD*/ void lputc(unsigned char lcr)


{
unsigned long int dat; lsts();
dat = ((unsigned long int)lcr)<<16; IODIR1 = LCD_RS | LCD_DATA; IOSET1 = LCD_RS;
IOCLR0 = LCD_RW;

IOCLR1 = LCD_DATA;
IOSET1 = dat;

IOSET0 = LCD_EN; IOCLR0 =LCD_EN;


Sundar Sripada V.S.
312216106111

IOSET0 = LCD_RW; IODIR1 =LCD_RS;


}

void put_s(char*str)
{ while(*str)
{ lputc(*str); str++; }
}

void adc_init()
{ unsigned long int ADC_CH;

ADC_CH = 0 | 1 << 3;
AD0CR = SOC | PDN | CLK_DIV | ADC_CH | BURST;
}

unsigned int adc_read( unsigned char channel)


{ unsigned int aval; unsigned long int val;

if (channel==1) val=AD0DR1;
else if (channel==2) val= AD0DR2; else if (channel==3) val=AD0DR3; val = val>> 6; val= val&
0x3FF; aval=val; aval=((aval*100)/465); return (aval);
}
void lputval(unsigned int lbuf)
{ unsigned int val; unsigned char tp1; val=lbuf; tp1=(val/10) + '0';
lputc(tp1); tp1=(val%10) + '0';
lputc(tp1);
}

void delay(unsigned int k){


unsigned int i,j; for(j=0;j<k;j++) for(i=0;i<=800;i++);
}
Sundar Sripada V.S.
312216106111

OUTPUT:

RESULT:
Thus, the room temperature was measured by interfacing the temperature sensor with
LPC2148 ARM Processor.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
EXTERNAL ADC INTERFACE
AIM:
To perform analog to digital conversion using the external ADC converter in LPC2148
ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Power Supply
3. Multimeter
4. ADC Interface
5. RS232 cable
6. Keil µvision IDE
7. Flash Magic

THEORY:
Analog to Digital Converter (ADC) is used to convert analog signal/voltage into its equivalent
digital number so that microcontroller can process that numbers and make it human readable. The
ADC characterized by resolution. The resolution of ADC indicates the number of digital values.
Let’s take example: In LPC2148 microcontroller we have in-built 10-bit ADC. So for 10-bit ADC
resolution is 10-bit and maximum value will be 210 = 1024 . This means our digital value or
discrete level lies between 0 to 1023. There is one more term important to understand while
dealing with ADC and it is step size. Step size is the minimum change in input voltage which can
be resolved by ADC. The concept of step size is closely associated with the resolution of ADC.
The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive approximation analog to
digital converter.

PSEUDO CODE:
• Configure the port0 as input lines.
• Configure the pins of port1 from P1.16-P1.23 as output lines.
• Get the inputs via IOPIN0 register.
Sundar Sripada V.S.
312216106111

• Initialy turn off the LED’s in the ADC interface with the help of IOCLR1 register.
• Check the value of input variable and Perform right shift on the variable to get 8 bit
digital value.
• To display the output in ADC interface module,
• Load the input variable value into IOSET1 to turn on the LED’s.
• Similarly, load the complement value of input variable into IOCLR1 to turn off the
LED’s.
• The LED’s will give the digital (Binary) output.
• For the next conversion, we need go back to inc subroutine or step5.

CONFIGURATION REGISTERS:

S. Configuration Configuration
Functionality Value loaded
No Register Name performed

Direction Control Register: It is It configure the


1. IODIR0 used in assigning a pin as 0X00000000 port0 pins as
input/output. input lines
It configures
Direction Control Register: It
port1 pins
2. IODIR1 is used in assigning a pin as 0X00FF0000
(P1.16 -P1.23)
input/output.
as output lines.
It provides the value of port pins It checks the
that are configured to perform Logic value of value of
3. IOPIN0
only digital functions. configured I/O. configured pins
from port0.
Produce low
IOCLR1 Output Clear Register: It is used level output
4. for clearing the value in a group 0x00FF0000 (logic 0) at
of pins port1 pins
(P1.16-P1.23).
Produce high
Output Set Register: It used to level output
The value of
5. IOSET1 produce a HIGH level output at (logic 1) at
input variable
the port pins configured as GPIO port1 pins
(P1.16- P1.23)

PROGRAM CODE:
#include <LPC21XX.H> /*preprocessor directive*/
Sundar Sripada V.S.
312216106111

void delay() /*Definition of delay function*/


{
unsigned int i;
for(i=0;i<=65000;i++);
}

int main()
{
unsigned long input ; /*local variable declaration*/
char output=0X00;
IODIR1 = 0X00FF0000; /*Configure the gpio1 (p1.16-p1.23) as output lines*/

IODIR0= 0X00000000; /*Configure the port0 as input lines*/

while(1)
{
while(!(IOPIN0& 0X00000008)); /*checking all the pins of port0 other than 3rd pin*/
while((IOPIN0& 0X00000008)); /*checking 3rd pin of port0*/
IOCLR1= 0x00ff0000; /*Set low level output at port1 pins (P1.16-P1.23)*/

output =0x00;

inc: /*definition of subroutine called inc*/


input = output ;
input <<= 16; /*Performing right shift*/
IOCLR1=~input; /*set the complement of input variable to port1
pins*/
IOSET1 =input; /*set high value corresponding to the input variable to port1
pins*/
Sundar Sripada V.S.
312216106111

if((IOPIN0& 0X00000004)) /*checking 2nd pin of port0*/


{
delay(); /*calling delay function*/
output+=1; /*increment the value of output variable*/
goto inc; /*calling subroutine*/
}
}
}

OUTPUT:
Experimental Setup:

Analog to Digital Conversion Table:


Analog Value Digital value Binary Equivalent
0 0 00000000
0.5 26 00011010
1 51 00110011
1.5 76 01001100
2 100 01100100
2.5 124 01111100
3 148 10010100
3.5 173 10101101
4 198 11000110
4.5 222 11011110
5 255 11111111
Sundar Sripada V.S.
312216106111

RESULT:
Thus, the Analog to Digital Conversion was done using the external ADC converter of the
LPC2148 ARM processor and the output was verified.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
ZIGBEE INTERFACE
AIM:
To perform transmission and reception of data using ZIGBEE modules with LPC2148
ARM Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. Zigbee modules
3. RS232 cable
4. Power Supply
5. Keil µvision IDE
6. Flash Magic

THEORY:
Zigbee is an IEEE 802.15.4-based specification for a suite of high-level communication protocols
used to create personal area networks with small, low-power digital radios, such as for home
automation, medical device data collection, and other low-power low-bandwidth needs, designed
for small scale projects which need wireless connection. Hence, Zigbee is a low-power, low data
rate, and close proximity (i.e., personal area) wireless ad hoc network.

PSEUDO CODE:
• Configure the output pins and set up the internal ADC.
• Initialize serial interface.
• Enable reception and transmission.
• Set up baud rate and frame format.
• Enter into AT command mode and send data.
• Make an infinite loop to perform A/D conversion.
• Read A/D data register, start conversion and wait till end of conversion.
• Extract and send the digital value to UART.
Sundar Sripada V.S.
312216106111

• In the receiver part, receive data from the UART.

CONFIGURATION REGISTERS:

S. Configuration Value Configuration


Functionality
No Register Name loaded performed
The Divisor Latch
Transmit Hold Register: The
Access Bit(DLAB)
register contains 8 - bit write data
in the UART0 Line
1 U0THR which can be transmitted through -
Control
UART0.
Register(U0LCR)
This is write only register
must be made zero.
Receive Buffer Register: This The received data is
register contains 8- bit received less than 8 bits, the
2 U0RBR -
data from UART0. This is read remaining bits are
only register padded with 0’s.
Line Control Register: The value
3 U0LCR or settings in this register configure 0x83 -
the UART0 block.
Standard UART0 baud rate
generator divider register: The DLAB bit
UART0 baud rate generator divider in the UART0
4 U0DLL registers. 97 Line Control
Register must
Each of this register holds 8-bit
be set to 1.
values.
Output Set Register: It used to The Produce high level
produce a HIGH level output at the value of output (logic 1) at
5 IOSET
input port1 pins (P1.16-
port pins configured as GPIO
variable P1.23)
Produce low
Output Clear Register: It is used level output
for clearing the 0x00FF00
6 IOCLR (logic 0) at port1
00 pins (P1.16-
value in a group of pins
P1.23).

PROGRAM CODE:
Transmitter:
#include <LPC214X.H>
#define CR 0x0D
void init_serial (void); /* Initialize Serial Interface */
int sendchar (int ch); /* Write character to Serial Port */
int getkey (void); /* Read character from Serial Port */
Sundar Sripada V.S.
312216106111

void delay (unsigned int i);


void sendstr (char *p); void sendhex (int hex); void ADC (void);
void init_serial (void) /* Initialize Serial Interface */
{
PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U1LCR = 0x03; /* DLAB = 0 */
}
void delay(unsigned int i)
{
long x,y;
for(y=0;y<i;y++){
for(x=0;x <= 90000;x++);
}
}

/* implementation of putchar (also used by printf function to output data) */


int sendchar (int ch) /* Write character to Serial Port */
{
while (!(U1LSR & 0x20));
return (U1THR = ch);
}
int getkey (void){ /* Read character from Serial Port */
while (!(U1LSR & 0x01));
return (U1RBR);
}
void sendhex (int hex){ /* Write Hex Digit to Serial Port */
if (hex > 9)
sendchar('A' + (hex - 10));
else
sendchar('0' + hex);
Sundar Sripada V.S.
312216106111

}
void sendstr (char *p) { /* Write string */
while (*p){
sendchar (*p++); delay(6);
}
}
void ADC (void){ /* ADC function */
unsigned int val;
AD0CR |= 0x01000000; /* Start A/D Conversion */
do{
val = AD0DR1; /* Read A/D Data Register */
}while ((val & 0x80000000) == 0); /* Wait for end of A/D Conversion */
AD0CR &= ~0x01000000; /* Stop A/D Conversion */
val = (val >> 6) & 0x03FF; /* Extract AIN0 Value */
sendchar(val & 0xFF); /* Send digital value to UART */ IOPIN1 = ((val &
0xFF)<<16);
}
int main (void){
IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */
PINSEL1 = 0x01000000;
AD0CR = 0x002E0402; /* Setup A/D: 10-bit AIN1 @ init_serial(); 3MHz */
/* Initialize Serial Interface */
/*AT Commands*/
sendstr("+++"); /* To enter AT command mode */
sendstr("ATNMY1000\r"); /* command sets the Source address as 1000 */
sendstr("ATGWR\r"); /* Write to flash*/
sendstr("ATNDA2000\r"); /*command sets the Destination address as 2000 */
sendstr("ATGWR\r"); /* Write to flash */
sendstr("ATGEX\r"); /* To Exit AT command mode*/
while (1){
ADC(); /* ADC conversion */
}
Sundar Sripada V.S.
312216106111

Receiver:
#include <LPC21XX.H>
#define CR 0x0d

void init_serial (void); /* Initialize Serial Interface */


int sendchar (int ch); /* Write character to Serial Port */
int getkey (void); /* Read character from Serial Port */
void delay(unsigned int i);
void sendstr (char *p); void sendhex (int hex); int putchar(int ch);

void delay(unsigned int i){


long x,y;
for(y=0;y<i;y++){
for(x=0;x <= 90000;x++);
}
}

void init_serial (void){ /* Initialize Serial Interface */


PINSEL0 = 0x00050000; /* Enable RxD1 and TxD1*/
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock*/
U1LCR = 0x03; /* DLAB = 0 */
}

int sendchar (int ch){


/* Write character to Serial Port */
while (!(U1LSR & 0x20));
return (U1THR = ch);
}

int getchar (void){ /* Routine to read a character from UART */


while(!(U1LSR & 0x01));
return U1RBR;
}

int putchar(int ch){ /* Send the character to UART */


while(!(U1LSR & 0x20));
return (U1THR = ch);
}

void sendhex (int hex){ /* Write Hex Digit to Serial Port */


if (hex > 9)
Sundar Sripada V.S.
312216106111

putchar('A' + (hex - 10));


else
putchar('0' + hex);
}

void sendstr(char *p){ /* Send the string of characters to UART */


while(*p){
putchar(*p++);
delay(6);
}
}

int main(){
unsigned char Recv_Data;
IODIR1 = 0x00FF0000; /* P1.16..23 defined as Outputs */
init_serial();

/*AT Commands*/
sendstr("+++"); /* To enter AT command mode */
sendstr("ATNMY2000\r"); /* This command sets the Source address as 2000 */
sendstr("ATGWR\r"); /* Write to flash */
sendstr("ATNDA1000\r"); /* This command sets the Destination address as 1000*/
sendstr("ATGWR\r"); /* Write to flash */
sendstr("ATGEX\r"); /* To Exit AT command mode */
while (1){
Recv_Data = getchar(); /* Receiving data from UART */
IOPIN1 = (Recv_Data <<16); /* Received data will be send to P1.16..23 */
}
}

OUTPUT:
Transmitter:
Sundar Sripada V.S.
312216106111

Receiver:

RESULT:
Thus, transmission and reception of data using Zigbee modules with LPC2148 ARM
Processor was performed.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
STUDY OF EEPROM INTERFACE
AIM:
To study the interface of EEPROM with LPC2148 ARM Processor to display the given
string.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. RS232 jack
3. EEPROM Module
4. Power Supply
5. Keil µvision IDE
6. Flash Magic

THEORY:
EEPROM (also E2PROM) stands for electrically erasable programmable read-only memory and
is a type of non-volatile memory used in computers, integrated in microcontrollers for smart
cards and remote keyless systems, and other electronic devices to store relatively small amounts
of data but allowing individual bytes to be erased and reprogrammed. EEPROMs are organized
as arrays of floating-gate transistors. EEPROMs can be programmed and erased in-circuit, by
applying special programming signals. Originally, EEPROMs were limited to single byte
operations, which made them slower, but modern EEPROMs allow multi-byte page operations.
An EEPROM has a limited life for erasing and reprogramming, now reaching a million
operations in modern EEPROMs. In an EEPROM that is frequently reprogrammed, the life of the
EEPROM is an important design consideration.

PSEUDO CODE:
• Enable I2C interface.
• Set the bit rate for the clock.
• Set I2C 7-Segment Address.
• Clear all the 7-Segment.
Sundar Sripada V.S.
312216106111

• Write the data into the EEPROM from 0x00.


• Read the data from the EEPROM from 0x00.
• Display the data onto the 7-Segment Display.

PROGRAM CODE:
#include <LPC214X.H>
void I2CWrite2402(unsigned char, unsigned char, unsigned char);
unsigned char I2CRead2402(unsigned char, unsigned char);
void LED_display(unsigned char, unsigned char);
void delay(void);
void Set_Address(void);
unsigned char Find_Address(unsigned char);
unsigned char U1,U2,U3,U4;
unsigned char Recv_Data[8],
Send_Data[8] = {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
/* Lookup table for display code of 0 to F on LED */
unsigned char lookup[0x10] = { 0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
main()
{
unsigned char i,k;
PINSEL0 = 0x00000050;/* Select I2C0 by selecting SCL0 & SDA0 */
I2C0SCLH = 0xC0;/* Set bit rate PCLK/(I2CSCLH + I2CSCLL) */
I2C0SCLL = 0xC0;
Set_Address(); /* Set the Addresses of I2C 7 Segments */
while(1)
{
LED_display(U1,0xFF); /* Clear all 7 segments */
LED_display(U2,0xFF);
LED_display(U3,0xFF);
LED_display(U4,0xFF);
I2CWrite2402(0xA0,0x00,0x08);/* Write data into EEPROMfrom 0x00 address */
Sundar Sripada V.S.
312216106111

for(i=0x00; i<0x08; i++)


Recv_Data[i] = I2CRead2402(0xA1,i); /* Read data from EEPROM from 0x00 address */
for(i=0x00; i<0x08; i++)
{
k = Recv_Data[i] & 0x0F ;
LED_display(U4,lookup[k]); /* Display the data */
k = (Recv_Data[i] & 0xF0) >>4 ;
LED_display(U3,lookup[k]);
delay();
}
}
}
void Set_Address()
{
U1 = Find_Address(0x40); /* Find Address of U1 */
U2 = Find_Address(0x42); /* Find Address of U2 */
U3 = Find_Address(0x44); /* Find Address of U3 */
U4 = Find_Address(0x46); /* Find Address of U4 */
}
unsigned char Find_Address(unsigned char Address)
{
unsigned long i;
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while((I2C0STAT != 0x08)); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = Address; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
for(i=0; i<0x10000; i++)
{
if(I2C0STAT == 0x18) /* Check status */
goto find;
Sundar Sripada V.S.
312216106111

}
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONCLR = 0x40; /* Disable I2C interface */
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while((I2C0STAT != 0x08)); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
Address = Address + 0x30;
I2C0DAT = Address; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
for(i=0; i<0x10000; i++)
{
if(I2C0STAT == 0x18) /* Check status */
goto find;
}
find:
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONCLR = 0x40; /* Disable I2C interface */
return(Address);
}
void I2CTransferByte(unsigned char Slv_Addr, unsigned char Data)
{
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while((I2C0STAT != 0x08)); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = Slv_Addr; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while((I2C0STAT != 0x18)); /* Check status */
I2C0DAT = Data; /* data */
Sundar Sripada V.S.
312216106111

I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */


while((I2C0STAT != 0x28)); /* Check status */
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONCLR = 0x40; /* Disable I2C interface */
}
void I2CWrite2402(unsigned char Slv_Addr, unsigned char wrd_adrs,unsigned char
no_locations)
{
unsigned char k;
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while(I2C0STAT != 0x08); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = Slv_Addr; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x18); /* Check status */
I2C0DAT = wrd_adrs; /* Word address */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x28); /* Check status */
for(k=0x00; k <no_locations; k++)
{
I2C0DAT = Send_Data[k]; /* data */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x28); /* Check status */
}
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
delay();
I2C0CONCLR = 0x40; /* Disable I2C interface */
}
unsigned char I2CRead2402(unsigned char Slv_Addr,unsigned char word_adrs)
Sundar Sripada V.S.
312216106111

{
unsigned char data;
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while(I2C0STAT != 0x08); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = 0xA0; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x18);
I2C0DAT = word_adrs; /* word address */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x28);
I2C0CONCLR = 0x40; /* Disable I2C interface */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while(I2C0STAT != 0x08); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = Slv_Addr; /* Slave address + Read signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while(I2C0STAT != 0x40);
I2C0CONSET = 0x04;
I2C0CONCLR = 0x08;
while(I2C0STAT != 0x50);
data = I2C0DAT ; /* Data from EEPROM */
I2C0CONCLR = 0x04;
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONCLR = 0x40; /* Disable I2C interface */
return(data);
}
void LED_display(unsigned char Slv_Addr, unsigned char Data)
Sundar Sripada V.S.
312216106111

{
I2C0CONSET = 0x40; /* Enable I2C interface in Master mode */
I2C0CONSET = 0x20; /* Set STA bit */
while((I2C0STAT != 0x08)); /* Check status */
I2C0CONCLR = 0x20; /* Clear STA bit */
I2C0DAT = Slv_Addr; /* Slave address + Write signal */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while((I2C0STAT != 0x18)); /* Check status */
I2C0DAT = Data; /* data */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
while((I2C0STAT != 0x28)); /* Check status */
I2C0CONSET = 0x10; /* Set STO bit */
I2C0CONCLR = 0x08; /* Clear I2C interrupt bit */
I2C0CONCLR = 0x40; /* Disable I2C interface */
}
void delay() /* delay routine */
{
unsigned int i,j;
for(j=0; j<0x300; j++)
for(i=0x00; i<=9999; i++);

OUTPUT:
55 23 45 67 89 AB CD EF.

RESULT:
Thus, the interfacing of EEPROM with LPC2148 to display the given string was studied.
Sundar Sripada V.S.
312216106111

Ex. No.:
Date:
STUDY OF MAILBOX
AIM:
To study the concept of Inter-Process communication using mail box in LPC2148 ARM
Processor.

EQUIPMENT AND COMPONENTS REQUIRED:


1. LPC2148 evaluation board
2. 20-pin flat ribbon cable
3. Power Supply
4. Keil µvision IDE
5. Flash Magic

THEORY:
Defining Source Code
A core must obtain a mailbox to send a message. To do this the core writes one of its channel ID’s
to the Mailbox Source Register and then reads the Mailbox Source Register back again to check
whether the write was successful. Mailbox Source Register must only contain one-hot encoded
value that is a single channel ID .The software must ensure that only a one hot encoded number is
written to the Mailbox Source Register. You can only clear Source Register after it is
programmed. Any writes other than 0x00000000 are ignored. This mechanism guarantees that
only a single core has control of the mailbox at any one time.
A core gives up a mailbox, when it is no longer required, by clearing the Mailbox Source
Register. Clearing the Mailbox Source Register also clears all the other registers in the mailbox.
This guarantees that a mailbox is always cleared when it is newly allocated.

Defining Destination code


The Mailbox Destination Register has separate Set and Clear write locations to enable you to set
individual bits in the Mailbox Destination Register without using read modify-write transfers.
You can set a single bit in the Mailbox Destination Register by writing that bit to the Destination
Set Register. This causes the hardware to OR that bit with the current Mailbox Destination
Sundar Sripada V.S.
312216106111

Register value. Similarly, you can clear a single bit in the Mailbox Destination Register by
writing at bit to the Destination Clear Register.
When the source core defines the mode of a mailbox, it defines which other cores are to receive
the message by programming the OR of all the Channel IDs into the Mailbox Destination
Register. If a core has more than one Channel ID only one is used per message. You can only
write to the Mailbox Destination Register after the Mailbox Source Register is defined.

Using the Mailbox Send Register


A message is sent by setting bit 0 of the Mailbox Send Register. This triggers the interrupt to the
destination core. Clearing this bit clears the interrupt to the destination core. The acknowledge
message is sent to the source core by setting bit 1 of the Mailbox Send Register. Clearing this bit
clears the interrupt to the source core. You can use one write to clear bit 0 and set bit 1 in the
Mailbox Send Register, although this is not mandatory. You cannot set bit 1 then clear bit 0
because 11 is an invalid value for the Mailbox Send Register. The Mailbox Send Register can
only be written to after the Mailbox Source Register is defined.

Mailbox Data Registers


The Mailbox Data Registers are general-purpose 32-bit registers that contain the message and can
only be written to after the Mailbox Source Register is defined. The Mailbox Data Registers are
normally written to before sending the message.

Setting mode
The Mailbox Mode Register controls how the acknowledge interrupt is sent back to the source
core, and whether the current mailbox is linked to the next mailbox in the IPCM. The Mailbox
Mode Register has two bits and you can only write to it after the Mailbox Source Register is
defined.

Auto Acknowledge
In Auto Acknowledge mode, an acknowledge interrupt is automatically sent to the source core
after the final destination core has cleared its interrupt. Destination cores must clear their
interrupts by writing their Channel ID value to the Destination Clear location. This clears their
Channel ID from the Mailbox Destination Register. When the Mailbox Destination Register
Sundar Sripada V.S.
312216106111

finally reaches zero, indicating that all destination cores have cleared their interrupts, the mailbox
automatically detects this, clears bit 0 and sets bit 1 of the Mailbox Send Register. The source
core then receives the acknowledge interrupt. The data associated with an Auto Acknowledge is
the same as that for the original message. You can use Auto Acknowledge mode for 1-32
destination cores.

Note
You can use Auto Acknowledge when the system contains just two cores, a source core and a
destination core.
When Auto Acknowledge mode is disabled, the acknowledge interrupt is optional. The
destination core must clear its interrupt by clearing bit 0 of the Mailbox Send Register. Only
when the destination core sets bit 1 of the Mailbox Send Register does the source core obtain it’s
acknowledge interrupt, indicating that the destination core has finished with the message. You can
only disable Auto Acknowledge mode when there is only one destination core, where there is also
a possibility of updating the message for the acknowledge.

Auto Link
Auto Link provides a mechanism to link mailboxes together so that when a message is
acknowledged in one mailbox, the next message is sent from the linked mailbox instead of
interrupting the source core. When Auto Link is enabled, the destination core clears bit 0 and sets
bit 1 of the Mailbox Send Register in the usual way, but the acknowledge interrupt to the source
core is masked out and Mailbox Send Register bit 0 is set in the next mailbox, sending that
message.
In this mode, a source core can allocate multiple mailboxes to itself, link them together by setting
the Auto Link bits and preload messages in all the mailboxes. When the first message is sent, it is
not acknowledged until all the messages have been sent. There is no restriction on the
destinations of these messages or whether Auto Acknowledge is enabled when Auto Link is used.
In the IPCM, Mailbox0 can be linked to Mailbox1, which in turn can be linked to Mailbox2, up
to Mailbox31. For example, if you want to link Mailbox0, Mailbox1, and Mailbox2, set the Auto
Link bits in Mailbox0 and Mailbox1. Do not set the Auto Link bit in Mailbox2, to enable the
acknowledge interrupt to be sent back to the source core.
Sundar Sripada V.S.
312216106111

When Auto Link is disabled, the source core is interrupted if an acknowledge interrupt is sent that
has no effect on any other mailbox.

Note
When using Auto Link with Auto Acknowledge, the mailbox automatically sets Mailbox Send
Register bit 1 in the first mailbox to send the acknowledge back to the source core but, because
Auto Link is also set, the mailbox automatically sets Mailbox Send Register bit 0 in the linked
mailbox.

Interrupts and status Registers


When a core receives an IPCM interrupt, it determines which mailbox triggered it by reading the
Masked Interrupt Status Register related to that interrupt line. Each Masked Interrupt Status
Register contains up to 32 bits, each bit referring to a single mailbox.
If a core is using a mailbox in polled mode, it can use the Raw Interrupt Status Register to
indicate which mailbox requires attention.
In each mailbox contains up to seven data registers to hold the message. Every mailbox instance
with a single IPCM must have the same number of data registers.

Fig. 1 Mailbox interrupt mapping to IPCM interrupt outputs


Sundar Sripada V.S.
312216106111

Mailbox interrupt mapping to IPCM interrupt outputs


Each mailbox can generate up to 32 interrupts, one for each Channel ID. The number of
interrupts defines the number of bits in the Mailbox Source Register, Mailbox Destination
Register, and Mailbox Mask Register. For example, in Figure 2.4, the IPCM has 32 interrupt
outputs. Mailbox0 generates bit 0 of the IPCMMIS0-31 buses, while Mailbox31 generates bit 31
of the IPCMMIS0-31 buses.
Multiple mailboxes are grouped together as shown in to form the 32-bit IPCM interrupt bus,
IPCMINT[31:0]. All the interrupt bits from each mailbox relating to a single Channel ID are
grouped together to form the masked interrupt status buses, IPCMMIS0[31:0] to
IPCMMIS31[31:0]. The bits within these buses are then ORed together to form the IPCM
interrupt bus, IPCMINT[31:0].

Configuration Status Register


The three configurable parameters for the IPCM are:
number of mailboxes, 1-32
number of data registers per mailbox, 0-7
number of interrupts, 1-32.

The configuration options that you choose define the read-only Configuration Status Register,
enabling software to determine the IPCM configuration by reading this register. This enables a
generic IPCM software driver to determine how to use each IPCM instance within a system.
To define the IPCM configuration, tie off the MBOXNUM, INTNUM, and DATANUM input
pins as follows:

Number of mailboxes
Program the number of active mailboxes by tying off the MBOXNUM input bus.
Table 1. Configuring number of mailboxes
Number of Mailboxes MBOXNUM
1 6’b000001
2 6’b000010
3 6’b000011
Sundar Sripada V.S.
312216106111

4 6’b000100
5 6’b000101
6 6’b000110
7 6’b000111
8 6’b001000
9 6’b001001
10 6’b001010
11 6’b001011
12 6’b001100
13 6’b001101
14 6’b001110
15 6’b001111
16 6’b010000
17 6’b010001
18 6’b010010
19 6’b010011
20 6’b010100
21 6’b010101
22 6’b010110
23 6’b010111
24 6’b011000
25 6’b011001
26 6’b011010
27 6’b011011
28 6’b011100
29 6’b011101
30 6’b011110
31 6’b011111
32 6’b100000

Note
Any setting of MBOXNUM other than the values shown in is unsupported.
Sundar Sripada V.S.
312216106111

Number of Interrupts
Program the number of active interrupt outputs by tying off the INTNUM input bus.

Table 2. Configuring number of interrupts


Number of Mailboxes INTNUM
1 6’b000001
2 6’b000010
3 6’b000011
4 6’b000100
5 6’b000101
6 6’b000110
7 6’b000111
8 6’b001000
9 6’b001001
10 6’b001010
11 6’b001011
12 6’b001100
13 6’b001101
14 6’b001110
15 6’b001111
16 6’b010000
17 6’b010001
18 6’b010010
19 6’b010011
20 6’b010100
21 6’b010101
22 6’b010110
23 6’b010111
24 6’b011000
25 6’b011001
26 6’b011010
27 6’b011011
28 6’b011100
29 6’b011101
Sundar Sripada V.S.
312216106111

30 6’b011110
31 6’b011111
32 6’b100000

Number of data registers in each mailbox


Program the number of active data registers in each mailbox by tying off the DATANUM input
bus
Table 3. Configuring number of data registers
Number of Mailboxes DATANUM
0 6’b000
1 6’b001
2 6’b010
3 6’b011
4 6’b100
5 6’b101
6 6’b110
7 6’b111

SOURCE CODE:
include<RTL.h> /* RTX kernel functions & defines */
#include <stdio.h>
#include <LPC214X.H>
OS_TID tsk1; /* assigned identification for task 1 *OS_TID tsk2; /* assigned identification for
task 2 */
typedefstruct { /* Message object structure */
unsignedint voltage; /* AD result of measured voltage */
unsignedint current; /* AD result of measured current */
U32 counter; /* A counter value */
} T_MEAS;
os_mbx_declare (MsgBox,16); /* Declare an RTX mailbox */
_declare_box (mpool,sizeof(T_MEAS),16);/* Dynamic memory pool */
__task void send_task (void);
__task void rec_task (void);
Sundar Sripada V.S.
312216106111

intputkey(intch) /* Function to send a character to Serial Port */


{
if(ch == '\n')
{
while(!(U1LSR & 0x20));
U1THR = 0xd;
}
while(!(U1LSR & 0x20));
return (U1THR = ch);
}
voidsendstr(char *p) /* Function to send a string to Serial Port */
{
while(*p)
{
putkey(*p++);
}
}/*----------------------------------------------------------------------------
* Task 1: RTX Kernel starts this task with os_sys_init (send_task)
*---------------------------------------------------------------------------*/
__task void send_task (void) {
T_MEAS *mptr;
tsk1 = os_tsk_self (); /* get own task identification number */
tsk2 = os_tsk_create (rec_task, 0); /* start task 2 */
os_mbx_init (MsgBox, sizeof(MsgBox));/* initialize the mailbox */
os_dly_wait (5); /* Startup delay for MCB21xx */
mptr = _alloc_box (mpool); /* Allocate a memory for the message */
for(;;)
{
mptr->voltage = 223; /* Set the message content */
mptr->current = 178;
mptr->counter = 120;
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
Sundar Sripada V.S.
312216106111

os_dly_wait(10);
}
}
/*----------------------------------------------------------------------------
* Task 2: RTX Kernel starts this task with os_tsk_create (rec_task, 0)
*---------------------------------------------------------------------------*/
__task void rec_task (void) {
T_MEAS *rptr;
for (;;) {
os_mbx_wait (MsgBox, (void **)&rptr, 0xffff); /* wait for the message */
_free_box (mpool, rptr); /* free memory allocated for message */
//os_dly_wait(5);
}
}/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */
PINSEL0 = 0x00050000; /* initialise serial interfaace 8*/
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97; /* 9600 Baud Rate @ 12 MHz VPB Clock */
U1LCR = 0x03;
_init_box (mpool, sizeof(mpool), /* initialize the 'mpool' memory for */
sizeof(T_MEAS)); /* the membox dynamic allocation */
os_sys_init (send_task); /* initialize and start task 1 */
}

RESULT:
Thus, the concept of Inter Process Communication has been studied using Mailbox.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy