0% found this document useful (1 vote)
575 views

Embedded System Lab Manual: B.Tech (Cse) Vi Semester

The document describes experiments conducted using an ARM LPC2148 microcontroller board. Experiment 1 involves studying the characteristics and architecture of the ARM LPC2148 processor. Key aspects covered include its ARM7TDMI-S CPU core, operating modes, general block diagram, features such as memory and interfaces. Experiment 2 involves writing assembly programs to perform simple computational problems like addition, subtraction, multiplication and division.

Uploaded by

jesudosss
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
575 views

Embedded System Lab Manual: B.Tech (Cse) Vi Semester

The document describes experiments conducted using an ARM LPC2148 microcontroller board. Experiment 1 involves studying the characteristics and architecture of the ARM LPC2148 processor. Key aspects covered include its ARM7TDMI-S CPU core, operating modes, general block diagram, features such as memory and interfaces. Experiment 2 involves writing assembly programs to perform simple computational problems like addition, subtraction, multiplication and division.

Uploaded by

jesudosss
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

1

EMBEDDED SYSTEM
LAB MANUAL

B.TECH (CSE)
VI SEMESTER

Department of Computer Science and Engineering


MANAKULA VINAYAGAR INSTITUTE OF TECHNOLOGY
2

LIST OF EXPERIMENTS

S.no Title of experiments

1. Study of ARM LPC 2148 processor

2. Simple computational problems

3. System Calls, Loops, Branches, GPIO Communication,


Communication between External Peripherals and Target Board

4. Timer Delay Program Using Built in Timer On IDE Environment

5. A Simple Interrupt Handler

6. Interface 8 Bit LED and Switch Interface

7. Buzzer Interface

8. Displaying a Message in LCD display

9. I2C Interface on IDE environment

10. I2C Interfacing with serial EEPROM

11. Serial Communication

12. Multi Tasking With RTOS Control

13. Mailbox
3

EX NO 1: STUDY OF ARM LPC 2148 PROCESSOR

AIM

To Study ARM LPC 2148 processor.

BASIC CHARACTERISTICS OF ARM (ADVANCED RISC MACHINE):-

The principle feature of the ARM 7 microcontroller is that it is a register based load-and-store
architecture with a number of operating modes. While the ARM7 is a 32 bit microcontroller, it is
also capable of running a 16-bit instruction set, known as ―THUMB‖. This helps it achieve a
greater code density and enhanced power saving. While all of the register-to-register data
processing instructions are single-cycle, other instructions such as data transfer instructions, are
multi-cycle. To increase the performance of these instructions, the ARM 7 has a three-stage
pipeline. Due to the inherent simplicity of the design and low gate count, ARM 7 is the industry
leader in low-power processing on a watts per MIP basis. Finally, to assist the developer, the
ARM core has a built-in JTAG debug port and on-chip ―embedded ICE‖ that allows programs to
be downloaded and fully debugged in-system.

GENERAL BLOCK DIAGRAM OF ARM LPC2148 KIT:


4

Introduction to ARM LPC 2148 Controller:

The LPC2148 micro-controllers are based on a 32/16 bit ARM7TDMI-S CPU core. They have
real-time emulation and embedded trace support, that combines the micro-controller with
embedded high speed flash memory of 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 (16bit instruction set)reduces code by
more than 30 % with minimal performance penalty.

Due to their tiny size and low power consumption, LPC2148 are ideal for applications where
miniaturization is a key requirement, such as access control systems and point-of-sale systems. It
has serial communications interfaces ranging from a USB 2.0 Full Speed device, multiple
UARTS, SPI, SSP to I2Cs. It has on-chip SRAM of 8 kB up to 40 kB. This makes 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, dual 10-bit ADC(s), single 10-bit DAC, PWM channels and 45 fast GPIO
lines with up to nine edge or level sensitive external interrupt pins make these microcontrollers
particularly suitable for industrial control and medical systems.
5

Features of ARM LPC 2148 Controller:

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

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


128 bit wide interface/accelerator enables high speed 60 MHz operation.
In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader software.
EmbeddedICE RT and Embedded Trace interfaces offer real-time debugging with the on-
chip RealMonitor 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/8 provide 8 kB of on-chip RAM accessible to USB by DMA.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of 6/14
analog inputs, with conversion times as low as 2.44 µs per channel.

Single 10-bit D/A converter provides variable analog output.


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 with independent power and dedicated 32 kHz clock input
Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus (400 kbit/s),
SPI and SSP with buffering and variable data length capabilities.

