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

Embedded Sysytem File

This document describes experiments performed with an ARM7 and ARM9 microcontroller development board. It includes a table of contents listing 7 experiments: 1) Studying the ARM processor architecture and pin diagram, 2) Writing a program to flash an LED, 3) Interfacing an LCD display, 4) Interfacing an ADC, 5) Generating a ramp waveform using a DAC, 6) Controlling a stepper motor, and 7) Interfacing a Zigbee module to control external devices. The document provides details on each experiment, including the aim, equipment required, theory, code examples, diagrams, and procedures.

Uploaded by

Gagan Maggo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
183 views

Embedded Sysytem File

This document describes experiments performed with an ARM7 and ARM9 microcontroller development board. It includes a table of contents listing 7 experiments: 1) Studying the ARM processor architecture and pin diagram, 2) Writing a program to flash an LED, 3) Interfacing an LCD display, 4) Interfacing an ADC, 5) Generating a ramp waveform using a DAC, 6) Controlling a stepper motor, and 7) Interfacing a Zigbee module to control external devices. The document provides details on each experiment, including the aim, equipment required, theory, code examples, diagrams, and procedures.

Uploaded by

Gagan Maggo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

RAYAT BAHRA INSTITUTE OF

ENGINEERING AND BIO TECHNOLOGY

ELECTRONICS & COMMUNICATION ENGINEERING


DEPARTMENT

EMBEDDED SYSTEM LAB

SUBMITTED TO:

SUBMITTED BY:

Er. Ankit Sharma

Gagan Maggo

ECE 7A
1247808

Table of Contents
Sr. No.

Topic

Page
No.

Signature

1.

Study of ARM7 & ARM9 Bit Processor Architecture


and Pin Diagram.

2.

Write ARM Processor program to Flash LED.

3.

Write a program Interfacing of an LCD Display.

4.

Write a program to interface an ADC.

5.

Write a program to generate a Ramp waveform using


DAC interface.

6.

Write a program to control a Stepper Motor.

7.

Write a Program to Interface ZIGBEE with ARM to


control more external devices.

8.

EXPERIMENT No. : 1
Aim: Study of ARM7 & ARM9 Bit Processor Architecture and Pin Diagram.
Equipments Required :

Scientech 2501A TechBook with Power Supply and mains cord


Optical Fibre cable
Scientech Oscilloscope

Theory :
Specifications:
MCU
ARM7TDMI LPC2148 MCU
Memory
512K Flash Program Memory
32K+8K RAM Data Memory
Clock

12MHz crystal for maximum (5xPLL = 60MHz CPU clock) | 32 KHz RTC crystal
On-Board Peripherals:

8 Nos. Point LEDs

8 Nos. Digital Input(Slide Switch)

4x4 Matrix Keypad

2X16 Character LCD with back Light

4 Nos. 7-Segment Display (I2C)

2 Nos. Analog Input (Potentiometer)

Temperature Sensor

Stepper Motor Interface

2 Nos. of SPDT Relay

RTC with Batter-Backup

2 Nos. UART(RS232)

USB 2.0 device interface

Buzzer (Alarm)

PS/2 (keyboard interface)

Digital/Analog Output

Interrupts Study, Reset Button

Power:
9-12V, AC/DC- Adaptors, Power form USB (+5V) (+3.3V, 800mA)
Connectors:

JTAG (Programming/ Debugging)

D-SUB Connector (Serial Port, ISP)

40 PIN Expansion Connector

Ext Analog Input Connector

LPC2148 Processor Features:

16-bit/32-bit ARM7TDMI-S microcontroller in a tiny LQFP64 package.

8 kB to 40 kB of on-chip static RAM and 32 kB to 512 kB of on-chip flash memory. 128-bit wide
interface/accelerator enables high-speed 60 MHz operation.

In-System Programming/In-Application Programming (ISP/IAP) via on-chip boot loader software.


Single flash sector/full chip erase in 400 ms and programming of 256 bytes in 1 ms.

USB 2.0 Full-speed compliant device controller with 2 kB of endpoint RAM. In addition, the
LPC2146/48 provides 8 kB of on-chip RAM accessible to USB by DMA.

