You are on page 1of 98

ECE DEPARTMENT Embedded Systems Lab Manual

CONTENTS
S.NO 1 2 3 4 5 6 7 8 9 10 11 12 13 14 NAME OF THE EXPERIMENTS Simple Assembly Language Programs 8 Bit Digital LED And Switch Interface Buzzer , Relay& Stepper Motor Interfaces 4x4 Matrix Keypad Interface Character Based LCD Interface (A)Analog to digital conversion & (B)Interfacing with lm 35 temperature sensor I2 C Device Interface Serial EEPROM I2 C Device Interface Seven Segment LED Interface Multidigit Seven Segment LED Interface Displaying A Number In A Seven Segment Display Timer delay program using built in timer/counter Feature External Interrupt Transmission From Kit And Recetion From Pc Using Serial Port Generation Of PWM Signal RTOS PROGRAMS 15 16 17 18 Blinking Two Different LEDS Displaying Two Different Messages In LCD Display In Two Lines Sending Messages To Mailbox By 1 Task And Reading Message From Mailbox By Another Task Sending message to pc through serial port by three Different tasks on priority basis 70-71 72-73 74-78 79-87 PAGE NO 1-10 11-14 15-20 21-24 25-27 28-35 36-44 45-48 49-52 53-56 57-59 60-63 64-66 67-68 SIGN

EX.NO: 1(A)

ASSEMBLY PROGRAM FOR 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

EXNO.1

SIMPLE ASSEMBLY LANGUAGE PROGRAMS


3

1. (A) ADDITION

AIM: Write an Assembly Language Program for Addition

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 window using ARM board.

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

EX.NO: 1(B)

ASSEMBLY PROGRAM FOR 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 BL UART ;B main stop END B stop //serial window language is hex.

1.

(B) SUBTRACTION

AIM: Write an Assembly Language Program for Subtraction 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 window using ARM board.

RESULT: Thus the assembly program for the subtraction is executed and output is observed in WINXTALK by using the ARM board. EX.NO: 1(C) ASSEMBLY PROGRAM FOR 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" 7

main NOP LDR R0,=0X00000005 LDR R1,=0X00000005 //output value display in a serial window. MUL R8,R0,R1 BL UART ;B main stop END B stop //serial window language is hex.

1.(C) MULTIPLICATION

AIM: Write an Assembly Language Program For Multiplication 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 window using ARM board.

RESULT: Thus the assembly program for the multiplication is executed and output is observed in WINXTALK by using the ARM board.

EX.NO: 1(D)

ASSEMBLY PROGRAM FOR DIVISON

#include <NXP/iolpc2148.h> NAME main

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

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

1.(D) DIVISION

AIM: Write an Assembly Language Program for Division APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board

10

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 window using ARM board.

RESULT: Thus the assembly program for the division is executed and output is observed in WINXTALK by using the ARM board.

EX.NO: 2(A) /* LED INTERFACE*/ #include<nxp/iolpc2148.H>

PROGRAM FOR LED INTERFACE

11

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; IO1DIR = 0XFF000000; while(1) { IO1SET=0XFF000000; delay(); IO1CLR=0XFF000000; delay(); } } // P1.24 TO P1.31 goes to low state // P1.24 TO P1.31 goes to high state // P1.24 TO P1.31 as GPIO // p1.24 TO P1.31 Configured as Output port.

EX.NO 2

8 BIT DIGITAL LED AND SWITCH INTERFACE

(A) BIT DIGITAL OUTPUT LED INTERFACE 12

AIM: Write a Program for Bit Digital output LED 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.

13

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