Vectored interrupt controller 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 nine edge or level sensitive external interrupt pins available.
60 MHz maximum CPU clock available from programmable on-chip PLL with settling
time of 100 µs.
On-chip integrated oscillator operates with an external crystal in range from 1 MHz to 30
MHz and with an external oscillator up to 50 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, USB, Brown-Out
Detect (BOD) or Real-Time Clock (RTC).
Single power supply chip with Power-On Reset (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.
6

ARCHITECTURE ARM LPC 2148 Controller


7

The ARM has seven operating modes:

• User (unprivileged mode under which most tasks run)

• FIQ (entered when a high priority (fast) interrupt is raised)

• IRQ (entered when a low priority (normal) interrupt is raised)

• Supervisor (entered on reset and when a Software Interrupt instruction is executed)

• Abort (used to handle memory access violations)

• Undef (used to handle undefined instructions)

• System (privileged mode using the same registers as user mode)

Accessing Registers using ARM Instructions

 No breakdown of currently accessible registers.


o All instructions can access r0-r14 directly.
o Most instructions also allow use of the PC.
 Specific instructions to allow access to CPSR and SPSR.

When in a privileged mode, it is also possible to load / store the (banked out) user mode registers
to or from memory.

Connector Details
40-Pin Expansion Connector
8

JTAG Connector

Jumper & Connector Details

Stepper / Relay Internal Supply (+5V) External Supply(+5V)


JP8

Analog I/P (P0.29) On-Board Analog Input(+3.3V)


JP4 External Analog Input-1 select

Analog I/P (P0.30) On-Board Analog Input(+3.3V)


JP5 External Analog Input-2 select

Buzzer (P0.7) Enable Buzzer


JP1 Disable Buzzer

JTAG Enable JTAG


JP6 Disable Power JTAG

USB Voltage Read


JP13 Enable/Disable USB Voltage Read

LED Enable LEDs, Port (P1.16 – P1.23)


J4 Disable LEDs.
9

Power Supply

The external power can be AC or DC, with a voltage between (9V/12V,1A output) at 230V AC
input. The ARM board produces +5V using an LM7805 voltage regulator, which provides
supply to the peripherals. LM1117 Fixed +3.3V positive regulator used for processor &
processor related peripherals. USB socket meant for power supply and USB communication,
user can select either USB or Ext power supply through JP14. Separate On/Off Switch (SW24)
for controlling power to the board.

+5V USB/EXT Power +5V (EXT through Adaptor)


SW1 Power +5V (USB)

Flash Programming Utility

NXP Semiconductors produce a range of Microcontrollers that feature both on-chip Flash
memory and the ability to be reprogrammed using In-System Programming technology.

Program/Execution Mode

ISP Programming Program Mode (LED on)


J11 Execution Mode

UART-0 / ISP PGM


P1 (DB-9 Male)

RS-232 Communication

RS-232 communication enables point-to-point data transfer. It is commonly used in data
acquisition applications, for the transfer of data between the microcontroller and a PC.

• The voltage levels of a microcontroller and PC are not directly compatible with those of
RS-232, a level transition buffer such as MAX3232 be used.
10

UART DB-9 LPC2148


Connector Processor Lines Serial Port Section

TXD-0 P0.0

UART0(P1)
ISP PGM RXD-0 P0.1

TXD-1 P0.8
UART1
(P2) RXD-1 P0.9

RESULT
Thus the ARM LPC 2148 Processor Kit was studied.
11

EX NO 2 SIMPLE COMPUTATIONAL PROBLEM

AIM
Write a Assembly Program to do the simple computational problem such as addition,
subtraction, division, multiplication
REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ADDITION OF TWO NUMBERS

ALGORITHM

1. Start the program


2. Create the Startup file
3. Initialize the necessary registers
4. Pass the required value to the registers
5. Execute the addition operation using assembly code
6. Print the result.
7. Stop the program

PROGRAM

GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
;Main loop begins
__main
LDR R0,=0X11111111 ;load first input
LDR R1,=0X22222222 ;load second input
ADD r2,r0,r1
12

stop B stop

end

SUBTRACTION OF TWO NUMBERS

ALGORITHM
1. Start the program
2. Create the Startup file
3. Initialize the necessary registers
4. Pass the required value to the registers
5. Execute the subtraction operation using assembly code
6. Print the result.
7. Stop the program

PROGRAM

GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY

;Main loop begins


__main
LDR R0,=0X22222222 ;load first input
LDR R1,=0X11111111 ;load second input
SUB r2,r0,r1
stop
B stop
end
13

MULTIPLICATION

ALGORITHM

1. Start the program


2. Create the Startup file
3. Initialize the necessary registers
4. Pass the required value to the registers
5. Execute the Multiplication operation using assembly code
6. Print the result.
7. Stop the program

PROGRAM
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
;Main loop begins

__main

LDR R0,=0X00000002 ;load first input

LDR R1,=0X22222222 ;load second input

MUL r2,r0,r1

stop B stop

end
14

PROCEDURE

1. Write Assembly program in KIEL complier software


2. Execute the above Assembly Program.
3. After compilation success, connect PC to ARM LPC 2148 kit via UART
cable.
4. Download the HEX code using Flash Magic software.

RESULT

Thus the simple computational problem such as addition, subtraction,


multiplication was performed successfully.
15

EX NO 3 SYSTEM CALLS, LOOPS, BRANCHES, GPIO


COMMUNICATION, COMMUNICATION BETWEEN
EXTERNAL PERIPHERALS AND TARGET BOARD.

AIM

Write a Simple assembly Program for System Calls, Loops, Branches, GPIO Communication,
Communication between External Peripherals and Target Board execute the output on the target
board.

REQUIREMENTS

 ARM LPC2148 KIT


 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM
1. Start the program
2. Create the Startup file
3. Initialize the necessary registers
4. Execute the Assembly code
5. Create the required HEX code.

PROGRAM
This ASM code blinks 8 LEDs at the rate define by delay_on and delay_off
; Crystal:12Mhz
; LED lines: P1.16 to P1.23;
GLOBAL __main
AREA main, CODE, READONLY
EXPORT __main
EXPORT __use_two_region_memory
__use_two_region_memory EQU 0
BX LR
ENTRY
16

;Addresses of Registers
IO1DIR EQU 0xE0028018
IO1PIN EQU 0xE0028010
IO1CLR EQU 0xE002801C
IO1SET EQU 0xE0028014
PINSEL2 EQU 0xE002C014

__main
ldr r1,=PINSEL2 ;P1.16 to P1.25 are
GPIO's, P1.26 to P1.31 are debug port
ldr r2,=0x00000000
str r2, [r1]

ldr r1,=IO1DIR ;P1.16 to P1.23 are


outputs
ldr r2,=0x000F0000
str r2, [r1]

loop
ldr r1,=IO1PIN ;Write high on LED lines
ldr r2,[r1]
mov r2,r2,lsr #8
and r2,#0x00FF0000
str r2, [r1]
B loop
END
17

PROCEDURE

1. Execute the above Assembly Program.


2. After compilation success, connect PC to ARM LPC2148 kit via UART cable.
3. Download the hex code using Flash Magic software
4. The LED‘s connected to Port 1 will be switched off and On for 1 second delay.

RESULT

Thus the Simple assembly Program for System Calls, Loops, Branches, GPIO
Communication, Communication between External Peripherals and Target Board execute the
output on the target board.
18

EX NO 4 TIMER DELAY PROGRAM USING BUILT IN TIMER ON


IDE ENVIRONMENT

AIM

Write a ‗C‘ Program to switch off and switch On the Led‘s connected to Port 1 for 1
SECOND delay using Timer.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files
3. To set timer registers
4. Define the main(), while(1) set port2 zero call timer(); and set all pins high call
timer();
5. Define delay , use for loop to find the delay count until I value reaches 60000
6. Use while to avoid the overflow, start and stop the timer
7. Stop the program

PROGRAM
#include <LPC214x.h>

#define DELAY_MS 2000 //0.5 Second(s) Delay

#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1

void Timer0_Init(void);

void Timer0_Run(void);
19

int main(void)
{
VPBDIV = 0x01; //PCLK=60Mhz
IO1DIR = 0x00FF0000; //P1.16 to P1.23 are output
Timer0_Init(); //Initialize Timer0
while(1)
{
Timer0_Run();
}
}

void Timer0_Init(void)
{
/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/
T0CTCR = 0x0;
T0PR = PRESCALE-1;
//(Value in Decimal!) - Increment T0TC at every 60000 clock cycles
//Count begins from zero hence subtracting 1
//60000 clock cycles @60Mhz = 1 mS

T0MR0 = DELAY_MS-1;
//(Value in Decimal!) Zero Indexed Count - hence subtracting 1
T0MCR = 3;
//Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0
T0TCR = 0x02; //Reset Timer
T0TCR = 0x01; //Enable timer
}

void Timer0_Run(void)

unsigned char regVal;

if(T0IR) //Polling the Interrupt Flag


20

regVal = T0IR; //Read current IR value

IO1PIN ^= 0x00FF0000; // Toggle LED pins in Port 1

T0IR = regVal; // Write back to IR to clear Interrupt Flag

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the C program using Flash Magic software
5. The LED‘s connected to Port 2 will be switched off and On for 1 second
delay.

RESULT

Thus the ―C‖ Program was written to generate delay using timer was executed and
verified successfully.
21

EX NO 5 A SIMPLE INTERRUPT HANDLER

AIM

Write a ‗C‘ Program to demonstrate a simple interrupt handler and setting up a Timer.

REQUIREMENTS

 ARM LPC2148 KIT


 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files
3. To set timer registers
4. Define the main (),set all pins high call timer();
5. Define interrupt, setup timer interrupt .
6. Use while to avoid the overflow, start and stop the timer
7. Stop the program

PROGRAM
#include <LPC214x.h>

#define DELAY_MS 500 //0.5 Second(s) Delay

#define PRESCALE 60000 //60000 PCLK clock cycles to increment TC by 1

void Timer0_Init(void);

void T0ISR(void) __irq;

int main(void)

VPBDIV = 0x01; //PCLK=60Mhz

IO1DIR = 0x00FF0000; //P1.16 to P1.23 are output


22

Timer0_Init(); //Initialize Timer0

while(1);

void Timer0_Init(void)

/*Assuming that PLL0 has been setup with CCLK = 60Mhz and PCLK also = 60Mhz.*/

T0CTCR = 0x0; // Timer Mode

T0PR = PRESCALE-1; //(Value in Decimal!) - Increment


T0TC at every 60000 clock cycles

//Count begins from zero hence subtracting 1


//60000 clock cycles @60Mhz = 1 mS

T0MR0 = DELAY_MS-1; //(Value in Decimal!) Zero Indexed Count - hence subtracting 1


T0MCR = 3; //Set bit0 & bit1 to High which is to : Interrupt & Reset TC on MR0

//----------Setup Timer0 Interrupt-------------

VICIntEnable = 0x10; //Enable timer0 int

VICVectAddr4 = (unsigned)T0ISR; //Pointer Interrupt Function (ISR)

VICVectCntl4 = 0x20 | 4; //0x20 (i.e bit5 = 1) -> to enable Vectored IRQ slot

//0x4 (bit [4:0]) -> this the source number - here its timer0 which has VIC channel mask # as 4

//You can get the VIC Channel number from Lpc214x manual R2 - pg 58 / sec 5.5

T0TCR = 0x02; //Reset Timer

T0TCR = 0x01; //Enable timer

void T0ISR(void) __irq

unsigned char regVal = T0IR; //Read current IR value;

IO1PIN ^= 0x00FF0000; //Toggle LED pins in Port 1


23

T0IR = regVal; //Write back to IR to clear Interrupt Flag

VICVectAddr = 0x0; //This is to signal end of interrupt execution

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the C program using Flash Magic software
5. The LED‘s connected to Port 1 will be switched off and On for 1 second delay
by interrupt.

RESULT

Thus the ―C‖ Program was written to demonstrate a simple interrupt handler and setting
up a Timer was executed and verified successfully.
24

EX NO 6 INTERFACE 8 BIT LED AND SWITCH INTERFACE

AIM

Write a ‗C‘ Program to interface 8 bit LED and switch interface.

REQUIREMENTS

 ARM LPC2148 KIT


 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files
3. To set timer registers
4. Define the main (), set all pins high call timer();
5. Define LED switch interface.
6. Stop the program

PROGRAM
#include<lpc214x.h>

#define LED0 (1<<16)

#define LED1 (1<<17)

#define LED2 (1<<18)

#define LED3 (1<<19)

#define LED4 (1<<20)

#define LED5 (1<<21)


25

#define LED6 (1<<22)

#define LED7 (1<<23)

unsigned int SW_RD;

int main()

IODIR1 |= 0x00FF0000; // GPIO pins 16 to 23 configured as output

IODIR1 &= ~(0xFF000000); //All the GPIO pins configured


as input

while(1)

SW_RD = ((IOPIN1 & 0xFF000000)>>24 & 0xFF);

if(SW_RD&0x01) IOSET1 = LED0; else IOCLR1 = LED0;

if(SW_RD&0x02) IOSET1 = LED1; else IOCLR1 = LED1;

if(SW_RD&0x04) IOSET1 = LED2; else IOCLR1 = LED2;

if(SW_RD&0x08) IOSET1 = LED3; else IOCLR1 = LED3;

if(SW_RD&0x10) IOSET1 = LED4; else IOCLR1 = LED4;

if(SW_RD&0x20) IOSET1 = LED5; else IOCLR1 = LED5;

if(SW_RD&0x40) IOSET1 = LED6; else IOCLR1 = LED6;

if(SW_RD&0x80) IOSET1 = LED7; else IOCLR1 = LED7;

}
26

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The LED‘s connected to GPIO pins will be switched off and On for 1 second
delay by interrupt.

