You are on page 1of 65

EMBEDDED SYSTEM

CHAPTER 1

ABOUT THE ORGANISATION

Technofly Solutions is a leading electronics product design, development and services


company. The professionals with industrial experience in embedded technology, real time
software, process control and industrial electronics held the company.
The company is the pioneers in design and development of Single Board Computers,
Compilers for micro-controllers within India. Talented professional in the field of embedded
hardware, software design and development toil to reach its excellence.
Technofly Solutions & Consulting was found in year 2017 by a team with 14+ years of
experience in embedded systems domain. Technofly Solutions focuses globally on
automotive embedded technologies and VLSI Design, Corporate Training & Consulting. Till
now we have delivered more than 15+ Corporate Trainings for companies working in
Embedded Automotive Technologies in India. Also involved in the Development of OBD2
(On Board Diagnose Product for Passenger cars) for clients in India.
Technical Expertise

Expertise in Embedded software development:


1. Microcontroller Drivers
2. Boot loader and System software
3. CAN, LIN and other serial communication software
4. On Board Diagnostics services [ISO-14229 and ISO-15765]
5. Model based software development: Modeling, Simulation, Auto coding and Reverse
Engineering
6. Application software development compliant with MISRA-C

Page 1
EMBEDDED SYSTEM

7. UTOSAR Configuration and generation.

Automotive domain expertise, Process quality:


1. Body Control Module
2. Power Electronics, DCDC Convertors
3. HVAC Systems
4. Cluster and Head-Up Display systems
5. Driver Information systems
6. Seat Modules

Expertise in ASIC VLSI:


1. Verilog courses
2. SystemVerilog for design and Verification
3. UVM Methodology for Verification
4. Functional Verification

Process Quality:
1. Experience in SPICE Level 3 development.
2. Functional Safety ISO 26262 - ASIL B products
3. Adaptable to Customer procedures and guidelines

Technologies:
1. Microcontrollers 8, 16, 32 bit
2. Embedded C, Python, Iot (PHP Front End & MY SQL Back End) Wireless –
Bluetooth, GPS, GPRS, Wi-Fi
3. Communication protocols – Spi, I2c, CAN, LIN
4. Mat Lab simlink, Xilinx, Modelsim, LabView

Management:
The Management team as mixture of Technical and Business development expertise with
14+years of experience in the Information Technology Field.
Current status of Technofly solution:
Present the company is involved with developing the GPS Training system for two wheels
with our associated partners also more focusing on Corporate Trainings on AUTOMOTIVE
EMBEDDED and Focused on providing ASIC solutions that involves Design and
Verification IP’s And Functional Verification of Designs.

Page 2
EMBEDDED SYSTEM

Company Profile:
TechnoFly was formed by professionals with formal qualifications and industrial experience
in the fields of embedded systems, real-time software, process control and industrial
electronics. The company is professionally managed and supported by qualified experienced
specialists and consultants with experience in embedded systems – including hardware and
software.
Initially, the company Developed system software tools; these include C Compilers for
micro-controllers and other supporting tools such as assembler, linker, simulator and
Integrated Development Environment. Later Single Board Computers (SBCs) – were
developed and are still manufactured. Such hardware boards support a broad range of
processors – including 8 bit, 16 and 32 bit processor.
Since 2015, company also started offering design and development services. This includes a
complete spectrum of activities in product development life cycle that is idea generation,
requirement gathering to prototype making, testing and manufacturing. Company has so far
provided product design services for various sectors which include the Industrial automation,
Instrumentation, Automotive, Consumer and Defense sector.

Services of Technofly:

Embedded Software engineering Services:

When you don’t have enough time, or the right skills on hand, you can supplement your team
with expert embedded engineers from Technofly, who can tackle your projects with
confidence, take out the risk, and hit your milestones. We’ll take as much ownership as you
want us to, and make sure your project is done right, on time and on budget. Go ahead, check
our reputation for on-time, on-budget delivery. We've earned it, time and again.
We can help you cut risk on embedded systems R&D, and accelerate time to market.
Technofly is your best choice for designing and developing embedded products from
concept to delivery. Our team is well-versed in product life cycles. We build complex
software systems for real-time environments and have unique expertise and core
competencies in the following domains: Wireless, Access and IOT/Cloud.
Technofly solution also offer services which includes
1. Developing client / server applications to run on Windows / Linux

Page 3
EMBEDDED SYSTEM

2. Develop / Test Internet based applications


3. Test suite development for applications and network protocols
4. Developing Networking tools for the enterprises
5. Verification & Validation of Enterprise applications
6. Software maintenance of enterprise applications

WORKING DEPARTMENT IN THE COMPANY


The team is associated with R&D in Wireless Communication Technologies department in
the company. The team is currently working on 4G-5G technologies associated with
Cognitive Devices such as WLAN, Bluetooth, Zigbee, other Mobile networks etc, for better
achievable network efficiencies. The work involves examining various methodologies
currently available and under development and implementation of the same for further
analysis and in depth understanding of the effects of these methods on network capacities.
The department is currently developing and examining optimal solutions for Network Data
Rate maximization in both co-operative and non-cooperative network users scenarios
involving cognitive(SU’s) and non-cognitive(PU’s) devices. The work is mainly concentrated
on:
1. Resource management (Spectrum management as well as power management),
2. Power Spectral analysis,
3. Detection Test statics computation methodology analysis,

Page 4
EMBEDDED SYSTEM

4. Low power VLSI design


5. Efficiency analysis

The department is actively involved in acquiring latest technologies related projects in Low
power VLSI, wireless domain and these projects are well thought out and detailed
implementations are carried out. Projects are mainly done on Verilog, MATLAB platform
(from math works) and may also depend on NS2, NetSim and Xilinx platforms as per the
requirements of the project in progress.
Current internship involves study implementation and analysis of High speed and Energy
Efficient Carry Skip adder (CSKA) with Hybrid model for achieving high speed and reducing
the power consumption.
1. Study Requirements: Low power VLSI design and fundamentals of Digital circuits
2. Implementation Requirements: Verilog code / Modelsim tool
3. Detection Test Static: Simulation results
4. Platform: Verilog and simulated by Modelsim 6.4cand synthesized by Xilinx tool.

Engineering Departments and services:


Technofly solution offers services in the areas of Real-Time Embedded Systems, Low power
VLSI design, Verification and Software Engineering Services. Its strong team of around 30
engineers is equipped with the right tools and right processes to deliver the best. Technofly
solution also offers customization of its products.

Real Time Embedded System and Low power VLSI design Department:
Technofly solution embedded software, hardware, system development, system integration,
verification and product realization services to customers in automotive electronics and
consumer electronics segments worldwide. Technofly solution has more than 14 years of
experience in embedded systems on a variety of platforms such as Microprocessors,
Programmable Logic Devices (PLDs) and ASICs. Accord develops applications based on the
various commercially available real time and embedded operating systems.
Technofly solution provides services in the following areas:
1. Design Services
2. Product Realization

Design Services:
Technofly solution offer services in the areas of:
1. Hardware design and development

Page 5
EMBEDDED SYSTEM

2. Software design and development

Hardware Design and Development:


Hardware design and development services are related to:
1. High-speed digital design
2. Mixed signal design
3. Analog and RF design
4. PLD (FPGA/EPLD/CPLD) based design
5. Processor (Micro-controllers, DSP) based design
6. Mechanical enclosure design