EX.NO: 2(A) /* 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 // LED0 - LED7

PROGRAM FOR SWITCH INTERFACE

: P0.16 - P0.23 : P1.23 - P1.31

// Switch Staus Displayed on LED void main() { // PINSEL0 = 0x00000000; PINSEL1 = 0x00000000; PINSEL2 = 0x00000000; IO0DIR = 0X00000000; IO1DIR = 0Xff000000; while(1) { // IO0CLR = 0XFF000000; 14 // Configured as GPIO port // Configured as GPIO port // P0.16 TO P0.23 Configured as input // P1.23 TO P1.31 Configured as output

// IO1CLR = 0XFF000000; IO1PIN = (~(IO0PIN & 0x00FF0000)<<0x08); // delay(); } } EX.NO.2(B) 8 BIT DIGITAL INPUT SWITCH INTERFACE

AIM: Write a Program for 8 Bit Digital input Switch 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.

15

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

EX.NO: 3(A) #include<nxp/iolpc2148.h> void delay() { for(int i=0;i<=0xff;i++) for(int j=0;j<=0xff;j++); } // // BUZZER

PROGRAM FOR BUZZER INTERFACE

BUZZER INTERFACE - P0.15

//-----------------------------------------------------------------------------void main() { PINSEL0 = 0X00000000; IO0DIR = 0X00008000; while(1) { IO0SET = 0X00008000; // Buzzer On // P0.15 - GPIO PORT // P0.15 - OUTPUT

16

delay(); IO0CLR = 0X00008000; // Buzzer off delay(); }

EX.NO.3 (A)

BUZZER INTERFACE

AIM: Write a Program for Buzzer 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 17

4. Download the program to the ARM evolution board 5. Verify the output in ARM board.

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

EX.NO: 3(B) #include <nxp/iolpc2148.h>

PROGRAM FOR RELAY INTERFACE

void delay() { unsigned int i,j; for(i=0;i<0xff;i++) for(j=0;j<0xff;j++); }

int main (void) { PINSEL0= 0X00000000; PINSEL1= 0X00000000; IO0DIR = 0Xf0000000;

18

while(1) { IO0SET = 0XA0000000; delay(); IO0CLR = 0XA0070000; delay(); } }

EX.NO.3 (B)

RELAY INTERFACE

AIM: Write a Program For Relay Interface APPARATUS REQUIRED:

1.ARM(LPC2148) Evolution Board

2.IAR software

3.PC

19

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.

RESULT: Thus the program for the RELAY interface is executed and RELAYoutput is observed in the ARM board.

EX.NO: 3(C) #include<nxp/iolpc2148.h> void delay_ms(); void main() { IO0DIR=0x000000F0; while(1)

PROGRAM FOR STEPPER MOTOR

20

{ IO0PIN = 0X00000090; delay_ms(); IO0PIN = 0X00000050; delay_ms(); IO0PIN = 0X00000060; delay_ms(); IO0PIN = 0X000000A0; delay_ms(); } } void delay_ms() { int i,j; for(i=0;i<0x0a;i++) for(j=0;j<750;j++); }

EX.NO.3(C)

STEPPER MOTOR

AIM: Write a Program for Stepper Motor Interface APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board 21

2. IAR software

3. PC

4. Stepper motor

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. Connect the stepper motor to the ARM board.

RESULT: Thus the program for the STEPPER MOTOR interface is executed and rotation of STEPPER MOTOR is observed.

EX.NO: 4

PROGRAM FOR 4X4 MATRIX KEYPAD INTERFACE:

22

/* 4 x 4 Matrix Key Pad Interface */ #include<nxp/iolpc2148.h> #define DESIRED_BAUDRATE 19200 #define CRYSTAL_FREQUENCY_IN_HZ 12000000 #define PCLK CRYSTAL_FREQUENCY_IN_HZ #define DIVISOR (PCLK/(16*DESIRED_BAUDRATE)) void delay_ms() { int i,j; for(i=0;i<=0xff;i++) for(j=0;j<=0xf0;j++); } int putchar(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)) {} U0THR=ch; return ch; } void Arm_Uart0_Init() { U0LCR=0x83; //wait until Transmit Holding Register is empty //then store to Transmit Holding Register

//UART Config.

// U0LCR: UART0 Line Control Register. // 0x83: enable Divisor Latch access, set 8-bit word length. // 1 stop bit, no parity, disable break transmission. // VPBDIV: VPB bus clock divider 0x01: PCLK =

VPBDIV=0x01; processor clock . U0DLL=DIVISOR&0xFF; U0DLM=DIVISOR>>8; U0LCR=0x03 ;

EX.NO.4

// 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. 4X4 MATRIX KEYPAD INTERFACE

23

AIM: Write a Program For 4x4 Matrix Keypad 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 WINXTALK by using ARM board.

RESULT: Thus the program for the 4X4 MATRIX KEYPAD interface is executed and output is observed in the WINXTALK by pressing the key in ARM board. 24