RESULT

Thus the ―C‖ Program was written to interface 8 bit LED and switch interface was
executed and verified successfully.
27

EX NO 7 BUZZER INTERFACE

AIM

Write a ‗C‘ Program to implement Buzzer interface on IDE environment.

REQUIREMENTS

 ARM LPC2148 KIT


 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files
3. Define the main (), set all pins high call buzzer();
4. Define Buzzer interface.
5. Stop the program

PROGRAM

#include <LPC214x.h>
#define BUZZ (1<<7)
void Delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<10000;j++);
}
int main()
{
IODIR0 |= BUZZ; //Configure Port0.7 as OutPut pin
28

while(1)
{
IOSET0 = BUZZ; // Buzzer On
Delay(100);
IOCLR0 = BUZZ; // Buzzer Off
Delay(100);
}
}

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The Buzzer connected to GPIO pins will be switched off and On for 1 second
delay.

RESULT

Thus the ―C‖ Program was written to implement Buzzer interface on IDE environment
was executed and verified successfully.
29

EX NO 8 DISPLAYING A MESSAGE IN LCD DISPLAY

AIM

Write a ‗C‘ Program to display a message in a 2 line X 16 characters LCD display.

REQUIREMENTS

 ARM LPC2148 KIT


 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files
3. Define the main (), set all the pins high and call 16x 2 LCD display ();
4. Define 16x2 LCD display interface.
5. Stop the program

