Top Banner

of 47

Embedded Lab II mtech arm7-r13

Jun 02, 2018

Download

Documents

log4iqbal
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/10/2019 Embedded Lab II mtech arm7-r13

    1/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 1

    EXPERIMENT 1

    SIMPLE ASSEMBLY LANGUAGE PROGRAMS

    AIM:

    Write an Assembly Language Program for Addition, Subtraction, Multiplication and Division.

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR/KEIL software

    3. PC

    PROCEDURE:

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

    PROGRAMS:

    Addition:

    #include

    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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    2/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 2

    Subtraction:

    #include

    NAME main

    PUBLIC __iar_program_start

    SECTION .intvec : CODE (2)

    CODE32

    __iar_program_start

    B main

    SECTION .text : CODE (2)

    CODE32

    #include "uart.asm"

    main NOP

    LDR R0,=0X0000FFFF

    LDR R1,=0X0000EEEE //output value display in a serial window.

    SUB R8,R0,R1 //serial window language is hex.BL UART

    ;B main

    stop B stop

    END

    Multiplication:

    #include

    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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    3/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 3

    Division:

    #include

    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 ERRCMP R0,R1

    BLT DONE

    ADD R8,R8,#1

    SUB R0,R0,R1

    B loop

    ERR: MOV R8,#0XFFFFFFFF

    DONE: BL UART

    stop: B stop

    END

    RESULT:

    Thus the assembly program for the addition , Substraction, Multiplication and Division is executed and

    output is observed in WINXTALK by using the ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    4/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 4

    EXPERIMENT 2

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

    AIM:

    Write a Programs to configure and control General Purpose Input/Output (GPIO)

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR/KEIL software

    3. PC

    PROCEDURE:

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

    PROGRAMM:

    #include

    void delay()

    {

    for(int i=0x00;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    5/47

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    6/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 6

    EXPERIMENT 3

    TIMER DELAY PROGRAM USING BUILT IN TIMER/COUNTER FEATURE

    AIM:

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

    APPARATUS REQUIRED:

    1. ARM(LPC2148) Evolution Board

    2. IAR software

    3.

    PC

    PROCEDURE:

    1. Write the source code in IAR programming window

    2. Build the program with setting the project options.

    3. Check the program in command window

    4. Download the program to the ARM evolution board

    5. Verify the output in ARM board.

    PROGRAM:

    #include #include

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    7/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 7

    PLLCON_bit.PLLC = 1; /* Connect the PLL */PLLFEED = 0xAA; /* Write to the PLL Feed register */PLLFEED = 0x55;VPBDIV = 0x00000001; /* Set the VPB frequency to one-half of the CPU

    clock */

    }void timer_1()

    {//Timer 0 InitialisationT1IR = 0xFF; // reset match and capture event interrupts

    T1TC = 0; // Clear timer counterT1PR = 59; // Timer counter Increments every 0.017 usecT1MR0 = 1000000;T1MCR = 3; // Reset Timer Counter & Interrupt on match

    void main(void)

    {LPC2148PLLInit();PINSEL2 = 0X00000000;IO1DIR = 0XFF000000;while(1)

    {timer_1();

    T1TCR = 1;while(T1TC!=1000000);T1TCR = 0;

    IO1SET = 0XFF000000;T1TC=0;

    timer_1();T1TCR = 1;while(T1TC!=1000000);

    T1TCR = 0;IO1CLR = 0XFF000000;

    T1TC=0;}

    }

    RESULT:

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

    in ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    8/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 8

    EXPERIMENT 4

    EXTERNAL INTERRUPT

    AIM:

    Write a Program for External Interrupt

    APPARATUS REQUIRED:

    1. ARM(LPC2148) Evolution Board

    2. IAR software

    3. PC

    PROCEDURE:

    1. Write the source code in IAR programming window

    2. Build the program with setting the project options.

    3. Check the program in command window

    4. Download the program to the ARM evolution board

    5. Verify the output in ARM board.

    PROGRAM:

    #include

    #include

    #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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    9/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 9

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

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

    interrupts */

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

    //LED Conmfiguration

    PINSEL2 = 0X00000000; // P1.24 TO P1.31 as GPIO

    IO1DIR = 0XFF000000; // p1.24 TO P1.31 Configured as Output port.

    VICProtection = 0; // Accesss VIC in USR | PROTECT

    // VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr

    /* Set up the button 1 pressed interrupt on EINT0 */

    VICIntSelect &= ~(1

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    10/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 10

    RESULT:

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

    board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    11/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 11

    EXPERIMENT 5

    PRESS BUTTON TO GENERATE AN INTERRUPT

    AIM:

    Write a Program for External Interrupt

    APPARATUS REQUIRED:

    4. ARM(LPC2148) Evolution Board

    5.

    IAR software

    6. PC

    PROCEDURE:

    6. Write the source code in IAR programming window

    7. Build the program with setting the project options.

    8. Check the program in command window

    9.

    Download the program to the ARM evolution board10.Verify the output in ARM board.

    PROGRAM:

    #include

    #include

    #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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    12/47

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    13/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 13

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

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

    }

    RESULT:

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

    board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    14/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 14

    EXPERIMENT 6

    8 BIT DIGITAL LED AND SWITCH INTERFACE

    (A)BIT DIGITAL OUTPUT LED INTERFACE

    AIM:

    Write a Program for Bit Digital output LED Interface

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR software

    3.

    PC

    PROCEDURE:

    1.

    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.

    /*LED INTERFACE*/

    #include

    void delay(){for(int i=0x00;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    15/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 15

    while(1){IO1SET=0XFF000000; // P1.24 TO P1.31 goes to high state

    delay();IO1CLR=0XFF000000; // P1.24 TO P1.31 goes to low statedelay();

    }}

    /* SWITCH INTERFACE*/

    #include

    static void delay(void ){

    volatile int i,j;for (i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    16/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 16

    EXPERIMENT 7

    BUZZER INTERFACE

    AIM:

    Write a Program for Buzzer Interface

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR software

    3. PC

    PROCEDURE:

    1. Write the source code in IAR programming window

    2. Build the program with setting the project options.

    3. Check the program in command window

    4. Download the program to the ARM evolution board

    5. Verify the output in ARM board.

    PROGRAM:

    #includevoid delay()

    {for(int i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    17/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 17

    RESULT:

    Thus the program for the BUZZER interface is executed and BUZZER output is observed in the ARM

    board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    18/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 18

    EXPERIMENT 8

    CHARACTER BASED LCD INTERFACE

    AIM:

    Write a Program For Character based LCD Interface

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR software

    3. PC

    PROCEDURE:

    1.

    Write the source code in IAR programming window

    2.

    Build the program with setting the project options.

    3.Check the program in command window

    4.

    Download the program to the ARM evolution board

    5.

    Verify the output in ARM board.

    PROGRAM:

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    19/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 19

    {delay_ms();

    }

    void command_write(int comm){

    busy_check();

    IO0CLR = RS;IO0CLR = DIOW;

    IO1PIN = comm

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    20/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 20

    IO0CLR = DIOW;IO0CLR = LCD_EN;

    lcd_init();command_write(0x80);for(int i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    21/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 21

    EXPERIMENT 9

    I2C DEVICE INTERFACE SERIAL EEPROM

    AIM:

    Write a Program For serial EEPROM interface with I2C device

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR software

    3. PC

    PROCEDURE:

    1.Write the source code in IAR programming window

    2.Build the program with setting the project options.

    3.Check the program in command window

    4.Download the program to the ARM evolution board

    5.Verify the output in WINXTALK by using ARM board.

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

    /* THIS PROGRAM FOR EEPROM INTERFACE(24LS256) */

    /* SDA LINE -P0.3 */

    /* SCL LINE -P0.2 */

    /* SLAVE ADDRESS WRITE=0XA2,READ =0XA3 */

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

    #include

    #include

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    22/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 22

    char addr;

    //FUNCTION DEFINTION

    static void delay1(void )

    {

    volatile int i,j;

    for (i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    23/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 23

    //LOWER ORDER ADDRESS

    I2C0DAT=lsb_addr;

    I2C0CONCLR=0x08;

    while(I2C0STAT!=0x28)

    delay1();

    //EEPROM DATA

    I2C0DAT=i2c_data;

    I2C0CONCLR=0x08;

    while(I2C0STAT!=0x28)

    delay1();

    //STOP CONDITION

    I2C0CONSET=0x10;

    I2C0CONCLR=0x8;

    delay();

    }

    void i2c_read(unsigned char msb_addr,unsigned char lsb_addr,int count)

    {

    //START CONDITION

    I2C0CONSET=0x60; //start I2C data transmission when set STA flag.

    delay1();

    while(I2C0STAT!=0x08);

    //SLAVE ADDRESS

    I2C0DAT=0xA2; //EEPROM DEVICE ADDRESS(0XA2)

    I2C0CONCLR=0x28;

    delay1();

    while(I2C0STAT!=0x18);

    delay1();

    //HIGHER ORDER ADDRESS

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

    I2C0CONCLR=0x8;

    while(I2C0STAT!=0x28);

    delay1();

    delay();

    //LOW ORDER ADDRESS

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    24/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 24

    I2C0DAT=lsb_addr; //WRITE THE EEPROM LOWER ORDER ADDRESS

    I2C0CONCLR=0x08;

    while(I2C0STAT!=0x28);

    delay1();

    //STOP CONDITION

    I2C0CONSET=0x10;I2C0CONCLR=0x08;

    delay1();

    I2C0CONSET=0x10;

    I2C0CONCLR=0x08;

    //RESTART CONDITION

    I2C0CONSET=0x60; //start I2C data transmission when set STA flag.

    delay1();

    while(I2C0STAT!=0x08);

    //WRITE SLAVE ADDRESS FOR READ MODE

    I2C0DAT=0xa3; //EEPROM READ ADDRESS

    I2C0CONCLR=0x2C;

    while(I2C0STAT!=0x40);

    I2C0CONSET = 0X04;

    I2C0CONCLR = 0X08;

    // READ THE EEPROM DATA

    for(int i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    25/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 25

    }

    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.

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    26/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 26

    RESULT:

    Thus the program for I2C device interface serial EEPROM is executed and output is observed

    in WINXTALK by using ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    27/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 27

    EXPERIMENT 10

    TRANSMISSION FROM KIT AND RECETION FROM PC USING SERIAL PORT

    AIM:

    Write a Program for transmission from kit and recetion from pc using serial port

    APPARATUS REQUIRED:

    1. ARM(LPC2148) Evolution Board

    2. IAR software

    3. PC

    PROCEDURE:

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

    PROGRAM:

    #include

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    28/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 28

    // (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; // U0LCR: UART0 Line Control Register.

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

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

    VPBDIV=0x01; // VPBDIV: VPB bus clock divider 0x01: PCLK = processor clock

    U0DLL=DIVISOR&0xFF; // U0DLL: UART0 Divisor Latch (LSB).

    U0DLM=DIVISOR>>8; // U0DLM: UART0 Divisor Latch (MSB).

    U0LCR=0x03 ; // U0LCR: UART0 Line Control Register

    // 0x03: same as above, but disable Divisor Latch access.

    // And same time U0THR (Transmitting register writing)holding the data.

    U0FCR=0x05 ; // U0FCR: UART0 FIFO Control Register

    // 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs

    }

    // BAUD RATE CALCULATION

    // DIVISOR = (PCLK/(16*DESIRED_BAUDRATE))// For Example

    // Peripheral Clock Frequency (PCLK) = 12 Mhz

    // Desired Baud Rate = 19200 bps

    // Divisor = (12000000/(16*19200)) = 39

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

    void main ()

    {

    int i;

    Arm_Uart0_Init(); // Serial Port Intialisation.

    while(1)

    { for(i=0;arr[i]!='\0';i++)

    {

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

    }

    } }

    RESULT:

    Thus the program for transmission from kit and recetion from pc using serial port is executed

    and output is observed in WINXTALK by using ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    29/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 29

    EXPERIMENT 11

    GENERATION OF PWM SIGNAL

    AIM:

    Write a Program for Generation of PWM Signal

    APPARATUS REQUIRED:

    1. ARM(LPC2148) Evolution Board

    2. IAR software

    3. PC

    4. CRO

    PROCEDURE:

    1.

    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.

    PROGRAM:

    #include

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

    }

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    30/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 30

    RESULT:

    Thus the program for Generation of PWM Signal is executed and output is observed in CRO

    by using ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    31/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 31

    RTOS PROGRAMS

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    32/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 32

    EXPERIMENT 12

    BLINKING TWO DIFFERENT LEDS

    AIM:

    Write a program for blinking two different LEDs tasks based on RTOS

    APPARATUS REQUIRED:

    1. ARM (LPC2148) Evolution Board

    2. IAR software

    3. PC

    4. RTOS

    PROCEDURE:

    1.

    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.

    PROGRAM FOR BLINKING TWO DIFFERENT LEDS

    #include

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

    }

    }

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    33/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 33

    void led_Task2(void *pdata){for(;;)

    {for(int i=0;i

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    34/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 34

    EXPERIMENT 13

    DISPLAYING TWO DIFFERENT MESSAGES IN LCD DISPLAY IN TWO LINES

    AIM:

    Write a program for displaying two different messages in LCD display in two lines

    APPARATUS REQUIRED:

    1. 1. ARM (LPC2148) Evolution Board

    2. IAR software

    3. PC

    4. RTOS

    PROCEDURE:

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

    PROGRAM FOR DISPLAYING TWO DIFFERENT MESSAGES IN LCD DISPLAY IN TWO

    LINES

    //HEADER FILE DECLARATION

    #include

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    35/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 35

    for(;;){i2c_read(0x02);

    OSTimeDly(30);}

    }

    void ADC_Task(void *pdata)

    {for(;;)

    {READ_ADC();OSTimeDly(10);

    }}

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

    Arm_Uart0_Init();OSInit();OSTaskCreate(RTC_Task,0,&RTC_Taskstk[999],0);OSTaskCreate(ADC_Task,0,&ADC_Taskstk[999],1);OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */

    }

    RESULT:

    Thus the program for displaying two different messages in LCD display is executed and output is

    observed in two lines of LCD display in ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    36/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 36

    EXPERIMENT 14

    SENDING MESSAGES TO MAILBOX BY 1 TASK AND READING MESSAGE

    FROM MAILBOX BY ANOTHER TASK

    AIM:

    To write a program based on RTOS for sending messages to mailbox by 1 task and reading message

    from mailbox by another task.

    APPARATUS REQUIRED:

    1.

    ARM (LPC2148) Evolution Board

    2. IAR software

    3.

    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.

    PROGRAM FOR SENDING MESSAGES TO MAILBOX BY 1 TASK AND

    READING MESSAGE FROM MAILBOX BY ANOTHER TASK

    //HEADER FILE DECLARATIONint a=10,b=20,c;#include

    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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    37/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 37

    OS_STK UART_Task1stk[100];OS_STK UART_Task2stk[100];

    OS_STK UART_Task3stk[100];

    //FUNCTION DEFINITION/*void UART_Task1(void *pdata)

    {char *msg;

    pdata = pdata;BSP_Init();for(;;)

    {msg=OSMboxPend(mailbox,0,&Error);

    // msg=OSMboxAccept(mailbox);if(Error==OS_NO_ERR)if(msg!=(void *)0){printf("\n");

    printf("\n Message :\t");while(*msg!='\0'){printf("%c",*msg);

    msg++;

    }}OSTimeDly(1);

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

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    38/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 38

    {printf("Task 2..");putchar(0x0d);

    putchar(0x0a);

    OSTimeDly(15);}

    }

    */void UART_Task3(void *pdata)

    {for(;;){

    printf("Task 3..");putchar(0x0d);

    putchar(0x0a);

    OSTimeDly(10);}

    }

    void Task1(void *pdata){

    char *msg;pdata = pdata;

    BSP_Init();for(;;){

    msg=OSMboxPend(mailbox,0,&Error);// msg=OSMboxAccept(mailbox);

    if(Error==OS_NO_ERR)if(msg!=(void *)0){

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

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

    }

    }OSTimeDly(1);

    }}

    void Task2(void *pdata){

    c=a+b;char data[]={" Message from Task2 "};

    pdata = pdata;

    BSP_Init();for(;;)

    {

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    39/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 39

    Error=OSMboxPost(mailbox,(void *)&data[0]);OSTimeDly(1);

    }

    }

    void main (void){

    BSP_IntDisAll();

    BSP_Init();Arm_Uart0_Init();

    printf("vasanth");OSInit();

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

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

    }

    /*void main (void)

    {BSP_IntDisAll();

    BSP_Init();Arm_Uart0_Init();

    printf("vasanth");

    OSInit();printf("vasanth");

    mailbox=OSMboxCreate ((void *)0); // create mailboxOSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);

    // OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);OSStart();

    }

    */

    RESULT:

    Thus the program for sending messages to mailbox by 1 task and reading message from mailbox

    by another task is executed and output is observed in WINXTALK by using ARM board.

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    40/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 40

    EXPERIMENT 15

    SENDING MESSAGE TO PC THROUGH SERIAL PORT BY THREE DIFFERENT TASKS ON

    PRIORITY BASIS

    AIM:

    To write a program based RTOS for sending messages to PC through serial port by three different

    tasks on priority basis.

    APPARATUS REQUIRED:

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

    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

    CPU_INT08U Task1Data;

    CPU_INT08U Task2Data;

    OS_STK Task1stk[100];

    OS_STK Task2stk[100];

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    41/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 41

    OS_EVENT *mailbox;

    INT8U Error;

    void Task1(void *pdata);

    void Task2(void *pdata);

    //0S TASK STACK ALLOCATION

    OS_STK UART_Task1stk[100];

    OS_STK UART_Task2stk[100];

    OS_STK UART_Task3stk[100];

    //FUNCTION DEFINITION

    /*

    void UART_Task1(void *pdata)

    {

    char *msg;

    pdata = pdata;

    BSP_Init();

    for(;;)

    {

    msg=OSMboxPend(mailbox,0,&Error);

    // msg=OSMboxAccept(mailbox);

    if(Error==OS_NO_ERR)

    if(msg!=(void *)0)

    {

    printf("\n");

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

    while(*msg!='\0')

    {

    printf("%c",*msg);

    msg++;

    }

    }

    OSTimeDly(1);

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    42/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 42

    }

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

    }

    }

    */

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    43/47

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    44/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 44

    }

    }

    void Task2(void *pdata)

    {

    c=a+b;

    char data[]={" Message from Task2 "};

    pdata = pdata;

    BSP_Init();

    for(;;)

    {

    Error=OSMboxPost(mailbox,(void *)&data[0]);

    OSTimeDly(1);

    }

    }

    void main (void)

    {

    BSP_IntDisAll();

    BSP_Init();

    Arm_Uart0_Init();

    printf("vasanth");

    OSInit();

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

    OSTaskCreate(Task1,(void *)&Task1Data,&Task1stk[99],1);

    OSTaskCreate(Task2,(void *)&Task2Data,&Task2stk[99],0);

    OSStart();

    }

    /*

    void main (void)

    {

    BSP_IntDisAll();

    BSP_Init();

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    45/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 45

    Arm_Uart0_Init();

    printf("vasanth");

    OSInit();

    printf("vasanth");

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

    OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);

    OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);

    // OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);

    OSStart();

    }

    */

    ////////////////////////////////////////////////////////////////////////////////

    //////////////////////////3 UART RTOS PROGRAM///////////////////////////////////

    ////////////////////////////////////////////////////////////////////////////////

    //HEADER FILE DECLARATION

    #include

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

    }

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    46/47

    Embedded Systems Laboratory

    Nishitha College of Engineering Page 46

    }

    void UART_Task2(void *pdata)

    {

    for(;;)

    {

    printf("Task 2..");

    putchar(0x0d);

    putchar(0x0a);

    OSTimeDly(200);

    }

    }

    void UART_Task3(void *pdata)

    {

    for(;;)

    {

    printf("Task 3..");

    putchar(0x0d);

    putchar(0x0a);

    OSTimeDly(300);

    }

    }

    void main (void)

    {

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

    BSP_Init();

    Arm_Uart0_Init();

    printf("vasanth");

    OSInit();

    /* Initialize "uC/OS-II, The Real-Time Kernel" */

  • 8/10/2019 Embedded Lab II mtech arm7-r13

    47/47

    Embedded Systems Laboratory

    OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],10);

    OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],11);

    OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],12);

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

    }

    RESULT:

    Thus the program based on RTOS for sending messages to PC through serial port by three

    different tasks on priority basis is executed and highest priority output is observed in WINXTALK by

    using ARM board.