108
ECE DEPARTMENT Embedded Systems Lab Manual 1

Embedded Lab

Embed Size (px)

Citation preview

Page 1: Embedded Lab

ECE DEPARTMENT

Embedded Systems Lab Manual

1

Page 2: Embedded Lab

CONTENTS

S.NO NAME OF THE EXPERIMENTS PAGE NO SIGN

1 Simple Assembly Language Programs 1-10

2 8 Bit Digital LED And Switch Interface 11-14

3 Buzzer , Relay& Stepper Motor Interfaces 15-20

4 4x4 Matrix Keypad Interface 21-24

5 Character Based LCD Interface 25-27

6(A)Analog to digital conversion &

(B)Interfacing with lm 35 temperature sensor28-35

7 I2 C Device Interface – Serial EEPROM 36-44

8 I2 C Device Interface – Seven Segment LED Interface 45-48

9 Multidigit Seven Segment LED Interface 49-52

10 Displaying A Number In A Seven Segment Display 53-56

11 Timer delay program using built in timer/counter Feature 57-59

12 External Interrupt 60-63

13Transmission From Kit And Recetion From Pc Using

Serial Port64-66

14 Generation Of PWM Signal 67-68

RTOS PROGRAMS

15 Blinking Two Different LEDS 70-71

16Displaying Two Different Messages In LCD

Display In Two Lines72-73

17Sending Messages To Mailbox By 1 Task And Reading Message From Mailbox By Another

Task74-78

18Sending message to pc through serial port by three

Different tasks on priority basis79-87

2

Page 3: Embedded Lab

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

3

Page 4: Embedded Lab

EXNO.1 SIMPLE ASSEMBLY LANGUAGE PROGRAMS

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. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

4

Page 5: Embedded Lab

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 //serial window language is hex.

BL UART

;B main

stop B stop

END

5

Page 6: Embedded Lab

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

6

Page 7: Embedded Lab

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"

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

7

Page 8: Embedded Lab

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

8

Page 9: Embedded Lab

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

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

9

Page 10: Embedded Lab

1.(D) DIVISION

AIM:

Write an Assembly Language Program for Division

APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board

2. IAR software

3. PC

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

10

Page 11: Embedded Lab

EX.NO: 2(A) PROGRAM FOR LED INTERFACE

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

while(1)

{

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

delay();

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

delay();

}

}

11

Page 12: Embedded Lab

EX.NO 2 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. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

12

Page 13: Embedded Lab

EX.NO: 2(A) PROGRAM FOR SWITCH INTERFACE

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

}

}

13

Page 14: Embedded Lab

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

14

Page 15: Embedded Lab

EX.NO: 3(A) PROGRAM FOR BUZZER INTERFACE

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

}

}

15

Page 16: Embedded Lab

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

16

Page 17: Embedded Lab

EX.NO: 3(B) PROGRAM FOR RELAY INTERFACE

#include <nxp/iolpc2148.h>

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;

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

17

Page 18: Embedded Lab

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

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

18

Page 19: Embedded Lab

EX.NO: 3(C) PROGRAM FOR STEPPER MOTOR

#include<nxp/iolpc2148.h>

void delay_ms();

void main()