One or two (LPC2141/42 vs. LPC2144/46/48) 10-bit ADCs provide a total of 6/14 analog inputs, with
conversion times as low as 2.44 s per channel.

Single 10-bit DAC provides variable analog output (LPC2142/44/46/48 only).

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 (RTC) with independent power and 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 (VIC) 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 21 external interrupt pins available.

60MHz maximum CPU clock available from programmable on-chip PLL with settling time of 100s.

On-chip integrated oscillator operates with an external crystal from 1 MHz to 25 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 or BOD.

Single power supply chip with POR and BOD circuits:

CPU operating voltage range of 3.0 V to 3.6 V (3.3 V 10 %) with 5 V tolerant I/O pads.

Pin Diagram:

EXPERIMENT No. : 2
Aim: Study and measurement of bending loss in optical fiber.
Equipments Required :

LPC2148 :VPL-2013 & ET-51L KIT


LEDs
LCD
Connecting Leads

Theory :
Light Emitting Diodes (LED) is the most commonly used components, usually for displaying pins digital states.
Typical uses of LEDs include alarm devices, timers and confirmation of user input such as a mouse click or
keystroke.

Interfacing LED:

Figure shows how to interface the LED to microcontroller. As you can see the Anode is connected through a
resistor to GND & the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the
LED is OFF & when the Port Pin is LOW the LED is turned ON.
Flash a LED using LPC2148 Primer Board. It works by turning ON a LED & then turning it OFF & then
looping back to START. However the operating speed of microcontroller is very high so the flashing frequency
will also be very fast to be detected by human eye.
The ARM7 LPC2148 Primer board has eight numbers of point LEDs, connected with I/O Port lines (P1.16
P1.23) to make port pins high.

Circuit Diagram :

C Program to switch ON and OFF LED using LPC2148:


LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
LED :
SHORT CN9 to CN18
#include <LPC21xx.H>
#include "Timer.h"

/* LPC21xx definitions */