PROGRAM

#include <lpc214x.h>
#define RS (1<<16)
#define RW (1<<17)
#define EN (1<<18)
#define D0 (1<<19)
#define D1 (1<<20)
#define D2 (1<<21)
#define D3 (1<<22)
unsigned char cmd[8] = {0x33,0x32,0x28,0x0C,0x06,0x01};
void lcd_cmd(unsigned char);
void lcd_data(unsigned char);
void lcd_Init(void);
void lcd_Convert(unsigned char);
30

void lcd_puts(unsigned char*);


void DelayMs(unsigned int ms);
int main(void)
{
lcd_Init();

while(1)
{
lcd_cmd(0x82);
lcd_puts("ARM7 LPC2148 KIT");
lcd_cmd(0xC0);
lcd_puts(" 16x2 LCD DEMO");
DelayMs(10000);
lcd_cmd(0x01);
}
}
void lcd_Init(void)
//LCD Initialize
{
unsigned int i;

IO0DIR = 0xFF0000;

for(i=0;i<6;i++)
{
lcd_cmd(cmd[i]);
DelayMs(5);
}
}
void lcd_cmd(unsigned char data) // LCD Command
Mode
{
IO0CLR = RS;
31

IO0CLR = RW;
lcd_Convert(data);
}
void lcd_data (unsigned char data) // LCD Data Mode
{
IOSET0 = RS;
IOCLR0 = RW;
lcd_Convert(data);
}
void lcd_Convert(unsigned char c)
{
if(c & 0x80) IOSET0 = D3; else IOCLR0 = D3;
if(c & 0x40) IOSET0 = D2; else IOCLR0 = D2;
if(c & 0x20) IOSET0 = D1; else IOCLR0 = D1;
if(c & 0x10) IOSET0 = D0; else IOCLR0 = D0;
IO0SET = EN; DelayMs(8); IO0CLR = EN;

if(c & 0x08) IOSET0 = D3; else IOCLR0 = D3;


if(c & 0x04) IOSET0 = D2; else IOCLR0 = D2;
if(c & 0x02) IOSET0 = D1; else IOCLR0 = D1;
if(c & 0x01) IOSET0 = D0; else IOCLR0 = D0;
IO0SET= EN; DelayMs(8); IO0CLR= EN;
}
void lcd_puts(unsigned char *string)
{
while(*string)
lcd_data(*string++);
}
void DelayMs(unsigned int ms) //Delay at 30Mhz frquency
{
unsigned int i,j;
for(i=0; i<ms;i++)
for(j=0;j<6659;j++);
}
32

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The 16 X 2 LCD display is connected and the output is displayed.