{

IO0DIR=0x000000F0;

while(1)

{

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

}

19

Page 20: Embedded Lab

EX.NO.3(C) STEPPER MOTOR

AIM:

Write a Program for Stepper Motor Interface

APPARATUS REQUIRED:

1. ARM (LPC2148) Evolution Board

2. IAR software

3. PC

4. Stepper motor

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

20

Page 21: Embedded Lab

EX.NO: 4 PROGRAM FOR 4X4 MATRIX KEYPAD INTERFACE:

/* 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 emptyU0THR='\r'; //then store to Transmit Holding Register

}

while (!(U0LSR&0x20)) {} //wait until Transmit Holding Register is emptyU0THR=ch; //then store to Transmit Holding Registerreturn ch;

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

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

21

Page 22: Embedded Lab

// 0x03: same as above, but disable Divisor Latch access. // And same time U0THR (Transmitting register writing)holding the data. EX.NO.4 4X4 MATRIX KEYPAD INTERFACE

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

22

Page 23: Embedded Lab

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) { case 0x00070000 : printf("F");break; case 0x000B0000 : printf("B");break; case 0x000D0000 : printf("7");break; case 0x000E0000 : printf("3");break;

23

Page 24: Embedded Lab

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

24

Page 25: Embedded Lab

EX.NO: 5 PROGRAM FOR CHARACTER BASED LCD INTERFACE:

#include <nxp/iolpc2148.h>#define LCD_EN 0X00000800#define RS 0X00000100#define DIOW 0X00000200unsigned 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); // 5 * 7 Matrix command_write(0x01); // Clear Display command_write(0x0f); // Display ON and Cursor Blinking command_write(0x86); // 5 * 7 Matrix command_write(0x06); }

25

Page 26: Embedded Lab

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

26

Page 27: Embedded Lab

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

27

Page 28: Embedded Lab

}

28

Page 29: Embedded Lab

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

AD0CR_bit.CLKS = 0; //11 clocks/10 bit accuracy

AD0CR_bit.PDN = 1; //power up the unit

AD0CR_bit.START = 0x0001; //start 1st cnvrsn immediately

}

void Arm_Uart0_Init() //UART Config.

{

U0LCR=0x83; // U0LCR: UART0 Line Control Register.

29

Page 30: Embedded Lab

// 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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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

30

Page 31: Embedded Lab

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

}

//------------------------------------------------------------------------------

// ADC INTERFACE

// P0.28 - ADC0.1

// ADC VALUE Displayed on UART0

//------------------------------------------------------------------------------

void main()

{

unsigned int ADCresult;

PINSEL0 = 0X00000005; // UART0 PIN SELECTION

PINSEL1 = 0x01000000; // ADC0.1 CHANNEL SELECT

Arm_Uart0_Init();

ADC_init();

while(1)

{

31

Page 32: Embedded Lab

while(AD0DR_bit.DONE == 0); //wait until conversion done

ADCresult = (AD0DR>>6)& 0x3ff ; // convesion data holds AD0DR0[6] to AD0DR0[15]

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

}

}

32

Page 33: Embedded Lab

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

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

AD0CR_bit.CLKS = 0; //11 clocks/10 bit accuracy

AD0CR_bit.PDN = 1; //power up the unit

33

Page 34: Embedded Lab

AD0CR_bit.START = 0x0001; //start 1st cnvrsn immediately

}

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

4. LM 35 Temperature Sensor

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Connect LM 35 Temperature Sensor to the ARM board

RESULT:

34

Page 35: Embedded Lab

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.

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

}

//------------------------------------------------------------------------------

// ADC INTERFACE

// P0.28 - ADC0.1

// ADC VALUE Displayed on UART0

//------------------------------------------------------------------------------

35

Page 36: Embedded Lab

void main()

{

float ADCresult;

PINSEL0 = 0X00000005; // UART0 PIN SELECTION

PINSEL1 = 0x01000000; // ADC0.1 CHANNEL SELECT

Arm_Uart0_Init();

ADC_init();

while(1)

{

while(AD0DR_bit.DONE == 0); //wait until conversion done

ADCresult = (AD0DR>>6)& 0x3ff ; // convesion data holds AD0DR0[6] to AD0DR0[15]

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

}

}

36

Page 37: Embedded Lab

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

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

#include<nxp/iolpc2148.h>

#include<stdio.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 array[15]="ViMicrosystems";

char addr;

//FUNCTION DEFINTION

static void delay1(void )

37

Page 38: Embedded Lab

{

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

2. IAR software

3. PC

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

38

Page 39: Embedded Lab

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; //SLAVE ADDRESS

I2C0CONCLR=0x28;

delay1();

39

Page 40: Embedded Lab

while(I2C0STAT!=0x18)

delay1();

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

40

Page 41: Embedded Lab

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

41

Page 42: Embedded Lab

I2C0DAT=msb_addr; //WRITE THE EEPROM HIGHER ORDER ADDRESS

I2C0CONCLR=0x8;

while(I2C0STAT!=0x28);

delay1();

delay();

//LOW ORDER ADDRESS

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.

42

Page 43: Embedded Lab

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;

43

Page 44: Embedded Lab

I2C0CONSET = 0X04;

I2C0CONCLR = 0X08;

}

}

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

44

Page 45: Embedded Lab

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

}

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

}

45

Page 46: Embedded Lab

46

Page 47: Embedded Lab

EX.NO: (8) PROGRAM FOR I2 C DEVICE INTERFACE – 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 // since VPBDIV=0x01#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 //start I2C data transmission when set STA flag.

delay();delay();temp=I2C0STAT;while(temp!=0x08)temp=I2C0STAT;

//SLAVE ADDRESSI2C0DAT=add;

47

Page 48: Embedded Lab

I2C0CONCLR=0x28;temp=I2C0STAT;delay();while(temp!=0x18)

{EX.NO.8 I2 C DEVICE INTERFACE – SEVEN SEGMENT LED INTERFACE

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 window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

48

Page 49: Embedded Lab

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++) i2c_write(i2c_data[i],0x42);

49

Page 50: Embedded Lab

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

50

Page 51: Embedded Lab

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 // since VPBDIV=0x01

#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

51

Page 52: Embedded Lab

I2C0CONSET=0x60; //0x60 change

//start I2C data transmission when set STA flag.

delay();

EX.NO.9 MULTIDIGIT SEVEN SEGMENT LED INTERFACE

AIM:

Write a Program for MULTIDIGIT Seven Segment LED

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

52

Page 53: Embedded Lab

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;

delay();

}

//STOP CONDITION

53

Page 54: Embedded Lab

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

i2c_write(i2c_data[i],0x42);

i2c_write(i2c_data[i],0x44);

i2c_write(i2c_data[i],0x46);

i2c_write(i2c_data[i],0x48);

i2c_write(i2c_data[i],0x4a);

}

54

Page 55: Embedded Lab

}

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 // since VPBDIV=0x01

#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

I2C0CONSET=0x60; //0x60 change

//start I2C data transmission when set STA flag.

55

Page 56: Embedded Lab

delay();

delay();

EX.NO.10 DISPLAYING A NUMBER IN A SEVEN SEGMENT DISPLAY

AIM:

Write a Program for displaying a number in a seven segment display

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

56

Page 57: Embedded Lab

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;

delay();

}

//STOP CONDITION

I2C0CONSET=0x10;

I2C0CONCLR=0x8;

57

Page 58: Embedded Lab

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

}

58

Page 59: Embedded Lab

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

}

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

59

Page 60: Embedded Lab

{

//Timer 0 Initialisation

T1IR = 0xFF; // reset match and capture event interrupts

EX.NO.11 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. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

60

Page 61: Embedded Lab

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

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;

}

61

Page 62: Embedded Lab

}

62

Page 63: Embedded Lab

EX.NO: (12) PROGRAM FOR EXTERNAL INTERRUPT

#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

VICDefVectAddr = 0; // Clear address of the default ISR

/*Configure the pins that the buttons are hooked up to to be external

interrupts */

63

Page 64: Embedded Lab

PINSEL1_bit.P0_30=0x2; // Set Port pin P0.15 function to EINT3

EX.NO.12 EXTERNAL INTERRUPT

AIM:

Write a Program for External Interrupt

APPARATUS REQUIRED:

1. ARM(LPC2148) Evolution Board

2. IAR software

3. PC

PROCEDURE:

1. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

RESULT:

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

64

Page 65: Embedded Lab

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

65

Page 66: Embedded Lab

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

}