The hardware design and development follow stringent life cycle guidelines laid out at
Technofly solution while accomplishing the following –
Design Assurance
1. Signal Integrity
2. Cross-talk
3. Matching and Impedance control
4. Power supply design with due emphasis for Low-power battery operated
5. applications
6. Thermal analysis
7. Clock distribution
8. Timing analysis
9. PCB layer stacking

Design optimization
Selection of components keeping in mind
1. Cost , Size
2. Operating and storage temperature
3. MIL/Industrial/Commercial grades based on application
4. Environmental specifications like vibration, humidity, and radiation

PCB design
1. Optimum number of layers for a given application
2. Material used for PCB
3. Rigid, Flexi and Rigid-Flexi designs based on applications

Page 6
EMBEDDED SYSTEM

Pilot production
1. Component sourcing, inward inspection and inventory management
2. PCB assembly
3. Assembled PCB testing

Software Development
Software design and development services are related to
1. Real-time Embedded Application Development
2. Device Driver Development
3. BSP Development
4. Processor/OS Porting Services
5. RTOS based development
6. Board bring-up
7. Digital Signal Processing Algorithms
8. Porting across platforms

ASIC
1. Design IP’s
2. Verification IP’s (VIP’s)
3. Complete verification Solution

Skill Set
1. Language: C, C++, Assembly languages, Verilog and SystemVerilog
2. Hardware Platforms: ADI DSPs, TI DSPs, ARM, PowerPC, Xscale architecture
3. RTOS: Integrity, VDK, DSP OS, Micro C OS and OASYS
4. FPGA: Xilinx (Spartan and Virtex), Actel, Altera

Tools
1. Development Tools: In-circuit emulators of various processor environments
2. Compilers: Compilers/IDEs of various processor environments

FPGA Tools
1. Front End Design: XST, Synplify, SynplifyPro, Precision Synthesis
2. Back End Design: Xilinx ISE 9.1.03i ,Actel’s Libero 6.0 , Altera’s MAXPlusII

Page 7
EMBEDDED SYSTEM

Simulation:
1. Xilinx ModelSim SE
2. Actel’s Libero 6.0
3. Altera’s MAXPlusII

Coverage Analysis:
TransEDA VN-Cover
Debugging:
ChipScope
Hardware Tools:
1. Spectrum Analyzer
2. Signal Generators
3. Logic Analyzer
4. Digital Storage Oscilloscopes
5. Multifunction Counters
6. Development Tools and In-circuit Emulators for all ADI DSP’s, TI DSP’s,
7. ARM Processor, PowerPC
8. ORCAD, Allegro, Pspice
9. Temperature and Humidity Chamber

Product Realization
Product Realization services are provided in the areas of:
1. Consumer Electronics
2. Automotive
3. Space
4. Defense
5. Simulation/Emulation
6. Temperature and Humidity Chamber
7. Temperature and Humidity Chamber

Software Engineering Department


Technofly solution has a dedicated group specializing in providing productivity tools
for work group collaboration, which also handles software projects for small and medium
scale enterprises.

Page 8
EMBEDDED SYSTEM

Our Work group productivity software suite Smart Works consists of software
applications which can help you plan and track your projects, Manage meetings and Track
various issues to its closures. Smart Works is affordably priced and uses TCP/IP based client
server architecture at its core. Smart Works server runs on all the windowing platforms
(Windows 95/98/NT/2000/ME). Efforts are on to make Smart works available on other
platforms as well.
Technofly solution also offer services which includes
1. Developing client / server applications to run on Windows / Linux
2. Develop / Test Internet based applications
3. Test suite development for applications and network protocols
4. Developing Networking tools for the enterprises
5. Verification & Validation of Enterprise applications
6. Software maintenance of enterprise applications

Following are the skill sets Technofly solution has garnered in the area of software:
1. Programming Languages: C, C++, VC++, Java, C#, ASP.Net, PHP, Lex &Yacc,
Perl, Python, Assembly Language and Ada
2. Operating Environments: Real Time Operating Systems such as, GreenHills
Integrity and Micro C-OS. DSP OS, VDK, OASYS and MS-WINCE, MS-
Windows, Unix/Linux and MPE/iX are the operating systems that Accord
provides services.

Page 9
EMBEDDED SYSTEM

Chapter 2
Introduction to Embedded Systems
2.1 Definition of Embedded System
An embedded system is one kind of a computer system mainly designed to perform several
tasks like to access, process, store and also control the data in various electronics-based
systems.
Embedded systems are a combination of hardware and software where software is usually
known as firmware that is embedded into the hardware.

Fig2.1: Basic block diagram of Embedded System

2.1.1 Embedded System Hardware:

As with any electronic system, an embedded system requires a hardware platform on which it
performs the operation. Embedded system hardware is built with a microprocessor or
microcontroller. The embedded system hardware has elements like input output (I/O)
interfaces, user interface, memory and the display. Usually, an embedded system consists of:

 Power Supply
 Processor
 Memory
 Timers
 Serial communication ports
 System application specific circuits

Page10
EMBEDDED SYSTEM

2.1.2 Embedded System Software:

The embedded system software is written to perform a specific function. It is typically


written in a high level format and then compiled down to provide code that can be lodged
within a non-volatile memory within the hardware. An embedded system software is
designed to keep in view of the three limits:

 Availability of system memory


 Availability of processor’s speed
 When the system runs continuously, there is a need to limit power dissipation for
events like stop, run and wake up.

2.1.3 Real Time Operating System

A system is said to be real time, if it is essential to complete its work and deliver its service
on time. Real time operating system manages the application software and affords a
mechanism to let the processor run. The Real Time operating system is responsible for
handling the hardware resources of a computer and host applications which run on the
computer.

Fig 2.2: Embedded System

Page11
EMBEDDED SYSTEM

2.2 Characteristics of Embedded Systems


1 Application-specific functionality – specialized for one or one class of
applications
2 Deadline constrained operation – system may have to perform its function(s)
within specific time periods to achieve successful results
3 Resource challenged – systems typically are configured with a modest set
of resources to meet the performance objectives
4 Power efficient – many systems are battery-powered and must conserve
power to maximize the usable life of the system.
5 Form factor – many systems are light weight and low volume to be used as
components in host systems
6 Manufacturable – usually small and inexpensive to manufacture based on the
size and low complexity of the hardware.

2.2.1Applications of Embedded Systems

Embedded systems find numerous applications in various fields such as digital electronics,
telecommunications, computing network, smart cards, satellite systems, military defense
system equipment, research system equipment, and so on.

Page12
EMBEDDED SYSTEM

2.3 Introduction to ARM Microcontroller

The ARM stands for Advanced RISC machine and it is a 32-bit reduced instructions set
computer (RISC) microcontroller. It was first introduced by the Acron computers’
organization in 1987. The ARM is a family of the microcontroller developed by the different
manufacturers such as ST microelectronics, Motorola and so on .The ARM microcontrollers
are cost sensitive and high performance devices which are used in a wide range of application
such as industrial instrument control systems, wireless networking and sensors and
automotive body system etc.

The ARM microcontroller architecture come with a few different versions such as ARMv1,
ARMv2 etc and each one has its own advantage and disadvantages.

2.3.1 ARM v7

ARM7 is one of the widely used micro-controller family in embedded system application.
This section is humble effort for explaining basic features of ARM-7.