U0FCR=0x05 ;

//

U0FCR: UART0 FIFO Control Register // 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs

} //-----------------------------------------------------------------------------// Keypad Interface // K1 TO K8 : P0.16 TO P0.23 // Key Value is displayed on UART0 // SCAN LINES : P0.20 TO P0.23 (OUTPUT) // READ LINES : PO.16 TO P0.19 (INPUT) //------------------------------------------------------------------------------

void main() {

PINSEL0 = 0x00000005; //Pin selction for UART0 PINSEL2 = 0x00000000; //P0.16 TO P0.23 Configured as GPIO. IO0DIR = 0X00F00005; //P0.20 TO P0.23 (O/P), P0.16 TO P0.19(I/P) Arm_Uart0_Init(); printf("\n\r 4 x 4 Matrix Key Pad Interface "); printf("\n\r Press any Key Pad Interface ");

while(1) {

IO0PIN=0x00E00000;

// First Scan Line

if(( IO0PIN & 0x000F0000 )!= 0x000F0000) { switch(IO0PIN & 0x000F0000) { 25

case 0x00070000 : printf("F");break; case 0x000B0000 : printf("B");break; case 0x000D0000 : printf("7");break; case 0x000E0000 : printf("3");break; } } IO0PIN=0x00D00000; if(( IO0PIN & 0x000F0000 )!= 0x000F0000) { switch(IO0PIN & 0x000F0000) { case 0x00070000 : printf("E");break; case 0x000B0000 : printf("A");break; case 0x000D0000 : printf("6");break; case 0x000E0000 : printf("2");break; } } IO0PIN=0x00B00000; if(( IO0PIN & 0x000F0000 )!= 0x0F000000) { switch(IO0PIN & 0x000F0000) { case 0x00070000 : printf("D");break; case 0x000B0000 : printf("9");break; case 0x000D0000 : printf("5");break; case 0x000E0000 : printf("1");break; } } IO0PIN=0x00700000; if(( IO0PIN & 0x000F0000 )!= 0x000F0000) { switch(IO0PIN & 0x000F0000) { case 0x00070000 : printf("C");break; case 0x000B0000 : printf("8");break; case 0x000D0000 : printf("4");break; case 0x000E0000 : printf("0");break; } } delay_ms(); } } 26

EX.NO: 5

PROGRAM FOR CHARACTER BASED LCD INTERFACE:

#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() { 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);

// 5 * 7 Matrix // Clear Display 27

command_write(0x0f); // Display ON and Cursor Blinking command_write(0x86); // 5 * 7 Matrix command_write(0x06); } void lcd_out(unsigned char z) EX.NO.(5) 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.

28

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

{ busy_check(); IO0SET = RS; //RS = 1 IO0CLR = DIOW; 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; 29

IO0PIN = 0X00000000; IO0CLR = RS; 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); }

30

EX.NO.(6) (A) /*

PROGRAM FOR ANALOG TO DIGITAL CONVERSION */

ON CHIP ADC INTERFACE

#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)) int putchar(int a) { while (!(U0LSR&0x20)); return(U0THR=a); } void ADC_init() { AD0CR_bit.SEL = 2; //enable AD0.3 only

AD0CR_bit.CLKDIV = 12000000 / 4500000; AD0CR_bit.BURST = 1; // put A/D into continuous convert mode

31

AD0CR_bit.CLKS = 0; AD0CR_bit.PDN = 1;

//11 clocks/10 bit accuracy //power up the unit //start 1st cnvrsn immediately

AD0CR_bit.START = 0x0001; } void Arm_Uart0_Init() {

//UART Config.

U0LCR=0x83;

// U0LCR: UART0 Line Control Register. // 0x83: enable Divisor Latch access, set 8-bit word length.

EX.NO.(6) (A)

ANALOG TO DIGITAL CONVERSION

AIM: Write a Program For Analog to Digital Conversion 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

32

4. Download the program to the ARM evolution board 5. Verify the output in WINXTALK by using ARM board.

RESULT: Thus the program for the ADC interface is executed and Digital output is observed in WINXTALK by varying the POT in ARM board

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

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

// VPBDIV: VPB bus clock divider //

0x01: PCLK = processor clock

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=0x05 ; // U0FCR: UART0 FIFO Control Register // 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs }

33

//-----------------------------------------------------------------------------// // P0.28 ADC INTERFACE - ADC0.1

// ADC VALUE Displayed on UART0 //-----------------------------------------------------------------------------void main() { unsigned int ADCresult; PINSEL0 = 0X00000005; PINSEL1 = 0x01000000; Arm_Uart0_Init(); ADC_init(); while(1) { while(AD0DR_bit.DONE == 0); ADCresult = (AD0DR>>6)& 0x3ff ; //wait until conversion done // convesion data holds AD0DR0[6] to AD0DR0[15] // UART0 PIN SELECTION // ADC0.1 CHANNEL SELECT

printf("\n\r ADC VALUE ---->%x",ADCresult); }

