Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PAGE
S.NO LIST OF EXPERIMENTS
NO.
2. Flashings of LEDs 10
PSO1. Analyze and design the analog and digital circuits or systems for a given
specification and function.
PSO3. Design, develop and test electronic and embedded systems for applications with
real time constraint and to develop managerial skills with ethical behavior to work in a
sustainable environment.
In the record, the index page should be filled properly by writing the corresponding
experiment number, experiment name, date on which it was done and the page number.
1. Title: The title of the experiment should be written in the page in capital letters.
2. In the left top margin, experiment number and date should be written.
3. Aim: The purpose of the experiment should be written clearly.
4. Apparatus/Tools/Equipments/Components used: A list of the Apparatus/Tools/
Equipments/ Components used for doing the experiment should be entered.
6. Procedure: Steps for doing the experiment and recording the readings should be briefly
described(flow chart/ Circuit Diagrams / programs in the case of computer/processor
related experiments)
7. Results: The results of the experiment must be summarized in writing and should be
fulfilling the aim.
a) Circuit/Program: Neatly drawn circuit diagrams for the experimental set up.
b) Design: The design of the circuit components for the experimental set up for
3. Observations:
iii) Relevant calculations should be shown. If repetitive calculations are needed, only show a
sample calculation and summarize the others in a table.
LIST OF EXPERIMENTS:
TOTAL: 45 PERIODS
Course outcomes:
INDEX
PAGE
S.NO LIST OF EXPERIMENTS
NO.
2. Flashings of LEDs 15
59
11. Mail Box
64
The μVision4 IDE is a Windows-based software development platform that combines a robust
editor, project manager, and makes facility. μVision4 integrates all tools including the C
compiler, macro assembler, linker/locator, and HEX file generator. μVision4 helps expedite the
development process of your embedded applications by providing the following:
Full-featured source code editor,
Device database for configuring the development tool setting,
Project manager for creating and maintaining your projects,
Integrated make facility for assembling, compiling, and linking your embedded
applications,
Dialogs for all development tool settings,
True integrated source-level Debugger with high-speed CPU and peripheral simulator,
Advanced GDI interface for software debugging in the target hardware and for
connection to Keil ULINK,
Flash programming utility for downloading the application program into Flash ROM,
Links to development tools manuals, device datasheets & user’s guides.
The μVision4 IDE offers numerous features and advantages that help you quickly and
successfully develop embedded applications. They are easy to use and are guaranteed to help you
achieve your design goals.
NXP Semiconductors produce a range of Microcontrollers that feature both on-chip Flash
memory and the ability to be reprogrammed using In-System Programming technology. Flash
Magic is Windows software from the Embedded Systems Academy 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 Bootloader mode
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. Note that in this manual third party Compilers are listed alphabetically. No
preferences are indicated or implied.
ARM 7 LPC2148 Trainer Kit designed for educational training purpose and the embedded
device from NXP. This document is a User’s guide which describes the complete hardware
design of the ARM 7 LPC2148 Trainer Kit.
Features:
Device daughter card, easy and flexible to upgrade the device.
Four 10 pin individual digital or analog I/O ports are available.
One16 pin digital I/O port is available.
Inbuilt LEDs are available for PWM output.
Inbuilt push to on switch for Reset.
Inbuilt push to on switch for External Interrupt.
USB ISP programmer inbuilt. And On board Serial to USB bridge is available
Aim:
Apparatus Required:
Theory:
The LPC2141/2/4/6/8 microcontrollers are based on a 32/16 bit ARM7TDMI-S CPU with
real-time 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 a
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, LPC2141/2/4/6/8 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.
ARCHITECTURAL OVERVIEW
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. LPC2141/2/4/6/8 peripheral functions (other than the interrupt
controller) are connected to the APB bus. The AHB to APB bridge interfaces the APB bus to the
AHB bus. APB peripherals are also allocated a 2 megabyte range of addresses, beginning at the
3.5 gigabyte address point. Each APB peripheral is allocated a 16 kB address space within the
APB address space.
ARM7TDMI-S PROCESSOR
The ARM7TDMI-S is a general purpose 32-bit microprocessor, which offers high performance
and very low power consumption. The ARM architecture is based on Reduced Instruction Set
Computer (RISC) principles, and the instruction set and related decode mechanism are much
simpler than those of micro programmed Complex Instruction Set Computers. This simplicity
results in a high instruction throughput and impressive real-time interrupt response from a small
and cost-effective processor core.
Pipeline techniques are employed so that all parts of the processing and memory systems can
operate continuously. Typically, while one instruction is being executed, its successor is being
decoded, and a third instruction is being fetched from memory.
The ARM7TDMI-S processor also employs a unique architectural strategy known as THUMB,
which makes it ideally suited to high-volume applications with memory restrictions, or
applications where code density is an issue.
The key idea behind THUMB is that of a super-reduced instruction set. Essentially, the
ARM7TDMI-S processor has two instruction sets:
The THUMB set’s 16-bit instruction length allows it to approach twice the density of standard
ARM code while retaining most of the ARM’s performance advantage over a traditional 16-bit
processor using 16-bit registers. This is possible because THUMB code operates on the same 32-
bit register set as ARM code.
THUMB code is able to provide up to 65% of the code size of ARM, and 160% of the
performance of an equivalent ARM processor connected to a 16-bit memory system.
The ARM7TDMI-S processor is described in detail in the ARM7TDMI-S Datasheet that can be
found on official ARM website.
Result:
Aim:
Apparatus Required:
ARM Trainer Kit
LED Card
PC
Software Required:
Keil μVision4
Flash Magic
Theory:
Light Emitting Diodes (LEDs) are popularly used display components used to indicate
the On and OFF state of system. These are also used to realize various counters like binary
counters experimentally. These LEDs can be easily interfaced with the port pins of any
Microcontroller by using current limiting resistors of the order of 220 Ohms.
The diagram below shows the interfacing of LED array ot the Port1 pins of LPC20148
ARM 7 microcontroller. This program blinks the LEDs continuously with a small delay. The
LEDs are connected to the Port 0 Pins P0.00 to P0.07 and the these Pins are configured as
general Purpose output pins.
Program:
#include <LPC214X.H>
void DELAY(unsigned long VALUE);
unsigned char A = 0x01;
int main()
{
IO0DIR = 0x000000FF; /* Port0 00-07 as output*/
while(1) /* Infinite loop*/
{
IO0SET |= A; /* Port0 00-07 High */
DELAY(1000000);
IO0CLR |= A; /* Port0 00-07 High */
A <<=1;
if(A==0x00) A=0x01;
DELAY(1000000);
}
}
void DELAY(unsigned long VALUE)
{
while(VALUE>0)
{
VALUE--;
}
}
Result:
Thus the Flashing of LEDs are verified and executed.
Aim:
Apparatus Required:
ARM Trainer Kit
LED Card
PC
Software Required:
Keil μVision4
Flash Magic
Program:
#include<LPC214x.h>
/*
******************************************************************************
****************
* Function : PwmInit
* Description : Routine for 120 Khz Frequency Generation
* Parameters : None
******************************************************************************
****************
*/
void INIT_ADC(void);
int READ_ADC(void);
void PwmInit()
{
PINSEL0 = 0X00008000; // Enable PWM2 -- P0.7
PWMLER = 0X00000004; // Set latch register
PWMPR = 0X00000000; // Prescale 0
PWMMR0 = 0X000003FF; // 120 KHz Frequency
int main()
{
PwmInit();
INIT_ADC();
//IO0DIR = 0x000000FF;
//IO0CLR &= 0x000000FF;
while(1)
{
PWM = READ_ADC();
if(PWM>0x000003FF) PWM=0x000003FF;
PWMMR2 = PWM;
PWMTCR = 0X00000000;
PWMTCR = 0X00000009;
}
}
void INIT_ADC()
{
PINSEL1 |= 0x01000000;
AD0CR = 0x00200602;
}
int READ_ADC()
{
int VAL;
AD0CR |= 0x01000000; /* Start A/D Conversion */
do
{
Result:
Thus the interfacing of LED and PWM is executed.
Aim:
Apparatus Required:
ARM Trainer Kit
ADC and DAC Card
PC
Software Required:
Keil μVision4
Flash Magic
LPC2148 controller has two on n-chip ADCs. In the present program the ADC0 with
channel 3 is used and configured to convert the analog input signal into its equivalent digital
output. The configuring of on chip ADC is given below.
The ARM7 LPC21xx processor is interfaced to the 2x16 LCD module in 8-bit mode. The
interface diagram is shown. The eight data pins are connected with eight data bits (P1.16 – P1.23
pins to bits D0 -D7), address bit (RS – P0.23), read / write bit (R/W – P0.22) and control signal (E
– P0.21) to make LCD display complete. The pins D0, D1, D2, D3 are left free without any
connections.
16X 2LCD is a 16 pin module. In which pins 1 & 16 are grounded, 2 & 15 are given to
Vcc and 3rd pin is given to potentiometer in order adjust the contrast of LCD. Pin 4, 5 & 6
corresponds to RS, R/W & EN respectively. Pins 8 to 15 are data lines from D0 to D7
respectively. Here the LCD is used in 8 bit mode. i.e., 8 bits are used to transfer the data with
MSB first and LSB next. Port 0 pins i.e. from P0.09 to 11, are used for both data and control
signals. The interfacing diagram of 16X2 LCD is shown.
Program:
FOR ADC
#include <LPC214x.H>
#include <STRING.H>
int main()
{
INIT_PLL();
INIT_GPIO();
LCD_INIT();
INIT_ADC();
LCDSTR(0x00000080," ADC ");
LCDSTR(0x000000C0,"VOLTAGE = ");
while(1)
{
for(count=0;count<10000;count++)
{
temp_sum = temp_sum+READ_ADC();
}
temp_adv=temp_sum/10000;
TEMP=temp_adv;
temp_sum=0;
ADC = 1000*(TEMP*(3.901/1024));
LCD_CMD(0x000000CA);
CONVERT_ADC(ADC);
}
}
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void INIT_GPIO()
{
IO0DIR =0x00000E00; // P0.8 ----- P0.15 LCD DATA
IO1DIR =0X00FF0000; // P1.21 --- P1.23 LCD CONTROL
}
void INIT_PLL()
{
PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
PLL0CON=0x00000001;
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK
IS GENERATED EXAXT VALUE
PLL0CON=0x00000003; // CONNECT PLL
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
VPBDIV=0x00000002; // PCLK=1/2*CCLK
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
void INIT_ADC()
{
PINSEL1 |= 0x01000000;
AD0CR = 0x00200602;
}
int READ_ADC()
{
int VAL;
AD0CR |= 0x01000000; /* Start A/D Conversion */ do
{
VAL = AD0DR1; /* Read A/D Data Register */
}
while (!(VAL & 0x80000000)); /* Wait for end of A/D Conversion
*/
AD0CR &= ~0x01000000; /* Stop A/D Conversion */
VAL >>=6;
VAL = VAL & 0x3FF;
return(VAL);
}
void CONVERT_ADC(unsigned int ADC)
{
unsigned int CNT1,CNT2,CNT3,CNT4;
unsigned char DATA1,DATA2,DATA3,DATA4;
CNT1 = ADC % 10000/1000;
CNT2 = ADC % 1000/100;
CNT3 = ADC % 100/10;
CNT4 = ADC % 10/1;
DATA1 = CNT1 | 0x30;
DATA2 = CNT2 | 0x30;
DATA3 = CNT3 | 0x30;
DATA4 = CNT4 | 0x30;
LCD_DATA(DATA1);
LCD_DATA('.');
LCD_DATA(DATA2);
LCD_DATA(DATA3);
LCD_DATA(DATA4);
return;
}
A digital to analog converter is a device for converting a digital signal into an analog
signal (current or voltage). Digital to analog converters are the interface between the abstract
digital world and the analog real world. Simple switches, a network of resistors, current source or
capacitors many be used to implement this conversion. A DAC inputs a binary number and
output an analog voltage or current signal.
The Microchip Technology Inc. MCP4921 is 2.7 – 5.5V, low power, 12-Bit Digital to
Analog Converter (DAC) with SPI interface. The MCP4921 DAC to provides high accuracy and
low noise performance for industrial applications where calibration or compensation of signals is
required.
With an SPI connection there is always one master device (usually a microcontroller)
which controls the peripheral devices. Typically there are three lines common to all the devices.
Master In Slave Out (MISO) – The Slave line for sending data to the master
Master Out Salve In (MOSI) – The master Line for sending data to the peripherals
Serial Clock (SCK) – The Clock pulses which synchronize data transmission generated by the
master
Slave Select Pin – The pin on each device that the master can be used to enable and disable
specific devices.
When device’s Slave Select pin is low, it communicates with the master. When it’s high ,
it ignores the master. In SPI, the clock signal is controlled by the master devices LPC2148. All
data is clocked in and out using this pin. These lines need to be connected to the relevant pins on
the LPC21xx processor. Any unused GIO pin can be used for CS, instead pull this pin high.
Conversion speed is the time it takes for the DAC – SPI connections with LPC21xx have four
I/O lines (P0.4 – P0.7) required. The analog output is generated by using these four lines.
Program:
FOR DAC (Sin Wave)
#include<lpc214x.h>
#include"math.h"
unsigned int t;
int main()
{
int value=0x3ff;
PINSEL1 = 0X00080000;
while(1)
{
value = 512+400*sin(t*0.01745);
DACR = value<<6;
if(++t==360)t=0;
}
}
Result:
Aim:
To write a program for Interfacing Real Time Clock and Serial Port
Apparatus Required:
ARM Trainer Kit
LCD Card
PC
Software Required:
Keil μVision4
Flash Magic
Theory:
The ARM7 LPC21xx processor is interfaced to the 2x16 LCD module in 8-bit mode. The
interface diagram is shown. The eight data pins are connected with eight data bits (P1.16 – P1.23
pins to bits D0 -D7), address bit (RS – P0.23), read / write bit (R/W – P0.22) and control signal (E
– P0.21) to make LCD display complete. The pins D0, D1, D2, D3 are left free without any
connections.
16X 2LCD is a 16 pin module. In which pins 1 & 16 are grounded, 2 & 15 are given to
Vcc and 3rd pin is given to potentiometer in order adjust the contrast of LCD. Pin 4, 5 & 6
corresponds to RS, R/W & EN respectively. Pins 8 to 15 are data lines from D0 to D7
respectively. Here the LCD is used in 8 bit mode. i.e., 8 bits are used to transfer the data with
MSB first and LSB next. Port 0 pins i.e. from P0.09 to 11, are used for both data and control
signals. The interfacing diagram of 16X2 LCD is shown.
Program:
For Real Time Clock:
#include <LPC214x.H>
#include <STRING.H>
void SETTIME(void)
{
CCR = 0x02;
HOUR = 0;
MIN = 0;
SEC = 0;
CCR = 0x11;
}
int main()
{
SETTIME();
INIT_GPIO();
LCD_INIT();
LCDSTR(0x00000080,"REAL TIME CLOCK ");
LCDSTR(0x000000C0," ");
while(1)
{
LCD_CMD (0x000000C3);
LCD_DATA(HOUR/10 + '0');
LCD_DATA(HOUR%10 + '0');
LCD_DATA(':') ;
LCD_DATA(MIN/10 + '0');
LCD_DATA(MIN%10 + '0');
LCD_DATA(':') ;
LCD_DATA(SEC/10 + '0');
LCD_DATA(SEC%10 + '0');
}
void INIT_GPIO()
{
IO0DIR =0x00000E00; // P0.8 ----- P0.15 LCD DATA
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
Program
For Serial Port:
/*****************************************************************
*************/
/* SERIAL.C: */
/**************
****************************************************************/
/* This file is part of the RhydoLabz development kit. */
/* Copyright (c) 2005-2006 Rhydo Software. All rights reserved. */
/* written to run with keil uvision 3v3.53 demo software. */
/***********************************************************************
*******/
{
while (!(U0LSR & 0x20));
return (U0THR = SDat);
}
Result:
Thus interfacing RTC and Serial Port are executed.
Aim:
Apparatus Required:
ARM Trainer Kit
Matrix Key Board and LCD Card
PC
Software Required:
Keil μVision4
Flash Magic
16X 2LCD is a 16 pin module. In which pins 1 & 16 are grounded, 2 & 15 are given to
Vcc and 3rd pin is given to potentiometer in order adjust the contrast of LCD. Pin 4, 5 & 6
corresponds to RS, R/W & EN respectively. Pins 8 to 15 are data lines from D0 to D7
respectively. Here the LCD is used in 8 bit mode. i.e., 8 bits are used to transfer the data with
MSB first and LSB next. Port 0 pins i.e. from P0.09 to 11, are used for both data and control
signals. The interfacing diagram of 16X2 LCD is shown.
Program:
#include <LPC214x.H>
#include <STRING.H>
#define O1 0X00E00000
#define O2 0X00D00000
#define O3 0X00B00000
#define O4 0X00700000
#define I1 0x000E0000
#define I2 0x000D0000
#define I3 0x000B0000
#define I4 0x00070000
int main()
{
INIT_PLL();
INIT_GPIO();
LCD_INIT();
LCDSTR(0x00000080,"Matrix KeyPad ");
LCDSTR(0x000000C0,"Key Pressed: ");
while(1)
{
IO0CLR = CLR;
IO0SET = O1;
delay(10);
if(scan(I1))LCDSTR(0x000000CC,"0"); //S1
if(scan(I2))LCDSTR(0x000000CC,"4"); //S5
if(scan(I3))LCDSTR(0x000000CC,"8"); //S9
if(scan(I4))LCDSTR(0x000000CC,"C"); //S13
IO0CLR = CLR;
IO0SET = O2;
if(scan(I1))LCDSTR(0x000000CC,"1"); //S2
if(scan(I2))LCDSTR(0x000000CC,"5"); //S6
if(scan(I3))LCDSTR(0x000000CC,"9"); //S10
if(scan(I4))LCDSTR(0x000000CC,"D"); //S14
IO0CLR = CLR;
IO0SET = O3;
if(scan(I1))LCDSTR(0x000000CC,"2"); //S3
if(scan(I2))LCDSTR(0x000000CC,"6"); //S7
if(scan(I3))LCDSTR(0x000000CC,"A"); //S11
if(scan(I4))LCDSTR(0x000000CC,"E"); //S15
IO0CLR = CLR;
IO0SET = O4;
if(scan(I1))LCDSTR(0x000000CC,"3"); //S4
if(scan(I2))LCDSTR(0x000000CC,"7"); //S8
if(scan(I3))LCDSTR(0x000000CC,"B"); //S12
if(scan(I4))LCDSTR(0x000000CC,"F"); //S16
}
}
char scan(int keystatus) /* scanning a a key */
{
while((IO0PIN & 0X000F0000)==keystatus)
{
delay(50);
if((IO0PIN & 0X000F0000)== 0X000F0000)return(1);
}
return(0) ;
}
void delay(int n) /* generates one milisecond delay */
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void INIT_GPIO()
{
IO0DIR =0x00F00E00; // P0.8 ----- P0.15 LCD DATA
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
Result:
Thus interfacing of Key Board and LCD are executed.
Aim:
Apparatus Required:
ARM Trainer Kit
Stepper Motor and Matrix Key Board
PC
Software Required:
Keil μVision4
Flash Magic
Theory:
A stepper motor is a brushless, synchronous electric motor that converts digital pulses
into mechanical rotation in steps. Every revolution of the stepper motor is divided into a discrete
number of steps, and receives the motor rotates through one step.
Figure shows the interface of the stepper motor to ARM7 controller. The stepper motor is
connected to Microcontroller using a ULN2003 driver IC. The ULN driver IC is connected to the
Port 1 pins P0.16 to P0.19 pins. So as the microcontroller gives pulses with a particular
frequency to ULN2003, the motor is rotated either in clockwise or anticlockwise.
This Program first configures the ARM Port0 as a GPIO and also as an port. The sequence code
is sent to the driver IC using these port pins. A suitable delay is incorporated between each step
rotation. By applying the code in the reverse order, the stepper motor can be rotated in the
anticlockwise direction.
Program:
For Stepper Motor:
#include<LPC214X.H>
#define O1 0X000000E0
#define O2 0X000000D0
#define O3 0X000000B0
#define O4 0X00000070
#define I1 0x0000000E
#define I2 0x0000000D
#define I3 0x0000000B
#define I4 0x00000007
int main(void){
IO0DIR = 0X000F00F0;
while(1){
unsigned char I;
IO0CLR = CLR;
IO0SET = O1;
while(scan(I1)) //S1
{
for(I=0;I<4;I++)
{
IO0SET |= CLOCK[I];
IO0CLR |= ~CLOCK[I];
delay(5);
}
}
while(scan(I2)) //S5
{
for(I=0;I<4;I++)
{
IO0SET |= CLOCK[I];
IO0CLR |= ~CLOCK[I];
delay(10);
}
}
IO0CLR = CLR;
IO0SET = O2;
while(scan(I1)) //S2
{
for(I=0;I<4;I++)
{
IO0SET |= ANTI_CLOCK[I];
IO0CLR |= ~ANTI_CLOCK[I];
delay(5);
}
}
while(scan(I2)) //S6
{
for(I=0;I<4;I++)
{
IO0SET |= CLOCK[I];
IO0CLR |= ~CLOCK[I];
delay(50);
}
}
IO0CLR = CLR;
IO0SET = O3;
while(scan(I2)) //S7
{
for(I=0;I<4;I++)
{
IO0SET |= CLOCK[I];
IO0CLR |= ~CLOCK[I];
delay(90);
}
}
}
}
char scan(int keystatus) /* scanning a a key */
{
while((IO0PIN & 0X0000000F)==keystatus)
{
return(1);
}
return(0);
}
void delay(int n) /* generates one milisecond delay */
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
Theory:
The ARM7 LPC21xx processor is interfaced to the 2x16 LCD module in 4-bit mode. The
interface diagram is shown. The four data pins are connected with 4 data bits (P1.19 – P1.22 pins
to bits D4 -D7), address bit (RS – P0.16), read / write bit (R/W – P0.17) and control signal (E –
P0.18) to make LCD display complete. The pins D0, D1, D2, D3 are left free without any
connections.
16X 2LCD is a 16 pin module. In which pins 1 & 16 are grounded, 2 & 15 are given to
Vcc and 3rd pin is given to potentiometer in order adjust the contrast of LCD. Pin 4, 5 & 6
corresponds to RS, R/W & EN respectively. Pins 8 to 15 are data lines from D0 to D7
respectively. Here the LCD is used in 4 bit mode. i.e., 4 bits are used to transfer the data with
MSB first and LSB next. Port 0 pins i.e. from P0.16 to 22, are used for both data and control
signals. The interfacing diagram of 16X2 LCD is shown.
Program:
For Temperature Sensor:
#include <LPC214x.H>
#include <STRING.H>
int main()
{
INIT_PLL();
INIT_GPIO();
LCD_INIT();
INIT_ADC();
LCDSTR(0x00000080," TEMPERATURE ");
LCDSTR(0x000000C0,"DEGREE C = ");
while(1)
{
TEMP = READ_ADC();
ADC = (1000*(TEMP*(3.901/1024)))-100;
LCD_CMD(0x000000CA);
CONVERT_ADC(ADC);
}
}
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void INIT_GPIO()
{
IO0DIR =0x00000E00; // P0.8 ----- P0.15 LCD DATA
IO1DIR =0X00FF0000; // P1.21 --- P1.23 LCD CONTROL
}
void INIT_PLL()
{
PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
PLL0CON=0x00000001;
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK
IS GENERATED EXAXT VALUE
PLL0CON=0x00000003; // CONNECT PLL
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
VPBDIV=0x00000002; // PCLK=1/2*CCLK
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
void INIT_ADC()
{
PINSEL1 |= 0x01000000;
AD0CR = 0x00200602;
}
int READ_ADC()
{
int VAL;
AD0CR |= 0x01000000; /* Start A/D Conversion */
do
{
VAL = AD0DR1; /* Read A/D Data Register */
}
while (!(VAL & 0x80000000)); /* Wait for end of A/D Conversion
*/
AD0CR &= ~0x01000000; /* Stop A/D Conversion */
VAL >>=6;
VAL = VAL & 0x3FF;
return(VAL);
}
void CONVERT_ADC(unsigned int ADC)
{
unsigned int CNT1,CNT2,CNT3,CNT4;
unsigned char DATA1,DATA2,DATA3,DATA4;
CNT1 = ADC % 10000/1000;
CNT2 = ADC % 1000/100;
CNT3 = ADC % 100/10;
CNT4 = ADC % 10/1;
DATA1 = CNT1 | 0x30;
DATA2 = CNT2 | 0x30;
DATA3 = CNT3 | 0x30;
DATA4 = CNT4 | 0x30;
LCD_DATA(DATA1);
LCD_DATA(DATA2);
LCD_DATA(DATA3);
LCD_DATA('.');
LCD_DATA(DATA4);
return;
}
Result:
Thus the interfacing of Stepper motor and Temperature Sensor are executed.
Aim:
Apparatus Required:
ARM Trainer Kit
EPROM Card
PC
Software Required:
Keil μVision4
Flash Magic
Theory:
The ARM7 LPC21xx processor is interfaced to the 2x16 LCD module in 8-bit mode. The
interface diagram is shown. The eight data pins are connected with eight data bits (P1.16 – P1.23
pins to bits D0 -D7), address bit (RS – P0.23), read / write bit (R/W – P0.22) and control signal (E
– P0.21) to make LCD display complete. The pins D0, D1, D2, D3 are left free without any
connections.
16X 2LCD is a 16 pin module. In which pins 1 & 16 are grounded, 2 & 15 are given to
Vcc and 3rd pin is given to potentiometer in order adjust the contrast of LCD. Pin 4, 5 & 6
corresponds to RS, R/W & EN respectively. Pins 8 to 15 are data lines from D0 to D7
respectively. Here the LCD is used in 8 bit mode. i.e., 8 bits are used to transfer the data with
MSB first and LSB next. Port 0 pins i.e. from P0.09 to 11, are used for both data and control
signals. The interfacing diagram of 16X2 LCD is shown.
Program:
For EPROM:
#include <LPC21xx.H>
#include <STRING.H>
#define O1 0X00E00000
#define O2 0X00D00000
#define O3 0X00B00000
#define O4 0X00700000
#define I1 0x000E0000
#define I2 0x000D0000
#define I3 0x000B0000
#define I4 0x00070000
char buf[16];
unsigned char cnt=0;
int main()
{
INIT_GPIO();
LCD_INIT();
LCDSTR(0x00000080,"Ext EEPROM TEST ");
LCDSTR(0x000000C0,"MESSAGE COUNT: 1");
cnt=1;
while(1)
{
IO0CLR = CLR;
IO0SET = O1;
delay(10);
if(scan(I1))
{
LCDSTR(0x000000C0,"MESSAGE COUNT: 1");
cnt=1;
}
if(scan(I2))
{
if(cnt==1)
{
eeprom_write(0 , "Enthu Technology");
LCDSTR(0x000000C0,"Writting ");
delay(120000);
}
if(cnt==2)
{
eeprom_write(0 , "Coimbatore ");
LCDSTR(0x000000C0,"Writting ");
delay(120000);
}
if(cnt==3)
{
eeprom_write(0 , "SSN Sqaure ");
LCDSTR(0x000000C0,"Writting ");
delay(120000);
}
if(cnt==4)
{
eeprom_write(0 , "Tamil Nadu ");
LCDSTR(0x000000C0,"Writting ");
delay(120000);
}
}
IO0CLR = CLR;
IO0SET = O2;
if(scan(I1))
{
LCDSTR(0x000000C0,"MESSAGE COUNT: 2");
cnt=2;
}
if(scan(I2))
{
eeprom_read(0,16, buf);
LCDSTR(0x000000C0,"Reading ");
DELAY(5000);
LCDSTR(0xC0,buf);
}
IO0CLR = CLR;
IO0SET = O3;
if(scan(I1))
{
LCDSTR(0x000000C0,"MESSAGE COUNT: 3");
cnt=3;
}
if(scan(I2))
{
eeprom_write(0 , " ");
LCDSTR(0x000000C0,"Erasing ");
delay(120000);
cnt=5;
}
IO0CLR = CLR;
IO0SET = O4;
if(scan(I1))
{
LCDSTR(0x000000C0,"MESSAGE COUNT: 4");
cnt=4;
}
}
}
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void INIT_GPIO()
{
IO0DIR =0x00F00E00; // P0.8 ----- P0.15 LCD DATA
IO1DIR =0X00FF0000; // P1.21 --- P1.23 LCD CONTROL
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
void delay(unsigned int del)
{
while(del-- > 0);
}
void i2c_init(void)
{
PINSEL0 = 0X50;
I2CONCLR = 0X0000002C; /* clears AA,I2C interrupt
flag,START flag bit*/
i2c_write(DEV_WRITE ,DEV_WR_STAT);
i2c_write(loc , LOC_WR_STAT);
i2c_stop();
delay(5000);
i2c_start();
i2c_write(DEV_READ ,DEV_RD_STAT);
while(loc_count-- > 0)
{
*ptr = i2c_read();
ptr++;
}
i2c_stop();
}
void eeprom_write(char loc , char *ptr)
{
i2c_init();
i2c_start();
i2c_write(DEV_WRITE ,DEV_WR_STAT);
i2c_write(loc , LOC_WR_STAT);
while(*ptr != '\0')
{
i2c_write(*ptr , LOC_WR_STAT);
ptr++;
}
i2c_stop();
}
char scan(int keystatus) /* scanning a a key */
{
while((IO0PIN & 0X000F0000)==keystatus){
delay1(50);
if((IO0PIN & 0X000F0000)== 0X000F0000)return(1);
}
return(0) ;
}
void delay1(int n) /* generates one milisecond delay */
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
Program:
For Interrupt:
#include<lpc21xx.h>
void DELAY(unsigned long VALUE);
unsigned int A = 0x00010000;
void ext_interrupt(void)__irq
{
EXTINT = 0X02; /* Clear interrupt flag
*/
DELAY(5000000);
VICVectAddr = 0x00000000; /*
Acknowledge Interrupt */
}
void init_ext(void)
{
PINSEL0 |= 0X20000000; /* enable
EXT1 */
EXTMODE = 0X02; /*
edge sensitive */
EXTPOLAR = 0X02; /* on rising
edge */
VICVectAddr0 =(unsigned int)ext_interrupt; /* Set Interrupt Vector in 0 */
VICVectCntl0 = 0x0000002F; /* Use it for
EXT1 Interrupt */
VICIntEnable = 0x00008000; /* enable
EXT1 INTERRUPT */
}
int main(void)
{
IO0DIR = 0X00FF0000;
init_ext();
while(1)
{
IO0SET |= A; /* Port0 00-07 High */
DELAY(1000000);
IO0CLR |= A; /* Port0 00-07 High */
A <<=1;
if(A==0x01000000) A=0x00010000;
DELAY(1000000);
}
}
void DELAY(unsigned long VALUE)
{
while(VALUE>0)
{
VALUE--;
}
}
Result:
Thus interfacing EPROM and Interrupt are executed.
Aim:
Apparatus Required:
ARM Trainer Kit
Zigbee
Key Pad
LCD
Stepper Motor
PC
Software Required:
Keil μVision4
Flash Magic
Program:
For Transmitter:
#include <LPC214x.H>
#include <STRING.H>
#define O1 0X00E00000
#define O2 0X00D00000
#define O3 0X00B00000
#define O4 0X00700000
#define I1 0x000E0000
#define I2 0x000D0000
#define I3 0x000B0000
#define I4 0x00070000
int main()
{
init_serial();
INIT_PLL();
INIT_GPIO();
LCD_INIT();
LCDSTR(0x00000080," Zig Bee Based ");
LCDSTR(0x000000C0,"Motor Controller");
DELAY(6000);
while(1)
{
IO0CLR = CLR;
IO0SET = O1;
while(scan(I1))
{
LCDSTR(0x000000C0,"Running C-wise ");
sendchar('C');
}
IO0CLR = CLR;
IO0SET = O2;
while(scan(I1))
{
LCDSTR(0x000000C0,"Running AC-wise ");
sendchar('A');
}
LCDSTR(0x000000C0,"Motor Stopped ");
}
}
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void INIT_GPIO()
{
IO0DIR =0x00F00E00; // P0.8 ----- P0.15 LCD DATA
IO1DIR =0X00FF0000; // P1.21 --- P1.23 LCD CONTROL
}
void INIT_PLL()
{
PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
PLL0CON=0x00000001;
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK
IS GENERATED EXAXT VALUE
PLL0CON=0x00000003; // CONNECT PLL
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
VPBDIV=0x00000002; // PCLK=1/2*CCLK
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
Program:
For Receiver:
#include <LPC21xx.H>
#include "serial.h"
int main(void)
{
init_serial ();
IO0DIR = 0X00FF0000;
while(1)
{
SBUF= getchar();
if(SBUF=='C')
{
IO0SET |= CLOCK[0];
IO0CLR |= ~CLOCK[0];
delay(5);
IO0SET |= CLOCK[1];
IO0CLR |= ~CLOCK[1];
delay(5);
IO0SET |= CLOCK[2];
IO0CLR |= ~CLOCK[2];
delay(5);
IO0SET |= CLOCK[3];
IO0CLR |= ~CLOCK[3];
delay(5);
}
if(SBUF=='A')
{
IO0SET |= ANTI_CLOCK[0];
IO0CLR |= ~ANTI_CLOCK[0];
delay(5);
IO0SET |= ANTI_CLOCK[1];
IO0CLR |= ~ANTI_CLOCK[1];
delay(5);
IO0SET |= ANTI_CLOCK[2];
IO0CLR |= ~ANTI_CLOCK[2];
delay(5);
IO0SET |= ANTI_CLOCK[3];
IO0CLR |= ~ANTI_CLOCK[3];
delay(5);
}
}}
void delay(int n)
{
int i,j;
for (i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
///// ----------------
Result:
Thus implementing Zigbee protocol with ARM are executed.
Aim:
Apparatus Required:
ARM Trainer Kit
Wire Connection
Functional Generator
PC
Software Required:
Keil μVision4
Flash Magic
Program:
#include <LPC214x.H>
#include <STRING.H>
void ext_interrupt(void)__irq
{
EXTINT = 0X02; /* Clear interrupt flag
*/
count++;
void init_ext(void)
{
PINSEL0 |= 0X20000000; /* enable EXT1
*/
EXTMODE = 0X02; /* edge
sensitive */
EXTPOLAR = 0X02; /* on rising
edge */
VICVectAddr0 =(unsigned int)ext_interrupt; /* Set Interrupt Vector in 0 */
VICVectCntl0 = 0x0000002F; /* Use it for EXT1
Interrupt */
INTERRUPT */
}
int main()
{
INIT_PLL();
init_ext();
INIT_GPIO();
LCD_INIT();
LCDSTR(0x00000080,"Counter: ");
while(1)
{
SEC_DELAY();
LCD_CMD(0x00000088);
CONVERT_DATA(count);
count=0;
}
}
void INIT_GPIO()
{
IO0DIR =0x00000E00; // P0.8 ----- P0.15 LCD DATA
IO1DIR =0X00FF0000; // P1.21 --- P1.23 LCD CONTROL
}
void INIT_PLL()
{
PLL0CFG=0x00000024; // TO GENERATE 60 MHZ CCLK
PLL0CON=0x00000001;
PLL0FEED=0x000000AA; // UPDATE THE PLL REGISTER
PLL0FEED=0x00000055;
while(!(PLL0STAT & 0x00000400)); // CHECK WHETHRT THE CCLK
IS GENERATED EXAXT VALUE
PLL0CON=0x00000003; // CONNECT PLL
PLL0FEED=0x00000055;
VPBDIV=0x00000002; // PCLK=1/2*CCLK
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
LCD_CMD(0x00000038);
LCD_CMD(0x0000000C);
LCD_CMD(0x00000001);
LCD_CMD(0x00000006);
}
void CONVERT_DATA(unsigned int DATA)
{
LCD_DATA((DATA % 100000000/10000000) | 0x30);
LCD_DATA((DATA % 10000000/1000000) | 0x30);
LCD_DATA((DATA % 1000000/100000) | 0x30);
LCD_DATA((DATA % 100000/10000) | 0x30);
LCD_DATA((DATA % 10000/1000) | 0x30);
LCD_DATA((DATA % 1000/100) | 0x30);
LCD_DATA((DATA % 100/10) | 0x30);
LCD_DATA((DATA % 10/1) | 0x30); return;
void SEC_DELAY()
{
T0PR = 0x0000270F; //0x0000270F
T0MR0 = 0x00000BA1 ; //0x000004B0
T0TCR = 0x01;
while(T0TC != T0MR0);
T0MCR = 0x00000002;
T0TCR = 0x02;
}
Result:
Thus Interrupt Performance characteristics of ARM and FPGA are executed.
Aim:
Apparatus Required:
PC
Software Required:
Keil μVision4
Flash Magic
Program:
#include <RTL.h>
#include <LPC21xx.H>
#include <stdio.h>
OS_TID tsk1;
OS_TID tsk2;
typedef struct
{
float voltage;
float current;
U32 counter;
}T_MEAS;
os_mbx_declare (MsgBox,16);
_declare_box (mpool,sizeof(T_MEAS),16);
void init_serial ()
{
PINSEL0 = PINSEL0 | 0X00000005;
U0LCR = 0X83;
U0DLL = 0Xbb;
U0DLM = 0X00;
U0LCR = 0X03;
os_tsk_delete_self ();
}
Result:
Thus mailbox are verified and executed.
Aim :
To write an embedded C code for interfacing Bluetooth Module with ARM
CORTEX M3-LPC2148.
Circuit Diagram
Procedure:
Give +3.3V power supply to LPC2148 Primer Board; connect the 5V adapter
with Bluetooth module which is connected with the LPC2148 Primer Board. There
are two Bluetooth modules are required. One is connected with LPC2148 Primer
Board; other one is connected with PC. First connect the serial cable between
LPC2148 Primer board & PC. Then open the Hyper Terminal screen, select which
port you are using and set the default settings. Now the screen should show some text
messages. If the messages are correctly displayed in Hyper Terminal, then only
connect the Bluetooth modules in LPC2148 Primer Board UART0 & PC. If you are
not reading any data from UART0, then you just check the jumper connections & just
check the serial cable is working. Otherwise you just check the code with debugging
mode in Keil.
Program:
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;
int main(void)
{
char *Ptr = "*** UART0 Demo ***\n\n\rType Characters to be echoed!!\n\n\r";
VPBDIV = 0x02; // Divide Pclk by two
init_serial();
while(1)
{
while (*Ptr) { putchar(*Ptr++);
} putchar(getchar()); // Echo terminal
}
}
void init_serial (void)
{
PINSEL0 = 0x00000005; // Enable RxD0 and
TxD0 U0LCR = 0x00000083; //8 bits, no Parity,
1 Stop bit
U0DLL = 0x000000C3; //9600 Baud Rate @ 30MHz VPB
Clock U0LCR = 0x00000003;
}
int putchar (int ch)
{
if (ch == '\n')
{
while (!(U0LSR &
0x20)); U0THR = CR;
}
while (!(U0LSR &
0x20)); return (U0THR
= ch);
}
int getchar (void)
{
while (!(U0LSR &
0x01)); return
(U0RBR);
}
Result:
Thus, interfacing of GSM module with ARM CORTEX M3- LPC2148 using embedded
C code was executed and verified successfully.
Aim:
To write an embedded C code for interfacing GSM Module with ARM
CORTEX M3-LPC2148.
Circuit Diagram:
Procedure:
Give +3.3V power supply to LPC2148 Primer Board; connect the +5V adapter
with GSM module which is connected with LPC2148 Primer Board through UART0.
Open the Hyper Terminal screen, select which port you are using and set the default
settings. Now the screen should show some text messages.
The following Commands and sequence of events performed for sending text
message to a mobile phone through GSM Modem interfaced with microcontroller:
First select the text mode for SMS by sending the following AT Command to GSM
Modem: AT+CMGF = 1 . This command configures the GSM modem in text mode.
Send the following AT Command for sending SMS message in text mode along
with mobile number to the GSM Modem : AT+CMGS =+923005281046 . This
command sends the mobile number of the recipient mobile to the GSM modem.
Send the text message string ("hello!") to the GSM Modem This is a test
message from UART".
If you not reading any text from UART0, then you just check the jumper connections &
just check the serial cable is working. Otherwise you just check the code with debugging
mode in Keil. If you want to see more details about debugging just see the videos in
below link.
If you not reading any text from UART0, then you just check the jumper connections &
just check the serial cable is working. Otherwise you just check the code with debugging
mode in Keil. If you want to see more details about debugging just see the videos in
below link.
Program:
#define CR 0x0D
#include <LPC21xx.H>
#include <stdio.h>
void getstring(unsigned char *);
int getchar (void) /* Read character from Serial
Port */ void status_ok(void);
void Serial_Init(void);
void delay(unsigned int n);
void main(void)
{
unsigned int
cnt=0x80,m; char xx;
Serial_Init();
delay(50);
while(1)
{
printf("AT\r"); // AT COMMAND FOR INITIALING status_ok();
printf("AT+IPR=9600\r"); // AT COMMAND FOR BAUD RATE
status_ok(); printf("AT+CMGR=2\r"); // Reading the message detail // at
Index 1 with phone number, data and time status_ok(); delay(250);
printf("ATD9790550124;\r");//AT COMMAND FOR CALL DIALING
delay(250); status_ok(); delay(500);
delay(500);
delay(500);
delay(500);
delay(500);
delay(500);
printf("ATH\r"); // AT COMMAND FOR CALL DISCONNECTING delay(250);
status_ok();
delay(500);
delay(500);
printf("ATDL\r"); // AT COMMAND FOR REDIALING delay(250); status_ok();
delay(500);
delay(500);
printf("ATH\r"); // AT COMMAND FOR ANSWERING THE CALL
delay(250); status_ok();
elay(500);
delay(500);
}
}
void getstring(unsigned char *array)
{
unsigned char temp=0, i=0;
do { temp = getchar();
*array++ = temp;
}
while((temp != '\r') && (temp != '\n'))
*array = '\0';
}
int getchar (void) /* Read character from Serial Port */
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
void status_ok(void)
{
getstring(y);
while(!(strstr(y,"OK")))
getstring(y);
pointr = strstr(y,"OK");
lcd_cmd(0xc0);
lcd_data(*pointr++);
lcd_data(*pointr);
delay(500);
lcd_cmd(0x01);
}
void Serial_Init(void)
{
PINSEL0 |= 0X00000005; //Enable Txd0 and Rxd0
U0LCR = 0x00000083; //8-bit data, no parity, 1-
stop bit U0DLL = 0x00000061; //for Baud
rate=9600,DLL=82 U0LCR = 0x00000003;
//DLAB = 0; }
void delay(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<12000;j++)
{;
}
}
Result:
Thus interfacing of GSM module with ARM CORTEX M3- LPC2148 using
embedded C code was executed and verified successfully