0% found this document useful (0 votes)
184 views

Chapter 3

The document describes the software implementation for an embedded system using an LPC2148 microcontroller. It discusses using the Keil μVision IDE for writing code in C and debugging. Programs are compiled to create a hex file then dumped onto the microcontroller using Flash Magic. Serial communication with peripherals like GSM and GPS modules is implemented using the microcontroller's UARTs and registers like UOTHR and UORBR for transmission and reception.

Uploaded by

nikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
184 views

Chapter 3

The document describes the software implementation for an embedded system using an LPC2148 microcontroller. It discusses using the Keil μVision IDE for writing code in C and debugging. Programs are compiled to create a hex file then dumped onto the microcontroller using Flash Magic. Serial communication with peripherals like GSM and GPS modules is implemented using the microcontroller's UARTs and registers like UOTHR and UORBR for transmission and reception.

Uploaded by

nikhil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

SOFTWARE DESCRIPTION| Chapter 3

CHAPTER 3
SOFTWARE DESCRIPTION
3.1.

Software Implementation for LPC2148


The software implementation plays an important role in designing an

embedded system as equally as the hardware implementation. In the software


implementation the programming of the microcontroller is done which is to achieve
the required behavior of an embedded system. In other words an embedded system
can be described as the software controlled hardware system where the complex
functionalities of a system are designed by a user friendly software interface.
3.2.

Programming Environment for ARM7


The programming of the micro controller as per the requirement can be done

in number of tools available as open source in the market. Among the number of the
tools for programming the ARM7 the Keil vision is used in the project for writing
the code. The vision IDE from the Keil combines the project management and make
facilities and source code editing with program debugging and complete simulation in
one powerful environment. It is easy to use and helps to quickly create embedded
program that work. The Vision editor and debugger are integrated in a single
application that provides a seamless embedded systems project development. The
programming language used in the project is Embedded C. The code is written and
complied to create a hexadecimal file that is to be dumped in to the microcontroller in
Keil tool. The successfully compiled source code in dumped in to the microcontroller
by using another tool called Flash Magic.
3.3.

Keil Vision2
This is an IDE (Integrated Development Environment) that helps you write,

compile, and debug embedded programs. It encapsulates the following components:

A project manager
A make facility
Page 50

SOFTWARE DESCRIPTION| Chapter 3

Tool configuration
Editor
A powerful debugger
To get start here are some several example programs

1.1.1. Building an Application in Vision2


The steps in programming in the Keil environment are as follows:

STEP1: Open the Keil vision tool by clicking on its icon then the
environment will be open as shown in the figure 3.1.

Figure 3.1. Keil Environment.

STEP2: In the tabs listed in the taskbar select the click on the project menu
and select new then a pop up window appears to give the name for the project.
Select a name and save it with which the project available in storage.

STEP3: After creating the path for saving the project a pop up window will be
appear to select the micro controller on which the programming is going to
done.

Page 51

SOFTWARE DESCRIPTION| Chapter 3

STEP4: From the list of the companies as listed in the window select the NXP
as the maker of the LPC2148 is Philips as shown in the figure 3.2.

Figure 3.2. Selection of the Manufacturer.

STEP5: After selecting the NXP click on the plus symbol left to the NXP to
see the step2 list of controllers manufactured by the Philips. From the list
select the LPC2148 as it is the controller used in the project as shown in
figure 3.3.

STEP6: After clicking ok by selecting the controller a pop up window will


appeared asking to add the start up code for LPC2148 which is a boot code
helps to start programming hazel free. Click on yes in the pop up window.

STEP7: After selecting yes on the pop up window asked for adding startup
code then a work environment window will be opened as before. In the left
side of the window right click on the tab target 1 and from the dropdown menu
select the "options for target1 menu". Then a popup window appears as shown
in the figure 3.4. In the window by selecting the target tab the oscillating
frequency will be set as required.
Page 52

SOFTWARE DESCRIPTION| Chapter 3

STEP8: After selecting the oscillating frequency click on the output tab and
tick the box left to the option create Hex fie in order to create a Hex file for
dumping in to the microcontroller after debugging as shown in the figure 3.4.

Figure 3.3. Selection of the Microcontroller.

STEP9: After selecting the option to create a Hex file, click on ok then work
environment window opens then click on the file menu and select the new
then an empty file opens where program is written.

STEP10: After writing the program click on the save button. Then click on
the option source group1 and click on the add files to source group1. Then a
list of programs available to add will be displayed. Then by selecting the
current file the program is added for debugging.

STEP11: After adding the program file to the source group then click on the
project menu and select the option build target then the program will be
compiled and after ensuring that no error and on warning a pop up window
will opens saying that program build successfully as shown in the figure 3.5.

Page 53

SOFTWARE DESCRIPTION| Chapter 3

STEP12: Now the program is ready to be dumped into the microcontroller


and by clicking on the debug section of the work we can also able to verify the
behavior of the program.

Figure 3.4. Selecting Frequency and the Options for Creating Hex File.

Page 54

SOFTWARE DESCRIPTION| Chapter 3


Figure 3.5. A Program showing Successful Compilation in Keil.

STEP13: After successful completion of building a program the HEX file is


available in the project name folder which can be dumped in to the micro
controller.
After creating the Hex files of the program it is ready to be dumped in to the

