Sunteți pe pagina 1din 47

Embedded Systems Laboratory

EXPERIMENT 1
SIMPLE ASSEMBLY LANGUAGE PROGRAMS

AIM:
Write an Assembly Language Program for Addition, Subtraction, Multiplication and Division.
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR/KEIL software
3. PC

PROCEDURE:
1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in winXTalk window using ARM board.

PROGRAMS:
Addition:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text: CODE (2)CODE32
#include "uart.asm"
Main NOP
LDR R0,=0X11111111
LDR R1,=0X12345678
ADD R8,R1,R0
BL UART ;B main
stop B stop
END

Nishitha College of Engineering

Page 1

Embedded Systems Laboratory

Subtraction:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X0000FFFF
LDR R1,=0X0000EEEE //output value display in a serial window.
SUB R8,R0,R1
//serial window language is hex.
BL UART
;B main
stop B stop
END
Multiplication:

#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X00000005
LDR R1,=0X00000005 //output value display in a serial window.
MUL R8,R0,R1
//serial window language is hex.
BL UART
;B main
stop B stop
END

Nishitha College of Engineering

Page 2

Embedded Systems Laboratory

Division:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X00001000
LDR R1,=0X00000100
MOV R8,#0
loop: CMP R1,#0
BEQ ERR
CMP R0,R1
BLT DONE
ADD R8,R8,#1
SUB R0,R0,R1
B loop
ERR: MOV R8,#0XFFFFFFFF
DONE: BL UART
stop: B stop
END

RESULT:
Thus the assembly program for the addition , Substraction, Multiplication and Division is executed and
output is observed in WINXTALK by using the ARM board.

Nishitha College of Engineering

Page 3

Embedded Systems Laboratory

EXPERIMENT 2
Programs to configure and control General Purpose Input/Output (GPIO)

AIM:
Write a Programs to configure and control General Purpose Input/Output (GPIO)
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR/KEIL software
3. PC

PROCEDURE:
1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in winXTalk window using ARM board.

PROGRAMM:
#include<nxp/iolpc2148.H>
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
/*-----------------------------------------------------------------------------*/
// LED INTERFACE LINES
// LED0 - LED7 : P1.24 - P1.31
//-----------------------------------------------------------------------------void main()
{
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.

Nishitha College of Engineering

Page 4

Embedded Systems Laboratory

while(1)
{
IO1SET=0XFF000000;
delay();
IO1CLR=0XFF000000;
delay();
}
}

// P1.24 TO P1.31 goes to high state


// P1.24 TO P1.31 goes to low state

RESULT:
Thus the assembly program for the Programs to configure and control General Purpose Input/Output
(GPIO) is executed and output is observed in WINXTALK by using the ARM board.

Nishitha College of Engineering

Page 5

Embedded Systems Laboratory

EXPERIMENT 3
TIMER DELAY PROGRAM USING BUILT IN TIMER/COUNTER FEATURE

AIM:
Write a Program for timer delay using built in timer/counter Feature

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

PROGRAM:
#include <nxp/ioLPC2148.h>
#include <intrinsics.h>
unsigned int FLAG,i,COUNT;
//---------------------------PLL SETTINGS---------------------------------------//
void LPC2148PLLInit(void)
{
unsigned long loop_ctr;
/* Configure PLL0, which determines the CPU clock
*/
PLLCFG
= 0x00000024;
/* Use PLL values of M = 4 and P = 2
*/
PLLCON_bit.PLLE = 1;
/* Set the PLL Enable bit
*/
PLLFEED
= 0xAA;
/* Write to the PLL Feed register
*/
PLLFEED
= 0x55;
loop_ctr = 10000;
/* Wait for the PLL to lock into the new frequency
*/
while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) {
loop_ctr--;
}

Nishitha College of Engineering

Page 6

Embedded Systems Laboratory