LPC2148 is the widely used IC from ARM-7 family. It is manufactured by Philips and it is pre-
loaded with many inbuilt peripherals making it more efficient and a reliable option for the
beginners as well as high end application developer.

Fig 2.3.1: LPC2148

Page13
EMBEDDED SYSTEM

2.3.2 Pin Configuration of LPC2148


MEMORY-LPC2148 has 32kB on chip SRAM and 512 kB on chip FLASH memory. It has
inbuilt support up to 2kB end point USB RAM also.
On chip FLASH memory system- The LPC2148 incorporates a 512 kB Flash memory
system. This memory may be used for both code and data storage.
I/O Ports- LPC 2148 has two I/O Ports each of 32 bit wide giving us total 64 I/O Pins. Ports
are named as P0 and P1.

Fig2.3.2 Pin configuration

Page14
EMBEDDED SYSTEM

2.3.3 Features of LPC214x series controllers.

• 8 to 40 kB of on-chip static RAM and 32 to 512 kB of on-chip flash program memory.128


bit wide interface/accelerator enables high speed 60 MHz operation.

• EmbeddedICE RT and Embedded Trace interfaces offer real-time debugging with


theonchip RealMonitor software and high speed tracing of instruction execution.

• USB 2.0 Full Speed compliant Device Controller with 2 kB of endpoint RAM.In addition,
the LPC2148 provides 8 kB of on-chip RAM accessible to USB by DMA.

• Two 32-bit timers/external event counters (with four capture and four comparechannels
each), PWM unit (six outputs) and watchdog.

• Low power real-time clock with independent power and dedicated 32 kHz clock input.

• Multiple serial interfaces including two UARTs (16C550), two Fast I2C-bus(400 kbit/s),
SPI and SSP with buffering and variable data length capabilities.

• Vectored interrupt controller with configurable priorities and vector addresses.

• Up to nine edge or level sensitive external interrupt pins available.

• On-chip integrated oscillator operates with an external crystal in range from 1 MHz to30
MHz and with an external oscillator up to 50 MHz.

2.4 Steps to configure LPC2148 :

1. Keil µVision.

2. Flash Magic.

2.4.1 Keil µVision

1. Open Keil µVision from the icon created on your desktop.

Page15
EMBEDDED SYSTEM

2. Click on Project menu, and then hit on New uVision Project.

3. Select target Device vendor. In this case NXP (founded by Phillips).

4. After this, a dialog box will pop-up on screen. This will ask you whether to copy startup
code for LPC2148. Click on Yes.

Page16
EMBEDDED SYSTEM

5. Now click on File menu and hit on New.

Write code in C and FileName.c Save.

6. Add startup.s file to source group.

Page17
EMBEDDED SYSTEM

7. Now right click on Target 1 and hit on Options for target “Target 1”.

8.In Options for target “Target 1”. In output tab, click on check box Create HEX File.
Then go to Linker tab. Click on Use Memory Layout for Target Dialog.

9.Add required files to source group.

Page18
EMBEDDED SYSTEM

10. Then hit on Rebuild All target files.

11. Now we can see Build output.

2.4.2 Flash Magic


Here is to setup Flash Magic and load HEX file into LPC2148 Microcontroller.

Page19
EMBEDDED SYSTEM

Chapter 3
TASK PERFORMED

3.1 LED Blinking:


A light-emitting diode (LED) is a two-lead semiconductor light source device used for
indicating the output status by making it ON or OFF
An LED is nothing but a p–n junction diode, which emits light when provided with power
supply. When voltage is applied to the leads of an LED, it forces the electrons to recombine
with electron holes within the device, emitting energy in the form of photons. This effect of
emitting energy in form of photons is called electroluminescence.
The colour of the light is determined by the energy band gap of the semiconductor
corresponding to the energy of the photon.

Fig 3.1: LED

3.1.1 Interfacing LEDprogram to LPC2148


#include<LPC214x.h>
#define LED (1<<16) // port0.20 pin
void delay(int i);

int main (void)


{
IO0DIR |= LED; // led as output
while(1)
{
IO0SET |= LED; // led on

Page20
EMBEDDED SYSTEM

delay(10000);
IO0CLR |= LED; // led off
delay(10000);
}
}

void delay(int i)
{
int j,k;
for (j=0;j<i;j++)
for (k=0;k<35;k++);
}

3.2 Liquid Crystal Display (LCD)


LCDs (Liquid Crystal Displays) are used for displaying status or parameters in embedded
systems.
LCD 16x2 is 16 pin device which has 8 data pins (D0-D7) and 3 control pins (RS, RW, EN).
The remaining 5 pins are for supply and backlight for the LCD.

Fig 3.2: LCD

Page21
EMBEDDED SYSTEM

The control pins help us configure the LCD in command mode or data mode. They also help
configure read mode or write mode and also when to read or write.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the requirement of the
application. In order to use it we need to send certain commands to the LCD in command
mode and once the LCD is configured according to our need, we can send the required data in
data mode.

Fig 3.3: Tabular Column of LCD

Since we are using LCD in 4-bit mode, we require only 4 Data pins.
LCD Data pins D4-D7 are connected to respective pins.
LCD control pins RS, RW and EN are connected to their respective pins.

3.2.1 Interfacing LCDprogram to LPC2148


#include <LPC214x.h>
#include "LCD.h"
#define back_light_timeout 1000 //IOODIR IO0CLR IO0SET
#define d4 (1<<18) // IO0DIR IO0CLR IO0SET
#define d5 (1<<19)
#define d6 (1<<20)
#define d7 (1<<21)
#define rs (1<<15) // IO0DIR IO1CLR IO1SET
#define rw (1<<16)

Page22
EMBEDDED SYSTEM

#define en (1<<17)
#define data_mask (d4 | d5 | d6 | d7)
#define flag d7
void wait_lcd (void);
void command_write(unsigned char command);
void set_lcd_port_output(void);
void lcd_clear(void);
void data_write (unsigned char data);
void putchar(int c);
void putstring(char *string);
void init_lcd(void);
int lcdgotoxy( unsigned int x, unsigned int y);
void delay(int count);
void test_cmd(void);
void wait_lcd (void)
{
IO0DIR &= ~flag;
IO0CLR |= rs;
IO0SET |= rw | en;
while(IO0PIN & flag);
IO0CLR |= en | rw;
IO0DIR |= data_mask;
delay(100);
}
void command_write(unsigned char command)
{
unsigned char temp=0;
unsigned int temp1=0;
temp=command;
temp=(temp>>4)&0x0F;
temp1=(temp<<18)&data_mask;

IO0CLR = rs;
IO0SET = en;

Page23
EMBEDDED SYSTEM

IO0CLR = data_mask;
IO0SET = temp1;
delay(100000);
IO0CLR = en;
temp=command;
temp&=0x0F;
temp1=(temp<<18)& data_mask;
delay(100*2);
IO0CLR |= rs;
IO0SET |= en;
IO0CLR = data_mask;
IO0SET = temp1;
delay(100000);
IO0CLR |= en;
wait_lcd();
}
void set_lcd_port_output(void)
{
IO0DIR |= (en | rs | rw);
IO0CLR |= (en | rs | rw);
IO0DIR |= data_mask;
}
void lcd_clear(void)
{
command_write(0x01);
}

void data_write (unsigned char data)