66

Page 67: Embedded Lab

EX.NO.13 PROGRAM TRANSMISSION FROM KIT AND RECETION FROM PC USING

SERIAL PORT

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

// (frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx).

67

Page 68: Embedded Lab

// ( LSB bit(2 and 3 bits) selected 01b for UART0 Rx).

U0LCR=0x83; // U0LCR: UART0 Line Control Register.

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

EX.NO.13 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. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. 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.

68

Page 69: Embedded Lab

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

{

69

Page 70: Embedded Lab

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

}

} }

70

Page 71: Embedded Lab

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

}

71

Page 72: Embedded Lab

EX.NO.14 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. Write the source code in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in CRO by using ARM board.

RESULT:

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

72

Page 73: Embedded Lab

RTOS PROGRAMS

73

Page 74: Embedded Lab

EX.NO.15 PROGRAM FOR BLINKING TWO DIFFERENT LEDS

#include <includes.h>//OS TASK STACK ALLOCATIONOS_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); }

} }

void main (void){ PINSEL0=0X00000000; PINSEL1=0X00000000; PINSEL2=0X00000000;

IO1DIR=0XFF000000;

BSP_IntDisAll(); /* Disable all interrupts until we are ready to accept them */

74

Page 75: Embedded Lab

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:

1. Write the source code based on RTOS in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in ARM board.

75

Page 76: Embedded Lab

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 RTC_Taskstk[1000]; OS_STK ADC_Taskstk[1000];

//FUNCTION DEFINITION

void RTC_Task(void *pdata){ 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();

76

Page 77: Embedded Lab

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

3. PC

4. RTOS

PROCEDURE:

1. Write the source code based on RTOS in IAR programming window2. Build the program with setting the project options.3. Check the program in command window4. Download the program to the ARM evolution board5. Verify the output in LCD Display by using ARM board.

77

Page 78: Embedded Lab

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 DECLARATIONint a=10,b=20,c;#include <includes.h>CPU_INT08U Task1Data;CPU_INT08U Task2Data;

OS_STK Task1stk[100];OS_STK Task2stk[100];

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

78

Page 79: Embedded Lab

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:

1. ARM (LPC2148) Evolution Board2. IAR software3. PC4. 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.

79

Page 80: Embedded Lab

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

80

Page 81: Embedded Lab

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(;;) { Error=OSMboxPost(mailbox,(void *)&data[0]); OSTimeDly(1); }}

void main (void){ BSP_IntDisAll(); BSP_Init(); Arm_Uart0_Init(); printf("vasanth"); OSInit();

81

Page 82: Embedded Lab

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

}

*/

82

Page 83: Embedded Lab

83

Page 84: Embedded Lab

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 Task1stk[100];

OS_STK Task2stk[100];

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

/*

84

Page 85: Embedded Lab

void UART_Task1(void *pdata)

{

char *msg;

pdata = pdata;

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 Board2. IAR software3. PC4. 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:

85

Page 86: Embedded Lab

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

86

Page 87: Embedded Lab

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

}

}

*/

87

Page 88: Embedded Lab

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

{

88

Page 89: Embedded Lab

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

89

Page 90: Embedded Lab

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

90

Page 91: Embedded Lab

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

}

}

void UART_Task2(void *pdata)

{

for(;;)

{

printf("Task 2..");

putchar(0x0d);

putchar(0x0a);

OSTimeDly(200);

}

}

91

Page 92: Embedded Lab

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

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

}

92

Page 93: Embedded Lab

93