#define RS
24
#define RW 25
#define Elcm 26
#define busy 0x0800
#define
uchar unsigned char
#define uint unsigned int
extern long volatile timeval;
unsigned char const mcu123[]="FLASHING OF LEDS"
unsigned char const mcu124[]="
";
void Io_Set(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;

}
}
void Sent_Byte2(unsigned char data)
{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+16);}
else {Io_Clr(n+16);}
data=data>>1;
}
}
void delay(unsigned int i)
{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
void
{

delay1s(unsigned char i)
while(i>1)
{
i--;
delayms(20);
}

void WaitForEnable( void ) {


//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);

/* Delay function */

delay(1);
Io_Set1(Elcm);
delayms(10);
//
i=IO1PIN;
while( IO1PIN & busy );
Io_Clr1(Elcm);

//P1

}
void LcdWrite_CMD( uchar CMD,uchar AttribC ) {
if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWrite_CMD(temp,0);
}

void DispOneChar(uchar x,uchar y,uchar Wdata) {


LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
void wait (void) {
unsigned long i;
i = timeval;
while ((i +10 ) != timeval);

/* wait function */

/* wait 100ms */

}
int main (void) {
unsigned int j;
unsigned char k;
IODIR1=0xFFFF0000;
IODIR0=0x40FFFF10;
init_timer();

/* LED var */
// P1.16-->P1.26 as o/p used in LCD
// P0.16-->P0.23 as o/p used in LED

delayms(1);
lcdreset();
delay1s(1);
disp(0,0,mcu123);
disp(0,1,mcu124);
while (1) {

/* Loop forever */
k=0x55;
Sent_Byte2(k);

wait();
wait();
k=0xAA;
Sent_Byte2(k);
wait();
wait();
}
}

Square Wave Output:

EXPERIMENT No. : 3

Aim: Interfacing of an LCD Display.


Equipments Required:

LPC2148 :VPL-2013 & ET-51L KIT


2x16 character LCD
Connecting Leads

Theory :
Liquid Crystal Display also called as LCD is very helpful in providing user interface as well as for debugging
purpose. A liquid crystal display (LCD) is a flat panel display that uses the light modulating properties of
liquid crystals (LCs). LCD Modules can present textual information to user.

Figure shows how to interface the LCD to microcontroller. The 2x16 character LCD interface card with
supports both modes 4-bit and 8-bit interface, and also facility to adjust contrast through trim pot. In 4-bit
interface 7 lines needed to create 4-bit interface; 4 data bits (D0 D3), three control lines, address bit (RS),
read/write bit (R/W) and control signal (E).

Interfacing 4 bit LCD with LPC2148:


We now want to display a text in LPC2148 Primer Board by using 4 bit LCD module.
The ARM7 LPC2148 Primer board has seven numbers of LCD connections are needed to create 4-bit interface;
connected with 4 data bits (P0.19 P0.22, D4-D7), address bit (RS-P0.16), read/write bit (R/W-P0.17) and
control signal (E-P0.18) to make LCD display.
Pin Assignment with LPC2148:

CONTRO
L

DATA
LINES

LCD
MODULE

LPC2148
LINES

RS

P0.16

RW

P0.17

P0.18

D0-D3

NC

D4

P0.19

D5

P0.20

D6

P0.21

D7

P0.22

Make switch SW28 to LCD label marking


position

LPC2148:
LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
#include <LPC214X.H>
#define uchar unsigned char
#define uint unsigned int

/* LPC214x definitions */

2x16 LCD Selection

Circuit
Diagram :
C Program
to
display a
text in 4
bit LCD
using

#define RS
24
#define RW 25
#define Elcm 26
#define busy

0x0800

unsigned char const mcu123[]=" VPL INFOTECH " ;


unsigned char const mcu124[]=" & CONSULTANTS ";
void Io_Set(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}

void delay(unsigned int i)


{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}

/* Delay function */

void delay1s(unsigned char i)


{
while(i>1)
{
i--;
delayms(20);
}
}
void init_port(void)
{
//port initialized
IODIR1=0xFFFF0000;
IODIR0=0x40600F10;
}
void WaitForEnable( void ) {
//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);
delay(1);
Io_Set1(Elcm);
delayms(10);
// i=IO1PIN;
//P1
while( IO1PIN & busy );

// P1.16-->P1.26 as o/p used in LCD

Io_Clr1(Elcm);
}
void LcdWrite_CMD( uchar CMD,uchar AttribC ) {
if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWrite_CMD(temp,0);
}
void DispOneChar(uchar x,uchar y,uchar Wdata) {

LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
int main(void)
{ init_port();
delayms(1);
lcdreset();
delay1s(1);
disp(0,0,mcu123);
disp(0,1,mcu124);
while(1)
{
delay1s(1);
}
}

EXPERIMENT No. : 4

Aim : Write a program to interface an ADC.


Equipments Required :

LPC2148 :VPL-2013 & ET-51L KIT


LCD
Connecting Leads

Theory :
LPC2148 Microcontroller has two on n-chip ADCs. In the present program the (ADO) with channel 3 is used and
configured to cxonvert the Analog input signal into its equivalent Digital output. The configuration of on chip
ADCis as follows :
ADO.3 at Port P0.28
Pin=13

Circuit Diagram :

C Program to covert ADC using LPC2148:


LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
ADC :

SHORT CN15/CN10 to CN7 & CN16/CN9 to CN8


#include <LPC21xx.H>
#include "Timer.h"
extern long volatile timeval;
#define
uchar unsigned char
#define uint unsigned int

/* LPC21xx definitions */

#define RS
24
#define RW 25
#define Elcm 26
#define EOC 10
#define p16 16
#define p17 17
#define p18 18
#define p19 19
#define p20 20
#define p21 21
#define p22 22
#define p23 23
#define busy 0x0800
unsigned char const mcu123[]=" ADC VALUE =
void delay(unsigned int i)
{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
void delay1s(unsigned char i)

"

/* Delay function */

{
while(i>1)
{
i--;
delayms(20);
}
}
void Io_Set(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}

void Sent_Byte1(unsigned char data)


{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+8);}
else {Io_Clr(n+8);}
data=data>>1;
}
}
void Sent_Byte2(unsigned char data)
{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+16);}
else {Io_Clr(n+16);}
data=data>>1;
}
}
void WaitForEnable( void ) {
//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);
delay(1);
Io_Set1(Elcm);
delayms(10);
// i=IO1PIN;
//P1
while( IO1PIN & busy );
Io_Clr1(Elcm);
}
void LcdWrite_CMD( uchar CMD,uchar AttribC ) {
if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);

Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWrite_CMD(temp,0);
}
void DispOneChar(uchar x,uchar y,uchar Wdata) {
LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};