PLLCON_bit.PLLC = 1;
/* Connect the PLL
*/
PLLFEED
= 0xAA;
/* Write to the PLL Feed register
*/
PLLFEED
= 0x55;
VPBDIV
= 0x00000001;
/* Set the VPB frequency to one-half of the CPU
clock
*/
}
void timer_1()
{
//Timer 0 Initialisation
T1IR = 0xFF;
// reset match and capture event interrupts

T1TC = 0;
// Clear timer counter
T1PR = 59;
// Timer counter Increments every 0.017 usec
T1MR0 = 1000000;
T1MCR = 3;
// Reset Timer Counter & Interrupt on match
void main(void)
{
LPC2148PLLInit();
PINSEL2 = 0X00000000;
IO1DIR = 0XFF000000;
while(1)
{
timer_1();
T1TCR = 1;
while(T1TC!=1000000);
T1TCR = 0;
IO1SET = 0XFF000000;
T1TC=0;
timer_1();
T1TCR = 1;
while(T1TC!=1000000);
T1TCR = 0;
IO1CLR = 0XFF000000;
T1TC=0;
}
}

RESULT:
Thus the program for timer delay using built in timer/counter is executed and delay is observed
in ARM board.

Nishitha College of Engineering

Page 7

Embedded Systems Laboratory

EXPERIMENT 4
EXTERNAL INTERRUPT
AIM:
Write a Program for External Interrupt

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#define XTALFREQ 12000000
//XTAL frequency in Hz
#define PCLKFREQ (XTALFREQ/4) //pclk must always be XTALFREQ/4?
int main(void);
__irq __arm void IRQ_ISR_Handler (void);
void Btn2DownISR(void);
void NonVectISR(void);
void feed (void);
int main(void)
{
/* Preliminary setup of the VIC. Assign all interrupt channels to IRQ */
VICIntSelect = 0;
// Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps
VICProtection = 0;
// VIC registers can be accessed in User or
// privileged mode
VICVectAddr = 0;
// Clear interrupt

Nishitha College of Engineering

Page 8

Embedded Systems Laboratory

VICDefVectAddr = 0;
// Clear address of the default ISR
/*Configure the pins that the buttons are hooked up to to be external
interrupts */
PINSEL1_bit.P0_30=0x2;
// Set Port pin P0.15 function to EINT3

//LED Conmfiguration
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.
VICProtection = 0;
// Accesss VIC in USR | PROTECT
// VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr
/* Set up the button 1 pressed interrupt on EINT0 */
VICIntSelect &= ~(1<<VIC_EINT3);
// IRQ on external int 0.
VICVectAddr1 = (unsigned int)&Btn2DownISR; // Install ISR in VIC addr slot
VICVectCntl1 = 0x20 | VIC_EINT3;
// Enable vec int for EINT 0.
VICIntEnable |= (1<<VIC_EINT3);
// Enable EINT0 interrupt.
__enable_interrupt();
// Global interrupt enable
/*This is the foreground loop, which looks at data coming from the background
loop. The user can insert own code to react to timer and button driven
events */
while(1)
// Foreground Loop
{
IO1SET=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // Get interrupt vector.
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // Call vectored interrupt function
VICVectAddr = 0;
// Clear interrupt in VIC
}
__fiq __arm void fiq_handler (void)
{
while(1);
}
void Btn2DownISR(void)
{
EXTINT_bit.EINT3 = 1; // Try to reset external interrupt flag.
IO1CLR=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
Nishitha College of Engineering

Page 9

Embedded Systems Laboratory

RESULT:
Thus the program for delay External Interrupt is executed and interrupt is observed in ARM
board.

Nishitha College of Engineering

Page 10

Embedded Systems Laboratory

EXPERIMENT 5
PRESS BUTTON TO GENERATE AN INTERRUPT

AIM:
Write a Program for External Interrupt

APPARATUS REQUIRED:

4. ARM(LPC2148) Evolution Board


5. IAR software
6. PC

PROCEDURE:

6.
7.
8.
9.
10.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#define XTALFREQ 12000000
//XTAL frequency in Hz
#define PCLKFREQ (XTALFREQ/4) //pclk must always be XTALFREQ/4?
int main(void);
__irq __arm void IRQ_ISR_Handler (void);
void Btn2DownISR(void);
void NonVectISR(void);
void feed (void);
int main(void)
{
/* Preliminary setup of the VIC. Assign all interrupt channels to IRQ */
VICIntSelect = 0;
// Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps
Nishitha College of Engineering

Page 11

Embedded Systems Laboratory

VICProtection = 0;

// VIC registers can be accessed in User or


// privileged mode
VICVectAddr = 0;
// Clear interrupt

VICDefVectAddr = 0;
// Clear address of the default ISR
/*Configure the pins that the buttons are hooked up to to be external
interrupts */
PINSEL1_bit.P0_30=0x2;
// Set Port pin P0.15 function to EINT3

//LED Conmfiguration
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.
VICProtection = 0;
// Accesss VIC in USR | PROTECT
// VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr
/* Set up the button 1 pressed interrupt on EINT0 */
VICIntSelect &= ~(1<<VIC_EINT3);
// IRQ on external int 0.
VICVectAddr1 = (unsigned int)&Btn2DownISR; // Install ISR in VIC addr slot
VICVectCntl1 = 0x20 | VIC_EINT3;
// Enable vec int for EINT 0.
VICIntEnable |= (1<<VIC_EINT3);
// Enable EINT0 interrupt.
__enable_interrupt();
// Global interrupt enable
/*This is the foreground loop, which looks at data coming from the background
loop. The user can insert own code to react to timer and button driven
events */
while(1)
// Foreground Loop
{
IO1SET=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // Get interrupt vector.
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // Call vectored interrupt function
VICVectAddr = 0;
// Clear interrupt in VIC
}
__fiq __arm void fiq_handler (void)
{
while(1);
}
void Btn2DownISR(void)
{
Nishitha College of Engineering

Page 12

Embedded Systems Laboratory

EXTINT_bit.EINT3 = 1; // Try to reset external interrupt flag.


IO1CLR=0XFF000000;
// P1.24 TO P1.31 goes to high state
}

RESULT:
Thus the program for delay External Interrupt is executed and interrupt is observed in ARM
board.

Nishitha College of Engineering

Page 13

Embedded Systems Laboratory

EXPERIMENT 6
8 BIT DIGITAL LED AND SWITCH INTERFACE

(A) BIT DIGITAL OUTPUT LED INTERFACE

AIM:
Write a Program for Bit Digital output LED Interface
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

/*LED INTERFACE*/
#include<nxp/iolpc2148.H>
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
/*-----------------------------------------------------------------------------*/
// LED INTERFACE LINES
// LED0 - LED7 : P1.24 - P1.31
//-----------------------------------------------------------------------------void main()
{
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.

Nishitha College of Engineering

Page 14

Embedded Systems Laboratory

while(1)
{
IO1SET=0XFF000000;
delay();
IO1CLR=0XFF000000;
delay();
}
}

// P1.24 TO P1.31 goes to high state


// P1.24 TO P1.31 goes to low state

/* SWITCH INTERFACE*/
#include <nxp/iolpc2148.h>
static void delay(void )
{
volatile int i,j;
for (i=0;i<0x3F;i++)
for (j=0;j<500;j++);
}
// SW0 - SW7 : P0.16 - P0.23
// LED0 - LED7 : P1.23 - P1.31
// Switch Staus Displayed on LED
void main()
{
// PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
// Configured as GPIO port
PINSEL2 = 0x00000000;
// Configured as GPIO port
IO0DIR = 0X00000000;
// P0.16 TO P0.23 Configured as input
IO1DIR = 0Xff000000;
// P1.23 TO P1.31 Configured as output
while(1)
{
// IO0CLR = 0XFF000000;
// IO1CLR = 0XFF000000;
IO1PIN = (~(IO0PIN & 0x00FF0000)<<0x08);
// delay();
}
}

RESULT:
Thus the program for the 8 bit LED interface is executed and LED blinking is observed in the
ARM board.

Nishitha College of Engineering

Page 15

Embedded Systems Laboratory

EXPERIMENT 7
BUZZER INTERFACE

AIM:
Write a Program for Buzzer Interface
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

PROGRAM:
#include<nxp/iolpc2148.h>
void delay()
{
for(int i=0;i<=0xff;i++)
for(int j=0;j<=0xff;j++);
}
//
BUZZER INTERFACE
// BUZZER - P0.15
//-----------------------------------------------------------------------------void main()
{
PINSEL0 = 0X00000000; // P0.15 - GPIO PORT
IO0DIR = 0X00008000; // P0.15 - OUTPUT
while(1)
{
IO0SET = 0X00008000; // Buzzer On
delay();
IO0CLR = 0X00008000; // Buzzer off
delay();
}
}

Nishitha College of Engineering

Page 16

Embedded Systems Laboratory

RESULT:
Thus the program for the BUZZER interface is executed and BUZZER output is observed in the ARM
board.

Nishitha College of Engineering

Page 17

Embedded Systems Laboratory

EXPERIMENT 8
CHARACTER BASED LCD INTERFACE

AIM:
Write a Program For Character based LCD Interface
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1. Write the source code in IAR programming window


2. Build the program with setting the project options.
3. Check the program in command window
4. Download the program to the ARM evolution board
5. Verify the output in ARM board.

PROGRAM:

#include <nxp/iolpc2148.h>
#define LCD_EN 0X00000800
#define RS
0X00000100
#define DIOW 0X00000200
unsigned char arr1[16]="Christ The King";
unsigned char arr2[16]=" CKPC-ECE.. ";
void delay_ms()
{
unsigned int i,j;
for(j=0;j<0xf;j++)
for(i=0;i<0xff;i++);
}

void busy_check()
Nishitha College of Engineering

Page 18

Embedded Systems Laboratory

{
delay_ms();
}
void command_write(int comm)
{
busy_check();
IO0CLR = RS;
IO0CLR = DIOW;
IO1PIN = comm<<16;
IO0SET = LCD_EN;
IO0CLR = LCD_EN;
}
void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0x86);
command_write(0x06);
}

// 5 * 7 Matrix
// Clear Display
// Display ON and Cursor Blinking
// 5 * 7 Matrix

void lcd_out(unsigned char z)


IO1PIN = (z<<16); //data with Rs=1
IO0SET = LCD_EN;
IO0CLR = LCD_EN;
}
void main()
{
//--------------------Used Port Lines--------------------------//
//LCD0-LCD7 - P1.16 to P1.23
//
//RS - P0.8
//
//DIOW - P0.9
//
//LCDEN2 - P0.11
//
//-------------------------------------------------------------//
PINSEL2=0x00000000;
IO0DIR =0xffffffff; // RS, DIOW & LCDEN - Output Pins
IO1DIR =0xFFFFFFFF; // LCD0 to LCD7 - Output Pins
IO0DIR =0x5FFF7FFF;
IO1DIR =0xFFFFFFFF;

IO0CLR = 0X00000800;
IO1PIN = 0X00000000;
IO0PIN = 0X00000000;
IO0CLR = RS;

Nishitha College of Engineering

Page 19

Embedded Systems Laboratory

IO0CLR = DIOW;
IO0CLR = LCD_EN;
lcd_init();
command_write(0x80);
for(int i=0;i<16;i++)
lcd_out(arr1[i]);
command_write(0xC0);
for(int i=0;i<16;i++)
lcd_out(arr2[i]);
while(1);
}
{
busy_check();
IO0SET = RS;
IO0CLR = DIOW;

//RS = 1

}
RESULT:
Thus the program for the LCD interface is executed and output is observed in the 2 line 16LCD
Display

Nishitha College of Engineering

Page 20

Embedded Systems Laboratory

EXPERIMENT 9
I2 C DEVICE INTERFACE SERIAL EEPROM

AIM:
Write a Program For serial EEPROM interface with I2 C device
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1. Write the source code in IAR programming window


2. Build the program with setting the project options.
3. Check the program in command window
4. Download the program to the ARM evolution board
5. Verify the output in WINXTALK by using ARM board.

/*----------------------------------------------------------------------------*/
/*
THIS PROGRAM FOR EEPROM INTERFACE(24LS256)
/*
SDA LINE -P0.3
*/
/*
SCL LINE -P0.2
*/
/*
SLAVE ADDRESS WRITE=0XA2,READ =0XA3
/*----------------------------------------------------------------------------*/

*/

*/

#include<nxp/iolpc2148.h>
#include<stdio.h>

#define DESIRED_BAUDRATE 19200


#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))

// since VPBDIV=0x01

char array[15]="ViMicrosystems";

Nishitha College of Engineering

Page 21

Embedded Systems Laboratory

char addr;

//FUNCTION DEFINTION
static void delay1(void )
{
volatile int i,j;

for (i=0;i<5;i++)
for (j=0;j<50;j++);
}
static void delay(void )
{
volatile int i,j;
for (i=0;i<100;i++)
for (j=0;j<500;j++);
}
void i2c_write(unsigned char msb_addr,unsigned char lsb_addr ,unsigned char i2c_data)
{
//START CONDITION
I2C0CONSET=0x60;
//start I2C data transmission when set STA flag.
delay1();
while(I2C0STAT!=0x08); //START ACK
//SLAVE ADDRESS
I2C0DAT=0xA2;
I2C0CONCLR=0x28;
delay1();

//SLAVE ADDRESS

while(I2C0STAT!=0x18)
delay1();
//HIGHER ORDER ADDRESS
I2C0DAT=msb_addr;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28)
delay1();
delay();

Nishitha College of Engineering

Page 22

Embedded Systems Laboratory

//LOWER ORDER ADDRESS


I2C0DAT=lsb_addr;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28)
delay1();
//EEPROM DATA
I2C0DAT=i2c_data;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28)
delay1();
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x8;
delay();
}
void i2c_read(unsigned char msb_addr,unsigned char lsb_addr,int count)
{
//START CONDITION
I2C0CONSET=0x60;
//start I2C data transmission when set STA flag.
delay1();
while(I2C0STAT!=0x08);
//SLAVE ADDRESS
I2C0DAT=0xA2;
//EEPROM DEVICE ADDRESS(0XA2)
I2C0CONCLR=0x28;
delay1();
while(I2C0STAT!=0x18);
delay1();
//HIGHER ORDER ADDRESS
I2C0DAT=msb_addr; //WRITE THE EEPROM HIGHER ORDER ADDRESS
I2C0CONCLR=0x8;
while(I2C0STAT!=0x28);
delay1();
delay();
//LOW ORDER ADDRESS

Nishitha College of Engineering

Page 23

Embedded Systems Laboratory

I2C0DAT=lsb_addr;
//WRITE THE EEPROM LOWER ORDER ADDRESS
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28);
delay1();
//STOP CONDITION
I2C0CONSET=0x10;
I2C0CONCLR=0x08;
delay1();
I2C0CONSET=0x10;
I2C0CONCLR=0x08;
//RESTART CONDITION
I2C0CONSET=0x60;
//start I2C data transmission when set STA flag.
delay1();
while(I2C0STAT!=0x08);
//WRITE SLAVE ADDRESS FOR READ MODE
I2C0DAT=0xa3;
//EEPROM READ ADDRESS
I2C0CONCLR=0x2C;
while(I2C0STAT!=0x40);

