Beruflich Dokumente
Kultur Dokumente
7. Mailbox
9. Flashing of LED
The ARM7 LPC2148 Syllabus Board based on a 32/16 Bit ARM7TDMI-s CPU with
real time Emulation and Embedded Trace support, that combines with microcontroller with
embedded high speed 512KB flash memory. It can also work in 16-bit Thumb Mode.
With the interfaced peripherals and on board peripherals, plentiful practical codes can be
implemented with ARM7 LPC2148 Syllabus Board. The board has fast and reliable tools
that can satisfy the needs of experienced engineers and beginners alike.
ARM7 LPC2148 Syllabus Boards achieve their small size through Modern SMD
technology and Multilayer Design. All Controller signals and ports extend from the
controller to high density pitch Connectors of the board.
ARM7 LPC2148 Syllabus Board Hardware Manual Describes the boards design and
functions. Precise Specifications for the NXP LPC2148 Microcontroller can be found in
the enclosed Micro-controller Data sheet/Users Manual. In this hardware manual,
schematic diagrams and Block Diagrams are attached.
IAR Embedded Workbench is the preferable IDE for this VSK-2148 board.
VLEDD 02
The VLEDD 02 boards is having 12 LEDs. The LEDs are controlled by two
transistors. The operating voltage can be varied as per the industrial requirement. The possible
voltages are 3.3V, 5V and 12V. The operational voltage can be selected depending on the
hardware design.
The LED sequence D1, D2, D3, D7, D8 and D9 are controlled by the transistor Q1 and
the sequence D4, D5, D6, D10, D11 and D12 are controlled by the transistor Q2.
The board is also having an LDR. The LEDs can be used to lighten the zone with this output of
the LDR.
Vi XBB
The Xbee board is a Wireless board that has to be interfaced with the controller. It can be
interfaced either by RS232 cable or USB cable. A switch is provided to select the mode
of communication.
About the Software
IAR EMBEDDED WORKBENCH FOR ARM
The IDE is the framework where all necessary tools are seamlessly integrated:
FEATURES
PROJECT MANAGEMNET
The IDE comes with functions that will help you to stay in control of all project modules
,for example, C or C++ source code files, assembler files, include files, and other related
modules. You create workspaces and let them contain one or several projects. Files can
be grouped, and options can be set on all levelsproject, group, or file. Changes are tracked so
that a request for rebuild will retranslate all required modules, making sure that no executable
files contain out-of-date modules. This list shows some additional
features:
Project templates to create a project that can be built and executed out of the box
for a smooth development startup
Hierarchical project representation
Source browser with a hierarchical symbol presentation
Options can be set globally, on groups of source files, or on individual source files
The Make command automatically detects changes and performs only the required
operations.
Text-based project files
Custom Build utility to expand the standard tool chain in an easy way
Command lines build with the project file as input.
FLASH MAGIC
Flash Magic provides a clear and simple user interface to these features and more as
described in the following sections. Under Windows, only one application may have
access the COM Port at any one time, preventing other applications from using the COM
Port. Flash Magic only obtains access to the selected COM Port when ISP operations are
being performed. This means that other applications that need to use the COM Port, such
as debugging tools, may be used while Flash Magic is loaded.
Win X talk
Win X talk software is windows software that allows send and receives the data from
serial port. COM port configuration is variable.
Working with IAR Embedded Workbench
1. To create a new project, choose Project>Create New Project. The Create New
Project
Dialog box appears, which lets you base your new project on a project template.
2. Make sure the Tool chain is set to ARM, and click OK.
3. Select the project template Empty project, and click ok button. This simply
creates an empty project that uses default project setting.
4. In the standard Save As dialog box that appears, specify where you want to
place your project file, that is, in your newly created projects directory. Type
your project name in the File name box, and click Save to create the new
project. E.g. LED.
1. In the Workspace window, select the destination to which you want to add a
source file; a group or, as in this case, directly to the project.
2. Choose Project>Add Files to open a standard browse dialog box. Locate the files
led.c Select them in the file selection list, and click Open to add them to the project.
To save your work space, Choose File>Save Workspace and specify where you
want to place your workspace file. In this tutorial, you should place it in your newly
created project directory. Type LED in the File name box, and click save button.
Now you will set the project options. For application projects, options can be set on all
levels of nodes. First you will set the general options to suit the processor configuration
in this tutorial. Because these options must be the same for the whole build configuration,
they must be set on the project node.
1. Select the project folder icon LED - Debug in the Workspace window and choose
Project>Options. Then select Output Converter in the Category list to display the
linker option pages.
The Output options are used for specifying details about the output format and the level
of debugging information included in the output file.
Select option on the popup menu. After selecting popup menu window shows as given
below. Select output format as Intel Extended, output file in the format of .hex format.
Select the linker file menu, linker configuration file available at project directory. To
Compile your Project, Choose Project>Rebuild ALL
If your project has no error, then it will show Building successfully and the Hex file will
be generated.
HOW TO CREATE RTOS PROGRAMS
1. To create a new project, choose Project>Create New Project. The Create New
Project
Dialog box appears, which lets you base your new project on a project template.
2. Make sure the Tool chain is set to ARM, and click OK.
3. Select the project template Empty project, and click ok button. This simply creates
an empty project that uses default project settings.
4. In the standard Save As dialog box that appears, specify where you want to place
your project file, that is, in your newly created projects directory. Type your
project name in the File name box, and click Save to create the new project. E.g.
LED.
RTOS Package comprises set of C files and headed files. C Files are classified as
Application file, CPU files, C/OS-II Files and BSP.
In this project, we have to split the C files according to the functions. So these files are
integrated under separate folder.
APP
BSP
CPU
UCOS-II
- PORT
- SOURCE
1. Creating several groups is a possibility for you to organize your source files
logically according to your project needs.
2. To create new group Choose Project>Add Group.
3. Type your group name and click ok button.
Now create APP group
Under ucos-ii group, create two group named as source and ports.
Add Corresponding files to above mentioned group
3. SETTING PROJECT OPTIONS
Now you will set the project options. For application projects, options can be set
on all levels of nodes. First you will set the general options to suit the processor
configuration in this tutorial. Because these options must be the same for the whole build
configuration, they must be set on the project node.
1. Select the project folder icon UART - Debug in the Workspace window and
choose Project>Options. Then select C/C++ Compiler where you have select
CODE menu, enable ARM Processor Mode.
After that Select Preprocessor menu from same window.
At Preprocessor, we have to include all the directories as given below
$PROJ_DIR$
$PROJ_DIR$\..\uCOS-II\ports
$PROJ_DIR$\..\uCOS-II\source
$PROJ_DIR$\..\BSP
$PROJ_DIR$\..\CPU
For Creating the Hex file, we choose output file format as given below.
Select Linker file as given below.
If there is no error, Message window shows like this. Now Hex file is created.
ISP UTILITY
NXP Semiconductors produce a range of Microcontrollers that feature both onchip
Flash memory and the ability to be reprogrammed using In-System Programming
technology. Flash Magic is Windows software that allows easy access to all the ISP
features provided by the devices. These features include:
Erasing the Flash memory (individual blocks or the whole device)
Programming the Flash memory
Modifying the Boot Vector and Status Byte
Reading Flash memory
Performing a blank check on a section of Flash memory
Reading the signature bytes
Reading and writing the security bits
Direct load of a new baud rate (high speed communications)
Sending commands to place device in Boot loader mode
Under Windows, only one application may have access the COM Port at any one
time, preventing other applications from using the COM Port. Flash Magic only obtains
access to the selected COM Port when ISP operations are being performed. This means
that other applications that need to use the COM Port, such as debugging tools, may be
used while Flash Magic is loaded. Note that in this manual third party Compilers are
listed alphabetically. No preferences are indicated or implied.
Procedure:
1. Select the COM Port
2. Select the Baud Rate
3. Select Device ( Eg.LPC2148)
4. Interface None ISP
5. Select Osc. Frequency 12Mhz
6. Enable Erase Blocks used by Hex files
7. Select the Hex File to be downloaded.
8. Click start
Processing..
Instruction:
Follow the given steps for getting started with the syllabus experiments:
1. Install IAR Embedded Workbench IDE software and Win X-Talk software.
2. After successful installation of IAR, Install Flash Magic.
3. Connect the RS232 cable/USB cable provided to the PC and the LPC2148
Syllabus Board, and Power on the VSK-2148 Development Board.
4. If you are using USB cable, then install the required USB to Serial driver (FTDI
for on beard converter).
5. Search/Set the COM Port no here :
Start >> My Computer >> Manage (on right click) >> Device Manager >> Ports
(COM & LPT).
6. Now, Identify the Mode-Select-Switch provided on the VSK 2148 Board marked
with the text PROG & EXEC.
PROG: Programming Mode used for downloading the code/program into
the flash memory.
EXEC: Execution Mode used for executing program after downloading.
7. After selecting any position (PROG / EXEC) press the reset switch provided on
the board.
8. After setting the proper COM port number & selecting the Mode-Select-Switch
position properly, Extract the VSK-2148 SOURCE CODES V 1.0 (WinRAR
archive) file.
9. Open the project and follow the instructions given in each experiment.
Experiment 1
Study of ARM Evaluation System
Aim
To learn about the evolution, core features, general characteristics and applications of
ARM processors.
Theory
The LPC2148 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with
realtime emulation and embedded trace support, that combines the microcontroller with
embedded high speed flash memory ranging from 32 kB to 512 kB. A 128-bit wide
memory interface and unique accelerator architecture enable 32-bit code execution at the
maximum clock rate. For critical code size applications, the alternative 16-bit Thumb
mode reduces code by more than 30 % with minimal performance penalty.
Due to their tiny size and low power consumption, LPC2148 are ideal for applications
where miniaturization is a key requirement, such as access control and point-of-sale. A
blend of serial communications interfaces ranging from a USB 2.0 Full Speed device,
multiple UARTS, SPI, SSP to I2Cs and on-chip SRAM of 8 kB up to 40 kB, make these
devices very well suited for communication gateways and protocol converters, soft
modems, voice recognition and low end imaging, providing both large buffer size and
high processing power. Various 32-bit timers, single or dual 10-bit ADC(s), 10-bit DAC,
PWM channels and 45 fast GPIO lines with up to nine edge or level sensitive external
interrupt pins make these microcontrollers particularly suitable for industrial control and
medical systems.
FEATURES
16/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.
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.
In-System/In-Application Programming (ISP/IAP) via on-chip boot-loader
software.
Single flash sector or full chip erase in 400 ms and programming of 256 bytes in 1ms.
Embedded ICE RT and Embedded Trace interfaces offer real-time debugging with
the on-chip Real Monitor 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 LPC2146/8 provides 8 kB of on-chip RAM accessible to USB by DMA.
One or two (LPC2141/2 vs. LPC2144/6/8) 10-bit A/D converters provide a total of
6/14 analog inputs, with conversion times as low as 2.44 s per channel.
Single 10-bit D/A converter provide variable analog output.
Two 32-bit timers/external event counters (with four capture and four compare
channels 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 45 of 5 V tolerant fast general purpose I/O pins in a tiny LQFP64 package.
Up to nine edge or level sensitive external interrupt pins available.
60 MHz maximum CPU clock available from programmable on-chip PLL with
settling time of 100s
On-chip integrated oscillator operates with an external crystal in range from 1
MHz to 30 MHz and with an external oscillator up to 50 MHz
Power saving modes include idle and Power-down.
Individual enable/disable of peripheral functions as well as peripheral clock
scaling for additional power optimization.
Processor wake-up from Power-down mode via external interrupt, USB, Brown-
Out Detect (BOD) or Real-Time Clock (RTC).
Single power supply chip with Power-On Reset (POR) and BOD circuits:
o CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O
ARCHITECTURE OVERVIEW
The LPC2148 consists of an ARM7TDMI-S CPU with emulation support, the ARM7
Local Bus for interface to on-chip memory controllers, the AMBA Advanced Highperformance
Bus AHB for interface to the interrupt controller, and the VLSI Peripheral
Bus (A compatible superset of ARMs AMBA Advanced Peripheral Bus) for connection
to on-chip peripheral functions. The LPC2148 configures the ARM7TDMI-S processor
in little-endian byte order. AHB peripherals are allocated a 2 megabyte range of
addresses at the very top of the 4 gigabyte ARM memory space. Each AHB peripheral is
allocated a 16 kB address space within the AHB address space. LPC2148 peripheral
functions are connected to the VPB bus. The AHB to VPB Bridge interfaces the VPB bus
to the AHB bus. VPB peripherals are also allocated a 2 megabyte range of addresses,
beginning at the 3.5 gigabyte address point. Each VPB peripheral is allocated a 16 kB
address space within the VPB address space. The connection of on-chip peripherals to
device pins is controlled by a Pin Connect Block. This must be configured by software to
fit specific application requirements for the use of peripheral functions and pins.
ARM7TDMI PROCESSOR
BLOCK DIAGRAM
Experiment 2
Theory
1. ADC
The LPC 2148 has 10-bit successive approximation analog to digital converter. Basic
clocking for the A/D converters is provided by the VPB clock. A programmable divider
is included in each converter, to scale this clock to the 4.5 MHz (max) clock needed by
the successive approximation process. A fully accurate conversion requires 11 of these
clocks. The ADC cell can measure the voltage on any of the ADC input signals.
VSK-2148 has one potentiometer for working with A/D Converter. Potentiometer outputs
are in the range of 0V to 3.3V. Short the J4 jumper for reading the Potentiometer
value by ADC.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name dac.c (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build the
program
4. Follow the procedures in How to Download a Code to Our Controller to
download your code.
Program
/* - - - - - HEADER FILES - - - - - */
#include<nxp/iolpc2148.h>
#include<stdio.h>
#include "uart.h"
#include "adc.h"
/* - - - - - User defined Variables - - - - - */
unsigned int val=0,volt;
/* - - - - - MAIN FUNCTION STARTS HERE - - - - - */
void main(void)
{
PINSEL1_bit.P0_28=1;
init(); /* Call the initialization function. Function definition is in uart.h */
uart_inital(); /* Call the uart function. Function definition is in uart.h */
adc(); /* Call adc function. Function definition is in adc.h */
PINSEL1=0X01000000; /*ADC0.1*/
while(1)
{
while(AD0DR_bit.DONE==0); /* Start A/D Conversion */
val=AD0DR1_bit.RESULT;
printf("adc = %d \r\n",val);
}
}
Procedure
Program
/* - - - - - Header Files - - - - - */
#include<nxp/iolpc2148.h>
/*The settling time of the DAC is 2.5 s and the maximum current is 350 A when BIAS=1*/
#define DAC_BIAS 0x00010000
/* - - - - - delay routine - - - - - */
void delay(unsigned int x)
{
for(int i=0;i<=x;i++);
}
/* - - - - - main function - - - - -*/
void main()
{
PINSEL1=0X00080000;
while(1)
{
/* The Datas has to be passed or moved on to the VALUE bits i.e 15 - 6 and the result will be
(VALUE/(1024*Vref)) */
DACR = (1023 << 6) | DAC_BIAS;
delay(100000);
delay(100000);
delay(100000);
delay(100000);
/* The Datas has to be passed or moved on to the VALUE bits i.e 15 - 6 and the result will be
(VALUE/(1024*Vref)) */
DACR = (0 << 6) | DAC_BIAS;
delay(100000);
delay(100000);
delay(100000);
delay(100000);
}
}
Output
output pin are connect in P9.
view the output in CRO .
Experiment 3
Interfacing LED and PWM
Aim
To write a C program to generate a PWM and to vary the brightness of the LED
depending on the duty cycle.
Theory
The PWM is based on the standard timer block and inherits all of its features, although
only the PWM function is pinned out on the LPC2148. The timer is designed to count
cycles of the peripheral clock (PCLK) and optionally generate interrupts or perform other
actions when specified timer values occur, based on seven match registers. The PWM
function is also based on match register events. VLEDD-02 board conned to VSK-2148 using
port P4,P5.
Procedure
1. Follow the steps 1 of How to create a New project
2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 and 3 of How to create a New Project to compile and build the
program
4. Follow the procedures in How to Download a Code to Our Controller to download
your code.
Program
/* - - - - - Header Files - - - - - */
#include<nxp\iolpc2148.h>
/* - - - - - User Defined Variables - - - - - */
int x;
/* - - - - - delay Routine - - - - - */
void delay()
{
for( int i=0;i<=1500;i++);
}
/* - - - - - PWM function - - - - - */
void pwm(int x)
{
PINSEL0 = 0X00088005; /* To select Port pin P0.8 and also p0.9 as pwm4 and pwm6 */
PWMPR = 0X00000000; /* To set Prescaler register value to one */
PWMPCR = 0X00004400; /* To select pwm2 as single edge controlled */
PWMMCR = 0X00000002; /* To Reset pwm timer counter when matches occur */
PWMMR0 = 1200 ; /* To set total time period of pwm output */
PWMMR2 = x;
PWMMR6 = 600;
PWMTCR = 0X00000002; /* To reset pwm timer */
PWMTCR = 0X00000009;
}
/* - - - - - main function starts here - - - - - */
void main()
{
PINSEL1_bit.P0_21=1;
IO0DIR_bit.P0_21=1;
PINSEL2 = 0X00000000;
IO1DIR = 0XFF000000;
int i;
while(1)
{
for(i=0;i<=1200;i++)
{
pwm(x);
delay();
x=x+1;
if(i>=1200)
{
x=0;
}
}
}
}
Procedure To View the Result
Output:
Aim
To develop a C-Language program for reading the RTC, convert into decimal and to
display it.
Theory
RTC
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.
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
}
/* Hint: ARM processor crystal freq. = 12 MHz = 12,000,000 Hz
RTC crystal freq. = 32.768 KHz = 32,768 Hz
Calculate,
PREINT = (12,000,000 / 32,768)-1 = 365 in Decimal = 0x16D in Hex.
PREFRAC = 12,000,000 - (365+1)*32,768 = 6912 in Decimal = 0x1B00 in Hex.
And, for
CIIR = Counter Increment Interrupt Register,
CCR = Clock Control Register
ILR = Interrupt Location Register
Refer, "Volume 1: LPC214x User Manual" PDF Document */
/* - - - - - Read Clock - - - - - */
void Read_rtc( void )
{
printf("TIME--->%d:%d:%d\t",HOUR,MIN,SEC);
printf("DATE--->%d:%d:%d\n",DOM,MONTH,YEAR);
}
/* - - - - - main function starts - - - - - */
void main()
{
baudrate_settings(); /* call function baudrate_settings */
RTC_Init(); /* call function RTC_Init */
RTCStart(); /* call function RTCStart */
while(1)
{
Read_rtc(); /* call function Read_rtc */
}
}
Output
view the output in PC-Hyper Terminal
Experiment 5
Interfacing Keyboard and LCD
Aim
To develop a C-Language program for displaying the Key pressed in the Keypad in the
LCD module. The display should come in the desired line and column.
Theory
Keypad
The Matrix keyboard is used to minimize the number of I/O lines. Normally it is
possible to connect only one key or switch with an I/O line. If the number of keys in the system
exceeds the more I/O lines are required. To reduce the number of I/O lines the keys are
connected in the matrix circuit. Keyboards use a matrix with the rows and columns made
up of wires. Each key acts like a switch. When a key is pressed a column wire makes
contact with row wire and completes a circuit.
For example 16 keys arranged in a matrix circuit uses only 8 I/O lines.
In VSK-2148 board Dip-switch and matrix keypad lines are multiplexed.
LCD
Liquid crystals are a phase of matter whose order is intermediate between that of a liquid
and that of a crystal. The molecules are typically rod-shaped organic matters about 25
Angstroms in length and their ordering is a function of temperature. The molecular
orientation can be controlled with applied electric fields.
CHARACTER BASED LCD
A standard character LCD is probably the most widely used data Visualization
component.
Character LCDs are available in various kinds of models.
1. No. Of characters x Lines: 8x1, 16x1, 16x2, 16x4, 20x4, 40x4
2. Color: Yellow, Green, Gray, Blue
The Character LCD communicates with the microcontroller via 8 bit data bus. The pin
description for character LCD is given below.
VCC, GND AND V0 - While VCC and VSS provide +5V and ground, respectively; V0
is used for controlling LCD contrast.
EN (Enable) - The LCD to latch information presented to its data pins uses the enable
pin. When data is supplied to data pins, a high to low pulse must be applied to this pin in
order for the LCD to latch in the data present at the data pins.
D0 D7 - The 8-bit data pins, are used to send information to the LCD or read the
contents of the LCDs internal registers. To display letters and numbers, we send ASCII
codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS = 1.
Procedure
Follow the steps 1 of How to create a New project
Type the below code and save it with the name keypad.c (anyname.c)
Follow the steps 2 and 3 of How to create a New Project to compile and build the
program
Follow the procedures in How to Download a Code to Our Controller to
download your code.
Program
/* Keypad Interface
// K1 TO K8 : P0.16 TO P0.23
// Key Value is displayed on UART0
// SCAN LINES : P0.20 TO P0.23 (OUTPUT)
// READ LINES : PO.16 TO P0.19 (INPUT) */
/* - - - - - Header Files - - - - - */
#include<nxp/iolpc2148.h>
#include<stdio.h>
# include "lcd.h"
#include "key.h"
/* - - - - - main function starts here - - - - - */
void main()
{
PINSEL2 = 0x00000000; /* P0.16 TO P0.23 Configured as GPIO. */
IO0DIR = 0X00F00F05; /* P0.20 TO P0.23 (O/P), P0.16 TO P0.19(I/P) */
IO1DIR=0x00FF0000; /* LCD data pins as output */
comm(command); /* function to call LCD commands */
data1("Press any Key"); /* call the function to display the data in LCD */
while(1)
{
scomm(0xC0); /* function to write single datas in LCD location C0 */
key(); /* call the keypad function*/
}
}
OUTPUT:
view the output in LCD
Input is 4x4 matrix
Experiment 6
Interfacing EEPROM and Interrupt
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
Procedure
Program
/* - - - - - Header Files - - - - - */
#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "intrinsics.h"
void TIMER0(void);
void TIMER1(void);
#include "int.h"
#include "uart.h"
#include "timer.h"
/* - - - - - main function starts here - - - - - */
void main()
{
uart_init(); /* call the uart initialization function. Function definition is in uart.h */
timer_config(); /* call the timer configuration function. Function definition is in timer.h*/
timerenable(); /* call the timer interrupt function. Function definition is in int.h */
while(1)
{
printf("\n Welcome... ");
}
}
OUTPUT:
View the output in PC-Hyper Terminal.
Experiment 7
` Mailbox
Aim
Theory
The most basic category of kernel services is Task Management. This set of services
allows application software developers to design their software as a number of separate
"chunks" of software -- each handling a distinct topic, a distinct goal, and perhaps its own
real-time deadline. Each separate "chunk" of software is called a "task." The main RTOS
service in this category is the scheduling of tasks as the embedded system is in operation.
The second category of kernel services is Intertask Communication and
Synchronization. These services make it possible for tasks to pass information from one to
another, without danger of that information ever being damaged. They also make it possible for
tasks to coordinate, so that they can productively cooperate with one another. Without the help
of these RTOS services, tasks might well communicate corrupted information or otherwise
interfere with each other.
Since many embedded systems have stringent timing requirements, most RTOS kernels
also provide some basic Timer services, such as task delays and time-outs. Many (but not all)
RTOS kernels provide Dynamic Memory Allocation services. This category of services allows
tasks to "borrow" chunks of RAM memory for temporary use in application software. Often
these chunks of memory are then passed from task to task, as a means of quickly
communicating large amounts of data between tasks. Some very small RTOS kernels that are
intended for tightly memory-limited environments, do not offer Dynamic memory allocation.
Many (but not all) RTOS kernels also provide a "Device I/O Supervisor" category of
services. These services, if available, provide a uniform framework for organizing and
accessing the many hardware device drivers that are typical of an embedded system.
Procedure
Program main.c
/* - - - - - Header Files - - - - - */
#include <includes.h>
#include <intrinsics.h>
#include<stdio.h>
#include uart.h
/* - - - - - User Defined Variables - - - - - */
OS_EVENT *comm;
INT8U err;
/* - - - - - OS TASK STACK ALLOCATION - - - - - */
OS_STK Task1stk[100];
OS_STK Task2stk[100];
/* - - - - - TASK FUNCTION - - - - - */
void Task1(void *pdata)
{
pdata = pdata;
INT32U temp;
while(1)
{
temp=123;
OSMboxPost(comm,(void *)&temp);
OSTimeDlyHMSM(0, 0, 0, 10);
}
}
void Task2(void *pdata)
{
INT8U err;
INT8U *msg;
char val1;
while(1)
{
msg = OSMboxPend(comm,0,&err);
val1 = *msg;
printf("\n data = %d ",val1);
OSTimeDlyHMSM(0, 0, 0, 100);
}
}
void main (void)
{
uart_init(); /* call the Uart initialization functions */
BSP_Init(); /* Call Board Supporting packages */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreate(Task1,0,&Task1stk[99],0);
OSTaskCreate(Task2,0,&Task2stk[99],1);
comm = OSMboxCreate((void *)0);
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
OUTPUT:
View the output in PC-Hyper Terminal.
Experiment 8
Interrupt Performance Characteristics of ARM and FPGA
Aim
To study about the Interrupt performance characteristics between ARM and FPGA
Theory
The ARM7 CPU has two external interrupt lines for the fast interrupt request (FIQ) and
general purpose interrupt IRQ request modes. As a generalization, in an ARM7 system there
should only be one interrupt source which generates an FIQ interrupt so that the processor can
enter this mode and start processing the interrupt as fast as possible. This means that all the
other interrupt sources must be connected to the IRQ interrupt. In a simple system they could
be connected through a large OR gate. This would mean that when an interrupt was asserted the
CPU would have to check each peripheral in order to determine the source of the interrupt. This
could take many cycles. Clearly a more sophisticated approach is required. In order to handle
the external interrupts efficiently an on-chip module called the Vector Interrupt Controller
(VIC) has been added.
Program
#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "intrinsics.h"
#define led1 IO0PIN_bit.P0_12
#define led2 IO0PIN_bit.P0_13
void TIMER0(void);
void TIMER1(void);
#pragma vector=0x18
__irq __arm void irq_handler (void)
{
void (*intrrupt_function)();
unsigned int vector;
vector = VICVectAddr;
intrrupt_function = (void(*)())vector;
(*intrrupt_function)();
VICVectAddr = 0;
}
__fiq __arm void fiq_handler(void)
{
while(1);
}
void timerenable()
{
VICIntSelect&=~(1<<VIC_TIMER0);
VICVectAddr0=(unsigned int)& TIMER0;
VICVectCntl0=0X20|(VIC_TIMER0);
VICIntEnable|=(1<<VIC_TIMER0);
VICIntSelect&=~(1<<VIC_TIMER1);
VICVectAddr1=(unsigned int)& TIMER1;
VICVectCntl1=0X20|(VIC_TIMER1);
VICIntEnable|=(1<<VIC_TIMER1);
__enable_interrupt();
}
void TIMER0(void)
{
led2=0;
printf("\n vimicrosystem \n");
T0IR=1;
}
void TIMER1(void)
{
led1=0;
led2=0;
printf("\n chennai \n");
T1IR=1;
}
int putchar(int ch)
{
if (ch=='\n')
{while ((U0LSR&0x20)!=0x20); //wait until Transmit Holding Register is empty
U0THR=0x0d; //then store to Transmit Holding Register
}
U0THR=ch;
while ((U0LSR&0x20)!=0x20) ; //wait until Transmit Holding Register is empty
return(ch); //then store to Transmit Holding Register
}
void main()
{
PINSEL0=0X00000005;
IO0DIR=0X00003000;
VPBDIV=0X01;
U0LCR=0X83;
U0DLL=0X4E;
U0DLM=0X00;
U0LCR=0X03;
T0IR=0XFF;
T0TC=0;
T0PR=0;
//T0MR0=0X00000000C;
T0MR0=0X002255100;
T0MCR=3;
T0TCR=1;
T1IR=0XFF;
T1TC=0;
T1PR=0;
T1MR0=0X000002EE0;
T1MCR=3;
T1TCR=1;
while(1)
{
timerenable();
printf("\n working... \n");
led1=1;
}}
Procedure to View Result in ARM
(Follow the same procedure from Step 5 to Step 8 for adding the VHDL modules for the
below program.)
Step 10: Right click on the Xilinx FPGA hardware in the Hierarchy window pane and select
add New Source.
Step 11: Select Implementation Constraint File and enter the file name before clicking
Next.
Step 12: Copy and Paste the Implementation Constraint File module in the appropriate
module.
Step 13: Click Generate Programming File in the Processes pane for the entire project.
(Now the .bit file has been generated for the project)
Step 14: Before continuing with the further process please Connect the FPGA hardware kit
with the CPU by using serial cable and Switch ON.
Step 15: Now Open the JTAG 5.5 software from Start menu in your computer and initialize
the FPGA device for dumping the program into it.
Step 16: While initializing please Assign the .bit file and Program your FPGA by in the
JTAG 5.5 application.
(Now the coded instructions have been loaded in the FPGA hardware kit.
Program:
Top module
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF THE PORT DETAILS IN TOP MODULE SECTION
ENTITY TOP_MODULE IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC;
INPUT1 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC
);
END TOP_MODULE;
ARCHITECTURE BEHAVIORAL OF TOP_MODULE IS
-- DECLARATION OF THE PORT DETAILS IN INPUT SIGNAL MODULE--
COMPONENT CLK_GEN IS PORT ( CLK : IN STD_LOGIC;
GEN_CLK1
: OUT STD_LOGIC;
GEN_CLK2
: OUT STD_LOGIC;
GEN_CLK3
: OUT STD_LOGIC
);
END COMPONENT;
-- DECLARATION OF THE PORT DETAILS IN INTERRUPT ROUTINE MODULE--
COMPONENT INTERRUPT IS PORT ( CLK : IN STD_LOGIC;
INPUT1
: IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT2
: IN STD_LOGIC; ---- SQUARE SIGNAL
INPUT3
: IN STD_LOGIC; ---- SQUARE SIGNAL
RISING_INTERRUPT
: OUT STD_LOGIC;
RISING_INTERRUPT1: OUT STD_LOGIC;
RISING_INTERRUPT2: OUT STD_LOGIC
);
END COMPONENT;
BEGIN
--DECLARING THE SIGNAL DETAILS OF THE COMPONENTS FOR PORT MAPPING --
CLK_SECTION :CLK_GEN PORT MAP
(CLK,GEN_CLK1,GEN_CLK2,GEN_CLK3);
INTERRUPT_SECTION :INTERRUPT PORT MAP
(CLK,INPUT1,INPUT2,INPUT3,RISING_INTERRUPT,RISING_INTERRUPT1,RISING_INT
ERRUPT2);
END BEHAVIORAL;
CLK_GEN
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-- DECLARATION OF PORT DETAILS --
ENTITY CLK_GEN IS
PORT ( CLK : IN STD_LOGIC;
GEN_CLK1 : OUT STD_LOGIC;
GEN_CLK2 : OUT STD_LOGIC;
GEN_CLK3 : OUT STD_LOGIC);
END CLK_GEN;
ARCHITECTURE BEHAVIORAL OF CLK_GEN IS
SIGNAL FREQ :INTEGER :=0; -- SIGNAL DECLARATION OF FREQ
BEGIN
PROCESS(CLK) -- INPUT CLOCK SIGNAL FOR GENERATING 3 INPUT SIGNALS
BEGIN
IF RISING_EDGE (CLK) THEN -- ROUTINE FOLLOWS WITH REFERENCE TO THE CLOCK
SIGNAL
FREQ <= FREQ +1; -- GENGERATING THE COUNTER FOR THE SIGNAL FREQ
IF(FREQ >0 AND FREQ <= 10000)THEN -- FOR GETTING 1KHZ SIGNAL WE ARE
EQUALLY SPLITTING UP THE TIMING VALUES '0' FOR 10000 COUNTS AND '1' FOR
10000 COUNTS
GEN_CLK1 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '1'; -- STATE OF '1' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ >10000 AND FREQ <= 20000)THEN
GEN_CLK1 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK2 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
GEN_CLK3 <= '0'; -- STATE OF '0' FOR 1ST INPUT SIGNAL AT 2KHZ
ELSIF (FREQ > 20000)THEN
FREQ <= 0; -- COUNTER RESETS TO '0' IT IT EXCEEDS 20000 COUNTS
END IF;
END IF; -- PROCESS ENDS BY GENERATING THE 3 INPUT SIGNALS
END PROCESS;
END BEHAVIORAL;
Interrupt
-------------------------------------------------------------------------
-- LIBRARY PART --
-------------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
-------------------------------------------------------------------------
-- PORT DECLARATION PART --
-------------------------------------------------------------------------
ENTITY INTERRUPT IS
PORT ( CLK : IN STD_LOGIC ; -- INPUT CLOCK
INPUT1 : IN STD_LOGIC; -- SQUARE SIGNAL
INPUT2 : IN STD_LOGIC; -- SQUARE SIGNAL
INPUT3 : IN STD_LOGIC; -- SQUARE SIGNAL
RISING_INTERRUPT : OUT STD_LOGIC; -- INTERRUPT OUTPUT 1
RISING_INTERRUPT1 : OUT STD_LOGIC; -- INTERRUPT OUTPUT 2
RISING_INTERRUPT2 : OUT STD_LOGIC -- INTERRUPT OUTPUT 3
);
END INTERRUPT ;
-------------------------------------------------------------------------
--DESIGN ARCHITECTURE BEGIN'S --
-------------------------------------------------------------------------
ARCHITECTURE BEHAVIORAL OF INTERRUPT IS
SIGNAL C1,C2,C3 : INTEGER :=0 ; --
INTERNAL INTEGER SIGNAL DECLARATION FOR GLOBAL PURPOSE
SIGNAL RISING,RISING1,RISING2,X,Y,Z: STD_LOGIC:='0'; --INTERNAL BINARY OR
SINGLE BIT SIGNAL FOR GLOBAL USE
BEGIN
--------------------------------------------------------------------------
-- FIRST INTERRUT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT1) --SENSITIVITY LIST FOR
INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N : INTEGER :=0 ; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT<= RISING;
-- ASSIGNING RISING_INTERRUPT AS RISING VALUE
CASE X IS
-- SUBJECTING X VALUE WITH THE STANDARD LOGIC FUNCTION '0'
AND '1'
WHEN '0' =>
IF INPUT1='1' THEN --ROUTINE WILL CONINUE IF INPUT1 IN
ON CONDITION
RISING<='1'; -- RISING VALUE SHOULD BE ON
& X VALUE SHOULD BE ON
X<='1';
END IF;
WHEN '1'=>
IF INPUT1='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1
IN OFF CONDITION
X<='0'; -- VALUE OF X TENDS TO
'0'
END IF;
WHEN OTHERS=> -- IF ANY CONDITION OTHER
THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING='1' THEN -- IF THE SIGNAL FOUND AS RISING EDGE
THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR
A := 30000+300000; -- ADDITION OPERATION
B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION
C1<=C1+1; -- HERE THE COUNTER STARTS TO SUPPORT THE DELAY
IF C1>= 9000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR CONVENIENCE
RISING<='0'; -- ONCE THE COUNTER EXCEEDS
THE VALUE OF 9000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINE
WILL END UP.
C1<=0; --ONCE THE COUNTER
EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; -- RISING = '1' CONDITION
ENDS HERE.
END IF;
END IF; -- ENTIRE PROCESS ENDS
UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN ARITHMETIC
OPERATIONS..
END PROCESS; -- THESE ABOVE CONDITIONS
PROVIDE US THE INTERRUPT PERFORMANCE OFTHE GIVEN INPUT SIGNAL THRU
RISING_INTERRUPT SIGNAL.
--------------------------------------------------------------------------
-- SECOND INTERRUPT DESIGN --
--------------------------------------------------------------------------
PROCESS(CLK,INPUT2) --SENSITIVITY LIST FOR INPUT USE
VARIABLE A,B,C,D,E,F,G,H,I,J,K,L,M,N:INTEGER :=0; --INTERNAL VARIABLE'S
DECLARATION FOR INTERNAL PROCESS
BEGIN
IF RISING_EDGE(CLK) THEN --CLOCK SIGNAL
RISING_INTERRUPT1<= RISING1; -- ASSIGNING RISING_INTERRUPT AS RISING
VALUE
CASE Y IS WHEN '0' => -- SUBJECTING Y VALUE WITH THE
STANDARD LOGIC FUNCTION '0' AND '1'
IF INPUT2='1' THEN --ROUTINE WILL CONINUE IF
INPUT1 IN ON CONDITION
RISING1<='1'; -- RISING VALUE SHOULD BE '1' & X
VALUE SHOULD BE ON
Y<='1';
END IF;
WHEN '1'=>
IF INPUT2='0' THEN --ROUTINE WILL CONTINUE IF INPUT 1 IN '0'
CONDITION
Y<='0'; -- VALUE OF X
TENDS TO '0'
END IF;
WHEN OTHERS=> -- IF ANY CONDITION OTHER
THAN '0' AND '1' THEN THE SUBJECT SHOULD BE ENDED.
END CASE;
IF RISING1 ='1' THEN -- IF THE SIGNAL FOUND AS
RISING EDGE THEN THE BELOW OPERATION SHOULD BE FOLLOWED BY THE PROCESSOR
A := 30000+300000; -- ADDITION OPERATION
B:= 5669*6587; --MULTIPLICATION OPERATION
C:= 5456496/564; --DIVISION OPERATION
E:=684986-546657; --SUBTRACTION OPERATION
F:=4858*555; --MULTIPLICATION
OPERATION
G:=45587486/6484; --DIVISION OPERATION
H:=5847962-45134; --SUBTRACTION OPERATION
I:=6872678+2587; -- ADDITION OPERATION
J:=245231+5454; -- ADDITION OPERATION
K:=86748/654; --DIVISION OPERATION
L:=816784*864; --MULTIPLICATION OPERATION
M:=54341/64112; --DIVISION OPERATION
N:=46845*4816; --MULTIPLICATION OPERATION
C2<=C2+1; -- HERE THE COUNTER
STARTS TO SUPPORT THE DELAY OF THE SIGNAL
IF C2>= 6000 THEN -- WE CAN MANUALLY SET THE LIMIT AS OUR
CONVENIENCE
RISING1<='0'; -- ONCE THE COUNTER EXCEEDS
THE VALUE OF 6000 THEN THE STATE OF RISING SHOULD BE '0'. THEN THE ROUTINE
WILL END UP.
C2<=0; --ONCE THE
COUNTER EXCEEDS OUR GIVEN LIMIT THEN THE COUNTER VALUE RESETS TO 0.
END IF; --THE RISING =
'1' CONDITION ENDS HERE.
END IF; -- ENTIRE PROCESS
ENDS UP ONCE THE COUNTER EXCEEDS THE GIVEN LIMIT ALOND WITH THE GIVEN
ARITHMETIC OPERATIONS..
END IF; -- THESE ABOVE
CONDITIONS PROVIDE US THE INTERRUPT PERFORMANCE OF THE GIVEN INPUT SIGNAL
THRU RISING_INTERRUPT SIGNAL.
END PROCESS;
END BEHAVIORAL;
Procedure to View Result in FPGA
By connecting the probes of CRO/MSO/DSO to the Desired Input and Output pins of
the I/O connectors we will acquire the result of the Interrupt performance of FPGA device.
Procedure to View Result in Simulation:
1. Run the Simulation process of the Project by selecting Simulation in the
View pane and select the Simulator (ModelSim) in the Processes pane.
2. Force clock input to the CLK variable by right clicking the variable
3. Now you can observe the Input and output result in the Simulator.
OUTPUT:
View the output in PC-Hyper Terminal.
Experiment 9
Flashing of LEDS
Aim
To develop a C program to make the LED blink (including delay routine). Upon
change in the delay program the speed should vary.
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. VSK-2148 has 12 LEDs that are connected to the P4,P5
Port .
Procedure
Follow the steps 1 of How to create a New project
Type the below code and save it with the name led.c (anyname.c)
Follow the steps 2 and 3 of How to create a New Project to compile and build the
program
Follow the procedures in How to Download a Code to Our Controller to download
your code.
Program
/* - - - - Header files - - - - */
#include<nxp\iolpc2148.h>
/* - - - - variable declaration - - - - */
int x;
/* - - - - delay routine - - - - */
void delay()
{
for( int i=0;i<=1500;i++);
}
/* - - - - PWM initialization - - - - */
void pwm(int x)
{
PINSEL0 = 0X000A0005; // To select Port pin P0.8 and also p0.9 as pwm4 and pwm6
PWMPR = 0X00000000; // To set Prescaler register value to one
PWMPCR = 0X00005000; // To select pwm2 as single edge controlled
PWMMCR = 0X00000002; // To Reset pwm timer counter when matches occur
PWMMR0 = 12000 ; // To set total time period of pwm output
PWMMR4 = x;
PWMMR6 = x;
PWMTCR = 0X00000002; // To reset pwm timer
PWMTCR = 0X00000009;
}
/* - - - - main routine - - - - */
void main()
{
while(1)
{
for(int i=0;i<=12000;i++)
{
x=x+10;
pwm(x);
delay();
if(x>=12000)
{
x=0;
}
}
}
}
OUTPUT:
VLEDD-02 terminal are connect to P5.
View the output in VLEDD-02
Experiment 10
Aim
Theory
So when the next electromagnet is turned on and the first will turn 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 precised angle.
There are two basic arrangements for the electromagnetic coils: bipolar and unipolar.
Jumper Position
Procedure
Program
/* - - - - Header files - - - - */
#include<nxp/iolpc2148.h>
/* - - - - - delay routine - - - - - */
void delay()
{
int i;
for(i=0;i<5000;i++);
}
/* - - - - - stepper motor functions - - - - - */
/* - - - - - forward rotation - - - - - */
void fwd()
{
IO0PIN = 0X90;
delay();
IO0PIN = 0X50;
delay();
IO0PIN = 0X60;
delay();
IO0PIN = 0XA0;
delay();
}
/* - - - - - reverse rotation - - - - - */
void rev()
{
IO0PIN = 0XA0;
delay();
IO0PIN = 0X60;
delay();
IO0PIN = 0X50;
delay();
IO0PIN = 0X90;
delay();
}
void main()
{
IO0DIR=0xF0; //Set port line as output port
for(int i=0;i<=50;i++)
{
fwd();
}
for(int i=0;i<=50;i++)
{
rev();
} }
OUTPUT:
stepper motor terminal are connect to P10 connector.
ii) Temperature Sensor
The temperature sensor that is used here is LM35. The LM35 series are precision
integrated-circuit temperature sensors, whose output voltage is linearly proportional to
the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear
temperature sensors calibrated in Kelvin, as the user is not required to subtract a large
constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does
not require any external calibration.
Procedure
Program
/* - - - - - header files - - - - - */
#include<nxp\iolpc2148.h>
#include<stdio.h>
#include "uart.h"
#include "adc.h"
/* - - - - - user defined variables - - - - - */
unsigned int val=0,volt;
/* - - - - - main function - - - - - */
void main(void)
{
PINSEL1_bit.P0_28=1;
init();
uart_inital();
adc();
PINSEL1=0X01000000; //ADC0.1
while(1)
{
while(AD0DR_bit.DONE==0); // Start A/D Conversion
val=AD0DR1_bit.RESULT;
volt=val/3.07;
printf("Temperature = %ddegree \n\r",volt);
}
}
OUTPUT:
change the jumper setting close the J6 and open the J4 jumer.
View the output in PC-Hyper Terminal Link.
Experiment 11
Aim
Theory
The X Bee/X Bee-PRO ZNet 2.5 (formerly known as Series 2 and Series 2 PRO) RF
Modules were directed to operate within the ZigBee protocol. The modules provide
reliable delivery of data between remote devices. Zigbee is the communication protocol
like wifi and Bluetooth. Xbee is the module using Zigbee protocol
Procedure
void timer0_conf()
{
VPBDIV = 0X01; //12MHZ
T0TCR = 0X00; //STOP TIMER
T0PR = 0X12000; //load prescasle or timer value
T0TCR = 0X02; //reset timer0
}
void uart0_conf()
{
PINSEL0 = 0X05;
VPBDIV = 0X01;
U0LCR = 0X83; // 8bit data,divisior latch
U0DLL = 0X4E; //9600 baudrate
U0DLM = 0X00; //msb
U0LCR = 0X03; //8bit data
void main()
{
PINSEL1 = 0X00000000;
IO0DIR = 0X00F00005; //P0.20 t0 P0.23 as o/p or P0.16 t0 P0.20 as i/P
timer0_conf();
uart0_conf();
while(1)
{
IO0PIN=0x00E00000; // First Scan Line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check if any key is pressed in //4th row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed
{
case 0x00070000 :
printf("F");
break;
case 0x000B0000 :
printf("B");
break;
case 0x000D0000 :
printf("7");
break;
case 0x000E0000 :
printf("3");
break;
}
}
IO0PIN=0x00D00000; //Move second data to scan line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check if any key is pressed in 3rd row.
{
switch(IO0PIN & 0x000F0000) //check which one of the key is pressed
{
case 0x00070000 :
printf("E");
break;
case 0x000B0000 :
printf("A");
break;
case 0x000D0000 :
printf("6");
break;
case 0x000E0000 :
printf("2");
break;
}
}
IO0PIN=0x00B00000; //Move 3rd scan data to port line
if(( IO0PIN & 0x000F0000 )!= 0x0F000000)//Scan any key is pressed in 2nd row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed in 2nd row
{
case 0x00070000 :
printf("D");
break;
case 0x000B0000 :
printf("9");
break;
case 0x000D0000 :
printf("5");
break;
case 0x000E0000 :
printf("1");
break;
}
}
IO0PIN=0x00700000; //Move 4th scan data to port line
if(( IO0PIN & 0x000F0000 )!= 0x000F0000) //Check any key is pressed in 1st row
{
switch(IO0PIN & 0x000F0000) //Check which one of the key is pressed in 1st row
{
case 0x00070000 :
printf("C");
break;
case 0x000B0000 :
printf("8");
break;
case 0x000D0000 :
printf("4");
break;
case 0x000E0000 :
printf("0");
break;
}
}
}
}
Rx Program:
#include<nxp/iolpc2148.h>
void uart0_conf()
{
VPBDIV = 0X01; //12Mhz clk
U0LCR = 0X83; //8bit data,
U0DLL = 0X4E; //9600 baudrate LSB
U0DLM = 0X00; //MSB
U0LCR = 0X03; //8bit data
}
void main()
{
}}
Output:
Xbee board are connected to P2 connector.
Input is using matrix keyboard.
View the output in onboard LED.