{
unsigned char temp=0;
unsigned int temp1=0;
temp=data;
temp=(temp>>4)&0x0F;
temp1=(temp<<18)& data_mask;

Page24
EMBEDDED SYSTEM

IO0SET |= en|rs;
IO0CLR = data_mask;
IO0SET = temp1;
IO0CLR |= en;
temp=data;
temp&=0x0F;
temp1=(temp<<18)& data_mask;
IO0SET |= en | rs;
IO0CLR=data_mask;
IO0SET=temp1;
IO0CLR |= en;
wait_lcd();
}
void putchar(int c)
{
data_write(c);
}
void putstring(char *string)
{
while ( *string != '\0' )
{
putchar( *string );
string++;
}
}
void init_lcd(void)
{
set_lcd_port_output();
command_write(0x28);
command_write(0x02);
command_write(0x06);
command_write(0x0F);
}
int lcdgotoxy( unsigned int x, unsigned int y)

Page25
EMBEDDED SYSTEM

{
int retval=0;
if ((x > 1) && (y > 15))
{
retval=-1;
} else {
if( x==0 )
{
command_write(0x80 + y);
} else
if (x==1)
{
command_write(0xC0 + y);
}
}
return retval;
}
void delay(int count)
{
int j=0,i=0;
for(j=0;j<count;j++)
{
for(i=0;i<65;i++);
}
}
int main(void)
{
init_lcd();
command_write(1);
command_write(0x80);
putstring("pulse");
delay(200000);
command_write(0xC0);
putstring("Bengaluru");

Page26
EMBEDDED SYSTEM

while(1)
{
command_write(0x1C);
delay(200000);
}
}
void test_cmd(void)
{
command_write(0x08); //Display off,cursor off
command_write(0x18);
command_write(0x0C); //Display on cursor off
command_write(0x10); //Move cursor left by 1 char
command_write(0x14); //Move cursor right by 1 char
command_write(0x01); //Clear display
}

3.3 DC Motor
DC motor converts electrical energy in the form of Direct Current into mechanical energy.
In case of a motor, the mechanical energy produced is in the form of rotational movement of
the motor shaft .The direction of rotation of the shaft of the motor can be reversed by
reversing the direction of Direct Current through the motor.
The motor can be rotated at a certain speed by applying a fixed voltage to it. If the voltage
varies, the speed of the motor varies.
Thus, the DC motor speed can be controlled by applying varying DC voltage; whereas the
direction of rotation of the motor can be changed by reversing the direction of current
through it.

Fig 3.4:DC Motor

Page27
EMBEDDED SYSTEM

3.3.1: Interfacing DC Motor program to LPC2148


#include <LPC214x.h>
#define In1 (1<<25)
#define In2 (1<<24)
#define count 5000
#define Sw1 (1<<16)
#define Sw2 (1<<18)
#define Sw3 (1<<19)
void delay (int i);
void motor_clk(void);
void motor_anticlk(void);
void motor_stop(void);
void delay (int i)
{
int j,k;
for (j=0;j<i;j++)
for (k=0;k<1024;k++);
}
void motor_clk(void)
{
//IO0SET |=En1;
IO1SET |=In1;
IO1CLR |=In2;
//delay(count);
}
void motor_anticlk(void)
{
// IO0SET |=En1;
IO1CLR |=In1;
IO1SET |=In2;
//delay(count);
}

Page28
EMBEDDED SYSTEM

void motor_stop(void)
{
//IO0CLR |=En1;
IO1CLR |=In1;
IO1CLR |=In2;
//delay(count);
}
int main (void)
{
IO1DIR&=~Sw1;
IO1DIR&=~Sw2;
IO1DIR&=~Sw3;
IO1DIR |= In1;
IO1DIR |= In2;
while(1)
{
if(!(IO1PIN & Sw1))
{
//while(1)
{ motor_clk();
delay(count);
}
}
else if (!(IO1PIN & Sw2))
{motor_anticlk();
delay(count);
}
else if (!(IO1PIN & Sw3))
{ motor_stop();
delay(count);
}
}
}

Page29
EMBEDDED SYSTEM

3.4 Sensors
A sensor is a device, module, or subsystem whose purpose is to detect events or changes in
its environment and send the information to other electronics, frequently a computer
processor.

3.4.1 Types of sensors


1. Object detector-
Object detection is a form of proximity sensing to determine if an object or material is
present (arrives) or absent (disappears).

Fig 3.5: Object sensor

2.Flame/Fire detector-
A flame detector is a sensordesigned to detect and respond to the presence of aflame or fire,
allowing flame detection. Responses to a detected flame depend on the installation, but can
include sounding an alarm, deactivating a fuel line (such as a propane or a natural gas line),
and activating a fire suppression system.

Fig 3.6:Fire sensor

Page30
EMBEDDED SYSTEM

3. Temperature detector-
A temperature sensor is a device, usually an RTD (resistance temperature detector) or a
thermocouple, that collects the data about temperature from a particular source and converts
the data into understandable form for a device or an observer and so on.

Fig 3.7:Temperature sensor

3.4.2 Interfacing Object and Fire sensorsprogram to LPC2148