34

EX.NO.(6) (B) PROGRAM FOR INTERFACING WITH LM 35 TEMPERATURE SENSOR /* ON BOARD TEMPERATURE SENSOR INTERFACE */

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

35

int putchar(int a) { while (!(U0LSR&0x20)); return(U0THR=a);

} void ADC_init() { AD0CR_bit.SEL = 2; //enable AD0.3 only

AD0CR_bit.CLKDIV = 12000000 / 4500000; AD0CR_bit.BURST = 1; AD0CR_bit.CLKS = 0; AD0CR_bit.PDN = 1; // put A/D into continuous convert mode //11 clocks/10 bit accuracy //power up the unit //start 1st cnvrsn immediately

AD0CR_bit.START = 0x0001; } EX.NO.6 (B)

INTERFACING WITH LM 35 TEMPERATURE SENSOR

AIM: Write a Program for Interfacing with LM 35 Temperature Sensor APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

36

4. LM 35 Temperature Sensor 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. Connect LM 35 Temperature Sensor to the ARM board

RESULT: Thus the program for the LM 35 Temperature Sensor interface is executed and output is observed in WINXTALK by sensing the output from LM35 temperature sensor.

void Arm_Uart0_Init() {

//UART Config.

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. 37

VPBDIV=0x01; .

// VPBDIV: VPB bus clock divider

0x01: PCLK = processor clock

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

//

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=0x05 ; // U0FCR: UART0 FIFO Control Register // 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs } //-----------------------------------------------------------------------------// // P0.28 ADC INTERFACE - ADC0.1

// ADC VALUE Displayed on UART0 //------------------------------------------------------------------------------

void main() { float ADCresult; PINSEL0 = 0X00000005; PINSEL1 = 0x01000000; // UART0 PIN SELECTION // ADC0.1 CHANNEL SELECT

Arm_Uart0_Init(); ADC_init();

38

while(1) { while(AD0DR_bit.DONE == 0); ADCresult = (AD0DR>>6)& 0x3ff ; //wait until conversion done // convesion data holds AD0DR0[6] to AD0DR0[15]

printf("\n\r Temperature Value ---->%f",ADCresult * 0.097); }

EX.NO: (7)

PROGRAM FOR I2 C DEVICE INTERFACE SERIAL EEPROM:

/*----------------------------------------------------------------------------*/ /* /* /* /* THIS PROGRAM FOR EEPROM INTERFACE(24LS256) SDA LINE -P0.3 SCL LINE -P0.2 */ */ */ */

SLAVE ADDRESS WRITE=0XA2,READ =0XA3

39

/*----------------------------------------------------------------------------*/

#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"; char addr;

//FUNCTION DEFINTION

static void delay1(void ) { volatile int i,j; EX.NO.7 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

40

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.

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

for (i=0;i<5;i++) 41

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; delay1(); while(I2C0STAT!=0x08);

//start I2C data transmission when set STA flag.

//START ACK

//SLAVE ADDRESS

I2C0DAT=0xA2; I2C0CONCLR=0x28; delay1();

//SLAVE ADDRESS

while(I2C0STAT!=0x18) delay1();

42

//HIGHER ORDER ADDRESS

I2C0DAT=msb_addr; I2C0CONCLR=0x08;

while(I2C0STAT!=0x28) delay1(); delay();

//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

43

I2C0CONSET=0x10; I2C0CONCLR=0x8; delay(); }

void i2c_read(unsigned char msb_addr,unsigned char lsb_addr,int count) { //START CONDITION

I2C0CONSET=0x60; delay1(); while(I2C0STAT!=0x08);

//start I2C data transmission when set STA flag.

//SLAVE ADDRESS

I2C0DAT=0xA2; I2C0CONCLR=0x28; delay1();

//EEPROM DEVICE ADDRESS(0XA2)

while(I2C0STAT!=0x18); delay1();

//HIGHER ORDER ADDRESS

I2C0DAT=msb_addr; I2C0CONCLR=0x8;

//WRITE THE EEPROM HIGHER ORDER ADDRESS

44

while(I2C0STAT!=0x28); delay1(); delay();

//LOW ORDER ADDRESS

I2C0DAT=lsb_addr; I2C0CONCLR=0x08;

//WRITE THE EEPROM LOWER ORDER ADDRESS

while(I2C0STAT!=0x28); delay1();

//STOP CONDITION

I2C0CONSET=0x10; I2C0CONCLR=0x08; delay1();

I2C0CONSET=0x10; I2C0CONCLR=0x08;

//RESTART CONDITION

I2C0CONSET=0x60; delay1(); while(I2C0STAT!=0x08);

//start I2C data transmission when set STA flag.

45

//WRITE SLAVE ADDRESS FOR READ MODE

I2C0DAT=0xa3; I2C0CONCLR=0x2C;

//EEPROM READ ADDRESS

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;

46

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 ;

//

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=0x05 ; // U0FCR: UART0 FIFO Control Register // 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs 47

void main() { PINSEL0=0x00000055; //I2C AND UART PORT SELECTION

UARTInit();

//UART INIT FUNCTION

printf("Wait for some time..."); I2C0CONCLR=0x6C; I2C0CONSET=0x40; I2C0SCLH=110; I2C0SCLL=90; //clear I2C0CONCLR register //Enable I2C.

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

48

EX.NO: (8)

PROGRAM FOR I2 C DEVICE INTERFACE SEVEN SEGMENT LED

49

INTERFACE #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)) int i,temp,Temp1,addr; unsigned char i2c_data[] = {0x00,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; static void delay(void ) { volatile int i,j; for (i=0;i<5;i++) for (j=0;j<50;j++); } static void delay1(void ) { volatile int i,j; for (i=0;i<100;i++) for (j=0;j<500;j++); } void i2c_write(char a,char add) { //START CONDITION I2C0CONSET=0x60; //0x60 change STA flag. delay(); delay(); temp=I2C0STAT; while(temp!=0x08) temp=I2C0STAT; //SLAVE ADDRESS I2C0DAT=add; I2C0CONCLR=0x28; temp=I2C0STAT; delay(); while(temp!=0x18) { EX.NO.8 I2 C DEVICE INTERFACE SEVEN SEGMENT LED INTERFACE 50

// since VPBDIV=0x01

//start I2C data transmission when set

AIM: Write a Program for I2 C device interface -Seven Segment LED 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.

RESULT: Thus the program for I2 C device interface seven segment LED is executed and output is observed in ARM board. 51

temp=I2C0STAT; delay(); } //Data Write I2C0DAT=a; I2C0CONCLR=0x08; temp=I2C0STAT; while(temp!=0x28) { temp=I2C0STAT;//& 0x28; delay(); } //STOP CONDITION I2C0CONSET=0x10; I2C0CONCLR=0x8; delay1(); } int putchar(int ch) { while (!(U0LSR&0x20)) {} return(U0THR=ch); } void main() { PINSEL0=0x00000055 ; VPBDIV=0x01 ; I2C0CONCLR=0x6C; //clear I2C0CONCLR register I2C0CONSET=0x40; //Enable I2C. I2C0SCLH=110; I2C0SCLL=90; while(1) { for(int i=0;i<=10;i++) i2c_write(i2c_data[i],0x40); for(int i=0;i<=10;i++) 52

i2c_write(i2c_data[i],0x42); for(int i=0;i<=10;i++) i2c_write(i2c_data[i],0x44); for(int i=0;i<=10;i++) i2c_write(i2c_data[i],0x46); for(int i=0;i<=10;i++) i2c_write(i2c_data[i],0x48); for(int i=0;i<=10;i++) i2c_write(i2c_data[i],0x4A); } }

53

EX.NO: (9)

PROGRAM FOR MULTIDIGIT SEVEN SEGMENT LED INTERFACE

#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)) int i,temp,Temp1,addr; unsigned char i2c_data[] = {0x00,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; static void delay(void ) { volatile int i,j; for (i=0;i<5;i++) for (j=0;j<50;j++); } static void delay1(void ) { volatile int i,j; for (i=0;i<10;i++) for (j=0;j<500;j++); } void i2c_write(char a,char add) { //START CONDITION 54 // since VPBDIV=0x01

I2C0CONSET=0x60; //0x60 change //start I2C data transmission when set STA flag. delay(); EX.NO.9 AIM: Write a Program for MULTIDIGIT Seven Segment LED APPARATUS REQUIRED: MULTIDIGIT SEVEN SEGMENT LED INTERFACE

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.

55

RESULT: Thus the program for MULTIDIGIT seven segment LED is executed and output is observed in ARM board.

delay(); temp=I2C0STAT; while(temp!=0x08) temp=I2C0STAT; //SLAVE ADDRESS I2C0DAT=add; I2C0CONCLR=0x28; temp=I2C0STAT; delay(); while(temp!=0x18) { temp=I2C0STAT; delay(); } //Data Write I2C0DAT=a; I2C0CONCLR=0x08; temp=I2C0STAT; while(temp!=0x28) { temp=I2C0STAT;//& 0x28; 56

delay(); }