I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;

// READ

THE EEPROM DATA

for(int i=0;i<=count;i++)
{
I2C0CONCLR=0x08;
while(I2C0STAT!=0x50);
delay1();
printf("\n\r%x%x----->%c",msb_addr,lsb_addr+i,I2C0DAT);
addr=addr+1;
I2C0CONCLR = 0X0C;
I2C0CONSET = 0X04;
I2C0CONCLR = 0X08;
}

Nishitha College of Engineering

Page 24

Embedded Systems Laboratory

}
int putchar(int ch)
{
while (!(U0LSR&0x20)) {}
return(U0THR=ch);
}
void UARTInit()
{
U0LCR=0x83;

// U0LCR: UART0 Line Control Register.


// 0x83: enable Divisor Latch access, set 8-bit word length.
// 1 stop bit, no parity, disable break transmission.

VPBDIV=0x01;
.

// VPBDIV: VPB bus clock divider

0x01: PCLK = processor clock

U0DLL=DIVISOR&0xFF;
U0DLM=DIVISOR>>8;
U0LCR=0x03 ;

U0FCR=0x05 ;

//
U0DLL: UART0 Divisor Latch (LSB).
// U0DLM: UART0 Divisor Latch (MSB).
// U0LCR: UART0 Line Control Register
// 0x03: same as above, but disable Divisor Latch access.
// And same time U0THR (Transmitting register writing)holding the data.
//
U0FCR: UART0 FIFO Control Register
// 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs

}
void main()
{
PINSEL0=0x00000055; //I2C AND UART PORT SELECTION
UARTInit();
//UART INIT FUNCTION
printf("Wait for some time...");
I2C0CONCLR=0x6C; //clear I2C0CONCLR register
I2C0CONSET=0x40; //Enable I2C.
I2C0SCLH=110;
I2C0SCLL=90;
//WRITE EEPROM DATA
for(int i=0;i<=13;i++)
i2c_write(0x00,(0x01+i),array[i]);
//READ EEPROM DATA
i2c_read(0x00,0x01,13);
while(1);
}
Nishitha College of Engineering