for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void disp1(uchar x,uchar y,const unsigned char ptr) {
DispOneChar(x++,y,ptr);
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
void wait (void) {
unsigned long i;
i = timeval;
while ((i +10 ) != timeval);

/* wait function */

/* wait 100ms */

}
unsigned char asc_code(unsigned char j)
{
if (j>9)
j=j+0x37;
else
j=j+0x30;

return j ;
}
int main (void) {
unsigned char i,dat1,dat2,j;
unsigned int k;
IODIR1 = 0xFFFF0000; // P1.16-->P1.26 as o/p used in LCD
IODIR0 = 0xFF00FB00; // P0.16-->P0.23 as i/p & P0.8,P0.9 as o/p
// P0.10 as i/p used in ADC
init_timer();
delayms(1);
lcdreset();
delay1s(1);
disp(0,0,mcu123);
while (1)
{
dat2=0x03;
Sent_Byte1(dat2);
//WR 1-0-1
dat2=dat2 & 0xFD;
Sent_Byte1(dat2);
dat2=dat2 | 0x02;
Sent_Byte1(dat2);
wait();
wait();
wait();
wait();
//up1:
k=IOPIN0;
//
if((k&1<<EOC)==0x00000400) goto dwn1;//data1=data1 || 0x02;
//
goto up1;

dwn1:

dat2=dat2 & 0xFE;


Sent_Byte1(dat2);

//RD low
//READ THE DATA

k=IOPIN0;
if((k&1<<p16)==0x010000) //data1=data1 || 0x02;
{
dat1=1;
}
else
{

dat1=0;
}
k=IOPIN0;
if((k&1<<p17)==0x020000) //data1=data1 || 0x02;
{
dat1=dat1 | 0x02;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p18)==0x040000) //data1=data1 || 0x02;
{
dat1=dat1 | 0x04;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p19)==0x080000)//data1=data1 || 0x8;
{
dat1=dat1 | 0x08;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p20)==0x100000)//data1=data1 || 0x10;
{
dat1=dat1 | 0x10;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p21)==0x200000)//data1=data1 || 0x20;

{
dat1=dat1 | 0x20;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p22)==0x400000)//data1=data1 || 0x40;
{
dat1=dat1 | 0x40;
}
else
{
dat1=dat1 | 0x00;
}
k=IOPIN0;
if((k&1<<p23)==0x800000)//data1=data1 || 0x80;
{
dat1=dat1 | 0x80;
}
else
{
dat1=dat1 | 0x00;
}
dat2=dat2 | 0x01;
Sent_Byte1(dat2);

//RD HIGH

//dat1=0x76;
j=dat1 & 0xf0;
j=j>>4;
j=asc_code(j);
disp1(13,0,j);
j=dat1 & 0x0f;
j=asc_code(j);
disp1(14,0,j);
}
}

EXPERIMENT No. : 5

Aim: Write a program to generate a Ramp waveform using DAC interface.


Equipments Required :

LPC2148 :VPL-2013 & ET-51L KIT


DAC
LCD
Connecting Leads

Theory :
A digital-to-analog converter is a device for converting a digital (usually binary) code to an analog signal
(current, voltage or charges). Digital-to-Analog Converters are the interface between the abstract digital world
and the analog real life. Simple switches, a network of resistors, current sources or capacitors may implement
this conversion. A DAC inputs a binary number and outputs an analog voltage or current signal.

Circuit Diagram :

C Program to generate a Ramp waveform using DAC with LPC2148:


LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
DAC :
SHORT CN9 to CN6

#include <LPC21xx.H>
#include "Timer.h"
extern long volatile timeval;

/* LPC21xx definitions */

#define
#define uint unsigned int
#define RS
#define RW
#define Elcm 26

uchar unsigned char

#define busy

0x0800

unsigned char const mcu123[]="OBSERVE THE RAMP"