//STOP CONDITION I2C0CONSET=0x10; I2C0CONCLR=0x8; delay1(); } int putchar(int ch) { while (!(U0LSR&0x20)) {} return(U0THR=ch); } void main() { PINSEL0=0x00000055 ; VPBDIV=0x01 ; I2C0CONCLR=0x6C; I2C0CONSET=0x40; I2C0SCLH=110; I2C0SCLL=90; while(1) { for(int i=0;i<=10;i++) { i2c_write(i2c_data[i],0x40); i2c_write(i2c_data[i],0x42); i2c_write(i2c_data[i],0x44); 57 //clear I2C0CONCLR register //Enable I2C.

i2c_write(i2c_data[i],0x46); i2c_write(i2c_data[i],0x48); i2c_write(i2c_data[i],0x4a); }

EX.NO: (10) PROGRAM FOR DISPLAYING A NUMBER IN A SEVEN SEGMENT DISPLAY #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)) int i,temp,Temp1,addr; unsigned char i2c_data[] = {0x00,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; static void delay(void ) { volatile int i,j; for (i=0;i<5;i++) for (j=0;j<50;j++); } static void delay1(void ) { volatile int i,j; for (i=0;i<10;i++) for (j=0;j<500;j++); } 58 // since VPBDIV=0x01