Page 25

Embedded Systems Laboratory

RESULT:
Thus the program for I2 C device interface serial EEPROM is executed and output is observed
in WINXTALK by using ARM board.

Nishitha College of Engineering

Page 26

Embedded Systems Laboratory

EXPERIMENT 10
TRANSMISSION FROM KIT AND RECETION FROM PC USING SERIAL PORT
AIM:
Write a Program for transmission from kit and recetion from pc using serial port
APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board


2. IAR software
3. PC

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in WINXTALK by using ARM board.

PROGRAM:
#include <nxp/iolpc2148.h>
#define DESIRED_BAUDRATE
19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK
CRYSTAL_FREQUENCY_IN_HZ
// since VPBDIV=0x01
#define DIVISOR
(PCLK/(16*DESIRED_BAUDRATE))
char arr[]=" \n\r Vimicro system Pvt ltd. Chennai - 96. " ;
char serial_tr(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20)); //wait until Transmit Holding Register is empty
U0THR='\r';
//then store to Transmit Holding Register
}
while (!(U0LSR&0x20)) {}
//wait until Transmit Holding Register is empty
U0THR=ch;
//then store to Transmit Holding Register
return ch;
}
void Arm_Uart0_Init(void)
{
PINSEL0 = 0x00000005;
// (probably not necessary: PINSELs default to zero).
// (lower 4bit selected for UART0 and remaining all bits selected for GPIO's).
Nishitha College of Engineering

Page 27

Embedded Systems Laboratory

U0LCR=0x83;

// (frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx).
// ( LSB bit(2 and 3 bits) selected 01b for UART0 Rx).
//
U0LCR: UART0 Line Control Register.
// 0x83: enable Divisor Latch access, set 8-bit word length.

// 1 stop bit, no parity, disable break transmission.


VPBDIV=0x01;
//
VPBDIV: VPB bus clock divider 0x01: PCLK = processor clock
U0DLL=DIVISOR&0xFF;
//
U0DLL: UART0 Divisor Latch (LSB).
U0DLM=DIVISOR>>8;
//
U0DLM: UART0 Divisor Latch (MSB).
U0LCR=0x03 ;
// U0LCR: UART0 Line Control Register
// 0x03: same as above, but disable Divisor Latch access.
// And same time U0THR (Transmitting register writing)holding the data.
U0FCR=0x05 ;
//
U0FCR: UART0 FIFO Control Register
// 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs
}
//
BAUD RATE CALCULATION
//
DIVISOR
=
(PCLK/(16*DESIRED_BAUDRATE))
//
For Example
//
Peripheral Clock Frequency (PCLK) = 12 Mhz
//
Desired Baud Rate
= 19200 bps
//
Divisor
= (12000000/(16*19200)) = 39
//----------------------------------------------------------------------------------------------void main ()
{
int i;
Arm_Uart0_Init();
// Serial Port Intialisation.
while(1)
{
for(i=0;arr[i]!='\0';i++)
{
serial_tr(arr[i]);
// Serial transmission.
}
}}