RESULT

Thus the ―C‖ Program was written to display a message in a 2 line X 16 characters LCD
display was executed and verified successfully.
33

EX NO 9 I2C INTERFACE ON IDE ENVIRONMENT

AIM

Write a ‗C‘ Program to demonstrate I2C interface on IDE environment by communicating


with Seven Segment Display.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.
SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

THEORY

A seven-segment display (abbreviation: "7-seg(ment) display"), less commonly known as a


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, and other electronic devices for displaying
numerical information.
7 – Segment Display

A seven segment display is the most basic electronic display device that can display digits from
0-9. They find wide application in devices that display numeric information like digital clocks, radio,
microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs
arranged in a special pattern to display these digits. They are laid out as a squared-off figure ‗8‘. Every
34

LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to
display the numerals while eighth LED 'h' is used to display the dot/decimal.

A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs,
the remaining two pins (at middle) are common and internally shorted. These segments come in two
configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the
negative terminals of all LEDs are connected to the common pins. The common is connected to ground
and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common
pin is given a high logic and the LED pins are given low to display a number.

ALGORITHM
1. Start the program
2. Load the required header files
3. Initialize the variables, array and for loop
4. Define main(),assign values to the variables SDA0, SCL0
5. Use FOR loop for incrementing the counter
6. Display the counter in seven segment display.
7. Stop the program.

PROGRAM

#include <LPC214x.h>
#include <stdio.h>
#defineI2C0CON_AA 2
#defineI2C0CON_SI 3
#defineI2C0CON_STO 4
#defineI2C0CON_STA 5
#defineI2C0CON_I2EN 6

void DelayMs(unsigned int ms);


void I2C_Init (void);
void Count_digit(unsigned int Val);
void Write_SAA1064(unsigned char SLAW,unsigned char Dig1,unsigned char Dig2,unsigned
char Dig3,unsigned char Dig4);

unsigned char Buff[4] = {0x00,0x27,0x3F,0x3F};


unsigned char CA[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char CC[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned int count=0;
35

int main()
{
DelayMs(300);
VPBDIV = 0x02;
PINSEL0 = 0x00000055; // P0.3 - SDA0 and P0.2
- SCL0
PINSEL2 = 0x00000004;
I2C_Init();
DelayMs(100);
while(1)
{
for(count=0;count<9999;count++)
{
Count_digit(count);
Write_SAA1064(0x70,Buff[2],Buff[3],Buff[1],Buff[0]);
}
}
}
void I2C_Init (void)
{
I2C0SCLH=150;//50%duty cycle ..... I2C Frequency ->100 KHz for PCLK = 30MHz
I2C0SCLL = 150;
I2C0CONSET =1 << I2C0CON_I2EN; //Enable I2C 0
I2C0CONCLR=1 << I2C0CON_SI;
}

void Write_SAA1064(unsigned char SLAW, unsigned char Dig4,unsigned char Dig3,unsigned


char Dig2,unsigned char Dig1)
{
I2C0CONSET=1 << I2C0CON_STA; //Start Bit
while(I2C0STAT != 0x08);
36

I2C0CONCLR=1 << I2C0CON_STA;

I2C0CONCLR=1 << I2C0CON_SI;


I2C0DAT=SLAW; //Slave +w
while(I2C0STAT != 0x18);
I2C0CONCLR = 1 << I2C0CON_SI;
I2C0DAT = 0x00; //Control word 1
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI; //Control word 2
I2C0DAT = 0x27;
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI; //Data digits 4,3,2,1
I2C0DAT = Dig4;
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI;
I2C0DAT = Dig3;
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI;
I2C0DAT = Dig2;
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI;
I2C0DAT = Dig1;
while(I2C0STAT != 0x28);
I2C0CONCLR = 1 << I2C0CON_SI;
I2C0CONSET = 1 << I2C0CON_STO; //Stop bit
DelayMs(100);
}
void Count_digit(unsigned int Val)
{
Buff[0] = CC[(Val/1000)];
Val = Val%1000;
Buff[1] = CC[(Val/100)];
Val = Val%100;
37

Buff[2] = CC[(Val/10)];
Buff[3] = CC[(Val%10)];
}

void DelayMs(unsigned int ms) //Delay Definition passing ms delay at 30Mhz frequency
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 6659; j++ );
}

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The output will be displayed in the seven segments Display.

RESULT

Thus the ―C‖ Program was written to demonstrate I2C interface on IDE environment by
communicating with Seven Segment Display was executed and verified successfully.
38

EX NO 10 I2C INTERFACING WITH SERIAL EEPROM

AIM

Write a ‗C‘ Program to demonstrate I2C interface on IDE environment by communicating


with Seven Segment Display.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.

SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

THEORY