#include<lpc214x.h>
#include "Lcdtask.h"
#define ir_sensor (1<<11)
#define fire_sensor (1<<12)
int main(void)
{
IO0DIR&=~ir_sensor;
IO0DIR&=~fire_sensor;
init_lcd();
while(1)
{
if((IO0PIN & ir_sensor)==0)
{
command_write(0x01);
command_write(0x80);
putstring("object detected");
}
else if((IO0PIN & fire_sensor)==0)
{
command_write(0x01);
command_write(0x80);

Page31
EMBEDDED SYSTEM

putstring("fire detected");
}
}

3.5 UART
UART stands for Universal Asynchronous Receiver/Transmitter. A UART’s main purpose is
to transmit and receive serial data.

3.5.1 Introduction to UART Communication

In UART communication, two UARTs communicate directly with each other. The
transmitting UART converts parallel data from a controlling device like a CPU into serial
form, transmits it in serial to the receiving UART, which then converts the serial data back
into parallel data for the receiving device. Only two wires are needed to transmit databetween
two UARTs. Data flows from the Tx pin of the transmitting UART to the Rx pin of the
receiving UART:

Fig 3.8: Basic UART Communication

UARTs transmit data asynchronously, which means there is no clock signal to synchronize
the output of bits from the transmitting UART to the sampling of bits by the receiving
UART. Instead of a clock signal, the transmitting UART adds start and stop bits to the data
packet being transferred. These bits define the beginning and end of the data packet so the
receiving UART knows when to start reading the bits.

When the receiving UART detects a start bit, it starts to read the incoming bits at a
specific frequency known as the baud rate. Baud rate is a measure of the speed of data
transfer, expressed in bits per second (bps). Both UARTs must operate at about the same

Page32
EMBEDDED SYSTEM

baud rate. The baud rate between the transmitting and receiving UARTs can only differ by
about 10% before the timing of bits gets too far off.

3.5.2 Interfacing UART program to LPC2148.

#include <LPC214x.H>
#include "Lcdtask.h" /* LPC21xx definitions */
//#include "Serial.h"
#define CR 0x0D
unsigned char ch;
int sendchar (int ch)
{ /* Write character to Serial Port */
if (ch == '\n')
{
while (!(U1LSR & 0x40));
U1THR = CR; /* output CR */
}
while (!(U1LSR & 0x40));
return (U1THR = ch);
}
int uart0_getkey (void) { /* Read character from Serial Port */
while (!(U0LSR & 0x01));
return (U0RBR);
}
int uart1_getkey (void) { /* Read character from Serial Port */
if((U1LSR & 0x01)){
ch = U1RBR;
return 1; //(U1RBR);
}
else
return 0;
}

Page33
EMBEDDED SYSTEM

void uart1_init()
{
PINSEL0 |= 0x00050000; /* Enable RxD1 and TxD1 */
U1LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U1DLL = 97;
// U1DLL = 195; /* 9600 Baud Rate @ 15MHz VPB Clock 97 , 4800=197 */
U1LCR = 0x03; /* DLAB = 0 */
}
void uart1_putc(char c)
{
while(!(U1LSR & 0x40)); // Wait until UART1 ready to send character
U1THR = c; // Send character
}
void uart1_puts(char *p)
{
while(*p) // Point to character
{
uart1_putc(*p++); // Send character then point to next character
}
}
void uart0_init()
{
PINSEL0 |= 0x00000005; /* Enable RxD0 and TxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLL = 97; /* 9600 Baud Rate @ 15MHz VPB Clock */
U0LCR = 0x03; /* DLAB = 0 */
}
void uart0_putc(char c)
{
while(!(U0LSR & 0x40)); // Wait until UART0 ready to send character
U0THR = c; // Send character
}
void uart0_puts(char *p)
{

Page34
EMBEDDED SYSTEM

while(*p) // Point to character


{
uart0_putc(*p++); // Send character then point to next character
}
}
int main (void)
{
int i=0;
char t[20],s;
init_lcd();
uart0_init();
uart0_putc('S');
uart0_puts("hello");
uart0_puts("World");
command_write(0x01);
command_write(0x80);
putstring("Hi");
uart0_puts("Yes");
}

3.6 Radio-frequency identification


A RFID system is made up of two parts: a tag or label and a reader. RFID tags or labels are
embedded with a transmitter and a receiver. The RFID components on the tags have two
parts: a microchip that stores and processes information, and an antenna to receive and
transmit a signal. The tag contains the specific serial number for one specific object.

Fig 3.9: RFID

Page35
EMBEDDED SYSTEM

3.6.1 Interfacing RFIDprogram to LPC2148


#include<LPC214x.h>
#include "Serial.h"
#include "Lcdtask.h"
#include<string.h>
unsigned char code[8]="02557698";
int i=0;
unsigned char buff[10];
int ret;
int main (void)
{
uart1_init();
uart0_init();
init_lcd();
command_write(0x01);
command_write(0x80);
putstring("Prashanth");
delay(10000);
command_write(0x01);
command_write(0x80);
putstring("Hariprasad");
uart0_puts("working");
while(1)
{
for(i=0;i<8;i++)
{
buff[i]=uart0_getkey();
}
buff[8]='\0';
command_write(0x01);
putstring(buff);
delay(5000);
uart0_puts(buff);

Page36
EMBEDDED SYSTEM

if(strcmp(buff,"02557698")==0)
if(ret==0)
{
command_write(0x01);
command_write(0x80);
putstring("valid user");
delay(10000);
}
else
{
command_write(0x01);
command_write(0x80);
putstring("invalid user");
delay(10000);
}
}
}

3.7 Keypad
A keypad is a set of buttons arranged in a block or "pad" which usually bear digits, symbols
and usually a complete set of alphabetical letters. If it mostly contains numbers then it can
also be called a numeric keypad. Here we are using 4 X 4 matrix keypad.

Fig 3.10: Keypad

Page37
EMBEDDED SYSTEM

The rows are connected to an output port and the columns are connected to an input port.
To detect a pressed key, the microcontroller grounds all rows by providing 0 to the output
latch, and then it reads the columns. If the data read from the columns is D3-D0=1111, no
key has been pressed and the process continues until a key press is detected. However, if one
of the column bits has a zero, this means that a key press has occurred. For example, if D3-
D0=1101, this means that a key in the D1 column has been pressed.

If the data read is all 1s, no key in that row is activated and the process is moved to the next
row. It grounds the next row, reads the columns, and checks for any zero. This process
continues until the row is identified. After identification of the row in which the key has been
pressed, the next task is to find out which column the pressed key belongs to.

3.7.1 Interfacing keypadprogram to LPC2148


#include <LPC214x.h>
#include "LCD.h"
#include "CHECK.h"
#define R_1 (1<<16)
#define R_2 (1<<17)
#define R_3 (1<<18)
#define R_4 (1<<19)
#define C_1 (1<<20)
#define C_2 (1<<21)
#define C_3 (1<<22)
#define C_4 (1<<23)
#define count 1000
void Check_1(void);
void Check_2(void);
void Check_3(void);
void Check_4(void);
void Keypad(void);
void Keypad(void)
{
Check_1();

Page38
EMBEDDED SYSTEM

Check_2();
Check_3();
Check_4();
}
int main (void)
{
IO1DIR|=R_1; // Row as output
IO1DIR|=R_2;
IO1DIR|=R_3;
IO1DIR|=R_4;
IO1DIR &=~C_1; //Column as input
IO1DIR &=~C_2;
IO1DIR &=~C_3;
IO1DIR &=~C_4;
IO1SET|=R_1;
IO1SET|=R_2;
IO1SET|=R_3;
IO1SET|=R_4;
init_lcd();
command_write(0x01);
command_write(0x80);
putstring("KEYPAD");
delay(count);
while(1)
{
Keypad();
}
}

Page39
EMBEDDED SYSTEM

3.8 PWM
Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a
processor's digital outputs. PWM is employed in a wide variety of applications, ranging from
measurement and communications to power control and conversion.

3.8.1 Calculations
1. We know that, v=IR as the resistance decreases the voltage increases and vice versa,there
we can control voltage by varying resistance.
𝑓 = 1⁄𝑇
2. We know that the time period, T=Ton +Toff.
𝐓𝐨𝐧
3. DC= 𝑻

4. Vout=vmax*DC

3.8.2 Interfacing PWM Program to LPC2148


#include<lpc214x.h>
//#define LED (1<<16)
#define count 50
void delay_for(unsigned int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<1000;j++);
}
void pwm_init(void) //1ms at 60Mhz
{
PINSEL0=0x00000002; //P0.0 as PWM
PWMPR=59;
PWMMR0=100; //PWM RATE
PWMMR1=50; //PWM CLEAR
PWMMCR=0x00000002; //PWM0 RESET
PWMTCR=0X02; //COUNTER RESET
}

Page40
EMBEDDED SYSTEM

int main()
{
VPBDIV=0x01; //60MHz CLOCK
pwm_init();
while(1)
{
PWMPCR=0x0200; //PWM1 ENABLED
PWMTCR=0X09; //COUNTER ENABLE
}
}

3.9 GSM (Global System for Mobile Communication)


GSM is a digital mobile telephony system. GSM digitizes and compresses data, then sends it
down a channel with two other streams of user data, each in its own time slot. It operates at
either the 900 MHz or 1800 MHz frequency band.
The below figure shows how to interface the GSM with microcontroller. The GSM module is
communicate the microcontroller with mobile phones through UART. To communicate over
UART or USART, we just need three basic signals which are namely, RXD (receive), TXD
(transmit), GND (common ground).

