Embedded Sysytem File
Embedded Sysytem File
SUBMITTED TO:
SUBMITTED BY:
Gagan Maggo
ECE 7A
1247808
Table of Contents
Sr. No.
Topic
Page
No.
Signature
1.
2.
3.
4.
5.
6.
7.
8.
EXPERIMENT No. : 1
Aim: Study of ARM7 & ARM9 Bit Processor Architecture and Pin Diagram.
Equipments Required :
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:
Temperature Sensor
2 Nos. UART(RS232)
Buzzer (Alarm)
Digital/Analog Output
Power:
9-12V, AC/DC- Adaptors, Power form USB (+5V) (+3.3V, 800mA)
Connectors:
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.
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.
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.
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.
Individual enable/disable of peripheral functions as well as peripheral clock scaling for additional power
optimization.
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 :
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 :
/* 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);
}
/* 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);
}
/* 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();
}
}
EXPERIMENT No. : 3
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).
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
LPC2148:
LCD :
SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1
#include <LPC214X.H>
#define uchar unsigned char
#define uint unsigned int
/* LPC214x definitions */
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
/* Delay function */
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
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 :
/* 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;
}
}
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:
//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
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 :
#include <LPC21xx.H>
#include "Timer.h"
extern long volatile timeval;
/* LPC21xx definitions */
#define
#define uint unsigned int
#define RS
#define RW
#define Elcm 26
#define busy
0x0800
24
25
/* 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 */
EXPERIMENT No. : 6
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.
Circuit Diagram :
/* LPC21xx definitions */
#define RS
24
#define RW
25
#define Elcm 26
#define busy
0x0800
/* 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 :
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.
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)
Circuit Diagram:
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
#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 */
/* Delay function */
}
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;
*/
*/
/* 4800 Baud Rate @ 15MHz VPB
lcdreset();
delay1s(1);
disp(0,0,"ZIGBEE TRAINER");
rpt1:flg1=getchar();
rpt2:if(flg1==0x31)
{
lcdreset();
delay1s(1);
disp(0,0," LCD DISPLAY");
}
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();
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