Embedded Systems Lab
EMBEDDED SYSTEMS LABORATORY
Note:
A.
The following programs are to be implemented on ARM based
Processors/Equivalent.
B. 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 demonstrates 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
15. Program to demonstrate SD-MMC Card Interface.
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.
Embedded Systems Lab
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.
Embedded Systems Lab
Experiment 1:
1. Simple Assembly Program for
a. Addition | Subtraction | Multiplication | Division
b. Operating Modes, System Calls and Interrupts
c. Loops, Branches
AIM: To write an assembly language program for ARM Processor to perform
Addition, Subtraction, Multiplication & Division.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
PROGRAM:
a) 32-bit Addition:
AREA Program, CODE, READONLY
ENTRY
Main
Value1
Value2
Result
LDR
LDR
ADD
STR
SWI
R1,
R2,
R1,
R1,
&11
Value1
Value2
R1, R2
Result
AREA
DCD
DCD
DCD
END
Data1, DATA
&11112222
&55556666
0
b) 32-bit Subtraction:
AREA Program, CODE, READONLY
ENTRY
Main
LDR
LDR
SUB
STR
SWI
Value1
R1,
R2,
R1,
R1,
&11
Value1
Value2
R1, R2
Result
AREA Data1, DATA
DCD &11112222
Embedded Systems Lab
Value2
Result
DCD
DCD
END
&55556666
0
c) 16-bit Multiplication:
AREA Program, CODE, READONLY
ENTRY
Main
LDR
LDR
MUL
STR
SWI
Value1
Value2
Result
R0,
R1,
R0,
R0,
&11
Value1
Value2
R1, R0
Result
AREA Data1, DATA
DCD &1111
DCD &5555
ALIGN
AREA Data2, DATA
DCD 0
ALIGN
END
d) Division (32Bit by 16 Bit):
AREA Program, CODE, READONLY
ENTRY
MAIN
LDR
LDR
MOV
R0, Number1
R1, Number2
R3, #0
CMP
BEQ
CMP
BLT
ADD
SUB
R1, #0
Err
R0, R1
Done
R3, R3, #1
R0, R0, R1
MOV
R3, #0xFFFFFFFF
STR
STR
R0, Remain
R3, Quotient
Loop
Err
Done
Embedded Systems Lab
SWI
Number1
Number2
Quotient
Remain
&11
AREA
Data1, DATA
DCD &0075CBB1
DCD &0141
ALIGN
AREA Data2, DATA
DCD 0
DCD 0
ALIGN
END
e) To move block of data from one location to another:
AREA Word, CODE, READONLY
num EQU 20
ENTRY
Main
wordcopy
src
dst
LDR
LDR
MOV
LDR
STR
SUBS
BNE
SWI
r0, =src
r1, =dst
r2, #num
r3, [r0], #4
r3, [r1], #4
r2, r2, #1
wordcopy
&11
AREA BlockData, DATA, READWRITE
DCD 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4
DCD 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
END
Embedded Systems Lab
Experiment 2:
2. To configure and control General Purpose Input/Output (GPIO) port pins
AIM: To write an assembly language program to configure and control
General Purpose Input/Output (GPIO) port pins.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
PROGRAM:
AREA Word, CODE, READONLY
PINSEL0
EQU 0xE002C000
IO0DIR
EQU 0xE0028008
IO0PIN
EQU 0xE0028000
ENTRY
Main
LOOP
MOV
LDR
STR
MOV
LDR
STR
MOV
LDR
STR
B
END
R0, #0
R1, =PINSEL0
R0, [R1]
R0, #0x00000300
R1, =IO0DIR
R0, [R1]
R0, #0x00000300
R1, =IO0PIN
R0, [R1]
LOOP
Embedded Systems Lab
Experiment 3:
10. Program to display message on 2x16 LCD display.
AIM: To write program for ARM Processor to display message on LCD.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
LPC2148 Development Board
PROGRAM:
#include <lpc214x.h>
/*
Connections from LPC2148 to LCD Module:
P0.0 to P0.7 used as Data bits.
P1.16 connected to pin4 i.e. RS
- Command / Data
P1.17 connected to pin6 i.e. E - Enable
Pin5 of LCD Module i.e. 'R/W' connected to ground
*/
void
void
void
void
void
void
initLCD(void);
enable(void);
LCD_WriteChar(char c);
LCD_WriteString(char * string);
LCD_Cmd(unsigned int cmd);
delay(void);
int main(void)
{
initLCD();
LCD_WriteString(".: Welcome to :.");
LCD_Cmd(0x80 + 0x40);
LCD_WriteString("TRML");
while(1);
return 0;
}
void initLCD(void)
{
IO0DIR = 0xFF;
IO1DIR |= (1<<16) | (1<<17);
IO0PIN = 0x0;
IO1PIN = 0x0;
delay();
LCD_Cmd(0x3C);
LCD_Cmd(0x0F);
LCD_Cmd(0x06);
Embedded Systems Lab
LCD_Cmd(0x01);
LCD_Cmd(0x80);
}
void enable(void)
{
delay();
IO1PIN |= (1<<17);
delay();
IO1PIN &= ~(1<<17);
delay();
}
void LCD_WriteChar(char c)
{
IO1PIN |= (1<<16);
IO0PIN = (int) c;
enable();
}
void LCD_WriteString(char * string)
{
int c=0;
while (string[c]!='\0')
{
LCD_WriteChar(string[c]);
c++;
}
}
void LCD_Cmd(unsigned int cmd)
{
IO1PIN = 0x0;
IO0PIN = cmd;
enable();
}
void delay(void)
{
int i=0,x=0;
for(i=0; i<19999; i++)
{
x++;
}
}
Embedded Systems Lab
Experiment 4:
13. Demonstration of Serial communication.
AIM: To write program for ARM Processor for serial communication.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
LPC2148 Development Board
PROGRAM:
#include <lpc214x.h>
#define
#define
#define
#define
#define
PLOCK 0x00000400
THRE (1<<5)
MULVAL 15
DIVADDVAL 1
NEW_LINE 0xA
void initUART0(void);
void U0Write(char data);
void initClocks(void);
int main(void)
{
char msg[] = { 'T','R','M','L','\0' };
int c=0;
initClocks();
initUART0();
for(;;)
{
while( msg[c]!='\0' )
{
U0Write(msg[c]);
c++;
}
U0Write(NEW_LINE);
c=0;
}
return 0;
}
void initUART0(void)
{
PINSEL0 = 0x5;
U0LCR = 3 | (1<<7) ;
U0DLL = 110;
Embedded Systems Lab
U0DLM = 1;
U0FDR = (MULVAL<<4) | DIVADDVAL;
U0LCR &= 0x0F;
}
void U0Write(char data)
{
while ( !(U0LSR & THRE ) );
U0THR = data;
}
Embedded Systems Lab
Experiment 5:
14. Generation of PWM Signal.
AIM: To write program for ARM Processor to generate PWM signal.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
LPC2148 Development Board
PROGRAM:
#include <lpc214x.h>
#define PLOCK 0x00000400
#define PWMPRESCALE 60
void initPWM(void);
void initClocks(void);
int main(void)
{
initClocks();
initPWM();
while(1)
{
if( !((IO0PIN) & (1<<1)) )
{
PWMMR1 = 2500;
PWMLER = (1<<1);
}
else if( !((IO0PIN) & (1<<2)) )
{
PWMMR1 = 5000;
PWMLER = (1<<1);
}
else if( !((IO0PIN) & (1<<3)) )
{
PWMMR1 = 7500;
PWMLER = (1<<1);
}
else if( !((IO0PIN) & (1<<4)) )
{
PWMMR1 = 10000;
PWMLER = (1<<1);
}
}
return 0;
}
Embedded Systems Lab
void initPWM(void)
{
PINSEL0 = (1<<1);
PWMPCR = 0x0;
PWMPR = PWMPRESCALE-1;
PWMMR0 = 10000;
PWMMR1 = 2500;
PWMMCR = (1<<1);
PWMLER = (1<<1) | (1<<0);
PWMPCR = (1<<9);
PWMTCR = (1<<1);
PWMTCR = (1<<0) | (1<<3);
}
Embedded Systems Lab
PART II
Experiment 6:
1. Create an application that creates two tasks that wait on a timer whilst
the main task loops.
AIM: To write program for ARM Processor to create two tasks that wait on a
timer whilst the main task loops.
.
APPARATUS:
MDK-ARM V4.71a (Keil Vision 4)
LPC2148 Development Board
PROGRAM:
#include "RTL.h"
OS_TID id1, id2;
__task void task1 (void);
__task void task2 (void);
__task void task1 (void)
{
id1 = os_tsk_self ();
id2 = os_tsk_create (task2, 0);
for (;;)
{
os_evt_set (0x0004, id2);
os_evt_wait_or (0x0004, 0xffff);
os_dly_wait (5);
}
}
__task void task2 (void)
{
for (;;)
{
os_evt_wait_or (0x0004, 0xffff);
os_dly_wait (2);
os_evt_set (0x0004, id1);
}
}
Embedded Systems Lab
void main (void)
{
os_sys_init (task1);
}