unsigned char const mcu124[]="AT DAC O/P " ;

24
25

void delay(unsigned int i)


{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{

/* Delay function */

for(n=65535;n>1;n--);
i--;
}
}
void
{

delay1s(unsigned char i)
while(i>1)
{
i--;
delayms(20);
}

}
void Io_Set(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;

}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}
void Sent_Byte1(unsigned char data)
{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+16);}
else {Io_Clr(n+16);}
data=data>>1;
}
}
void WaitForEnable( void ) {
//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);
delay(1);
Io_Set1(Elcm);
delayms(10);
// i=IO1PIN;
//P1
while( IO1PIN & busy );
Io_Clr1(Elcm);
}
void LcdWrite_CMD( uchar CMD,uchar AttribC ) {

if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;
temp |= 0x80;
LcdWrite_CMD(temp,0);
}
void DispOneChar(uchar x,uchar y,uchar Wdata) {
LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}

}
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
void wait (void) {
unsigned long i;
i = timeval;
while ((i +10 ) != timeval);
}
int main (void) {
unsigned char k;

/* wait function */

/* wait 100ms */
/* LED var */

IODIR1 = 0xFFFF0000; // P1.16-->P1.26 as o/p used in LCD*/


IODIR0 = 0xFFFFFF00; // P0.16-->P0.23 as o/p used in DAC*/
init_timer();
delayms(1);
lcdreset();
delay1s(1);
disp(0,0,mcu123);
disp(0,1,mcu124);
while (1)
{
for(k=0;k<=255;k++)
{
Sent_Byte1(k);
}
}
}

EXPERIMENT No. : 6

Aim: Write a program to control a Stepper Motor.


Equipments Required :

LPC2148 :VPL-2013 & ET-51L KIT


Stepper Motor
LCD
Connecting Leads

Theory :
A stepper motor is a brushless, synchronous electric motor that converts digital pulses into mechanical shaft
rotation. Every revolution of the stepper motor is divided into a discrete number of steps, and the motor must be
sent a separate pulse for each step.
Interfacing Stepper Motor:
Figure shows how to interface the Stepper Motor to microcontroller. As you can see the stepper motor is
connected with Microcontroller output port pins through a ULN2803A array. So when the microcontroller is
giving pulses with particular frequency to ULN2803A, the motor is rotated in clockwise or anticlockwise.

Interfacing Stepper Motor with LPC2148


Controlling a stepper motor using LPC2148 Primer Board. It works by turning ON & OFF a four I/O port lines
generating at a particular frequency.
The ARM7 LPC2148 Primer board has four numbers of I/O port lines, connected with I/O Port lines (P1.16
P1.19) to rotate the stepper motor. ULN2803 is used as a driver for port I/O lines, drivers output connected to
stepper motor, connector provided for external power supply if needed.

Circuit Diagram :

C Program to control stepper motor using LPC2148:


LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
STEPPER MOTOR :
SHORT CN9 to CN4
#include <LPC21xx.H>
#include "Timer.h"
extern long volatile timeval;
#define uchar unsigned char
#define uint unsigned int

/* LPC21xx definitions */

#define RS
24
#define RW
25
#define Elcm 26
#define busy

0x0800

unsigned char const mcu123[]=" RUNNING OF "