The I2C (Inter-IC) bus is a bi-directional two-wire serial bus that provides a communication link between
integrated circuits (ICs).I2C is a synchronous protocol that allows a master device to initiate
communication with a slave device. Data is exchanged between these devices .

I2C is a Master-Slave protocol. I2C has a clock pulse along with the data. Normally, the master device
controls the clock line, SCL. This line dictates the timing of all transfers on the I2C bus. No data will be
transferred unless the clock is manipulated. All slaves are controlled by the same clock, SCL.

I2C bus supports many devices, each device is recognized by a unique address—whether it‘s a micro-
controller, LCD Driver, memory or keyboard interface and can operate as transmitter or receiver based on
the functioning of the device. The controller designed controls the EEPROM device
through I2C protocol. The I2C Controller here acts as a master device and controls EEPROM which acts
as a slave. The read-write operations are accomplished by sending a set of control signals including the
address and/or data bits. The control signals must be accompanied with proper clock signals.
39

ALGORITHM

1. Start the program


2. Load the required header files.
3. Initialize the variable required to perform an Communication
4. Initiate I2C to start the transaction
5. Write the read value of EEPROM
6. Stop the I2C

PROGRAM:
#include <lpc214x.h> //Includes LPC2148 register definitions

#define SW3 1<<24


#define SW4 1<<25
#define SW5 1<<26

#define MAX_BUFFER_SIZE 16
#define DEVICE_ADDR 0xA0
#define BLK_0 0x00
#define BLK_1 0x02
#define MAX_BLOCK_SIZE 256

#define LED1_ON() IO1SET=(1<<16) //I2C write indicator


#define LED2_ON() IO1SET=(1<<17) //I2C read indicator
#define LED3_ON() IO1SET=(1<<18) //Comm failure indicator
#define LED4_ON() IO1SET=(1<<19) //Comm success indicator

#define LED1_OFF() IO1CLR=(1<<16)


#define LED2_OFF() IO1CLR=(1<<17)
#define LED3_OFF() IO1CLR=(1<<18)
#define LED4_OFF() IO1CLR=(1<<19)

#define Fosc 12000000


#define Fcclk (Fosc * 5)
#define Fcco (Fcclk * 4)
#define Fpclk (Fcclk / 4)

void Delay(unsigned char j);


void Send_Start(void);
void Send_Stop(void);
unsigned char Send_I2C(unsigned char *Data,unsigned char Len);
unsigned char Read_I2C(unsigned char *Data,unsigned char Len);
unsigned char Page_Write(unsigned char BLOCK_NUMBER,unsigned char
BLOCK_ADDR,unsigned char *str);
unsigned char Page_Read(unsigned int BLOCK_NUMBER,unsigned char BLOCK_ADDR);
40

unsigned char I2C_Status(unsigned char status_code);

unsigned char I2C_WR_Buf[MAX_BUFFER_SIZE]={"ARM7 PRIMER BRD "};


unsigned char I2C_RD_Buf[MAX_BUFFER_SIZE];
unsigned char I2C_ER_Buf[MAX_BUFFER_SIZE]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char Status=0;
unsigned char Status_Flag=0;

void Delay(unsigned char j)


{
unsigned int i;
for(;j>0;j--)
{
for(i=0; i<60000; i++);
}
}

void Send_Start()
{
I2C1CONSET=0x20;
}

void Send_Stop()
{
I2C1CONSET=0x10;
}

// This function sends sequential data to the EEPROM 24LC04


// The buffer size for EEPROM 24LC04 is 16 bytes
// The Len parameter should not exceed this value
unsigned char Send_I2C(unsigned char *Data,unsigned char Len)
{
while(Len)
{
I2C1DAT=*Data;
if(I2C_Status(0x28))
{
return 1;
}
Len--;
Data++;
}
return 0;
}

// This function reads random data from the EEPROM 24LC04


41

unsigned char Read_I2C(unsigned char *Data,unsigned char Len)


{
while(Len)
{
if(Len==1) //Last byte
{
I2C1CONCLR=0x04; //set hardware to send nack
if(I2C_Status(0x58)) //last byte has been received and NACK has been returned
{
return 1;
}
*Data=I2C1DAT;
}
else
{
I2C1CONSET=0x04; //set hardware to send ack
if(I2C_Status(0x50)) //Byte has been received ACK has been returned
{
return 1;
}
*Data=I2C1DAT;
}
Data++;
Len--;
}
return 0;
}

unsigned char I2C_Status(unsigned char status_code)


{
while(Status_Flag==0);
Status_Flag=0;
if(Status!=status_code)
{
return 1;
}
else
{
return 0;
}
}

unsigned char Page_Write(unsigned char BLOCK_NUMBER,unsigned char BLOCK_ADDR,


unsigned char *str)
42

{
Send_Start();
if(I2C_Status(0x08)) //Start has been transmitted
{
return 1;
}

I2C1DAT=DEVICE_ADDR | BLOCK_NUMBER; // Send Address


if(I2C_Status(0x18)) //Device address, block num and write has
been transmitted
{
return 1;
}

I2C1DAT=BLOCK_ADDR; // Send block address


if(I2C_Status(0x28)) //Block address has been transmitted
{
return 1;
}

if(Send_I2C(str,MAX_BUFFER_SIZE)) //Send Data


{
Send_Stop();
return 1;
}
Send_Stop();
return 0;
}

unsigned char Page_Read(unsigned int BLOCK_NUMBER,unsigned char BLOCK_ADDR)