RESULT:
Thus the program for transmission from kit and recetion from pc using serial port is executed
and output is observed in WINXTALK by using ARM board.

Nishitha College of Engineering

Page 28

Embedded Systems Laboratory

EXPERIMENT 11
GENERATION OF PWM SIGNAL

AIM:
Write a Program for Generation of PWM Signal
APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board


2. IAR software
3. PC
4. CRO

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in CRO by using ARM board.

PROGRAM:
#include<NXP/iolpc2148.h>
void main(void)
{
PINSEL0 = 0X00008055;// select Port pins p0.2 and p0.3 as i2c configurable and
// also to select pwm2 as output
PWMPR = 0X00000001;
PWMPCR = 0X00000400;
PWMMCR = 0X00000003;
PWMMR0 = 0X00000010;
PWMMR2 = 0X00000008;
PWMTCR = 0X00000002;
PWMTCR = 0X00000009;
while(1);
}

Nishitha College of Engineering

Page 29

Embedded Systems Laboratory

RESULT:
Thus the program for Generation of PWM Signal is executed and output is observed in CRO
by using ARM board.

Nishitha College of Engineering

Page 30

Embedded Systems Laboratory

RTOS PROGRAMS

Nishitha College of Engineering

Page 31

Embedded Systems Laboratory

