ESD Manual Students
ESD Manual Students
ESD Manual Students
-VII, Electronics
LAB MANUAL
Page 1
LIST OF EXPERIMENTS
1. Arithmetic and logic unit using mixed C/C++ and assembly language
2.
3.
4.
5.
6.
programming.
To study the ADC functionality using LPC2148.
To simulate UART functionality of LPC2148 on hyperterminal.
Design traffic light controller system with LPC2148 using Proteus and
Keil-4.
Implementation of RMS and EDF task scheduling algorithm.
To plot Gantt chart for RMS and EDF scheduling using Torsche toolbox in
MATLAB.
7. Mobile application using J2ME to display text message and to display
images.
8. Write a program to implement multithreading in LINUX.
9. Implement RTOS function for Semaphore in LINUX.
10.To demonstrate RTOS application of tank monitoring system using ucos-2.
11.Case study seminar.
Page 2
Experiment-1
Title:- Arithmetic and Logic Unit
Aim:- Using mixed C/C++ and assembly language programming, implement Arithmetic and
Logic Unit to perform following operations: +, -, *, /, power, log, square root, factorial, nth root,
AND, OR ,XOR, NOR, left shift, right shift.
Learning Objective:-Embedding the assembly language code in high level language is the
powerful feature of C programming for Embedded systems. This is the way to optimize
speed/memory requirements from embedded system point of view.
Theory:1. With the help of suitable examples, describe following C-program elements:
I.
Header file
II.
Preprocessor directives
III.
MACROS
IV. Modifiers
V. Functions
2. What is a Device Driver? Discuss its role in layered embedded system.
3. What is Interrupt latency in embedded system? Suggest methods to reduce latency.
4. Explain the following data types used in C programming:
I.
Array
II.
Structure
III.
Link list
IV. Queues
Algorithm:1.
2.
3.
4.
5.
Preprocessor directives
Variable declaration
Input statements
Switch-case
Result
Conclusion:-
ALU program:#include<stdio.h>
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 3
Page 4
Page 5
Experiment-2
Title:- ADC Implementation
Aim:- Write a program in Embedded C to study the ADC functionality of LPC2148.
Learning Objective:-To study inbuilt ADC functionality, data register AD0DR3 and get digital
output of corresponding analog input voltages of LPC2148.
Theory:1. Draw and explain basic architecture of ARM7 TDMI.
2. List and explain various program modeling techniques.
3. Draw and explain basic architecture of ARM CORTEX M3.
Algorithm:1.
2.
3.
4.
5.
6.
7.
Procedure:1.
2.
3.
4.
5.
6.
7.
Conclusion:-
Page 6
Page 7
: adc.c
#include "uart.h"
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for Initial system clock --------------------------------//
//------------------------------------------------------------------------------------------------//
void init()
{
PLL0CFG=0x24;
// MSEL = 4,PSEL = 2
PLL0FEED=0xAA;
// Feed process
PLL0FEED=0x55;
PLL0CON=0x1;
PLL0FEED=0xAA; // Feed process
PLL0FEED=0x55;
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 8
PLL0CON=0x3;
PLL0FEED=0xAA;
// Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash
memory fetch (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02;
// PCLK at 30 MHz
}
//------------------------------------------------------------------------------------------------//
//---------------------------------- Function delay ----------------------------------------------//
//------------------------------------------------------------------------------------------------//
void delay_ms(long ms) // delay 1 ms per count @ CCLK 60 MHz
{
long i,j;
for (i = 0; i < ms; i++ )
for (j = 0; j < 6659; j++ );
}
//------------------------------------------------------------------------------------------------//
//---------------------------------- Main Program ------------------------------------------------//
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 9
Page 10
Vref
1.5
3.3
Analog I/P
(AD03)
1.1
1.2
1.3
1.1
2.2
3.3
Result
Conclusion:-
Page 11
Experiment-3
Title:- UART Implementation
Aim:- Write a program in Embedded C to study the UART functionality of LPC2148.
Learning Objective:-To transmit data from UART0/UART1 module in LPC2148 by using serial
port interface unit and observe the operation in hyper terminal window
Theory:1. Draw and explain basic architecture of ARM CORTEX M4.
2. Compare and discuss difference between the two cortex architectures.
3. How will you interface I2C, LCD, RS232 and Alarm circuit with any ARM based
microcontroller?
4. Give detail comparison between RS232 and RS485.
Algorithm:1.
2.
3.
4.
5.
Page 12
// Description : Library for about serial communication UART0 and UART1 of LPC2148
// Frequency : Crystal 12 MHz at PLL 5x(CCLK = 60 MHz),PCLK = 30 MHz
// Filename
: uart.h
Page 13
Page 14
U0LCR = 0x00000003;
// DLAB =0
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send character 1 time via UART0-----------------------//
//------------------------------------------------------------------------------------------------//
void uart0_putc(char c)
{
while(!(U0LSR & 0x20)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
//------------------------------------------------------------------------------------------------//
//---------------------------- Function for send string via UART1---------------------------------//
//------------------------------------------------------------------------------------------------//
void uart0_puts(char *p)
{
while(*p) // Point to character
UART Program:SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 15
UART_0_1.c
//------------------------------------------------------------------------------------------------//
// Program
: UART example
: uart_0_1.c
#include "stdio.h"
//------------------------------------------------------------------------------------------------//
//---------------------------------- Initial system clock ----------------------------------------//
//------------------------------------------------------------------------------------------------//
void init()
{
PLL0CFG=0x24;
// MSEL = 4,PSEL = 2
PLL0FEED=0xAA;
// Feed process
PLL0FEED=0x55;
UART_0_1.c program:SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 16
PLL0CON=0x3;
PLL0FEED=0xAA;
// Feed process
PLL0FEED=0x55;
MAMCR=0x2;
// Enabling MAM and setting number of clocks used for Flash
memory fetch (4 cclks in this case)
MAMTIM=0x4;
VPBDIV=0x02;
// PCLK at 30 MHz
}
//------------------------------------------------------------------------------------------------//
//---------------------------------- Main Program ------------------------------------------------//
//------------------------------------------------------------------------------------------------//
void main()
{
init();
// Initial UART0 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
uart1_init(9600);
// Initial UART1 @ 9600 bps,8 bit data ,1 stop bit ,no parity bit
Page 17
}
}
Experiment-4
Title:- Design and test circuit for demonstration of traffic lights using ARM processor.
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 18
Start
Set port direction
Send
data to port
0 for
SHAH AND ANCHOR KUTCHHI
ENGINEERING
COLLEGE
sequence
Send
data
port
forsequence
sequence
Send
datatoto
portport
00for
4
Clear
0
Give delay
Page 19
Give delay
Clear port
Send data to port 0 for sequence 2
Give delay
Clear port 0
Page 20
Experiment-5
Title:- Implementation of RMS and EDF scheduling algorithms.
Aim:- Write a program in C/C++ to implement task scheduling algorithms:
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 21
Conclusion:
Experiment-6
Title: - TORSCHE scheduling toolbox in MATLAB
Aim:- To plot Gantt chart for Rate monotonic & Earliest Deadline First Scheduling using
TORSCHE Toolbox in Matlab.
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 22
Page 23
Release date, rj , is the moment at which a task becomes ready for execution (also called
arrival time, ready time, request time).
Deadline, dj , specifies a time limit by which the task has to be completed, otherwise the
scheduling is assumed to fail.
Due date, dj , specifies a time limit by which the task should be completed, otherwise
the criterion function is charged by penalty.
Weight expresses the priority of the task with respect to other tasks (also called priority).
Processor specifies dedicated processors at which the task must be execute.
Start time, sj , is the time when the execution of the task is started.
Completion time, cj , is the time when the execution of the task is finished.
Lateness, Lj = cj dj .
Tardiness, Dj = max{cj dj , 0}. The task is represented by the object data structure with the
name Task in Matlab.
This object is created by the command with the following syntax rule:
t1 = task([Name,]ProcTime[,ReleaseTime ... [,Deadline[,DueDate[,Weight[,Processor]]]]])
The object Problem is used for classification of deterministic scheduling problems.
prob = problem(P|prec|Cmax)
The first part describes the processor environment, the second part describes the task
characteristics of the scheduling problem as the precedence constrains, or the release time. The
last part denotes an optimality criterion.
Steps to solve Scheduling Problems
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 24
TORSCHE PROGRAM
1). EDF
t1=task('t1',3,0,12);
t2=task('t2',5,2,14);
t3=task('t3',4,3,16);
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 25
2). RMS
t1=ptask('t1',3,7);
t2=ptask('t2',3,12);
t3=ptask('t3',5,20);
ts= [t1 t2 t3];
setprio(ts, 'rm')
[r,s] = resptime(ts)
s = fps(ts)
plot(s, 'proc',1);
Experiment-7
Title:-
Page 26
Page 27
Page 28
Page 29
Page 30
Page 31
Experiment-8
Title: - Multithreading in LINUX
Aim: - Write a program in C to implement RTOS concept of multithreading and implement it in
LINUX.
Learning Objective: - To unerstand the concepts of thread, process used in Real Time operating
System and implement the same.
Theory:1.
2.
Algorithm:
Create a thread to read the text entered in lower case.
Create a thread to convert the lower case text into upper case.
Check then whether the thread creation is correct or failed.
The program should keep on converting lower case text to upper case text till input
string is stop
Program should end with the string stop and should not convert it to STOP.
Conclusion:-
Page 32
Page 33
Page 34
Experiment-9
Title: - Use of Semaphore in LINUX
Aim: - Write a program in C to implement RTOS concept of semaphore and implement it in
LINUX.
Learning Objective: - To understand the concepts of thread, process used in Real Time
operating System and implements the same.
Theory:- List the Linux functions for IPC: the signal, Multithreading and Semaphore as well as
Message Queue.
Algorithm:
Create a thread to read the text entered in lower case.
Create a thread to convert the lower case text into upper case.
Check then whether the thread creation is correct or failed.
The program should keep on converting lower case text to upper case text till input string
is stop
Program should end with the string stop and should not convert it to STOP.
Conclusion:-
Page 35
Page 36
Page 37
OUTPUT:sakec@pc22:~$ ./a.out
Enter text, the program will convert it into upper case, to stop enter 'stop'
Enter text: asdf
Enter text: converted text: ASDF
cc
Enter text: converted text: CC
fgh
Enter text: converted text: FGH
stop
read_thread joined, read_thread exit successful
convert_thread joined, convert_thread exit successful
sakec@pc22:~$
Page 38
Experiment-10
Title: - Tank Monitoring System
Aim: - Using RTOS C-OS/II simulate Tank monitoring system to perform following
operations: Timer, Button, Floats, Printer, Display and Bell
Learning Objective: -Real time embedded system can be designed with C-OS/II RTOS
functions. Various modules of Tank monitoring system are written using these functions. We
understand how the tasks are actually created, the way in which the various tasks communicate
with each other.
Theory:With the help of suitable examples, describe following functions of RTOS C-OS/II :
1. OSInit ( )
2.OSStart ( )
3. OSTaskCreate
4.OS_Event *OSQCreate
5.*OSQPend
6.*OSQPost
7. OSSemPend
8.OSSemPost
9. OSTimeDly
BUTTON.C
DISPLAY.C
FLOAT.C
LEVELS.C
OVERFLOW.C
PRINT.C
TIMER.C
MAIN.C
PROBSTYL.H
PUBLICS.H
UCOS.H
UCOS186C.H
Conclusion:-
Page 39
Page 40
/****************************************************************
PRINT.C
****************************************************************/
/* System Include Files */
#include "os_cfg.h"
#include "ix86s.h"
#include "ucos.h"
#include "probstyl.h"
PRINT.C:#include <stdio.h>
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 41
0x0020
/* Static Functions */
static far void vPrinterTask (void *p_vData);
/* Static Data */
/* The stack and input queue for the Printer task */
#define STK_SIZE 1024
static UWORD PrinterTaskStk[STK_SIZE];
#define Q_SIZE 10
static OS_EVENT *QPrinterTask;
static void *a_pvQPrinterData[Q_SIZE];
Page 42
Page 43
{
/*
LOCAL VARIABLES: */
#define MAX_HISTORY 5
BYTE byErr;
WORD wMsg;
int aa_iTime[MAX_HISTORY][4];
/* Time of day */
int iTank;
/* Tank iterator. */
int a_iLevel[MAX_HISTORY];
/* Place to get level of tank. */
PRINT.C:int iLevels;
int i;
/*-------------------------------------------------------------*/
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 44
if (wMsg == MSG_PRINT_ALL)
{
/* Format 'all' report. */
iLinesTotal = 0;
vTimeGet (aa_iTime[0]);
sprintf (a_chPrint[iLinesTotal++],
"Time: %02d:%02d:%02d",
aa_iTime[0][0], aa_iTime[0][1], aa_iTime[0][2]);
for (iTank = 0; iTank < COUNTOF_TANKS; ++iTank)
{
if (iTankDataGet (iTank, a_iLevel, NULLP, 1) IS 1)
/* We have data for this tank; display it. */
PRINT.C:sprintf (a_chPrint[iLinesTotal++],
" Tank %d: %d gls.", iTank + 1, a_iLevel[0]);
}
sprintf (a_chPrint[iLinesTotal++],
"--------------------");
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 45
Page 46
PRINT.C:/*-------------------------------------------------------------*/
if (iLinesPrinted IS iLinesTotal)
/* The report is done. Release the semaphore. */
OSSemPost (semPrinter);
else
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 47
OSQPost (QPrinterTask,
(void *) (MSG_PRINT_TANK_HIST + iTank));
}
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 48
Page 49
/*
LOCAL VARIABLES: */
/*-------------------------------------------------------------*/
/* Initialize the time. */
iHours = 0;
iMinutes = 0;
iSeconds = 0;
iSecondTenths = 0;
TIMER.C:/* Initialize the semaphore that protects the data. */
SemTime = OSSemCreate (1);
}
/***** vTimerOneThirdSecond *********************************
This routine increments the timer stuff.
RETURNS: None.
*/
void vTimerOneThirdSecond (
/*
INPUTS: */
SHAH AND ANCHOR KUTCHHI ENGINEERING COLLEGE
Page 50
/*-------------------------------------------------------------*/
/* Get the time semaphore. */
OSSemPend (SemTime, WAIT_FOREVER, &byErr);
case 3:
iSecondTenths = 7;
break;
Page 51
Page 52
/*-------------------------------------------------------------*/
Page 53
Page 54
Experiment-11
REQUIREMENT ANALYSIS:
SOFTWARE ARCHITECTURE:
CONCLUSION:
Page 55