GSM modem interfacing with microcontroller for SMS control of industrial equipment’s. The
sending SMS through GSM modem when interfaced with microcontroller or PC is much
simpler as compared with sending SMS through UART.
The transmit signal of serial port of microcontroller is connected with transmit signal (TxD)
of the serial interface of GSM Modem while receive signal of microcontroller serial port is
connected with receive signal (RxD) of serial interface of GSM Modem.

Fig 3.11: Pin assignment diagram of GSM.

Page41
EMBEDDED SYSTEM

3.9.1 Interfacing GSM to LPC2148


#include <LPC21xx.H>
#include <stdio.h>
#include "Serial.h"
#include "gsm.h"
#include "string.h"
//#include "delay.h"
#include "lcd.h"
#define GsmPutSSerial(string) uart0_puts( string )
#define GsmGetCSerial( ) uart0_getkey()
#define GsmPutCSerial(chr) uart0_putc(chr)
unsigned char gprs_temp;
int k=0;
unsigned char balance_buff[50];
struct rmc
{ char header[6];
char time[10], speed[8], date[7];
char latitude[11], longitude[11];
char dir1, dir2,status;
};
struct rmc gpsdata;
unsigned char zx=0,d=1;

void getGps(struct rmc *gpsdata);


void recvResponse1(unsigned char *response)
{
unsigned char ch;
while(GsmGetCSerial() != '\n' );
while( (ch = GsmGetCSerial()) != '\r' ) *response++ = ch;
*response = '\0' ;
GsmGetCSerial();
}

Page42
EMBEDDED SYSTEM

void intGsm( void )


{
unsigned char buff[10];
GsmPutCSerial('A');
delay(100);
GsmPutCSerial('T');
delay(100);
GsmPutCSerial('E');
delay(100);
GsmPutCSerial('0');
delay(100);
GsmPutCSerial('\r');
GsmPutSSerial("AT+CMGF=1\r"); //Initialize GSM For mobile
GsmPutSSerial("AT+CNMI=0,0,0,0\r"); //Disabling unsolicited sms indication.
GsmPutSSerial("AT+CSAS\r"); //Save the SMS Settings
}
unsigned char sendSMS( unsigned char *num, unsigned char * str )
{
unsigned char ch;
unsigned char res[10];
unsigned char *response = res;
GsmPutSSerial("AT+CMGS=\"");
GsmPutSSerial(num);
GsmPutSSerial("\"\r");
while( (ch = GsmGetCSerial()) != '>' && ch !='+' ) ;
if( ch == '+' )
{
*response++ = ch;
while( (ch = GsmGetCSerial()) != '\r' ) *response++ = ch;
*response = '\0' ;
GsmGetCSerial();
return 0;
}
GsmGetCSerial();

Page43
EMBEDDED SYSTEM

GsmPutSSerial( str );
GsmPutCSerial(26); //Send Control Z.
recvResponse1( response );
if( response[3] != 'S' )
{
recvResponse1( response );
return 1;
}
return 0 ;
}
unsigned char getSMS(sms_data *sms_data_ptr)
{
unsigned char ch, i;
GsmPutSSerial("AT+CMGL=\"ALL\"\r");
while( (ch = GsmGetCSerial()) != 'K' && ch != '+' ) ;
if( ch == 'K' )
{
while( GsmGetCSerial() != '\r' );
while( GsmGetCSerial() != '\n' );
return 0;
}
while( (ch = GsmGetCSerial()) != 'S' && ch != 'G' ) ;
if( ch == 'S' )
{
while( GsmGetCSerial() != '\r' );
while( GsmGetCSerial() != '\n' );
return 0;
}
while( GsmGetCSerial() != ' ' );
i=0;
while( (ch = GsmGetCSerial()) != ',' ) sms_data_ptr->index[i++] = ch;
sms_data_ptr->index[i++] = '\0';
while( GsmGetCSerial() != ',' );
while( GsmGetCSerial() != '\"' );

Page44
EMBEDDED SYSTEM

i=0;
while( (ch = GsmGetCSerial()) != '\"' ) sms_data_ptr->phone_num[i++] = ch;
sms_data_ptr->phone_num[i++] = '\0';
while( GsmGetCSerial() != '\n' );
i=0;
while( (ch = GsmGetCSerial()) != '\r' ) sms_data_ptr->dat[i++] = ch;
sms_data_ptr->dat[i++] = '\0';
while( GsmGetCSerial() != '\n' );
while(1)
{
if( GsmGetCSerial() == '+' )
{
while( GsmGetCSerial() != '\n' );
while( GsmGetCSerial() != '\r' );
while( GsmGetCSerial() != '\n' );
}
else
{ while( GsmGetCSerial() != '\n' );
while( GsmGetCSerial() != '\n' );
return 1;
}
}
}
unsigned char deleteSms(unsigned char *index)
{
unsigned char response[10];
GsmPutSSerial("AT+CMGD=");
GsmPutSSerial(index);
GsmPutSSerial("\r");
recvResponse1( response );
return 1;
}

Page45
EMBEDDED SYSTEM

3.10 Analog to digital converter


Analog to Digital Converter (ADC) is used to convert analog signal/voltage into its
equivalent digital number so that microcontroller can process that numbers and make it
human readable. The ADC characterized by resolution. The resolution of ADC indicates the
number of digital values. Let’s take example: In LPC2148 microcontroller we have in-built
10-bit ADC. So for 10-bit ADC resolution is 10-bit and maximum value will be 1024. This
means our digital value or discrete level lies between 0 to 1023.

3.10.1: ADC in LPC2148 ARM7 Microcontroller


The ADC in LPC2148 ARM7 Microcontroller is 10-bit successive approximation analog to
digital converter. The features are listed as:
LPC2148 has two inbuilt ADC Modules, named as ADC0 & ADC1.
ADC0 has 6-Channels (AD0.1-AD0.6).
ADC1 has 8-Channels (AD1.0-AD1.7).
ADC operating frequency is 4.5 MHz (max.), operating frequency decides the conversion
time.
Supports power down mode.
There are several registers which will be used to setup and configure ADC feature in
LPC2148. The two registers we will be concerning about: ADCR (A/D Control Register) and
ADGDR (A/D Global Data register).

Page46
EMBEDDED SYSTEM

Fig 3.12: Tabular column of register

3.10.2 Accelerometer
Accelerometer is an electromechanical device that measures the force of acceleration due to
gravity in g unit.
The ADXL335 measures acceleration along X, Y and Z axes and gives analog voltage output
proportional to the acceleration along these 3 axes.
Microcontrollers can process these voltages by converting them to digital signals using ADC.

Fig 3.13: Accelerometer

Page47
EMBEDDED SYSTEM

 Interfacing of Accelerometer program to LPC2148