;
unsigned char const mcu124[]="STEPPER MOTOR " ;
void delay(unsigned int i)
{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
void delay1s(unsigned char i)
{
while(i>1)
{
i--;
delayms(20);
}
}
void Io_Set(uchar pin)
{
unsigned int io_data=1;

/* Delay function */

io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}
void Sent_Byte1(unsigned char data)
{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1)
{
Io_Set(n+16);
}
else
{
Io_Clr(n+16);
}
data=data>>1;
}

}
void WaitForEnable( void )
{
//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);
delay(1);
Io_Set1(Elcm);
delayms(10);
//
i=IO1PIN;
//P1
while( IO1PIN & busy );
Io_Clr1(Elcm);
}
void LcdWrite_CMD( uchar CMD,uchar AttribC )
{
if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;

temp |= 0x80;
LcdWrite_CMD(temp,0);
}
void DispOneChar(uchar x,uchar y,uchar Wdata) {
LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
void wait (void) {
unsigned long i;
i = timeval;
while ((i +10 ) != timeval);

/* wait function */

/* wait 100ms */

}
int main (void)
{
unsigned int j;
unsigned char i,k;
IODIR1 = 0xFFFF0000; // P1.16-->P1.26 as o/p used in LCD
IODIR0 = 0xFFFFFF00; // P0.16-->P0.19 as o/p used in MOTOR
init_timer();

delayms(1);
lcdreset();
delay1s(1);
disp(0,0,mcu123);
disp(0,1,mcu124);
while (1)
{
/* Loop forever */
k=0xf5;
Sent_Byte1(k);
wait();
wait();
k=0xf6;
Sent_Byte1(k);
wait();
wait();

k=0xfA;
Sent_Byte1(k);
wait();
wait();
k=0xf9;
Sent_Byte1(k);
wait();
wait();
}
}

EXPERIMENT No. : 7

Aim: Write a Program to Interface ZIGBEE with ARM to control more external devices.
Equipments Required :

LPC2148 :VPL-2013 & ET-51L KIT


Module used : ZIGBEE MODULEWIRELESS with RS232 ADAPTER
LCD
CROSS CABLE
Connecting Leads

Theory :
ZigBee is a specification for a suite of high level communication protocols using small, low-power digital
radios based on an IEEE 802 standard for personal area networks.
Digi ZigBee:
The Digi Xbee 802.15.4 modules are the easiest to use, most reliable and cost-effective RF devices we've
experienced. The 802.15.4 Xbee modules provide two friendly modes of communication - a simple serial
method of transmit/receive or a framed mode providing advanced features. These modules can communicate
point to point, from one point to a PC, or in a mesh network.

Interfacing Zigbee:
Figure shows how to interface the Zigbee with microcontroller. The Xbee modules work at the 2.4 GHz
frequency which means smaller board and antenna size. Xbee modules have the ability to transmit Digital,
PWM, Analog or Serial RS232 signals wirelessly. To communicate over UART or USART, we just need three
basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART
with LPC2148, we just need the basic signals.

Interfacing Zigbee with LPC2148:


Interfacing ZigBee module with LPC2148 Primer Board for used for controlling application through UART0.
The data communication is done in internet by using the ZigBee module through MAX232 into the SBUF
register of LPC2148 microcontroller (refer serial interfacing with LPC2148). The serial data from the Zigbee
receiver is taken by using the Serial Interrupt of the controller. +5V and ground is connected to provide power
to the module. While TX and RX pin is connected for communication.

Pin Assignment with LPC2148:

LPC2148
UART
DB-9
Connector
Processor Lines

TXD-0

P0.0

RXD-0

P0.1

TXD-1

P0.8

RXD-1

P0.9

UART0(P1)
ISP PGM

UART1
(P2)

Serial Port Section

Circuit Diagram:

C Program to interface ZigBee with LPC2148 to control more external devices:


ZIGBEE Example

Module used: ZIGBEE MODULEWIRELESS with RS232 ADAPTER

LCD :
SHORT CN13 to CN2 & CN14 to CN1
USE CROSS CABLE male to female from Trainer 51lboard to Zigbee
#include <stdio.h>
#include <LPC21xx.H>
#include "Timer.h"
#define uchar unsigned char
#define uint unsigned int
#define RS
24
#define RW
25
#define Elcm 26

/* prototype declarations for I/O functions */


/* LPC21xx definitions
*/

#define KEY1 20
#define KEY2 21
#define KEY3 22
#define KEY4 23
#define busy 0x0800
extern long volatile timeval;
unsigned char slct1[]={2,0,67,4,0,0,1,49,119};
unsigned char ab1,ab2,ab5,bb1[31],jj1,flg1;
int csum1,kk1;
/****************/
/* main program */
/****************/
void wait (void) {
unsigned long i;
i = timeval;
while ((i +10 ) != timeval);
}
void Io_Set(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET0=io_data;
}
void Io_Clr(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR0=io_data;
}
void Io_Set1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOSET1=io_data;
}
void Io_Clr1(uchar pin)
{
unsigned int io_data=1;
io_data=io_data<<pin;
IOCLR1=io_data;
}
void Sent_Byte(unsigned char data)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(data&1) {Io_Set1(i+16);}
else {Io_Clr1(i+16);}
data=data>>1;
}
}