{
Send_Start();
if(I2C_Status(0x08)) //Start has been transmitted
{
return 1;
}

I2C1DAT=DEVICE_ADDR | BLOCK_NUMBER; // Send Address


if(I2C_Status(0x18)) //Device address, block num and write has been transmitted
{
return 1;
}

I2C1DAT=BLOCK_ADDR;
if(I2C_Status(0x28)) //Block address has been transmitted
{
43

return 1;
}

Send_Start(); // Repeat Start


if(I2C_Status(0x10)) //Repeated Start has been transmitted
{
return 1;
}
I2C1DAT=DEVICE_ADDR | BLOCK_NUMBER | 0x01;
//Device address, block num and read has been transmitted
if(I2C_Status(0x40)) //
{
return 1;
}
if(Read_I2C(I2C_RD_Buf,MAX_BUFFER_SIZE))//Receive 16bytes of Data from EEPROM
{
Send_Stop();
return 1;
}
Send_Stop();
return 0;
}
void __irq I2C1_Status(void)
{
Status_Flag=0xFF; //update status flag
Status=I2C1STAT; //Read Status byte
I2C1CONCLR=0x28;
VICVectAddr = 0x00; //Acknowledge Interrupt
}

void I2C_Init()
{
PINSEL0|=0x30C00000;
I2C1CONCLR=0x6C;
I2C1CONSET=0x40;
I2C1SCLH =80;
I2C1SCLL =70;

/* Init VIC for I2C1 */


VICIntSelect = 0x00000000; // Setting all interrupts as IRQ(Vectored)
VICVectCntl0 = 0x20 | 19; // Assigning Highest Priority Slot to I2C1 and enabling this
slot
VICVectAddr0 = (unsigned long)I2C1_Status; // Storing vector address of I2C1
VICIntEnable = (1<<19);

}
44

void UART0_Init(unsigned int baudrate)


{
unsigned int BAUD_VAL;
BAUD_VAL = (Fpclk/(16*baudrate));

PINSEL0 |= 0x00000005; // Enable rx,tx


U0LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U0DLL = BAUD_VAL & 0xFF; // U0DL for low byte
U0DLM = (BAUD_VAL>>8); // U0DL for high byte
U0LCR = 0x00000003; // DLAB =0
}
void UART0_Txmt(unsigned char Chr) /* Write character to Serial Port */
{
while (!(U0LSR & 0x20));
U0THR = Chr;
}

unsigned char UART0_Recv(void) /* Write character to Serial Port */


{
while (!(U0LSR & 0x01));
return (U0RBR);
}

void UART0_puts(unsigned char *string)


{
while(*string)
UART0_Txmt(*string++);
}