microcontroller. The tool used for dumping the Hex files in to the microcontroller is
Flash Magic.

Flash Magic

3.4.

The Flash Magic tool is a open source software that allows us to port the
hexadecimal codes in to the microcontroller. The flash magic supports over a large
range of the microcontrollers widely used. The in system programming feature of the
LPC2148 enables the user not to use any separate device for the porting of the Hex
files.
The steps in the porting of the hexadecimal codes in to the LPC2148 are as
follows:
a. Interface RS232 Cable between RS232 Serial Port of PC and Board UART-0
(CN3).
b. Supply power into board in the case, we can see red LED1 is in status O.
c.

Set jumper BR4 (INT1) in ON state.

d. Run Program Flash Magic, it will display result as shown in figure 3.6.
e. Select COM port corresponding with (in this example, it is COM1). Start
setting the initial values into program as desired, so we configure values into
program as follows:

Set the baud rate to 9600.


Set Device to be LPC2148.
Set Interface to be None ISP.
Set Crystal Oscillator with MHz corresponding with the value internal Board.
In this case, it is 12.000MHz, so we must set to be 12.

Page 55

SOFTWARE DESCRIPTION| Chapter 3


f. Press ISP LOAD Switch (S1) and RESET Switch (S2) on Board ARM7
LPC2148 development Board to reset MCU to run in Boot Loader following
the processes:

Press ISP LOAD Switch (S1) and hold.


Press RESET Switch (S2) while ISP LOAD Switch (S1) is being held.
Remove RESET Switch (S2) but ISP LOAD Switch (S1) is being held.
Lastly, remove ISP LOAD Switch (S1).
Select the format of the erasing of the data should be Erase all flash + code
read port.
The entire processing of burning the data to the microcontroller is as shown in

figure3.6.

Figure 3.6. Porting Program into the Controller by Flash Magic.


After porting the program in to the microcontroller the system is ready to use
and the section of porting program into controller play an important role as the failure
of which can cause catastrophic damage to the controller. Hence the cable connections
and the switches are taken care properly to ensure the correct operation. The main part
of code that is used in the design of the embedded system in this project is broadly
divided in to three sections which are communication and interfacing sensors and
Page 56

SOFTWARE DESCRIPTION| Chapter 3


programming external interrupts. In the next sections these are explained in a clear
manner.
However the number of the peripherals may be different but the
communication techniques that are used for them are the same which supported by the
controller. The serial communication only used in the project as the number of the
peripherals connected are matched with the number of the UART's that are supported
by the LPC2148.
3.5.

Serial Communication in LPC2148


The serial communication has played a major role in designing the project as

the communication with every external peripheral that are used to form a
communication network is communicated with the serial protocol. The GSM module
used in the project connected to the UART1 for both reception and transmission with
the micro controller. The GPS module also communicates in the serial manner with
the reception of the location information. The GPS module interfaced with the
UART0 of the micro controller that too with the Rx pin of the UART0. The
communication between the PC and the microcontroller is done by using the
transmitter pin of the UART0 as there is only one way communication between the
PC and the microcontroller. The registers used for the serial communication in the
LPC2148 and the programming steps are as follows:

UOLCR: The line control register helps to set the pattern of the data stream
that is the number of bits and the parity considered and the number of stop
bits. In the project the value is set to 0x83 as the pattern is considered with no
parity and one stop bit.

UODLL and UODLM: The UODLL and the UODLM registers are used to set
the baud rate with the transmission or the reception is going to take place and
for the baud rate of 9600 in this project the UODLL is set to 0x62.

UOTHR: The UOTHR register is the transmit hold register which contains the
data to be transmitted. To check if any data is available in the UOTHR the

Page 57

SOFTWARE DESCRIPTION| Chapter 3


UOLSR register is and with the value of 0x20 which indicates that the data is
available for transmission.

UORBR: The UORBR is the receive buffer register which is used to receive
data same as the UOTHR. To check if any data is available for the reception
UOLSR register value is and with the value of 0x01 which indicates the status
of the receiving data.

UOLSR: The UOLSR register is the line status register which contains the
important data about the transmit and receive data ready bits for
communication.
The registers discussed above are the just needed registers to establish a

simple communication between two terminals using microcontroller. Similarly


theUART1 contains the same registers with a change of the number of the UART like
U1LCR and U1LSR. The flow chart for transmitting data is as shown in the flowchart
3.1.

Page 58

SOFTWARE DESCRIPTION| Chapter 3

Flowchart 3.1. Serial Communication of Transmission in LPC2148.


The data to be transmitted from the controller uses above registers in basically
for the transmission of the data as shown in flowchart 3.1. However advanced
registers like UOIER, UOACR are available for advanced applications. The data from
the PIR, IR sensors and metal detector and the commands to GSM modem are
transmitted in the above pattern. The flow chart for the reception of the data from the
serial port is as shown in the flowchart 3.2. The reception also uses the same data rate
and the data pattern in order to process.
The below flow chart is used for reception of the GPS data and to send the
GSM messages from the serial port to the LCD. The entire communication between
the controller to its peripherals is follows the described flow above. Apart from the

Page 59

SOFTWARE DESCRIPTION| Chapter 3

Flowchart 3.2. Serial Communication of Receiver in LPC2148.

Page 60

You might also like