VE4072-RTES-lab Manual
VE4072-RTES-lab Manual
Submitted in III Semester in partial fulfillment for the award of the degree of
MASTER OF ENGINEERING
II Year / 3 rd SEMESTER
Name :
Register No. :
BONAFIDE CERTIFICATE
REAL TIME EMBEDDED SYSTEMS LABORATORY during the academic year 2024–
2025.
1
Read input from switch and automatic
control/flash led for arm processor
4
Working of a thread is to trace a realtime
program using rtlinux
5
Interfacing stepper motor and temperature
sensor
List of Experiments
4
To write a C program for Switch & LED ON or OFF depending on the status of the pin.
3. Flash Magic.
4. USB cable.
5. CRO.
Theory
LEDs are based on the semiconductor diode. When the diode is forward biased (switched on),
Electrons are able to recombine with holes and energy is released in the form of light. This effect is
called electroluminescence and the color of the light is determined by the energy gap of
the semiconductor
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
Program:
#include <lpc214x.h>
#include <stdint.h>
int main(void)
{
//PINSEL0 = 0x00000000; /* Configuring P0.0 to P0.15 as GPIO */
/* No need for this as PINSEL0 reset value is 0x00000000 */
IO0DIR = 0x00000001; /* Make P0.0 bit as output bit, P0.1 bit as an input pin */
while(1)
{
if ( IO0PIN & (1<<1) ) /* If switch is open, pin is HIGH */
{ IO0CLR = 0x00000001; /* Turn on LED */
}
else /* If switch is closed, pin is LOW */
{
IO0SET = 0x00000001; /* Turn off LED */
}
}
}
Result :
Thus C code is generated for Switch & LED and output is verified in LED’s by Switches.
6
Aim
To develop a C-Language program for reading the RTC, convert into decimal and to
display it.
Apparatus & Software Required
3. Flash Magic.
4. USB cable.
Theory
The Real Time Clock (RTC) is a set of counters for measuring time when system power is on,
and optionally when it is off. It uses little power in Power-down mode. On the
LPC2141/2/4/6/8, the RTC can be clocked by a separate 32.768 KHz oscillator, or by a
programmable prescale divider based on the VPB clock. Also, the RTC is powered by its own
power supply pin,VBAT,which can be connected to a battery or to the same 3.3 V supply used
by the rest of the device.
7
Serial Communication
Serial communication takes a byte of data and transmits the 8 bits in the byte one at a time.
The advantage is that a serial port needs only one wire to transmit the 8 bits (while a parallel
port needs 8). The disadvantage is that it takes 8 times longer to transmit the data than it would
if there were 8 wires. Serial ports lower cable costs and make cables smaller.
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using
Flash Magic Software.
8
/**************************************************************/
RTC.C
/**************************************************************/
split_numbers(hrs);
lcdd at(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(min);lc
d dat(tens+0x30);
lcddat(ones+0x30);
lcddat(':');
split_numbers(sec);l
cdd at(tens+0x30);
lcddat(ones+0x30);
//lcddat(':');
}
}
PORT
10
/* This is a test program to send and receive data via uart0 in theARMLPC2148 */
Development board itself
/
******************************************************************
******************
#include<LPC214x.H> /* LPC214x definitions*/
#include"uart0.h" /* contains prototypes of
driverfunctions*/
}
/
***********************************************************************
*************/ SERIAL PORT PROGRAM
/****************************************************************************/
/* Uart1 Initialization */
/
****************************************************************************/
#include<lpc214x.h>#inc
lude<stdio.h>
#include<stdlib.h>
#include "uart1_driver.c"
int main()
{
unsigned char *a;
//unsigned char
*w;
11
a=malloc(sizeof(1
00));
12
inituart1();
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ
");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVWXYZ
");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVW
XYZ");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVW
XYZ");
sendstring1("ABCDEFGHIJKLMNOPQRSTUVW
XYZ");
/*sendstring1(" * ");
sendstring1(" ** ");
sendstring1(" *** "); s
endstring1(" * *** "); sendstring1(" *
* * * * ");
sendstring1(" SM MICRRO ");
sendstring1(" * * * * * ");
sendstring1(" * *** "); sendstring1("
*** ");
sendstring1(" ** ");
sendstring1(" * "); */
while(1)
{
receivestring1(a);sen
d string1(a);
}
}
SERIAL PROGRAM
PORTDETAILSUART0
ARM DETAILS
P0.0 TXDO
P0.1 RXDO
UART1
ARM DETAILS
P0.8 TXD1
P0.9 RXD1
Result
The C-Language program for reading RTC and displaying it in LCD was written & output is
verified with running the RTC from a default/specified time.
13
Aim
To develop a C-Language program to write and read a data in EEPROM and also
to analyze its performance with the interrupt
Theory
Serial-interface EEPROM’s are used in a broad spectrum of consumer, automotive,
telecommunication, medical, industrial and PC related markets. Primarily used to store
personal preference data and configuration/setup data, Serial EEPROM’s are the most flexible
type of nonvolatile memory utilized today. Compared to other NVM solutions, Serial
EEPROM devices offer a lower pin count, smaller packages, lower voltages, as well as lower
power consumption.
14
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using
Flash Magic Software.
15
EPROM PROGRAM
/******************************************************************************/
I2C .C
/**************************************************************************/
printstr("Read Sucess",0,0);
}
unsigned char r;
wait();
wait();
wait();
wait();
lcdinit();clr
sc r(2);
printstr("SM MICRRO SYSTEM",0,0);
printstr(" ARMDEVKIT
",0,1); InitI2C ();
StartI2C ();
SendI2C Address(0xa0); // EEPROM device
17
}
/
*************************************************************************************
******/
LCD.C
/
*************************************************************************************
******/
void lcdinit()
{
18
19
IODIR0 = 0xFFFFFFFF;
IOCLR0 =0X00000FFF;
lcdcmd(0x8);
lcdcmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();//(1600)
;
}
void gotoxy(char x, char y)
{
if(y == 0)
lcdcmd(0x80+x);
else
lcdcmd(0xc0+x);
}
void printstr(char *str, char x, char y)
{
char i; gotoxy(x,y);
wait();//(500);
for(i=0;str[i]!='\0';i+
+)lcddat(str[i]);
}
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher
nibble IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 =
CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04)&0xf0); //lower
nibble IOSET0 =LCDDAT;
IOSET0 = RS;
IOSET0 =
CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void clrscr(char ch)
{
if(ch==0)
{
printstr(" ",0,0);
gotoxy(0,0);
}
else if(ch ==1)
{
printstr(" ",0,1);
gotoxy(0,1);
}
els
e
lcdcmd(0x01);
{ //delay(100);
}
}
#include
<LPC214x.h>
void
init_VIC(void)
{
/* initialize VIC*/
VICIntEnClr
=0xffffffff;
VICVectAddr =0;
VICIntSelect =0;
}
void ExtInt_ISR(void)irq
{
//EXTINT=(1<<2); /* clear EINT2 flag by writing HIGH to corespondingbit*/
//IOCLR0 = 0x40000000; /* Trigger the relay*/
IOCLR1 = 0x400f0000; /* P1.18 Trigger the relay*/
//IOPIN1 =
0x00000000; EXTINT =
(1<<2);
VICVectAddr=0; /* Acknowledge Interrupt*/
}
void init_Interrupt(void)
{
PINSEL0=0x80000000; // select P0.15 for EINT2
VICIntEnable = (1<<16); // External interrupt
2(EINT2)
VICVectCntl0=(1<<5)|(16); // set the VIC control reg for
EINT2 VICVectAddr0 = (unsignedlong)ExtInt_ISR;
EXTMODE&=~(1<<2);// set VIC for egdse sensitive forEINT2
// EXTPOLAR = ~(1<<2); // set VIC for falling edge sensitive forEINT2
}
void init_ports(void)
{
IODIR0 =
0x40000000; IODIR1
= 0x400f0000;
IOPIN1 =
0xff010000; IOSET0
= 0x40000000;
IOSET1 = 0x400f0000;
}
/*void wait_for_turnoffRelay(void)
{
22
int val;
val=IOPIN1; // read the ports for key board input
while((~(val>>20))!=0); // wait until 1st key in the matrixkeyboard
is
pressed IOCLR0=0x00010000; // switch off therelay
}*/
23
/***********************************************************************************/
XINTR _RELAY.C
/
********************************************************************
**************/ #include <LPC214x.h>
#include
"ext.h" int
main()
{
init_VIC();
init_Interrupt();init
_po rts();
while(1)
{
//wait_for_turnoffRelay();
}
}
INTERRUPT BUZZERPROGRAM
ARM DETAILS
P1.18 TRIGGER THE RELAY
P0.15 EINT2
Result
The C program to write and read a data in EEPROM and also to analyze its
performance with the interrupt is developed and is verified.
24
USING RTLINUX
Aim
To write C Program to understand the working of a thread is to trace a realtime program using
RTlinux
Theory
A realtime application is usually composed of several ``threads'' of execution. Threads are
light-weight processes which share a common address space. In RTLinux, all threads share the
Linux kernel address space. The advantage of using threads is that switching between threads
is quite inexpensive when compared with context switch. We can have complete control over
Procedure
1. RTLinux uses the kernel space for executing the programs and there will be not be any protection
against errors in the user's code. Programming errors may lead to system down.
2. Use the debugger which the RTLinux supplies in order to reduce the risk of system crashes.
3. If the floating point unit is required in the task, we must explicitly set permissions, because by
4. default RTLinux tasks are not having floating point unit access.
5. Command prompt arguments can't be passed in RTLinux
25
Program
#include <rtl.h>
#include <time.h>
#include <pthread.h>
pthread_t thread;
void * thread_code(void)
{
pthread_make_periodic_np(pthread_self(), gethrtime(), 1000000000);
while (1)
{
pthread_wait_np ();
rtl_printf("Hello World\n");
}
return 0;
}
int init_module(void)
{
return pthread_create(&thread, NULL, thread_code, NULL);
}
void cleanup_module(void)
{
pthread_delete_np(thread);
}
Result
Thus C Program to understand the working of a thread is to trace a realtime program is verified
using RTlinux
26
Aim
To write C Programs for running stepper motor either in clock- wise or counter-clock- wise and
the direction of the rotation of the stepper motor depends on the variation in the temperature
sensor.
Theory
So when the next electromagnet is turned on and the first willturn off, the gear rotates
slightly to align with the next one and from there the process is repeated. Each of those slight
rotations is called a "step." In that way, the motor can be turned to a précised angle. There are
two basic arrangements for the electromagnetic coils: bipolar and unipolar.
27
Procedure
1. Follow the steps to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps to create a New Project to compile and build the program
4. Follow the procedures in to download your Hex code to processor using Flash Magic
Software.
call_stepper_forw()
{
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00040000;
//wait();
//wait();
wait();
wait();
IOCLR1 = 0X00FF0000;
IOSET1 = 0X00060000;
//wait();
//wait();
28
wait();
wait();
IOCLR1 =
0X00FF0000;
IOSET1 =
0X00070000;
//wait();
//wait();
wait();
wait();
IOCLR1 =
0X00FF0000;
IOSET1 =
0X00050000;
//wait();
//wait();
wait();
wait();
}
/*************************************************************/
MAIN ADC TEST
/*************************************************************/
/* This is a test program to temperature sensor in the ARM LPC2148 developmentboard*/
/************************************************************************************/
#include<LPC214x.H> /* LPC214x definitions*/
#include"ADC_Driver.c" /* contains prototypes of driverfunctions*/
#include"lcd.c" #include <stdio.h>
}
}
/************************************************************************************/
LCD.C
/************************************************************************************/
#include <LPC214x.h>
#define
SET1
#define
OFF0
unsigned int thousands,hundreds,tens,ones;
voidwait(void) { /* wait
function */ intd;
for (d = 0; d <100000;d++); /* only to delay for LED flashes*/
}
void lcdinit()
{
IODIR0 |= 0xFFFFFFFF;
IOCLR0 |=
0X00000FFF;
lcdcmd(0x28);
lcd cmd(0x28);
lcdcmd(0x0c);
lcdcmd(0x06);
lcdcmd(0x01);
lcdcmd(0x0f);
wait();
}
}
void lcdcmd(charcmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0);//higher nibble
32
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0= CE;
wait();//(100);//enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
LCDDAT = ((cmd<<0x04)&0xf0);//lower nibble
IOSET0 =LCDDAT;
IOCLR0 = RS;
IOSET0 = CE;
wait();//(100);//enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
}
void lcddat(char cmd)
{
unsigned charLCDDAT;
LCDDAT = (cmd&0xf0); //higher nibble IOSET0 =LCDDAT;
IOSET0 = RS; IOSET0 = CE;
wait();//(100); //enablelcd
IOCLR0 = CE;
IOCLR0 = 0X00000FFF;
void Wait_Msg(void)
{
lcdcmd(0x01);
printstr(" Please Wait ", 0,0);
}
void Welcome_Msg(void)
{
lcdcmd(0x01);
printstr(" Welcometo ", 0,0);
printstr(" SMMICRRO ", 0,1);
}
34
ADC_ DRIVER.C
/**************************************************************/
#include<LPC214x.H> /* LPC214x
definitions */ Void ADCInit(void)
{
PINSEL1|=0x04000000; /*For Channel AD0.2
is P0.29*/ IODIR0 |=~(0x04000000);
AD0CR |=0x00200204; /*0x04 selects AD0.2 to mux output, 0x20 makes
ADCin operational*/ AD0GDR; /*A read on AD0GDR clears the
DONEbit*/
}
void ADC_StartConversion(void)
{
AD0CR |= (1<<24);
}
void ADC_StopConversion(void)
{
AD0CR &= (~(1<<24));
}
unsigned int ADC_ReadChannel(void)
{
// unsigned int i;
unsigned long
ADC_Val, t;
ADC_StartConversion(
);
while((AD0DR2&0x80000000)==0); /*wait until ADC
conversion completes*/ if(AD0STAT & 0x00000400)
{
//printstr("OVR",0,1);return(0);
}
t = AD0DR2;
ADC_Val = ((t>>6) & 0x000003FF);//(AD0DR2 & 0x000003FF); //((AD0CR>>6) & 0x000003FF);
//
ADC_StopConversion();retu
rn( ADC_Val);
}.
TEMPERATURE SENSOR PROGRAM PORT DETAILS
ARM DETAILS
P0.29 ADC0.2
PO.10 RS LCD PIN
P1.11 CE LCD PIN
Result