int main(void)
{
PINSEL2 = 0;
IO1DIR = (1<<19) | (1<<18) | (1<<17) | (1<<16); // Set P1.16, P1.17, P1.18, P1.19 as Output
IO1DIR &= 0xfC7fffff;

LED1_OFF();LED2_OFF();LED3_OFF();LED4_OFF();

UART0_Init(9600);
I2C_Init();
UART0_puts("\033[2J");
UART0_puts ("********* ARM Primer LPC-2148 I2C EEPROM Demo **********\n\n\r");
UART0_puts
(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n\r");
UART0_puts ("[~] Turn SW 20 ON to Write default data to EEPROM! \n\r");
UART0_puts ("[~] Turn SW 21 ON to Read and Display data from EEPROM! \n\r");
UART0_puts ("[~] Turn SW 22 ON to Erase data from EEPROM \n\r");
45

while(1)
{
if ((IOPIN1 & SW3) == 0) /*...To Load the Default Data to the EEPROM ...*/
{
LED1_ON(); //Write Indicator
if(Page_Write(BLK_1,0x00,I2C_WR_Buf))
{
UART0_puts("Write Failed");
LED4_ON();
}
Delay(50);
LED1_OFF();
UART0_puts("Data Written Successfully\r\n");
while (!(IOPIN1 & SW3));
}
else if ((IOPIN1 & SW4) == 0) /*..To Read the Data Stored in the EEPROM...*/
{
LED2_ON(); //Read indicator
if(Page_Read(BLK_1,0x00))
{
UART0_puts("Read Failed");
LED4_ON();
}
else
{
UART0_puts("Data Read:");
UART0_puts(I2C_RD_Buf);
UART0_puts("\r\n");
}
Delay(50);
LED2_OFF();
while (!(IOPIN1 & SW4));
}
else if ((IOPIN1 & SW5) == 0)
{
LED3_ON(); //Write Indicator
if(Page_Write(BLK_1,0x00,I2C_ER_Buf))
{
UART0_puts("Write Failed");
LED4_ON();
}
Delay(50);
LED3_OFF();
UART0_puts("Data Erase Successfully\r\n");
while (!(IOPIN1 & SW5));
46

}
}
}

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The output will be displayed in the system.

RESULT

Thus the ―C‖ Program was written to demonstrate I2C interface with serial EEPROM was
executed and verified successfully.
47

EX NO 11 SERIAL COMMUNICATION

AIM

Write a ‗C‘ Program to demonstrate I2C interface on IDE environment by communicating


with Seven Segment Display.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.

SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files.
3. Initialize the variable required to perform an Communication
4. Initiate Serial communication to start the transaction
5. Write the read value of UART
6. Stop the Serial communication

PROGRAM
#include <LPC214x.H>
#define PCLK 30000000 // PCLK for configuration
baudrate
void UART0_Init(unsigned int baudrate);
void UART0_PutC(char c);
void UART0_PutS(char *p);
unsigned int getchar (void);
int main(void)
{
VPBDIV = 0x02; //Divide Pclk by two
UART0_Init(9600);
48

UART0_PutS("\f!!! Welcome to ARM7 Primer Demo for Serial Communication !!!\r\n\n");

while(1)
{
UART0_PutS("Pressed Key is: ");
UART0_PutC(getchar());
UART0_PutS("\r\n");
}
}

unsigned int getchar (void) /* Read character from Serial Port */


{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void UART0_Init(unsigned int baudrate)
{
unsigned short BAUD_REG;
BAUD_REG = PCLK/(16*baudrate); // Calculate for U0DL value
PINSEL0 |= 0x00000005; // Enable rx,tx
U0LCR = 0x00000083; // 8 bit data,1 stop bit,no parity bit
U0DLL = BAUD_REG & 0xFF; // U0DL for low byte
U0DLM = (BAUD_REG>>8); // U0DL for high byte
U0LCR = 0x00000003; // DLAB =0
}
void UART0_PutC(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
void UART0_PutS(char *p)
{
while(*p) // Point to character
{
UART0_PutC(*p++); // Send character then point to next character
}
}
49

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The communication between Kit and PC will be seen.

RESULT

Thus the ―C‖ Program was written to demonstrate I2C interface with serial EEPROM was
executed and verified successfully.
50

EX NO 12 MULTI TASKING WITH RTOS CONTROL

AIM

Write an application to that creates Multi tasking with RTOS Control for two different
task of rolling led with time delay.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.

SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files.
3. Initialize the variable required to perform an RTOS task
4. Initiate Serial communication to start the transaction
5. Write the read value of UART
6. Stop the RTOS tasks.

PROGRAM

#include "config.h"

#include "stdlib.h"

//unsigned int i;

//unsigned int LED[8]= {0x00010000,0x00020000,0x00040000,0x00080000,

0x00100000,0x00200000,0x00400000,0x00800000};

extern void Roll_LED(void)


51

IO1DIR |= 0x00FF0000;

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

if(i<8)

IO1SET |= ((LED[7-i]));

OSTimeDly(60);

IO1CLR |= ((LED[7-i]));

else

IO1SET |= ((LED[i-8]));

OSTimeDly(60);

IO1CLR |= ((LED[i-8]));

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The communication between Kit and PC will be seen.
52

RESULT

Thus the application to an application to that creates Multi tasking with RTOS Control
for two different task of rolling led with time delay was executed and verified
successfully.
53

EX NO 13 MAIL BOX

AIM

Write an application to send and receive mail from mail box.

REQUIREMENTS
 ARM LPC2148 KIT
 RS232 CABLE
 POWER CHORD.

SOFTWARE SPECIFICATION
 KEIL COMPILER
 FLASH MAGIC

ALGORITHM

1. Start the program


2. Load the required header files.
3. Initialize the variable required to perform an RTOS task
4. Initiate Serial communication to start the MAIL BOX
5. Stop the RTOS tasks.

PROGRAM

#include <RTL.h> /* RTX kernel functions & defines */


#include <LPC21xx.H> /* LPC21xx definitions */
#include <stdio.h>
OS_TID tsk1; /* assigned identification for task 1 */
OS_TID tsk2; /* assigned identification for task 2 */
typedef struct { /* Message object structure */
float voltage; /* AD result of measured voltage */
float 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 */
54

__task void send_task (void);


__task void rec_task (void);
/*----------------------------------------------------------------------------
* Initialize serial interface
*---------------------------------------------------------------------------*/
void init_serial () {
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 */
}
/*----------------------------------------------------------------------------
* 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 */


mptr->voltage = 223.72; /* Set the message content */
mptr->current = 17.54;
mptr->counter = 120786;
os_mbx_send (MsgBox, mptr, 0xffff); /* Send the message to the mailbox */
IOSET1 = 0x10000;
os_dly_wait (100);

mptr = _alloc_box (mpool);


55

mptr->voltage = 227.23; /* Prepare a 2nd message */


mptr->current = 12.41;
mptr->counter = 170823;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
os_tsk_pass (); /* Cooperative multitasking */
IOSET1 = 0x20000;
os_dly_wait (100);

mptr = _alloc_box (mpool);


mptr->voltage = 229.44; /* Prepare a 3rd message */
mptr->current = 11.89;
mptr->counter = 237178;
os_mbx_send (MsgBox, mptr, 0xffff); /* And send it. */
IOSET1 = 0x40000;
os_dly_wait (100);

os_tsk_delete_self (); /* We are done here, delete this task */


}
/*----------------------------------------------------------------------------
* 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 */
printf ("\nVoltage: %.2f V\n",rptr->voltage);
printf ("Current: %.2f A\n",rptr->current);
printf ("Number of cycles: %d\n",rptr->counter);
_free_box (mpool, rptr); /* free memory allocated for message */
}
56

/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void) { /* program execution starts here */

IODIR1 = 0xFF0000; /* P1.16..22 defined as Outputs */


init_serial (); /* initialize the serial interface */
_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 */
}

PROCEDURE

1. Write C program in KIEL complier software.


2. Execute the above ‗C‘ Program.
3. After compilation success, connect PC to ARM LPC 2148kit via UART cable.
4. Download the hex code using Flash Magic software
5. The communication between Kit and PC will be seen.

RESULT

Thus the application to send and receive mail from mail box was executed and verified
successfully.

You might also like