EXPERIMENT 12
BLINKING TWO DIFFERENT LEDS

AIM:
Write a program for blinking two different LEDs tasks based on RTOS
APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC
4. RTOS

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code based on RTOS in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in ARM board.

PROGRAM FOR BLINKING TWO DIFFERENT LEDS


#include <includes.h>
//OS TASK STACK ALLOCATION
OS_STK led_Task1stk[100];
OS_STK led_Task2stk[100];
void led_Task1(void *pdata)
{
for(;;)
{
IO1SET=0XF0000000;
OSTimeDly(150);
IO1CLR=0Xf0000000;
OSTimeDly(150);
}
}

Nishitha College of Engineering

Page 32

Embedded Systems Laboratory

void led_Task2(void *pdata)


{
for(;;)
{
for(int i=0;i<0xf;i++)
{
IO1SET=0X00000000 | (i <<24);
OSTimeDly(250);
IO1CLR=0X00000000 | (i <<24);
}
}
}
void main (void)
{
PINSEL0=0X00000000;
PINSEL1=0X00000000;
PINSEL2=0X00000000;
IO1DIR=0XFF000000;
BSP_IntDisAll();
/* Disable all interrupts until we are ready to accept them */
BSP_Init();
OSInit();
/* Initialize "uC/OS-II, The Real-Time Kernel"
*/
OSTaskCreate(led_Task1,0,&led_Task1stk[99],5);
OSTaskCreate(led_Task2,0,&led_Task2stk[99],6);
OSStart();
/* Start multitasking (i.e. give control to uC/OS-II)
*/
}

RESULT:
Thus the program for blinking two different LEDs based on RTOS is executed and output is
observed in ARM board.

Nishitha College of Engineering

Page 33

Embedded Systems Laboratory

EXPERIMENT 13
DISPLAYING TWO DIFFERENT MESSAGES IN LCD DISPLAY IN TWO LINES

AIM:
Write a program for displaying two different messages in LCD display in two lines
APPARATUS REQUIRED:

1. 1. ARM (LPC2148) Evolution Board


2. IAR software
3. PC
4. RTOS

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code based on RTOS in IAR programming window


Build the program with setting the project options.
Check the program in command window
Download the program to the ARM evolution board
Verify the output in LCD Display by using ARM board.

PROGRAM FOR DISPLAYING TWO DIFFERENT MESSAGES IN LCD DISPLAY IN TWO


LINES
//HEADER FILE DECLARATION
#include <includes.h>
extern char rtc_data[12];
//0S TASK STACK ALLOCATION
OS_STK
OS_STK

RTC_Taskstk[1000];
ADC_Taskstk[1000];

//FUNCTION DEFINITION
void RTC_Task(void *pdata)
{
Nishitha College of Engineering

Page 34

Embedded Systems Laboratory

for(;;)
{
i2c_read(0x02);
OSTimeDly(30);
}
}
void ADC_Task(void *pdata)
{
for(;;)
{
READ_ADC();
OSTimeDly(10);
}
}
void main (void)
{
BSP_IntDisAll();
/* Disable all interrupts until we are ready to accept them */
BSP_Init();
Arm_Uart0_Init();
OSInit();
OSTaskCreate(RTC_Task,0,&RTC_Taskstk[999],0);
OSTaskCreate(ADC_Task,0,&ADC_Taskstk[999],1);
OSStart();
/* Start multitasking (i.e. give control to uC/OS-II)
*/
}