void i2c_write(char a,char add) { //START CONDITION I2C0CONSET=0x60; //0x60 change //start I2C data transmission when set STA flag. delay(); delay(); EX.NO.10 AIM: Write a Program for displaying a number in a seven segment display APPARATUS REQUIRED: DISPLAYING A NUMBER IN A SEVEN SEGMENT DISPLAY

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.

59

RESULT: Thus the program for displaying a number in a seven segment display is executed and output is observed in ARM board.

temp=I2C0STAT; while(temp!=0x08) temp=I2C0STAT; //SLAVE ADDRESS I2C0DAT=add; I2C0CONCLR=0x28; temp=I2C0STAT; delay(); while(temp!=0x18) { temp=I2C0STAT; delay(); } //Data Write I2C0DAT=a; I2C0CONCLR=0x08;

60

temp=I2C0STAT; while(temp!=0x28) { temp=I2C0STAT;//& 0x28; delay(); }

//STOP CONDITION I2C0CONSET=0x10; I2C0CONCLR=0x8; delay1(); } int putchar(int ch) { while (!(U0LSR&0x20)) {} return(U0THR=ch); } void main() { PINSEL0=0x00000055 ; VPBDIV=0x01 ; I2C0CONCLR=0x6C; I2C0CONSET=0x40; I2C0SCLH=110; I2C0SCLL=90; while(1) { for(int i=0;i<=10;i++) 61 //clear I2C0CONCLR register //Enable I2C.

{ i2c_write(i2c_data[i],0x40); }

EX.NO: (11)

PROGRAM TIMER DELAY PROGRAM USING BUILT IN TIMER/COUNTER FEATURE

#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 */ PLLCON_bit.PLLE = 1; PLLFEED PLLFEED = 0xAA; = 0x55; /* Set the PLL Enable bit /* Write to the PLL Feed register */ */ = 0x00000024; /* Use PLL values of M = 4 and P = 2 */

62

loop_ctr = 10000; */

/* Wait for the PLL to lock into the new frequency

while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) { loop_ctr--; } PLLCON_bit.PLLC = 1; PLLFEED PLLFEED VPBDIV clock */ } void timer_1() { //Timer 0 Initialisation T1IR = 0xFF; EX.NO.11 // reset match and capture event interrupts TIMER DELAY PROGRAM USING BUILT IN TIMER/COUNTER FEATURE AIM: Write a Program for timer delay using built in timer/counter Feature = 0xAA; = 0x55; = 0x00000001; /* Set the VPB frequency to one-half of the CPU /* Connect the PLL /* Write to the PLL Feed register */ */

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

63

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.

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

T1TC = 0; T1PR = 59;

// Clear timer counter // Timer counter Increments every 0.017 usec

T1MR0 = 1000000; T1MCR = 3; void main(void) { LPC2148PLLInit(); PINSEL2 = 0X00000000; IO1DIR = 0XFF000000; 64 // Reset Timer Counter & Interrupt on match

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

65

EX.NO: (12) #include <NXP/iolpc2148.h> #include <intrinsics.h> #define XTALFREQ 12000000

PROGRAM FOR EXTERNAL INTERRUPT

//XTAL frequency in Hz //pclk must always be XTALFREQ/4?

#define PCLKFREQ (XTALFREQ/4) int main(void);

__irq __arm void IRQ_ISR_Handler (void); void Btn2DownISR(void);

66

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 // Diasable all interrupts

VICIntEnClear = 0xFFFFFFFF;

VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps VICProtection = 0; // VIC registers can be accessed in User or // privileged mode VICVectAddr = 0; VICDefVectAddr = 0; // Clear interrupt // 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

EX.NO.12 AIM:

EXTERNAL INTERRUPT

Write a Program for External Interrupt

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

67

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.

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

//LED Conmfiguration PINSEL2 = 0X00000000; IO1DIR = 0XFF000000; // P1.24 TO P1.31 as GPIO // p1.24 TO P1.31 Configured as Output port. 68

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. // Install ISR in VIC addr slot

VICVectAddr1 = (unsigned int)&Btn2DownISR; VICVectCntl1 = 0x20 | VIC_EINT3; VICIntEnable |= (1<<VIC_EINT3); __enable_interrupt();

// Enable vec int for EINT 0. // Enable EINT0 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) { IO1SET=0XFF000000; } } __irq __arm void irq_handler (void) { void (*interrupt_function)(); unsigned int vector; vector = VICVectAddr; // Get interrupt vector. // P1.24 TO P1.31 goes to high state // Foreground Loop

interrupt_function = (void(*)())vector; (*interrupt_function)(); // Call vectored interrupt function VICVectAddr = 0; } __fiq __arm void fiq_handler (void) // Clear interrupt in VIC

69

{ 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

EX.NO.13 PROGRAM TRANSMISSION FROM KIT AND RECETION FROM PC USING SERIAL PORT #include <nxp/iolpc2148.h>

70

#define DESIRED_BAUDRATE

19200

#define CRYSTAL_FREQUENCY_IN_HZ 12000000 #define PCLK #define DIVISOR CRYSTAL_FREQUENCY_IN_HZ (PCLK/(16*DESIRED_BAUDRATE)) // since VPBDIV=0x01

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'; } while (!(U0LSR&0x20)) {} //wait until Transmit Holding Register is empty U0THR=ch; return ch; } void Arm_Uart0_Init(void) { PINSEL0 = 0x00000005; zero). selected for GPIO's). // (frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx). // ( LSB bit(2 and 3 bits) selected 01b for UART0 Rx). U0LCR=0x83; length. // U0LCR: UART0 Line Control Register. // (probably not necessary: PINSELs default to //then store to Transmit Holding Register //then store to Transmit Holding Register

// (lower 4bit selected for UART0 and remaining all bits

// 0x83: enable Divisor Latch access, set 8-bit word

EX.NO.13

TRANSMISSION FROM KIT AND RECETION FROM PC USING SERIAL PORT 71

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

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. 72

// 1 stop bit, no parity, disable break transmission. VPBDIV=0x01; = processor clock U0DLL=DIVISOR&0xFF; U0DLM=DIVISOR>>8; U0LCR=0x03 ; access. // And same time U0THR (Transmitting register writing)holding the data. U0FCR=0x05 ; // U0FCR: UART0 FIFO Control Register // VPBDIV: VPB bus clock divider 0x01: PCLK

// U0DLL: UART0 Divisor Latch (LSB). // U0DLM: UART0 Divisor Latch (MSB). // U0LCR: UART0 Line Control Register // 0x03: same as above, but disable Divisor Latch

// 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs } // // // // // // DIVISOR For Example Peripheral Clock Frequency (PCLK) = 12 Mhz Desired Baud Rate Divisor = 19200 bps = (12000000/(16*19200)) = 39 BAUD RATE CALCULATION = (PCLK/(16*DESIRED_BAUDRATE))

//----------------------------------------------------------------------------------------------void main () { int i; Arm_Uart0_Init(); while(1) { for(i=0;arr[i]!='\0';i++) 73 // Serial Port Intialisation.

{ serial_tr(arr[i]); } }} // Serial transmission.

74

EX.NO.14

PROGRAM FOR GENERATION OF PWM SIGNAL

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

75

EX.NO.14 AIM:

GENERATION OF PWM SIGNAL

Write a Program for Generation of PWM Signal APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

4. CRO

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 CRO by using ARM board.

76

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

RTOS PROGRAMS
77

EX.NO.15

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); } } void led_Task2(void *pdata) { for(;;) { for(int i=0;i<0xf;i++) { IO1SET=0X00000000 | (i <<24); OSTimeDly(250); IO1CLR=0X00000000 | (i <<24); }

78

} } 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) */ } EX.NO.15 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:

79

1. Write the source code based on RTOS 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.

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

EX.NO.16

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) 80

{ 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) */ }

EX.NO.16

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

81

3. PC

4. RTOS

PROCEDURE:

1. Write the source code based on RTOS 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 LCD Display by using ARM board.

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.

EX.NO.17

PROGRAM FOR SENDING MESSAGES TO MAILBOX BY 1 TASK AND READING MESSAGE FROM MAILBOX BY ANOTHER TASK 3 UART RTOS PROGRAM

//HEADER FILE DECLARATION 82

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 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); EX.NO.17 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:

83

1. ARM (LPC2148) Evolution Board 2. IAR software 3. PC 4. RTOS

PROCEDURE: 1. Write the source code based on RTOS 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.

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.

msg++; 84

} } 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(;;) { printf("Task 2.."); putchar(0x0d); putchar(0x0a); OSTimeDly(15); } } */ void UART_Task3(void *pdata) { for(;;) { printf("Task 3.."); putchar(0x0d); putchar(0x0a); OSTimeDly(10); } }

85

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(;;) { 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(); } 86

/* 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(); } */

87

88

EX.NO.18 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 OS_STK Task1stk[100]; Task2stk[100];

OS_EVENT *mailbox; INT8U Error; void Task1(void *pdata); void Task2(void *pdata); //0S TASK STACK ALLOCATION 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; 89

EX.NO.18

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. ARM (LPC2148) Evolution Board 2. IAR software 3. PC 4. RTOS

PROCEDURE:

1. Write the source code based on RTOS 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.

RESULT: 90

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.

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

91

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); } } */

92

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') {

93

printf("%c",*msg); msg++; } } OSTimeDly(1); } } 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();

94

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(); } */

//////////////////////////////////////////////////////////////////////////////// //////////////////////////3 UART RTOS PROGRAM/////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //HEADER FILE DECLARATION

95

#include <includes.h> //0S TASK STACK ALLOCATION OS_STK OS_STK OS_STK UART_Task1stk[100]; UART_Task2stk[100]; UART_Task3stk[100];

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

96

void UART_Task3(void *pdata) { for(;;) { printf("Task 3.."); putchar(0x0d); putchar(0x0a); OSTimeDly(300); } } void main (void) { BSP_IntDisAll(); them */ BSP_Init(); Arm_Uart0_Init(); printf("vasanth"); OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */ /* Disable all interrupts until we are ready to accept

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)

97

98