Embedded Lab II Mtech Arm7-R13
Embedded Lab II Mtech Arm7-R13
Embedded Lab II Mtech Arm7-R13
EXPERIMENT 1
SIMPLE ASSEMBLY LANGUAGE PROGRAMS
AIM:
Write an Assembly Language Program for Addition, Subtraction, Multiplication and Division.
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAMS:
Addition:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text: CODE (2)CODE32
#include "uart.asm"
Main NOP
LDR R0,=0X11111111
LDR R1,=0X12345678
ADD R8,R1,R0
BL UART ;B main
stop B stop
END
Page 1
Subtraction:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X0000FFFF
LDR R1,=0X0000EEEE //output value display in a serial window.
SUB R8,R0,R1
//serial window language is hex.
BL UART
;B main
stop B stop
END
Multiplication:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X00000005
LDR R1,=0X00000005 //output value display in a serial window.
MUL R8,R0,R1
//serial window language is hex.
BL UART
;B main
stop B stop
END
Page 2
Division:
#include <NXP/iolpc2148.h>
NAME main
PUBLIC __iar_program_start
SECTION .intvec : CODE (2)
CODE32
__iar_program_start
B
main
SECTION .text : CODE (2)
CODE32
#include "uart.asm"
main NOP
LDR R0,=0X00001000
LDR R1,=0X00000100
MOV R8,#0
loop: CMP R1,#0
BEQ ERR
CMP R0,R1
BLT DONE
ADD R8,R8,#1
SUB R0,R0,R1
B loop
ERR: MOV R8,#0XFFFFFFFF
DONE: BL UART
stop: B stop
END
RESULT:
Thus the assembly program for the addition , Substraction, Multiplication and Division is executed and
output is observed in WINXTALK by using the ARM board.
Page 3
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:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAMM:
#include<nxp/iolpc2148.H>
void delay()
{
for(int i=0x00;i<=0xff;i++)
for(int j=0x00;j<=0xFf;j++);
}
/*-----------------------------------------------------------------------------*/
// LED INTERFACE LINES
// LED0 - LED7 : P1.24 - P1.31
//-----------------------------------------------------------------------------void main()
{
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.
Page 4
while(1)
{
IO1SET=0XFF000000;
delay();
IO1CLR=0XFF000000;
delay();
}
}
RESULT:
Thus the assembly program for the Programs to configure and control General Purpose Input/Output
(GPIO) is executed and output is observed in WINXTALK by using the ARM board.
Page 5
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:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAM:
#include <nxp/ioLPC2148.h>
#include <intrinsics.h>
unsigned int FLAG,i,COUNT;
//---------------------------PLL SETTINGS---------------------------------------//
void LPC2148PLLInit(void)
{
unsigned long loop_ctr;
/* Configure PLL0, which determines the CPU clock
*/
PLLCFG
= 0x00000024;
/* Use PLL values of M = 4 and P = 2
*/
PLLCON_bit.PLLE = 1;
/* Set the PLL Enable bit
*/
PLLFEED
= 0xAA;
/* Write to the PLL Feed register
*/
PLLFEED
= 0x55;
loop_ctr = 10000;
/* Wait for the PLL to lock into the new frequency
*/
while (((PLLSTAT_bit.PLOCK) == 0) && (loop_ctr > 0)) {
loop_ctr--;
}
Page 6
PLLCON_bit.PLLC = 1;
/* Connect the PLL
*/
PLLFEED
= 0xAA;
/* Write to the PLL Feed register
*/
PLLFEED
= 0x55;
VPBDIV
= 0x00000001;
/* Set the VPB frequency to one-half of the CPU
clock
*/
}
void timer_1()
{
//Timer 0 Initialisation
T1IR = 0xFF;
// reset match and capture event interrupts
T1TC = 0;
// Clear timer counter
T1PR = 59;
// Timer counter Increments every 0.017 usec
T1MR0 = 1000000;
T1MCR = 3;
// Reset Timer Counter & Interrupt on match
void main(void)
{
LPC2148PLLInit();
PINSEL2 = 0X00000000;
IO1DIR = 0XFF000000;
while(1)
{
timer_1();
T1TCR = 1;
while(T1TC!=1000000);
T1TCR = 0;
IO1SET = 0XFF000000;
T1TC=0;
timer_1();
T1TCR = 1;
while(T1TC!=1000000);
T1TCR = 0;
IO1CLR = 0XFF000000;
T1TC=0;
}
}
RESULT:
Thus the program for timer delay using built in timer/counter is executed and delay is observed
in ARM board.
Page 7
EXPERIMENT 4
EXTERNAL INTERRUPT
AIM:
Write a Program for External Interrupt
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#define XTALFREQ 12000000
//XTAL frequency in Hz
#define PCLKFREQ (XTALFREQ/4) //pclk must always be XTALFREQ/4?
int main(void);
__irq __arm void IRQ_ISR_Handler (void);
void Btn2DownISR(void);
void NonVectISR(void);
void feed (void);
int main(void)
{
/* Preliminary setup of the VIC. Assign all interrupt channels to IRQ */
VICIntSelect = 0;
// Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps
VICProtection = 0;
// VIC registers can be accessed in User or
// privileged mode
VICVectAddr = 0;
// Clear interrupt
Page 8
VICDefVectAddr = 0;
// Clear address of the default ISR
/*Configure the pins that the buttons are hooked up to to be external
interrupts */
PINSEL1_bit.P0_30=0x2;
// Set Port pin P0.15 function to EINT3
//LED Conmfiguration
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.
VICProtection = 0;
// Accesss VIC in USR | PROTECT
// VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr
/* Set up the button 1 pressed interrupt on EINT0 */
VICIntSelect &= ~(1<<VIC_EINT3);
// IRQ on external int 0.
VICVectAddr1 = (unsigned int)&Btn2DownISR; // Install ISR in VIC addr slot
VICVectCntl1 = 0x20 | VIC_EINT3;
// Enable vec int for EINT 0.
VICIntEnable |= (1<<VIC_EINT3);
// Enable EINT0 interrupt.
__enable_interrupt();
// Global interrupt enable
/*This is the foreground loop, which looks at data coming from the background
loop. The user can insert own code to react to timer and button driven
events */
while(1)
// Foreground Loop
{
IO1SET=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // Get interrupt vector.
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // Call vectored interrupt function
VICVectAddr = 0;
// Clear interrupt in VIC
}
__fiq __arm void fiq_handler (void)
{
while(1);
}
void Btn2DownISR(void)
{
EXTINT_bit.EINT3 = 1; // Try to reset external interrupt flag.
IO1CLR=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
Nishitha College of Engineering
Page 9
RESULT:
Thus the program for delay External Interrupt is executed and interrupt is observed in ARM
board.
Page 10
EXPERIMENT 5
PRESS BUTTON TO GENERATE AN INTERRUPT
AIM:
Write a Program for External Interrupt
APPARATUS REQUIRED:
PROCEDURE:
6.
7.
8.
9.
10.
PROGRAM:
#include <NXP/iolpc2148.h>
#include <intrinsics.h>
#define XTALFREQ 12000000
//XTAL frequency in Hz
#define PCLKFREQ (XTALFREQ/4) //pclk must always be XTALFREQ/4?
int main(void);
__irq __arm void IRQ_ISR_Handler (void);
void Btn2DownISR(void);
void NonVectISR(void);
void feed (void);
int main(void)
{
/* Preliminary setup of the VIC. Assign all interrupt channels to IRQ */
VICIntSelect = 0;
// Set all VIC interrupts to IRQ for now
VICIntEnClear = 0xFFFFFFFF; // Diasable all interrupts
VICSoftIntClear = 0xFFFFFFFF; // Clear all software interrutps
Nishitha College of Engineering
Page 11
VICProtection = 0;
VICDefVectAddr = 0;
// Clear address of the default ISR
/*Configure the pins that the buttons are hooked up to to be external
interrupts */
PINSEL1_bit.P0_30=0x2;
// Set Port pin P0.15 function to EINT3
//LED Conmfiguration
PINSEL2 = 0X00000000;
// P1.24 TO P1.31 as GPIO
IO1DIR = 0XFF000000;
// p1.24 TO P1.31 Configured as Output port.
VICProtection = 0;
// Accesss VIC in USR | PROTECT
// VICDefVectAddr = (unsigned int)&NonVectISR; // Install default ISR addr
/* Set up the button 1 pressed interrupt on EINT0 */
VICIntSelect &= ~(1<<VIC_EINT3);
// IRQ on external int 0.
VICVectAddr1 = (unsigned int)&Btn2DownISR; // Install ISR in VIC addr slot
VICVectCntl1 = 0x20 | VIC_EINT3;
// Enable vec int for EINT 0.
VICIntEnable |= (1<<VIC_EINT3);
// Enable EINT0 interrupt.
__enable_interrupt();
// Global interrupt enable
/*This is the foreground loop, which looks at data coming from the background
loop. The user can insert own code to react to timer and button driven
events */
while(1)
// Foreground Loop
{
IO1SET=0XFF000000;
// P1.24 TO P1.31 goes to high state
}
}
__irq __arm void irq_handler (void)
{
void (*interrupt_function)();
unsigned int vector;
vector = VICVectAddr; // Get interrupt vector.
interrupt_function = (void(*)())vector;
(*interrupt_function)(); // Call vectored interrupt function
VICVectAddr = 0;
// Clear interrupt in VIC
}
__fiq __arm void fiq_handler (void)
{
while(1);
}
void Btn2DownISR(void)
{
Nishitha College of Engineering
Page 12
RESULT:
Thus the program for delay External Interrupt is executed and interrupt is observed in ARM
board.
Page 13
EXPERIMENT 6
8 BIT DIGITAL LED AND SWITCH INTERFACE
AIM:
Write a Program for Bit Digital output LED Interface
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
/*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.
Page 14
while(1)
{
IO1SET=0XFF000000;
delay();
IO1CLR=0XFF000000;
delay();
}
}
/* SWITCH INTERFACE*/
#include <nxp/iolpc2148.h>
static void delay(void )
{
volatile int i,j;
for (i=0;i<0x3F;i++)
for (j=0;j<500;j++);
}
// SW0 - SW7 : P0.16 - P0.23
// LED0 - LED7 : P1.23 - P1.31
// Switch Staus Displayed on LED
void main()
{
// PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
// Configured as GPIO port
PINSEL2 = 0x00000000;
// Configured as GPIO port
IO0DIR = 0X00000000;
// P0.16 TO P0.23 Configured as input
IO1DIR = 0Xff000000;
// P1.23 TO P1.31 Configured as output
while(1)
{
// IO0CLR = 0XFF000000;
// IO1CLR = 0XFF000000;
IO1PIN = (~(IO0PIN & 0x00FF0000)<<0x08);
// delay();
}
}
RESULT:
Thus the program for the 8 bit LED interface is executed and LED blinking is observed in the
ARM board.
Page 15
EXPERIMENT 7
BUZZER INTERFACE
AIM:
Write a Program for Buzzer Interface
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAM:
#include<nxp/iolpc2148.h>
void delay()
{
for(int i=0;i<=0xff;i++)
for(int j=0;j<=0xff;j++);
}
//
BUZZER INTERFACE
// BUZZER - P0.15
//-----------------------------------------------------------------------------void main()
{
PINSEL0 = 0X00000000; // P0.15 - GPIO PORT
IO0DIR = 0X00008000; // P0.15 - OUTPUT
while(1)
{
IO0SET = 0X00008000; // Buzzer On
delay();
IO0CLR = 0X00008000; // Buzzer off
delay();
}
}
Page 16
RESULT:
Thus the program for the BUZZER interface is executed and BUZZER output is observed in the ARM
board.
Page 17
EXPERIMENT 8
CHARACTER BASED LCD INTERFACE
AIM:
Write a Program For Character based LCD Interface
APPARATUS REQUIRED:
PROCEDURE:
PROGRAM:
#include <nxp/iolpc2148.h>
#define LCD_EN 0X00000800
#define RS
0X00000100
#define DIOW 0X00000200
unsigned char arr1[16]="Christ The King";
unsigned char arr2[16]=" CKPC-ECE.. ";
void delay_ms()
{
unsigned int i,j;
for(j=0;j<0xf;j++)
for(i=0;i<0xff;i++);
}
void busy_check()
Nishitha College of Engineering
Page 18
{
delay_ms();
}
void command_write(int comm)
{
busy_check();
IO0CLR = RS;
IO0CLR = DIOW;
IO1PIN = comm<<16;
IO0SET = LCD_EN;
IO0CLR = LCD_EN;
}
void lcd_init()
{
command_write(0x38);
command_write(0x01);
command_write(0x0f);
command_write(0x86);
command_write(0x06);
}
// 5 * 7 Matrix
// Clear Display
// Display ON and Cursor Blinking
// 5 * 7 Matrix
IO0CLR = 0X00000800;
IO1PIN = 0X00000000;
IO0PIN = 0X00000000;
IO0CLR = RS;
Page 19
IO0CLR = DIOW;
IO0CLR = LCD_EN;
lcd_init();
command_write(0x80);
for(int i=0;i<16;i++)
lcd_out(arr1[i]);
command_write(0xC0);
for(int i=0;i<16;i++)
lcd_out(arr2[i]);
while(1);
}
{
busy_check();
IO0SET = RS;
IO0CLR = DIOW;
//RS = 1
}
RESULT:
Thus the program for the LCD interface is executed and output is observed in the 2 line 16LCD
Display
Page 20
EXPERIMENT 9
I2 C DEVICE INTERFACE SERIAL EEPROM
AIM:
Write a Program For serial EEPROM interface with I2 C device
APPARATUS REQUIRED:
PROCEDURE:
/*----------------------------------------------------------------------------*/
/*
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>
// since VPBDIV=0x01
char array[15]="ViMicrosystems";
Page 21
char addr;
//FUNCTION DEFINTION
static void delay1(void )
{
volatile int i,j;
for (i=0;i<5;i++)
for (j=0;j<50;j++);
}
static void delay(void )
{
volatile int i,j;
for (i=0;i<100;i++)
for (j=0;j<500;j++);
}
void i2c_write(unsigned char msb_addr,unsigned char lsb_addr ,unsigned char i2c_data)
{
//START CONDITION
I2C0CONSET=0x60;
//start I2C data transmission when set STA flag.
delay1();
while(I2C0STAT!=0x08); //START ACK
//SLAVE ADDRESS
I2C0DAT=0xA2;
I2C0CONCLR=0x28;
delay1();
//SLAVE ADDRESS
while(I2C0STAT!=0x18)
delay1();
//HIGHER ORDER ADDRESS
I2C0DAT=msb_addr;
I2C0CONCLR=0x08;
while(I2C0STAT!=0x28)
delay1();
delay();
Page 22
Page 23
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
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;
}
Page 24
}
int putchar(int ch)
{
while (!(U0LSR&0x20)) {}
return(U0THR=ch);
}
void UARTInit()
{
U0LCR=0x83;
VPBDIV=0x01;
.
U0DLL=DIVISOR&0xFF;
U0DLM=DIVISOR>>8;
U0LCR=0x03 ;
U0FCR=0x05 ;
//
U0DLL: UART0 Divisor Latch (LSB).
// U0DLM: UART0 Divisor Latch (MSB).
// U0LCR: UART0 Line Control Register
// 0x03: same as above, but disable Divisor Latch access.
// And same time U0THR (Transmitting register writing)holding the data.
//
U0FCR: UART0 FIFO Control Register
// 0x05: Clear Tx FIFO and enable Rx and Tx FIFOs
}
void main()
{
PINSEL0=0x00000055; //I2C AND UART PORT SELECTION
UARTInit();
//UART INIT FUNCTION
printf("Wait for some time...");
I2C0CONCLR=0x6C; //clear I2C0CONCLR register
I2C0CONSET=0x40; //Enable I2C.
I2C0SCLH=110;
I2C0SCLL=90;
//WRITE EEPROM DATA
for(int i=0;i<=13;i++)
i2c_write(0x00,(0x01+i),array[i]);
//READ EEPROM DATA
i2c_read(0x00,0x01,13);
while(1);
}
Nishitha College of Engineering
Page 25
RESULT:
Thus the program for I2 C device interface serial EEPROM is executed and output is observed
in WINXTALK by using ARM board.
Page 26
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:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAM:
#include <nxp/iolpc2148.h>
#define DESIRED_BAUDRATE
19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define PCLK
CRYSTAL_FREQUENCY_IN_HZ
// since VPBDIV=0x01
#define DIVISOR
(PCLK/(16*DESIRED_BAUDRATE))
char arr[]=" \n\r Vimicro system Pvt ltd. Chennai - 96. " ;
char serial_tr(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20)); //wait until Transmit Holding Register is empty
U0THR='\r';
//then store to Transmit Holding Register
}
while (!(U0LSR&0x20)) {}
//wait until Transmit Holding Register is empty
U0THR=ch;
//then store to Transmit Holding Register
return ch;
}
void Arm_Uart0_Init(void)
{
PINSEL0 = 0x00000005;
// (probably not necessary: PINSELs default to zero).
// (lower 4bit selected for UART0 and remaining all bits selected for GPIO's).
Nishitha College of Engineering
Page 27
U0LCR=0x83;
// (frist LSB 2bit(0 and 1 bits) selected 01b for UART0 Tx).
// ( LSB bit(2 and 3 bits) selected 01b for UART0 Rx).
//
U0LCR: UART0 Line Control Register.
// 0x83: enable Divisor Latch access, set 8-bit word length.
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.
Page 28
EXPERIMENT 11
GENERATION OF PWM SIGNAL
AIM:
Write a Program for Generation of PWM Signal
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
PROGRAM:
#include<NXP/iolpc2148.h>
void main(void)
{
PINSEL0 = 0X00008055;// select Port pins p0.2 and p0.3 as i2c configurable and
// also to select pwm2 as output
PWMPR = 0X00000001;
PWMPCR = 0X00000400;
PWMMCR = 0X00000003;
PWMMR0 = 0X00000010;
PWMMR2 = 0X00000008;
PWMTCR = 0X00000002;
PWMTCR = 0X00000009;
while(1);
}
Page 29
RESULT:
Thus the program for Generation of PWM Signal is executed and output is observed in CRO
by using ARM board.
Page 30
RTOS PROGRAMS
Page 31
EXPERIMENT 12
BLINKING TWO DIFFERENT LEDS
AIM:
Write a program for blinking two different LEDs tasks based on RTOS
APPARATUS REQUIRED:
PROCEDURE:
1.
2.
3.
4.
5.
Page 32
RESULT:
Thus the program for blinking two different LEDs based on RTOS is executed and output is
observed in ARM board.
Page 33
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:
PROCEDURE:
1.
2.
3.
4.
5.
RTC_Taskstk[1000];
ADC_Taskstk[1000];
//FUNCTION DEFINITION
void RTC_Task(void *pdata)
{
Nishitha College of Engineering
Page 34
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.
Page 35
EXPERIMENT 14
SENDING MESSAGES TO MAILBOX BY 1 TASK AND READING MESSAGE
FROM MAILBOX BY ANOTHER TASK
AIM:
To write a program based on RTOS for sending messages to mailbox by 1 task and reading message
from mailbox by another task.
APPARATUS REQUIRED:
1.
2.
3.
4.
PROCEDURE:
1.
2.
3.
4.
5.
Task1stk[100];
Task2stk[100];
OS_EVENT *mailbox;
INT8U Error;
void Task1(void *pdata);
void Task2(void *pdata);
//0S TASK STACK ALLOCATION
Page 36
OS_STK
OS_STK
OS_STK
UART_Task1stk[100];
UART_Task2stk[100];
UART_Task3stk[100];
//FUNCTION DEFINITION
/*
void UART_Task1(void *pdata)
{
char *msg;
pdata = pdata;
BSP_Init();
for(;;)
{
msg=OSMboxPend(mailbox,0,&Error);
// msg=OSMboxAccept(mailbox);
if(Error==OS_NO_ERR)
if(msg!=(void *)0)
{
printf("\n");
printf("\n Message :\t");
while(*msg!='\0')
{
printf("%c",*msg);
msg++;
}
}
OSTimeDly(1);
}
for(;;)
{
printf("Task 1..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}
*/
/*
void UART_Task2(void *pdata)
{
c=a+b;
char data[]={" Message from Task2 "};
pdata = pdata;
BSP_Init();
for(;;)
{
Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
for(;;)
Page 37
{
printf("Task 2..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(15);
}
}
*/
void UART_Task3(void *pdata)
{
for(;;)
{
printf("Task 3..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(10);
}
}
Page 38
Error=OSMboxPost(mailbox,(void *)&data[0]);
OSTimeDly(1);
}
}
void main (void)
{
BSP_IntDisAll();
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
/*
void main (void)
{
BSP_IntDisAll();
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
printf("vasanth");
mailbox=OSMboxCreate ((void *)0); // create mailbox
OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);
OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);
// OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);
OSStart();
}
*/
RESULT:
Thus the program for sending messages to mailbox by 1 task and reading message from mailbox
by another task is executed and output is observed in WINXTALK by using ARM board.
Page 39
EXPERIMENT 15
SENDING MESSAGE TO PC THROUGH SERIAL PORT BY THREE DIFFERENT TASKS ON
PRIORITY BASIS
AIM:
To write a program based RTOS for sending messages to PC through serial port by three different
tasks on priority basis.
APPARATUS REQUIRED:
1.
2.
3.
4.
PROCEDURE:
1.
2.
3.
4.
5.
Task1stk[100];
OS_STK
Task2stk[100];
Page 40
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);
Page 41
}
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);
}
}
*/
Page 42
Page 43
}
}
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();
Page 44
Arm_Uart0_Init();
printf("vasanth");
OSInit();
printf("vasanth");
mailbox=OSMboxCreate ((void *)0); // create mailbox
OSTaskCreate(UART_Task1,0,&UART_Task1stk[99],0);
OSTaskCreate(UART_Task2,0,&UART_Task2stk[99],1);
// OSTaskCreate(UART_Task3,0,&UART_Task3stk[99],2);
OSStart();
}
*/
////////////////////////////////////////////////////////////////////////////////
//////////////////////////3 UART RTOS PROGRAM///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//HEADER FILE DECLARATION
#include <includes.h>
//0S TASK STACK ALLOCATION
OS_STK
UART_Task1stk[100];
OS_STK
UART_Task2stk[100];
OS_STK
UART_Task3stk[100];
//FUNCTION DEFINITION
void UART_Task1(void *pdata)
{
for(;;)
{
printf("Task 1..");
putchar(0x0d);
putchar(0x0a);
OSTimeDly(500);
}
Page 45
}
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();
them */
BSP_Init();
Arm_Uart0_Init();
printf("vasanth");
OSInit();
/* Initialize "uC/OS-II, The Real-Time Kernel"
Nishitha College of Engineering
*/
Page 46
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();
*/
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.
Page 47