RESULT:
Thus the program for displaying two different messages in LCD display is executed and output is
observed in two lines of LCD display in ARM board.

Nishitha College of Engineering

Page 35

Embedded Systems Laboratory

EXPERIMENT 14
SENDING MESSAGES TO MAILBOX BY 1 TASK AND READING MESSAGE
FROM MAILBOX BY ANOTHER TASK

AIM:
To write a program based on RTOS for sending messages to mailbox by 1 task and reading message
from mailbox by another task.
APPARATUS REQUIRED:

1.
2.
3.
4.

ARM (LPC2148) Evolution Board


IAR software
PC
RTOS

PROCEDURE:
1.
2.
3.
4.
5.

Write the source code based on RTOS in IAR programming window.


Build the program with setting the project options.
Check the program in command window.
Download the program to the ARM evolution board.
Verify the output in WINXTALK by using ARM board.

PROGRAM FOR SENDING MESSAGES TO MAILBOX BY 1 TASK AND


READING MESSAGE FROM MAILBOX BY ANOTHER TASK

//HEADER FILE DECLARATION


int a=10,b=20,c;
#include <includes.h>
CPU_INT08U Task1Data;
CPU_INT08U Task2Data;
OS_STK
OS_STK

Task1stk[100];
Task2stk[100];

OS_EVENT *mailbox;
INT8U Error;
void Task1(void *pdata);
void Task2(void *pdata);
//0S TASK STACK ALLOCATION

Nishitha College of Engineering

Page 36

Embedded Systems Laboratory

OS_STK
OS_STK
OS_STK

UART_Task1stk[100];
UART_Task2stk[100];
UART_Task3stk[100];

