ES Lab Manual 1
ES Lab Manual 1
LAB MANUAL
Prepared By
B.Srinivas
Associate Professor
LIST OF EXPERIMENTS
Note:
Minimum of 10 programs from Part I and 6 programs from Part -II are to be
conducted.
Part -I:
The following Programs are to be implemented on ARM Processor
1. Simple Assembly Program for
a. Addition | Subtraction | Multiplication | Division
b. Operating Modes, System Calls and Interrupts
c. Loops, Branches
2. Write an Assembly programs to configure and control General Purpose Input/output
(GPIO)
Port pins.
3. Write an Assembly programs to read digital values from external peripherals and execute
them with the Target board.
4. Program for reading and writing of a file
5. Program to demonstrate Time delay program using built in Timer / Counter feature on IDE
Environment
6. Program to demonstrate a simple interrupt handler and setting up a timer.
7. Program demonstrates setting up interrupt handlers. Press button to generate an interrupt
and trace the program flow with debug terminal.
8. Program to Interface 8 Bit LED and Switch Interface
9. Program to implement Buzzer Interface on IDE environment
10. Program to Displaying a message in a 2 line x 16 Characters LCD display and verify the
result in debug terminal.
11. Program to demonstrate I2C Interface on IDE environment
12. Program to demonstrate I2C Interface Serial EEPROM
13. Demonstration of Serial communication. Transmission from Kit and reception from PC
using
Serial Port on IDE environment use debug terminal to trace the program.
14. Generation of PWM Signal
2
Part -II:
Write the following programs to understand the use of RTOS with ARM Processor on IDE
Environment using ARM Tool chain and Library:
1. Create an application that creates two tasks that wait on a timer whilst the main task loops.
2. Write an application that creates a task which is scheduled when a button is pressed, which
illustrates the use of an event set between an ISR and a task
3. Write an application that Demonstrates the interruptible ISRs(Requires timer to have
higher
priority than external interrupt button)
4. a).Write an application to Test message queues and memory blocks.
b).Write an application to Test byte queues
5. Write an application that creates two tasks of the same priority and sets the time slice
period
to illustrate time slicing.
Interfacing Programs:
6. Write an application that creates a two task to Blinking two different LEDs at different
timings
7. Write an application that creates a two task displaying two different messages in LCD
display
in two lines.
8. Sending messages to mailbox by one task and reading the message from mailbox by
another
task.
9. Sending message to PC through serial port by three different tasks on priority Basis.
10. Basic Audio Processing on IDE environment.
CYCLE-1
LPC2148 (ARM)
4
MICROCONTROLLER
LPC2148 (ARM7)
6
Features:
1. Nine basic data types including 32-bit IEEE floating point.
2. Flexible, variable allocation with bit, data, bdata, idata, xdata and pdata of the
memory types.
3. Interrupt functions may be written in C.
4. Fall use of the 8051 register banks.
5. Complete symbol and type information for source level debugger.
6. Use of AIMP and ACAII instructions.
7. Bit addressable data objects.
8. Built in interface for the RTX51 real time kernel.
9. Support for dual data pointers at the ATMEL, AED, EMPRESS, and DELL as
semiconductor in line on Philips and transcend microcontroller.
Step 1: Give a double click on vision 4 icon on the desk top, it will generate a
window as shown below.
Step 2: To create new project go to project select new micro vision project.
Step 3: select a drive where you would like to create your project.
10
Step 4: Create a new folder and name it with your project name.
Step 5: Open that project folder and give a name of your project executable file
and save it.
11
Step 6: After saving it will show some window there you select your microcontroller
company i.e NXP from Phillips.
12
Step 8: After selecting chip click on OK then it will display some window asking
to add STARTUP file. Select YES.
Step 9: A target is created and startup file is added to your project target and is
shown below.
13
Step 10: To write your project code select a new file from FILE menu bar or
click on
icon.
Step 11: It will display some text editor, to save that file select SAVE option
from FILE menu bar.
14
Step 12: By giving a file name with extension .C for c files and save it.
Step 13: Write the code of your project and save it.
15
Step 14: To add our c file to target give a right click on Source Group, choose
ADD files to Group option.
Step 15: It displays some window there select the file you have to add and
click on ADD option.
16
Step 16: The file will be added to our target and it shows in the project window.
Step 17: Now give a right click on target in the project window and select
Options for Target.
17
Step 18: It will show some window, in that go to output option and choose
Create Hex file option by selecting that box.
Step 19: In the same window go to Linker option and choose Use Memory
Layout from Target Dialog by selecting the box, and click OK.
18
Step 20: Now to Compile your project go to Project select Build Target option or
press F7 or click on (Build) icon or (Build All) icon.
Step 21: In the build OUT PUT window you can see the errors and warnings if
there exits. And here Your project Hex file will be created.
19
DEBUGGER:
We can debug and also simulate the program using debugger option, just click on
icon or can also select fron menu bar go to Debug option and in that the first one Start/Stop
debug.
When you click on that it will show you one window as shown below, click ok.
20
21
Window 1 is Command window which will display any errors or warning when we
build the file.
Window 2 is Symbol window where we can see each and every variables of .c files like
lcd.c, main.c etc
Window 3 is a memory window where we can see values stored in a particular
memory.
Window 4 is Watch window where we can see run time changes in the variables similar
to symbol window but in symbol window we cannot see Global variables, in this window we
can all variables.
Window 5 is a local window in this we can see functions local variables which are
23
Execution of program:
For executing the program we need to press
press F5 function key from keyboard. This execution will be done all at a time we can also
execute the program step wise by pressing F11 or clicking on
line, for step over the current line click on
24
25
Program 1
Arithmetic and Branching Operations
Aim:
To verify arithmetic and branching operations by writing an assembly language program.
Tools:
(1)PC
(2)Keil Microvision4
Program:
AREA Arithmetic, CODE, READONLY
ENTRY
start
MOV
r0, #2
MOV
r1, #5
ADD
r2, r0, r1
MUL
r3, r0, r1
r1, #0
MOV
r8, r0
BNE
here
MOV
divd
r8, r7
stop B stop
26
divd
SUB
r8, r8, r1
ADD
r7, #1
CMP
r8, #0
BEQ
here
BNE
divd
END
Output:
Result:
Hence performed assembly level programming to verify arithmetic and branching operations
in keil.
27
Program-2
Configuration and Controlling Of GPIO Ports
Aim:
To write an assembly level program for Configuring and Controlling of GPIO ports
Tools Used:
(1) PC
(2)Keil microvision4
Program:
AREA myprogram, CODE, READONLY
ENTRY
PINSEL0 EQU 0xE002C000
PINSEL1 EQU 0xE002C004
PINSEL2 EQU 0xE002C014
IODIR0 EQU 0xE0028008
IOSET0 EQU 0xE0028004
IOCLR0 EQU 0xE002800C
IODIR1 EQU 0xE0028018
IOSET1 EQU 0xE0028014
IOCLR1 EQU 0xE002801c
MOV r0, #0
LDR r1, =PINSEL0
STR r0, [r1]
MOV r0, #0
LDR r1, =PINSEL1
STR r0, [r1]
28
MOV r0, #0
LDR r1, =PINSEL2
STR r0, [r1]
MOV r0, #0xFFFFFFFF
LDR r1, =IODIR0
STR r0, [r1]
MOV r0, #0xFFFFFFFF
LDR r1, =IODIR1
STR r0, [r1]
stop
MOV r0, #0xFFFFFFFF
LDR r1, =IOSET0
STR r0, [r1]
MOV r0, #0XFFFFFFFF
LDR r1, =IOSET1
STR r0, [r1]
MOV r3, #0
BL DELAY
MOV r3, #0
MOV r0, #0xFFFFFFFF
LDR r1, =IOCLR0
STR r0, [r1]
MOV r0, #0XFFFFFFFF
LDR r1, =IOCLR1
STR r0, [r1]
MOV r3, #0
29
BL DELAY
MOV r3, #0
B stop
DELAY
LDR r5, =0xFFFFFF
;MOV r4, #255
HERE
CMP R3, R5
;HERE_1
;CMP r4, r6
;ADD r6, #1
;BNE HERE_1
ADD R3, #1
BNE HERE
BX LR
END
Output:
Set:
Clear:
30
Results:
Hence performed assembly level programming to configure and control GPIO ports.
31
Program-3
Timer Subroutine in ARM7 Microprocessor
Aim:
To write program to demonstrate time delay using built in timer/counter features on IDE
environment.
Tools:
(1)PC
(2)keil microvision4
Program:
#include <LPC214X.H>
void timer_delay(void);
int main()
{
PINSEL0 = 0x00000000;
IODIR0 = 0xFFFFFFFF;
while(1)
{
IO0SET = 0x55;
timer_delay();
IO0CLR = 0x55;
timer_delay();
IO0SET = 0xAA;
32
timer_delay();
IO0CLR = 0xAA;
timer_delay();
}
}
void timer_delay()
{
T0TCR = 0x02;
T0TC = 0;
T0PC = 0;
T0PR = 15000;
T0MR0 = 1000;
T0MCR = 0x02;
T0TCR = 1;
while(T0TC != T0MR0);
}
Output:
Set:
Clear:
33
Timer0:
34
Result:
Timer delay program using built in timer/counter feature on IDE environment is
demonstrated.
Program-4
Simple Interrupt Handler with Time Delay
Aim:
To write a program to demonstrate a simple interrupt handler and setting up timer features on
IDE Environment.
Tools:
(1)PC
(2)Keil microvision 4
Program:
#include <LPC214X.H>
void Timer_0_Init(void);
void Timer_0_ISR(void) __irq;
unsigned char g_flag = 0;
int main()
{
35
PINSEL0 = 0x0000000;
PINSEL1 = 0x0000000;
PINSEL2 = 0x0000000;
IO0DIR = 0x000F0000;
Timer_0_Init();
T0TCR = 0x01;
while(1);
}
void Timer_0_Init(void)
{
T0TCR = 0x02;
T0TC = 0x00;
T0PR = 15000;
T0PC = 0;
T0MR0 = 1000;
T0MCR = 0x03;
VICIntSelect |= 0x00000000;
VICVectCntl0 |= 0x20|4;
VICVectAddr0 = (unsigned)Timer_0_ISR;
VICIntEnable |= (1<<4);
}
void Timer_0_ISR(void) __irq
{
if(VICIRQStatus & 0x00000010)
{
if(T0IR == 0x01)
{
T0IR = 0x01;
if(g_flag == 0)
{
IO0SET = 0x00003F00;
36
g_flag = 1;
}
else
{
IO0CLR = 0x000003F00;
g_flag = 0;
}
}
}
VICVectAddr = 0x00000000;
}
Output:
Reset:
Enable:
VIC reset
37
VIC enable
Result:
Simple interrupt handler & setting up a timer is demonstrated on IDE environment
38
Program 5
Buzzer
Aim:
To write a program to implement Buzzer Interface on IDE environment
Tools:
(1) PC
(2) Keil Microvision 4
Program:
(a)buzzer.c
#include <LPC214X.H>
#include "Exp7.h"
int main()
39
{
PINSEL0 = 0x00000000;
PINSEL2 = 0x00000000;
IODIR0 = 0x00000800;
IODIR1 = 0x000F0000;
while(1)
{
if(SW1==0)
while(SW1 == 0)
BuZZer_ON;
else
BuZZer_OFF;
}
}
(b)Exp7.h
#define BuZZer_OFF IO0SET=(1<<11)
#define BuZZer_ON IO0CLR=(1<<11)
#define SW1 (IO0PIN&(1<<15))
Output:
Buzzer-off:
GPIO0
40
GPIO1
Buzzer-on
GPIO0
GPIO1
41
Result:
Hence Written a program to Implement Buzzer Interface on IDE environment.
Program 6
LCD Display
Aim:
To write a program for Displaying message in a 2 line * 16 characters LCD display and
verify the result in debug terminal.
Tools:
(1)PC
(2)Keil Microvision 4
Program:
(a)LCD.c:
#include <LPC214X.H>
#include "Exp6.h"
int main(void)
42
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
IO1DIR = 0x01C00000;
IO0DIR = 0x00003C00;
LCD_init();
LCD_Command(0x80);
LCD_Send_String(" UNISTRING TECH ");
LCD_Delay(10);
LCD_Command(0xC0);
LCD_Send_String("SOLUTION PVT LTD");
while(1);
}
(b)Exp6.h
#define LCD_RS_DATA IO1SET=(1<<24)
#define LCD_RS_CMD IO1CLR=(1<<24)
#define
LCD_WR IO1CLR=(1<<23)
#define
LCD_RD IO1SET=(1<<23)
LCD_EN_LOW IO1CLR=(1<<22)
43
LCD_Delay(10);
}
void LCD_Send_String(unsigned char *data)
{
while(*data)
LCD_Data(*data++);
}
void LCD_Command(unsigned int data)
{
unsigned char temp;
LCD_RS_CMD;
LCD_WR;
temp = data;
LCD_EN_HI;
LCD_EN_LOW;
IO0CLR = (temp & 0xF0)<<6;
Output:
46
Result:
Hence written a program for Displaying message in a 2 line * 16 characters LCD display and
verify the result in debug terminal.
Program 7
External Interrupt Handler
Aim:
To Write a Program to demonstrate Setting up interrupt handlers and generate an interrupt
when button is pressed.
47
Tools:
(1) PC
(2) Keil microvison 4
Program:
(a)extinterrupthandler.c
#include <LPC214X.H>
#include "Exp 7.h"
void ExtInt_Init(void);
void ExtInt_Service(void)__irq
{
UART_0_Send_String("External Interrupt has arrived \r\n");
EXTINT |= 4;
VICVectAddr = 0;
}
void ExtInt_Init(void)
{
EXTMODE |= 4;
EXTPOLAR = 4;
VICVectCntl0 = 0x20 | 16;
VICVectAddr0 = (unsigned long) ExtInt_Service;
VICIntEnable |= 1<<16;
}
int main()
48
{
PINSEL0 |= 0x80000005;
PINSEL1 = 0x00000000;
ExtInt_Init();
UART_0_Init();
UART_0_Send_String("* External Interrupt Demo *\n\n\r");
DelayMs(100);
UART_0_Send_String(">>> Press Interrupt Key SW1(INT1) for Output... \n\n\n\r");
DelayMs(100);
while(1);
}
(b)Exp7.h
#define UART_0_BPS 115200
#define Fpclk 15000000
void UART_0_Init(void)
{
unsigned int Baud16;
U0LCR = 0x83;
Baud16 = ((Fpclk / 16)/ UART_0_BPS);
U0DLL = Baud16 % 256;
U0DLM = Baud16 / 256;
U0LCR = 0x03;
49
}
void UART_0_Send_Char(unsigned char value)
{
U0THR = value;
while((U0LSR & 0x40 ) == 0);
}
void UART_0_Send_String(unsigned char *data)
{
while(*data != '\0')
UART_0_Send_Char(*data++);
}
void DelayMs(unsigned int count)
{
unsigned int i,j;
for(i=0;i<count;i++)
{
for(j=0;j<1000;j++);
}
}
Output:
50
Result:
Hence Written a Program to demonstrate Setting up interrupt handlers and generate an
interrupt when button is pressed
51
Program 8
Interface 8-Bit LED and Switch
Aim:
To Write a program to Interface 8-bit LED and Switch Interface
52
Tools:
(1)PC
(2)Keil Microvision 4
Program:
(a)LED.c
#include <LPC214X.H>
#include "Exp8.h"
unsigned int count =0;
int main()
{
PINSEL0 = 0x00000000;
PINSEL1 = 0x00000000;
IODIR0 = 0x00003F00;
IODIR1 = 0x00C00000;
while(1)
{
if(SW1)
{
count = count+1;
while(SW1);
53
//pattern_1_on;
pattern_off;
}
if(count == 1)
{
IO0SET=0x00003F00;
IO1SET=0x00C00000;
}
else if(count == 2)
{
IO0SET=0x00001200;
IO1SET=0x00C00000;
}
else if(count == 3)
{
IO0SET=0x00002D00;
count=0;
}
}
}
(b)Exp8.h
#define pattern_1_on IO0SET=0x00003F00;IO1SET=0x00C00000;
#define pattern_1_off IO0CLR=0x00003F00;IO1CLR=0x00C00000;
54
Output:
Pattern: 1
Pattern: 2
55
Pattern: 3
Result:
Hence Written a program to Interface 8-Bit LED and Switch Interface.
Program 9
Serial driver
Aim:
To write a program to demonstrate serial drivers Transmission from kit and Reception From
PC using Serial Port on IDE environment.
Tools:
56
(1)PC
(2) Keil Microvision4
Program:
(a)serialdriver.c
#include <LPC214X.H>
void Tx_string(unsigned char *);
void InitUart0(void);
void main()
{
PINSEL0=0x05;
InitUart0();
Tx_string("Hello world\n");
while(1);
}
(b)serialdriver.c
//#include "LPC2148.h"
#include <LPC214X.H>
#define DESIRED_BAUDRATE 19200
#define CRYSTAL_FREQUENCY_IN_HZ 12000000
#define MAX_PCLK (CRYSTAL_FREQUENCY_IN_HZ*5)
#define PCLK (MAX_PCLK/4)
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
57
void InitUart0(void)
{
U0LCR=0x83;
VPBDIV=0x00;
U0DLL=DIVISOR&0xFF;
U0DLM=DIVISOR>>8;
U0LCR=0x03 ;
U0FCR=0x05 ;
}
void Tx_char(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20)) {}
U0THR='\r';
}
while (!(U0LSR&0x20)) {}
U0THR=ch;
}
unsigned char Rx_char(void)
{
char ch;
58
while (!(U0LSR&0x01)) {}
ch=U0RBR;
return ch;
}
int Tx_string(char *s)
{
int i=0;
while(s[i]!='\0')
{
Tx_char(s[i]);
i++;
}
return(i);
}
void Tx_num(unsigned int num)
{
char str[9];
int i=0,temp;
for(i=0;i<8;i++)
{
temp=num%16;
if(temp>9)
str[7-i]=(0x37)+temp;
59
else
str[7-i]=(0x30)+temp;
num=num/16;
}
str[8]='\0';
Tx_string(str);
}
void Tx_num_dec(int num)
{
char str[12];
int i=0,temp,length;
if(num<0)
{
num=-num;
str[0]='-';
i=1;
length=11;
}
else
{
i=0;
length=10;
}
60
for(;i<length;i++)
{
temp=num%10;
if(temp>9)
str[length-1-i]=(0x37)+temp;
else
str[length-1-i]=(0x30)+temp;
num=num/10;
}
str[length]='\0';
Tx_string(str);
}
Output:
Flash magic tool
61
Terminal
Result:
Hence written a program to demonstrate serial drivers Transmission from kit and Reception
From PC using Serial Port on IDE environment.
62
Program 10
Serial Echo Driver Communication
Aim:
63
To write a program to demonstrate serial drivers Echo Transmission from kit and Reception
From PC using Serial Port on IDE environment.
Tools:
(1) PC
(2) Keil Micro Vision 4
Program:
(a)echo.c
#include <LPC214X.H>
void main()
{
PINSEL0=0x05;
InitUart0();
Output:
66
Result:Hence written a program to demonstrate serial drivers Echo Transmission from kit
and Reception from PC using Serial Port on IDE environment.
67
CYCLE-2
69
S_Q.c,OS_SEM.c,OS_TASK.c,OS_TIME.c
6. In Options for Target 1 change the Start address and Size in IROM 1 and
IRAM 1under target tab
7. Under the Output tab check the option Create HEX file
71
Program-1
72
Tools Required:
1. pc
2. Keil micro vision4
3. Arm board
Program:
Main.c :
#include "config.h"
#include "stdlib.h"
#define
TaskStkLengh 64
OS_STK
TaskStk1 [TaskStkLengh];
OS_STK
TaskStk2 [TaskStkLengh];
void
Task1(void *pdata);
void
Task2(void *pdata);
void Initpll(void);
int main (void)
{
PINSEL0 = 0x00000005;
Initpll();
73
InitUart0();
TargetInit();
OSInit ();
OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 1);
OSTaskCreate (Task2,(void *)0, &TaskStk2[TaskStkLengh - 1], 2);
OSStart ();
return 0;
}
void Task1
(void *pdata)
{
while (1)
{
Tx_string("\nTask 1");
OSTimeDly(500);
}
}
void Task2
(void *pdata)
{
while (1)
{
Tx_string("\nTask 2");
OSTimeDly(200);
74
}
}
void Initpll()
{
PLL0CFG=0x00000024;
PLL0CON=0x00000001;
PLL0FEED=0x000000AA;
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400));
PLL0CON = 0x00000003;
PLL0FEED =0x000000AA;
PLL0FEED=0x00000055;
}
Uart0.C:
//#include "LPC2148.h"
75
#include <LPC214X.H>
#define DESIRED_BAUDRATE 9600
#define CRYSTAL_FREQUENCY_IN_HZ 60000000
#define PCLK CRYSTAL_FREQUENCY_IN_HZ/4
#define DIVISOR (PCLK/(16*DESIRED_BAUDRATE))
void InitUart0(void)
{
U0LCR=0x83;
VPBDIV=0x00;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03 ;
U0FCR=0x05 ;
}
char putchar(char ch)
{
if (ch=='\n')
{
while (!(U0LSR&0x20)) {}
U0THR='\r';
}
while (!(U0LSR&0x20)) {}
U0THR=ch;
76
return ch;
}
char getchar(void)
{
char ch;
while (!(U0LSR&0x01)) {}
ch=U0RBR;
return ch;
}
int Tx_string(char *s)
{
int i=0;
while(s[i]!='\0')
{
putchar(s[i]);
i++;
}
return(i);
}
Output:
77
Result:
A program that create two tasks that wait on a timer while the main task loops is obtained.
Program: 2
78
Tools Required:
1. pc
2. Keil micro vision4
3. Arm board
Program:
Main.c:
#include "config.h"
#include "stdlib.h"
#define
TaskStkLengh 64
OS_STK
TaskStk1 [TaskStkLengh];
void
Task1(void *pdata);
void Initpll(void);
int main (void)
{
PINSEL0 = 0x80000005;
IODIR1 |= (1<<25);
IOSET1 |= (1<<25);
Initpll();
79
InitUart0();
TargetInit();
init_extint();
OSInit ();
OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 1);
OSStart ();
return 0;
}
void Task1
(void *pdata)
{
while (1)
{
Tx_string("\nTask 1");
OSTimeDly(500);
}
}
void Initpll()
{
PLL0CFG=0x00000024;
PLL0CON=0x00000001;
PLL0FEED=0x000000AA;
80
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400));
PLL0CON = 0x00000003;
PLL0FEED =0x000000AA;
PLL0FEED=0x00000055;
}
Enit.c:
#include <LPC214X.H>
void eint(void) __irq;
unsigned int i=0;
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
for(i=0;i<35;i++);
}
}
void init_extint()
{
EXTMODE = 0x04;
EXTPOLAR = 0x00;
VICIntSelect=0x00000000;
81
VICVectCntl1=0x20|16;
VICVectAddr1=(unsigned long )eint;
EXTINT = 0x00;
VICIntEnable=0x00010000;
}
void eint(void) __irq
{
if(VICIRQStatus==0x00010000)
{
Tx_string("\nInterrupt");
IOCLR1 |= (1<<25);
delay(10000);
IOSET1 |= (1<<25);
}
EXTINT = 0x04;
VICVectAddr = 0;
}
Output:
82
Result:
An application that creates a task which is scheduled when button is pressed, illustrates the
use of an event set between ISR & a task is obtained.
Program: 3
83
Tools Required:
1. pc
2. Keil micro vision4
3. Arm board
Program:
Main:
#include "config.h"
#include "stdlib.h"
#define
TaskStkLengh 64
OS_STK
TaskStk0 [TaskStkLengh];
OS_STK
TaskStk1 [TaskStkLengh];
OS_STK
TaskStk2 [TaskStkLengh];
void
Task0(char *pdata);
void
Task1(void *pdata);
void
Task2(void *pdata);
void Initpll(void);
OS_EVENT *msg_queue;
unsigned char *msgs[2]={"Hello","World"};
unsigned char *msg1,*msg2;
84
}
void Task0
(char *pdata)
msg_queue = OSQCreate(&msgs[0],2);
while (1)
{
OSQPost(msg_queue,(char *)msgs[0]);
OSQPost(msg_queue,(char *)msgs[1]);
85
(void *pdata)
{
while (1)
{
msg1 = OSQAccept(msg_queue);
if(msg1)
{
Tx_string("\nMessage 1 : ");
Tx_string(msg1);
}
OSTimeDlyHMSM(0,0,0,500);
}
}
void Task2
(void *pdata)
{
while (1)
{
msg2 = OSQAccept(msg_queue);
86
if(msg2)
{
Tx_string("\nMessage 2 : ");
Tx_string(msg2);
}
OSTimeDlyHMSM(0,0,0,500);
}
}
void Initpll()
{
PLL0CFG=0x00000024;
PLL0CON=0x00000001;
PLL0FEED=0x000000AA;
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400));
PLL0CON = 0x00000003;
PLL0FEED =0x000000AA;
PLL0FEED=0x00000055;
}
Output:
87
Result:
A program to test message queues and memory blocks is obtained.
Program: 4
Application that demonstrate the interruptible ISR
Aim:
88
Tools Required:
1. pc
2. Keil micro vision4
3. Arm board
Program:
Main.c:
#include "config.h"
#include "stdlib.h"
#define
TaskStkLengh 64
OS_STK
TaskStk1 [TaskStkLengh];
void
Task1(void *pdata);
void Initpll(void);
int main (void)
{
PINSEL0 = 0x80000005;
IODIR1 = (1<<25);
IOSET1 = (1<<25);
Initpll();
InitUart0();
TargetInit();
init_timer();
89
init_extint();
OSInit ();
OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 1);
OSStart ();
return 0;
}
void Task1
(void *pdata)
{
T1TCR = 0x01;
while (1)
{
Tx_string("\nTask 1");
OSTimeDly(100);
}
}
void Initpll()
{
PLL0CFG=0x00000024;
PLL0CON=0x00000001;
PLL0FEED=0x000000AA;
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400));
90
PLL0CON = 0x00000003;
PLL0FEED =0x000000AA;
PLL0FEED=0x00000055;
}
Output:
Result:
An application that demonstrates the interruptible ISR is obtained.
Program: 5
Sending message to PC through serial port
Aim:
To send message to PC through serial port by three different task on priority bases.
91
Tools Required:
1. pc
2. Keil micro vision4
3. Arm board
Program:
Main.c :
#include "config.h"
#include "stdlib.h"
#define
TaskStkLengh 64
OS_STK
TaskStk0 [TaskStkLengh];
OS_STK
TaskStk1 [TaskStkLengh];
OS_STK
TaskStk2 [TaskStkLengh];
void
Task0(char *pdata);
void
Task1(void *pdata);
void
Task2(void *pdata);
void Initpll(void);
int main (void)
{
PINSEL0 = 0x00000005;
Initpll();
InitUart0();
92
OSInit ();
OSTaskCreate (Task0,(void *)0, &TaskStk0[TaskStkLengh 1], 2);
OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 3);
OSTaskCreate (Task2,(void *)0, &TaskStk2[TaskStkLengh - 1], 4);
OSStart ();
return 0;
}
void Task0
(char *pdata)
{
TargetInit ();
while (1)
{
Tx_string("\nTask 1");
OSTimeDlyHMSM(0,0,0,900);
}
}
void Task1
(void *pdata)
{
while (1)
{
Tx_string("\nTask 2");
93
OSTimeDlyHMSM(0,0,0,500);
}
}
void Task2
(void *pdata)
{
while (1)
{
Tx_string("\nTask 3");
OSTimeDlyHMSM(0,0,0,300);
}
}
void Initpll()
{
PLL0CFG=0x00000024;
PLL0CON=0x00000001;
PLL0FEED=0x000000AA;
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400));
PLL0CON = 0x00000003;
PLL0FEED =0x000000AA;
PLL0FEED=0x00000055;
}
Output:
94
Result:
Hence program written for sending message to PC through serial port by three different tasks,
and to write three different tasks in priority basis.
95