#include "adc.h"
#include "Lcd.h"
#include <LPC214x.H> /* LPC214x definitions */
void init_adc0(void)
{
PINSEL1 = (PINSEL1 & ~(3 << 28)) | (1 << 28);//AD0.3
PINSEL1 = (PINSEL1 & ~(3 << 26)) | (1 << 26); //AD0.2.
PINSEL1 = (PINSEL1 & ~(3 << 24)) | (1 << 24);//AD0.1
}
unsigned short adc_read(unsigned char adc_num, unsigned char ch)
{
unsigned int i=0;
switch(adc_num)
{
case ADC0:
AD0CR = 0x00200D00 | (1<<ch); // select channel
AD0CR |= 0x01000000; // Start A/D Conversion
do
{
i = AD0GDR; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
break;
}
return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value
}
int main (void)
{
int tempx=0,tempy=0,tempz=0;
char buff[50];
init_lcd();
init_adc0();
command_write(0x01);
command_write(0x80);

Page48
EMBEDDED SYSTEM

putstring("technology");
delay(10000);
while(1)
{
tempx=adc_read(0,1);
tempy=adc_read(0,2);
tempz=adc_read(0,3);
command_write(0x01);
command_write(0x80);
sprintf(buff,"%d",tempx);
putstring(buff);
delay(100000);
command_write(0x87);
sprintf(buff,"%d",tempy);
putstring(buff);
delay(100000);
command_write(0xC0);
sprintf(buff,"%d",tempz);
putstring(buff);
delay(100000);
}
}

3.10.3Temperature Sensor
A temperature sensor is a device, usually an RTD (resistance temperature detector) or a
thermocouple, that collects the data about temperature from a particular source and converts
the data into understandable form for a device or an observer and so on.

Fig 3.14:Temperature sensor

Page49
EMBEDDED SYSTEM

 Interfacing of temperature sensor to LPC2148


#include "adc.h"
#include "Lcd.h"
#include <LPC214x.H> /* LPC214x definitions */
unsigned char buf[20];
void TEMP_MONITOR(void);
void init_adc0(void)
{
PINSEL1 = (PINSEL1 & ~(3 << 28)) | (1 << 28);//AD0.3
PINSEL1 = (PINSEL1 & ~(3 << 26)) | (1 << 26); //AD0.2.
PINSEL1 = (PINSEL1 & ~(3 << 24)) | (1 << 24);//AD0.1
}
void init_adc1(void)
{
PINSEL0 = ((1 << 8)) | (1 << 9);//AD0.3
}
unsigned short adc_read(unsigned char adc_num, unsigned char ch)
{
unsigned int i=0;
switch(adc_num)
{
case ADC0:
AD0CR = 0x00200D00 | (1<<ch); // select channel
AD0CR |= 0x01000000; // Start A/D Conversion
do
{
i = AD0GDR; // Read A/D Data Register
} while ((i & 0x80000000) == 0); // Wait for end of A/D Conversion
break;
case ADC1:
AD1CR = 0x00200D00 | (1<<ch); // select channel
AD1CR |= 0x09000000; // Start A/D Conversion

Page50
EMBEDDED SYSTEM

do
{
i = AD1GDR; // Read A/D Data Register
} while ((i & 0x90000000) == 0); // Wait for end of A/D Conversion
break;
}
return (i >> 6) & 0x03FF; // bit 6:15 is 10 bit AD value
}
int main (void)
{
init_lcd();
init_adc0();
command_write(0x01);
command_write(0x80);
putstring("ELECTRONIC VALVE");
command_write(0xC0);
putstring("USING WIFI");
delay(100000);
while(1)
{
TEMP_MONITOR();
}
}
void TEMP_MONITOR(void)
{
short adc_value = 0;
float volts = 0.0 ,temp = 0.0;
adc_value = adc_read (ADC0,CHANNEL_2);
volts = ( (adc_value * 3.3))/1023;
temp = volts * 100;
sprintf ((char * )buf, "TEMP:%.3fC ", temp);
command_write(0x01);
command_write(0x80);
putstring((char *)buf);

Page51
EMBEDDED SYSTEM

delay (1000);
if (temp>33)
{
command_write(0x01);
command_write(0x80);
putstring("MORE TEMPERATURE");
delay(1000000);
}
else
{
command_write(0x01);
command_write(0x80);
putstring("NORMAL TEMPERATURE");
delay(1000000);
}

3.10.4Timer
LPC2148 comes loaded with two 32-bit-Timer blocks. Each Timer block can be used as a
‘Timer’ (like for e.g. triggering an interrupt every ‘t’ microseconds) or as a ‘Counter’ and can
be also used to demodulate PWM signals given as input.

A timer has a Timer Counter(TC) and Prescale Register(PR) associated with it. When Timer
is Reset and Enabled TC is set to 0 and incremented by 1 every ‘PR+1’ clock cycles. When it
reaches its maximum value it gets reset to 0 and hence restarts counting. Prescale Register is
used to define the resolution of the timer. If PR=0 then TC is incremented every 1 clock cycle
of the peripheral clock. If PR=1 then TC is incremented every 2 clock cycles of peripheral
clock and so on. By setting an appropriate value in PR we can make timer increment or count
: every peripheral clock cycle or 1 microsecond or 1 millisecond or 1 second and so on.

 Interfacing timer program to LPC2148


#include<LPC214x.h>
#define LED (1<<22)
void timer0delay(unsigned int a);
//void timer0delay1(unsigned int b);

Page52
EMBEDDED SYSTEM

int main(void)
{
VPBDIV=0x01;
IO0DIR|=LED;
while(1)
{
IO0SET|=LED;
//while(1);
timer0delay(10);
IO0CLR|=LED;
timer0delay(200);
}
}
void timer0delay(unsigned int a) //1ms
{
T0CTCR=0X0000;
T0PR=59; // 1ms
T0MR0=a;
T0MCR=0x00000004;
T0TCR=0X02; //reset
T0TCR=0X01; //start
while(T0TC!=T0MR0);
T0TC=0;
}

Page53
EMBEDDED SYSTEM

Chapter 4
OUTCOMES
4.1 Robot with security
A robot is a machine—especially one programmable by a computer— capable of carrying
out a complex series of actions automatically. Robots can be guided by an external control
device or the control may be embedded within. Robots may be constructed to take on human
form but most robots are machines designed to perform a task with no regard to how they
look. By interfacing the above programs, we can run the robot.

4.2 Functioning of a Robot


The sub functions that are carried out by our designed robot include the following functions:
1. After running a program, the robot will run in forward direction.
2. The robot will stop if it detects any object or fire, and display on the LCD screen.
3. If object is detected, the buzzer will turn on.
4. If fire is detected, the LED will glow.
5. In order to restart the robot, the RFID security check will appear on LCD.
6. If the RFID card number matches with the security number in program, then it asks for
password.
7. The password should be entered with the help of keypad, if the password is correct, then
the access is granted to the robot for restarting.

4.2.1Interfacing robot program to LPC2148


#include <LPC214x.h>
#include "Lcdtask.h"
#include "Motor.h"
#include "Serial.h"
#include<string.h>
#include "scanrow.h"
#define ir_sensor (1<<11)
#define fire_sensor (1<<12)
#define LED (1<<13)
#define BUZZ (1<<7)

Page54
EMBEDDED SYSTEM

#define count 5000


#define Sw1 (1<<28)
#define Sw2 (1<<29)
#define Sw3 (1<<30)
#define ROW1 (1 << 20)
#define ROW2 (1 << 21)
#define ROW3 (1 << 22)
#define ROW4 (1 << 23)
#define COL1 (1 << 16)
#define COL2 (1 << 17)
#define COL3 (1 << 18)
#define COL4 (1 << 19)
#define FIRST_ROW 0
#define SECOND_ROW 4
#define THIRD_ROW 8
#define FOURTH_ROW 12
#define KEY_OUTPUT (COL1 |COL2 |COL3 | COL4);
#define KEY_INPUT (ROW1 |ROW2 |ROW3 | ROW4);
unsigned char code[8]="02557698";
int i=0;
unsigned char buff[10], buffer[4];
int ret;
unsigned char keyboard[] = {'0','4','8','C','1','5','9','D','2','6','A','E','3','7','B','F'};
unsigned char keypressed = 0;
unsigned char key=0;
int key_num = 0;
unsigned char scan_key(void);
void scan_row(unsigned char i);
int hold;
void delay2 (int i);
int RFID_Func(void);
void init_key(void);
void scan_row1(void);
void scan_row2(void);

Page55
EMBEDDED SYSTEM

void scan_row3(void);
void scan_row4(void);
int keypad_arm (void);
void PASSWORD();
void delay (int i);
void ir_sen(void);
void fire_sen(void);
int rfid1(void);
unsigned char code1[8]="02557698";
int a=0;
unsigned char buff1[10];
void init_key()
{ IO1DIR = (ROW1 |ROW2 |ROW3 | ROW4);
IO1DIR = ~(COL1 |COL2 |COL3 | COL4); //columns as INPUT
IO1SET = (ROW1 |ROW2 |ROW3 | ROW4);
}
unsigned char scan_key()
{ scan_row1();
scan_row2();
scan_row3();
scan_row4();
return key;
}
void scan_row(unsigned char i)
{ if(!(IO1PIN & COL1))
{
while(!(IOPIN1 & COL1));
{
// continue;
}
key_num = keyboard[0+i];
key = keyboard[0+i];
keypressed = 1;
}

Page56
EMBEDDED SYSTEM

else if(!(IOPIN1 & COL2))


{
while(!(IOPIN1 & COL2));
{
// continue;
}
key_num = keyboard[1+i];
key = keyboard[1+i];
keypressed = 1;
}
else if(!(IOPIN1 & COL3))
{
while(!(IOPIN1 & COL3));
{
// continue;
}
key_num = keyboard[2+i];
key = keyboard[2+i];
keypressed = 1;
}
else if(!(IOPIN1 & COL4))
{
while(!(IOPIN1 & COL4));
{
// continue;
}
key_num = keyboard[3+i];
key = keyboard[3+i];
keypressed = 1;
}
}
void delay2 (int i)
{ int j,k;
for (j=0;j<i;j++)

Page57
EMBEDDED SYSTEM

for (k=0;k<1024;k++);
}
void delay(int i)
{ int j,k;
for (j=0;j<i;j++)
for (k=0;k<1024;k++);
}
void ir_sen(void)
{ if((IO0PIN & ir_sensor)==0)
{ motor_stop();
command_write(0x01);
command_write(0x80);
putstring("object detected");
IO0SET |= LED; // led on
delay(10000);
IO0CLR |= LED; // led off
delay(10000);
rfid1();
}
}
void fire_sen(void)
{ if((IO0PIN & fire_sensor)==0)
{ motor_stop();
command_write(0x01);
command_write(0x80);
putstring("fire detected");
IO0SET |= BUZZ; // led on
delay(10000);
rfid1();
}
}
int rfid1(void)
{ int k=0;
command_write(0x01);

Page58
EMBEDDED SYSTEM

command_write(0x80);
putstring("swipe");
delay(10000);
command_write(0x01);
command_write(0x80);
putstring("the card");
while(1)
{
for(k=0;k<8;k++)
{ buff1[k]=uart0_getkey();
}
buff1[8]='\0';
command_write(0x01);
putstring(buff1);
delay(5000);
if(strcmp(buff1,"02557698")==0)
{ command_write(0x01);
command_write(0x80);
putstring("valid user");
delay(10000);
PASSWORD();
}
else{
command_write(0x01);
command_write(0x80);
putstring("invalid user");
delay(10000);
}
}
}
void PASSWORD()
{ command_write(0x01);
command_write(0x80);
putstring("ENTER PASSWORD");

Page59
EMBEDDED SYSTEM

delay(10000);
command_write(0xC0);
while(1)
{ while(a<4)
{ hold=scan_key();
if(keypressed==1)
{ putchar(hold);
keypressed=0;
buffer[a++]=hold;
}
}
buffer[4]=0;
if(strcmp(buffer,"1234")==0)
{ command_write(0x01);
command_write(0x80);
putstring("valid");
delay(10000);
motor_clk();
}
else{ command_write(0x01);
command_write(0x80);
putstring("invalid");
delay(10000);
}
}
}
int main (void)
{ IO1DIR&=~Sw1;
IO1DIR&=~Sw2;
IO1DIR&=~Sw3;
IO1DIR |= In1;
IO1DIR |= In2;
IO1DIR |= In3;

Page60
EMBEDDED SYSTEM

IO1DIR |= In4;
IO0DIR&=~ir_sensor;
IO0DIR&=~fire_sensor;
IO0DIR |= LED;
IO0DIR|=BUZZ;
init_lcd();
init_key();
while(1)
{ if(!(IO1PIN & Sw1))
{motor_clk();
ir_sen();
fire_sen();
}
else if (!(IO1PIN & Sw2))
{ motor_anticlk();
ir_sen();
fire_sen();
}
else if (!(IO1PIN & Sw3))
{ motor_stop();
ir_sen();
fire_sen();
}
}
}

Page61
EMBEDDED SYSTEM

Conclusion and Future Improvement

Conclusion
Many embedded systems have requirements that differ significantly both in details and in
scope from desktop computers. In particular, the demands of the specific application and the
interface with external equipment may dominate the system design. Also, long life-cycles and
in some cases extreme cost sensitivity require more attention to optimization based on these
goals rather than maximizing the computational throughput.

Scope for improvement:


1. Difficult to change configurations and features -Once an embedded system is deployed (or
finalized), it will be difficult to change its configuration - both its hardware and software..
2. Issue of scalability -Because it is difficult to change configuration, an embedded system
cannot be easily scaled up as demand/scope changes.
3. Limitation of hardware - There is always a limitation on our software design.
4. Applied for a specific purpose - If it is decided to "rehash" an existing embedded system
for a completely different purpose, it will normally result in significant change(s) in either or
both its hardware or/and software.

Page62
EMBEDDED SYSTEM

Outcomes

I have carried out my internship my in Technofly Solutions. I have learnt about Embedded
Systems, ARM LPC-2148 and Arduino microcontroller. Designed an embedded system to
control robotic motions using various sensors.
Outcomes of internship are
1. Enhancement the client interface to make it more intuitive and user-friendly.
2. Enhancements of clients to work on all types of clients.
3. Enhancement of embedded system to control more types of embedded systems.
4. Handling of error scenarios.

I have learnt in a friendly environment and all my friends and mentors were supportive to
me.
I have also learnt about interfacing of LED, LCD, Switch, DC Motor, Sensors, RFID card,
Wi-Fi, GSM, Buzzer and UART.
I have also learnt to control speed of DC motor and to control brightness of LED using
PWM.
I have done mini-project which involves the control of movement of Robot using LED,
LCD, Switch, DC Motor, Sensors, RFID card, Buzzer and 4X4 keyboard.

Page63
EMBEDDED SYSTEM

References
1. “Computers as Components: Principles of Embedded Computing Systems Design” by
Wayne Wolf.
2.”Embedded Systems: A Contemporary Design Tool” by James K Peckol.
3.”Embedded Systems: Design and Applications” by Barrett

Page64
EMBEDDED SYSTEM

Page65

You might also like