/* wait function */

/* wait 100ms */

void Sent_Byte1(unsigned char data)


{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+8);}
else {Io_Clr(n+8);}
data=data>>1;
}
}
void Sent_Byte2(unsigned char data)
{
unsigned char n;
for(n=0;n<8;n++)
{
if(data&1) {Io_Set(n+16);}
else {Io_Clr(n+16);}
data=data>>1;
}
}
void delay(unsigned int i)
{
unsigned int k=1000;
while(i>0)
{
i--;
}
while(k>1)k--;
}
void delayms (unsigned int i) {
unsigned int n;
while(i>1)
{
for(n=65535;n>1;n--);
i--;
}
}
void delay1s(unsigned char i)
{
while(i>1)
{
i--;
delayms(20);
}
}
void init_port(void)
{
//port initialized
IODIR1=0xFFFF0000;
// IODIR0=0xFF0F0F10;
IODIR0=0xFFFF017F;

/* Delay function */

//P0.2,P0.21,P0.22 as o/p,P0.4,P0.6,p0.7.p0.14 as i/p

}
void WaitForEnable( void ) {
//unsigned int i;
Io_Clr1(RS);
delay(1);
Io_Set1(RW);
delay(1);
Io_Set1(Elcm);
delayms(10);
//
i=IO1PIN;
while( IO1PIN & busy );
Io_Clr1(Elcm);

//P1

}
void LcdWrite_CMD( uchar CMD,uchar AttribC ) {
if (AttribC) WaitForEnable();
Io_Clr1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(CMD);
Io_Set1(Elcm);
delay(1);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LcdWrite_D( char dataW ) {
WaitForEnable();
Io_Set1(RS);
delay(1);
Io_Clr1(RW);
delay(1);
Sent_Byte(dataW);
Io_Set1(Elcm);
delay(1);
Io_Clr1(Elcm);
delay(1);
}
void LocateXY( char posx,char posy) {
uchar temp;
temp = posx & 0xf;
posy &= 0x1;
if ( posy )temp |= 0x40;

temp |= 0x80;
LcdWrite_CMD(temp,0);
}
void DispOneChar(uchar x,uchar y,uchar Wdata) {
LocateXY( x, y );
LcdWrite_D( Wdata );
}
void disp(uchar x,uchar y,const unsigned char *ptr) {
uchar i,l=0;
while (ptr[l] >31){l++;};
for (i=0;i<l;i++) {
DispOneChar(x++,y,ptr[i]);
if ( x == 16 ){
x = 0; y ^= 1;
}
}
}
void disp1(uchar x,uchar y,const unsigned char ptr) {
DispOneChar(x++,y,ptr);
}
void lcdreset(void)
{
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD(0x38, 0);
delayms(50);
LcdWrite_CMD( 0x38, 1);
LcdWrite_CMD( 0x08, 1);
LcdWrite_CMD( 0x01, 1);
LcdWrite_CMD( 0x06, 1);
LcdWrite_CMD( 0x0f, 1);
}
unsigned char Scan_Key(void)
{
unsigned int k,key,j;
unsigned char ab1;
ab1=0;
key=0;
j=0x00010000;
IOSET0=j;
j=0x00020000;
IOSET0=j;
j=0x00040000;
IOSET0=j;

j=0x00080000;
IOCLR0=j;
k=IOPIN0;
if((k&1<<KEY4)==0)key+=1;
key=key<<1;
if((k&1<<KEY3)==0)key+=1;
key=key<<1;
if((k&1<<KEY2)==0)key+=1;
key=key<<1;
if((k&1<<KEY1)==0)key+=1;
key=key<<1;
j=0x00010000;
IOSET0=j;
j=0x00020000;
IOSET0=j;
j=0x00040000;
IOCLR0=j;
j=0x00080000;
IOSET0=j;
k=IOPIN0;
if((k&1<<KEY4)==0)key+=1;
key=key<<1;
if((k&1<<KEY3)==0)key+=1;
key=key<<1;
if((k&1<<KEY2)==0)key+=1;
key=key<<1;
if((k&1<<KEY1)==0)key+=1;
key=key<<1;
j=0x00010000;
IOSET0=j;
j=0x00020000;
IOCLR0=j;
j=0x00040000;
IOSET0=j;
j=0x00080000;
IOSET0=j;
k=IOPIN0;
if((k&1<<KEY4)==0)key+=1;
key=key<<1;
if((k&1<<KEY3)==0)key+=1;
key=key<<1;
if((k&1<<KEY2)==0)key+=1;
key=key<<1;
if((k&1<<KEY1)==0)key+=1;
key=key<<1;
j=0x00010000;
IOCLR0=j;
j=0x00020000;
IOSET0=j;
j=0x00040000;
IOSET0=j;
j=0x00080000;
IOSET0=j;

k=IOPIN0;
if((k&1<<KEY4)==0)key+=1;
key=key<<1;
if((k&1<<KEY3)==0)key+=1;
key=key<<1;
if((k&1<<KEY2)==0)key+=1;
key=key<<1;
if((k&1<<KEY1)==0)key+=1;
key=key<<1;
switch(key)
{
case 0x10000:
ab1=4;
break;
case 0x8000:
ab1=3;
break;
case 0x4000:
ab1=2;
break;
case 0x2000:
ab1=1;
break;
case 0x1000:
ab1=8;
break;
case 0x800:
ab1=7;
break;
case 0x400:
ab1=6;
break;
case 0x200:
ab1=5;
break;
case 0x100:
ab1=0X13;
break;
case 0x80:
ab1=0x12;
break;
case 0x40:
ab1=0x11;
break;
case 0x20:
ab1=9;
break;
case 0x10:
ab1=0;
break;
case 0x8:

ab1=0x16;
break;
case 0x4:
ab1=0x15;
break;
case 0x2:
ab1=0x14;
break;
default:
ab1=0x0C;
break;
}
return ab1;
}
void fun1(void)
{
if (ab2>=0x0a)
ab2=ab2+0x37;
else
ab2=ab2+0x30;
}
void keysense(void)
{
if(ab1==0x0b)
{
ab1=Scan_Key();
if (ab1==0x0b|ab1==0x0c) goto agg1;
if (ab1==0x00|ab1==0x0a) goto agg1;
if (ab1==0x07|ab1==0x08) goto agg1;
if (ab1==0x09) goto agg1;

agg1:

ab5=9+ab1;
ab1=ab1+16;
}
}
//Main Program/
int main (void)
{
/* execution starts here
unsigned int ii,i,j,k;
unsigned char ab3,ab4;

*/

/* initialize the serial interface */


PINSEL0 = 0x00050000;
/* Enable RxD1 and TxD1
U1LCR = 0x83;
/* 8 bits, no Parity, 1 Stop bit
*/
U1DLL =97;
//16(57600);//195(4800);// 97(9600);
Clock
*/
U1LCR = 0x03;
/* DLAB = 0
*/
init_port();
delayms(1);

*/
/* 4800 Baud Rate @ 15MHz VPB

lcdreset();
delay1s(1);
disp(0,0,"ZIGBEE TRAINER");

//LCD UPPER LINE

rpt1:flg1=getchar();
rpt2:if(flg1==0x31)
{
lcdreset();
delay1s(1);
disp(0,0," LCD DISPLAY");
}

//LCD UPPER LINE

else if(flg1==0x32)
{
lcdreset();
delay1s(1);
disp(0,0," LED DISPLAY");
init_timer();
while (1)
{

/* Loop forever */

k=0x55;
Sent_Byte2(k);
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
k=0xAA;
Sent_Byte2(k);
wait();
wait();

//LCD UPPER LINE

wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
wait();
}
}
else if(flg1==0x34)
{
lcdreset();
delay1s(1);
disp(0,0," TRANSMIT DATA");
//LCD UPPER LINE
disp(0,1," TO PC");
//LCD UPPER LINE
while(1)
{
for (kk1=0;kk1<9;kk1++)
putchar(slct1[kk1]);
}

// Transmit Data

}
goto rpt1;
}

//main

You might also like