//FUNCTION DEFINITION
/*
void UART_Task1(void *pdata)
{
char *msg;
pdata = pdata;
BSP_Init();
for(;;)
{
msg=OSMboxPend(mailbox,0,&Error);
// msg=OSMboxAccept(mailbox);
if(Error==OS_NO_ERR)
if(msg!=(void *)0)
{
printf("\n");
printf("\n Message :\t");
while(*msg!='\0')
{
printf("%c",*msg);

msg++;
}
}
OSTimeDly(1);
}
for(;;)
{
printf("Task 1..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}
*/
/*
void UART_Task2(void *pdata)
{
c=a+b;
char data[]={" Message from Task2 "};
pdata = pdata;
BSP_Init();
for(;;)
{
Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
for(;;)

Nishitha College of Engineering

Page 37

Embedded Systems Laboratory

{
printf("Task 2..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(15);
}
}
*/
void UART_Task3(void *pdata)
{
for(;;)
{
printf("Task 3..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}

void Task1(void *pdata)


{
char *msg;
pdata = pdata;
BSP_Init();
for(;;)
{
msg=OSMboxPend(mailbox,0,&Error);
// msg=OSMboxAccept(mailbox);
if(Error==OS_NO_ERR)
if(msg!=(void *)0)
{
printf("\n\r Message :\t");
while(*msg!='\0')
{
printf("%c",*msg);
msg++;
}
}
OSTimeDly(1);
}
}
void Task2(void *pdata)
{
c=a+b;
char data[]={" Message from Task2 "};
pdata = pdata;
BSP_Init();
for(;;)
{

Nishitha College of Engineering

Page 38

Embedded Systems Laboratory

Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
}
void main (void)
{
BSP_IntDisAll();
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();

mailbox=OSMboxCreate ((void *)0); // create mailbox


OSTaskCreate(Task1,(void *)&Task1Data,&Task1stk[99],1);
OSTaskCreate(Task2,(void *)&Task2Data,&Task2stk[99],0);
OSStart();
}

/*
void main (void)
{
BSP_IntDisAll();
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
printf("vasanth");
mailbox=OSMboxCreate ((void *)0); // create mailbox
OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);
OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);
// OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);
OSStart();
}
*/

RESULT:
Thus the program for sending messages to mailbox by 1 task and reading message from mailbox
by another task is executed and output is observed in WINXTALK by using ARM board.

Nishitha College of Engineering

Page 39

Embedded Systems Laboratory

EXPERIMENT 15
SENDING MESSAGE TO PC THROUGH SERIAL PORT BY THREE DIFFERENT TASKS ON
PRIORITY BASIS
AIM:
To write a program based RTOS for sending messages to PC through serial port by three different
tasks on priority basis.
APPARATUS REQUIRED:

1.
2.
3.
4.

ARM (LPC2148) Evolution Board


IAR software
PC
RTOS

PROCEDURE:

1.
2.
3.
4.
5.

Write the source code based on RTOS in IAR programming window.


Build the program with setting the project options.
Check the program in command window.
Download the program to the ARM evolution board.
Verify the output in WINXTALK by using ARM board.

PROGRAM FOR SENDING MESSAGE TO PC THROUGH SERIAL PORT BY


THREE DIFFERENT TASKS ON PRIORITY BASIS
////////////////////////////////////////////////////////////////////////////////
//////////////////////////3 UART RTOS PROGRAM///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//HEADER FILE DECLARATION
int a=10,b=20,c;
#include <includes.h>
CPU_INT08U Task1Data;
CPU_INT08U Task2Data;
OS_STK

Task1stk[100];

OS_STK

Task2stk[100];

Nishitha College of Engineering

Page 40

Embedded Systems Laboratory

OS_EVENT *mailbox;
INT8U Error;
void Task1(void *pdata);
void Task2(void *pdata);
//0S TASK STACK ALLOCATION
OS_STK

UART_Task1stk[100];

OS_STK

UART_Task2stk[100];

OS_STK

UART_Task3stk[100];

//FUNCTION DEFINITION
/*
void UART_Task1(void *pdata)
{
char *msg;
pdata = pdata;
BSP_Init();
for(;;)
{
msg=OSMboxPend(mailbox,0,&Error);
// msg=OSMboxAccept(mailbox);
if(Error==OS_NO_ERR)
if(msg!=(void *)0)
{
printf("\n");
printf("\n Message :\t");
while(*msg!='\0')
{
printf("%c",*msg);
msg++;
}
}
OSTimeDly(1);

Nishitha College of Engineering

Page 41

Embedded Systems Laboratory

}
for(;;)
{
printf("Task 1..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}
*/
/*
void UART_Task2(void *pdata)
{
c=a+b;
char data[]={" Message from Task2 "};
pdata = pdata;
BSP_Init();
for(;;)
{
Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
for(;;)
{
printf("Task 2..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(15);
}
}
*/

Nishitha College of Engineering

Page 42

Embedded Systems Laboratory

void UART_Task3(void *pdata)


{
for(;;)
{
printf("Task 3..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}
void Task1(void *pdata)
{
char *msg;
pdata = pdata;
BSP_Init();
for(;;)
{
msg=OSMboxPend(mailbox,0,&Error);
// msg=OSMboxAccept(mailbox);
if(Error==OS_NO_ERR)
if(msg!=(void *)0)
{

printf("\n\r Message :\t");


while(*msg!='\0')
{
printf("%c",*msg);
msg++;
}
}
OSTimeDly(1);

Nishitha College of Engineering

Page 43

Embedded Systems Laboratory

}
}
void Task2(void *pdata)
{
c=a+b;
char data[]={" Message from Task2 "};
pdata = pdata;
BSP_Init();
for(;;)
{
Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
}
void main (void)
{
BSP_IntDisAll();
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
mailbox=OSMboxCreate ((void *)0); // create mailbox
OSTaskCreate(Task1,(void *)&Task1Data,&Task1stk[99],1);
OSTaskCreate(Task2,(void *)&Task2Data,&Task2stk[99],0);
OSStart();
}
/*
void main (void)
{
BSP_IntDisAll();
BSP_Init();

Nishitha College of Engineering

Page 44

Embedded Systems Laboratory

Arm_Uart0_Init();
printf("vasanth");
OSInit();
printf("vasanth");
mailbox=OSMboxCreate ((void *)0); // create mailbox
OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);
OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);
// OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);
OSStart();
}
*/

////////////////////////////////////////////////////////////////////////////////
//////////////////////////3 UART RTOS PROGRAM///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//HEADER FILE DECLARATION
#include <includes.h>
//0S TASK STACK ALLOCATION
OS_STK

UART_Task1stk[100];

OS_STK

UART_Task2stk[100];

OS_STK

UART_Task3stk[100];

//FUNCTION DEFINITION
void UART_Task1(void *pdata)
{
for(;;)
{
printf("Task 1..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(500);
}

Nishitha College of Engineering

Page 45

Embedded Systems Laboratory

}
void UART_Task2(void *pdata)
{
for(;;)
{
printf("Task 2..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(200);
}
}
void UART_Task3(void *pdata)
{
for(;;)
{
printf("Task 3..");

putchar(0x0d);
putchar(0x0a);
OSTimeDly(300);
}
}
void main (void)
{
BSP_IntDisAll();

/* Disable all interrupts until we are ready to accept

them */
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
/* Initialize "uC/OS-II, The Real-Time Kernel"
Nishitha College of Engineering

*/
Page 46

Embedded Systems Laboratory

OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],10);
OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],11);
OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],12);
OSStart();

/* Start multitasking (i.e. give control to uC/OS-II)

*/

RESULT:
Thus the program based on RTOS for sending messages to PC through serial port by three
different tasks on priority basis is executed and highest priority output is observed in WINXTALK by
using ARM board.

Nishitha College of Engineering

Page 47

S-ar putea să vă placă și