+ All Categories
Home > Documents > Embedded Sysytem File

Embedded Sysytem File

Date post: 16-Feb-2016
Category:
Upload: gagan-maggo
View: 238 times
Download: 0 times
Share this document with a friend
Description:
lab file
Popular Tags:
58
RAYAT BAHRA INSTITUTE OF ENGINEERING AND BIO – TECHNOLOGY ELECTRONICS & COMMUNICATION ENGINEERING DEPARTMENT EMBEDDED SYSTEM LAB SUBMITTED TO: SUBMITTED BY:
Transcript
Page 1: Embedded Sysytem  File

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

Page 2: Embedded Sysytem  File

Table of Contents

Sr. No. Topic Page No.

Signature

1.

2.

3.

4.

5.

6.

7.

8.

Study of ARM7 & ARM9 Bit Processor Architecture and Pin Diagram.

Write ARM Processor program to Flash LED.

Write a program Interfacing of an LCD Display.

Write a program to interface an ADC.

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

Write a program to control a Stepper Motor.

Write a Program to Interface ZIGBEE with ARM to control more external devices.

Page 3: Embedded Sysytem  File

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)

Page 4: Embedded Sysytem  File

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.

Page 5: Embedded Sysytem  File

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 100μs. 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.

Page 6: Embedded Sysytem  File

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.

Page 7: Embedded Sysytem  File

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> /* LPC21xx definitions */#include "Timer.h"

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

Page 8: Embedded Sysytem  File

#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){

Page 9: Embedded Sysytem  File

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) { /* Delay function */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(1);Io_Set1(Elcm);delayms(10);// i=IO1PIN; //¶ÁP1while( IO1PIN & busy );

Page 10: Embedded Sysytem  File

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 );

Page 11: Embedded Sysytem  File

}

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) { /* wait function */ unsigned long i;

i = timeval; while ((i +10 ) != timeval); /* wait 100ms */}

int main (void) { unsigned int j; /* LED var */

unsigned char k; IODIR1=0xFFFF0000; // P1.16-->P1.26 as o/p used in LCD IODIR0=0x40FFFF10; // P0.16-->P0.23 as o/p used in LED

init_timer();

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

Page 12: Embedded Sysytem  File

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.

Page 13: Embedded Sysytem  File

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: 

Page 14: Embedded Sysytem  File

 

Circuit Diagram :

C Program to display a text in 4 bit LCD using LPC2148:LCD : SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1

 LCD MODULE

LPC2148 LINES 2x16 LCD Selection

CONTROL

RS P0.16

 

RW P0.17

E P0.18

DATA LINES

D0-D3 NC

D4 P0.19

D5 P0.20

D6 P0.21

D7 P0.22

 Make switch SW28 to ‘LCD’ label marking position  

Page 15: Embedded Sysytem  File

#include <LPC214X.H> /* LPC214x definitions */#define uchar unsigned char#define uint unsigned int

#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);}

Page 16: Embedded Sysytem  File

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) { /* Delay function */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; // P1.16-->P1.26 as o/p used in LCD IODIR0=0x40600F10; }

void WaitForEnable( void ) {

//unsigned int i;

Io_Clr1(RS);delay(1);Io_Set1(RW);delay(1);

Page 17: Embedded Sysytem  File

Io_Set1(Elcm);delayms(10);// i=IO1PIN; //¶ÁP1while( 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;

Page 18: Embedded Sysytem  File

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

Page 19: Embedded Sysytem  File

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 :

Page 20: Embedded Sysytem  File

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> /* LPC21xx definitions */#include "Timer.h"extern long volatile timeval;#define uchar unsigned char#define uint unsigned int

#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) { /* Delay function */unsigned int n;while(i>1){

for(n=65535;n>1;n--);

Page 21: Embedded Sysytem  File

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);}

Page 22: Embedded Sysytem  File

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; //¶ÁP1while( IO1PIN & busy );Io_Clr1(Elcm);

}

void LcdWrite_CMD( uchar CMD,uchar AttribC ) {

Page 23: Embedded Sysytem  File

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 );

}

Page 24: Embedded Sysytem  File

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) { /* wait function */ unsigned long i;

i = timeval; while ((i +10 ) != timeval); /* wait 100ms */}

unsigned char asc_code(unsigned char j) {

if (j>9)

Page 25: Embedded Sysytem  File

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-1dat2=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 DATAk=IOPIN0;if((k&1<<p16)==0x010000) //data1=data1 || 0x02;{

Page 26: Embedded Sysytem  File

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;

Page 27: Embedded Sysytem  File

}

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

Page 28: Embedded Sysytem  File

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 :

Page 29: Embedded Sysytem  File

C Program to generate a Ramp waveform using DAC with LPC2148:LCD : SHORT CN13/CN12 to CN2 & CN14/CN11 to CN1DAC : SHORT CN9 to CN6

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

#define uchar unsigned char#define uint unsigned int#define RS 24 #define RW 25 #define Elcm 26

#define busy 0x0800

unsigned char const mcu123[]="OBSERVE THE RAMP" ;unsigned char const mcu124[]="AT DAC O/P " ;

void delay(unsigned int i){

unsigned int k=1000;while(i>0){

i--;}while(k>1)k--;

}void delayms (unsigned int i) { /* Delay function */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;io_data=io_data<<pin;IOSET0=io_data;

Page 30: Embedded Sysytem  File

}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);

Page 31: Embedded Sysytem  File

// i=IO1PIN; //¶ÁP1while( 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;

Page 32: Embedded Sysytem  File

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) { /* wait function */ unsigned long i;

i = timeval; while ((i +10 ) != timeval); /* wait 100ms */}int main (void) { unsigned char k; /* 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);

} }}

Page 33: Embedded Sysytem  File

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 LPC2148Controlling 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 :

Page 34: Embedded Sysytem  File

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> /* LPC21xx definitions */#include "Timer.h"extern long volatile timeval;#define uchar unsigned char#define uint unsigned int

#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) { /* Delay function */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;

Page 35: Embedded Sysytem  File

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; }

Page 36: Embedded Sysytem  File

}void WaitForEnable( void ) {

//unsigned int i;Io_Clr1(RS);delay(1);Io_Set1(RW);delay(1);Io_Set1(Elcm);delayms(10);// i=IO1PIN; //¶ÁP1while( 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;

Page 37: Embedded Sysytem  File

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) { /* wait function */ unsigned long i;

i = timeval; while ((i +10 ) != timeval); /* 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();

Page 38: Embedded Sysytem  File

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();

}

}

Page 39: Embedded Sysytem  File

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.

Page 40: Embedded Sysytem  File

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:

 

Circuit Diagram:

C Program to interface ZigBee with LPC2148 to control more external devices:ZIGBEE Example Module used: ZIGBEE MODULEWIRELESS with RS232 ADAPTER

 UART DB-9 Connector

LPC2148Processor Lines Serial Port Section

UART0(P1)ISP PGM

TXD-0 P0.0

            

RXD-0 P0.1

UART1(P2)

TXD-1 P0.8

RXD-1 P0.9

Page 41: Embedded Sysytem  File

LCD : SHORT CN13 to CN2 & CN14 to CN1

USE CROSS CABLE male to female from Trainer 51lboard to Zigbee

#include <stdio.h> /* prototype declarations for I/O functions */#include <LPC21xx.H> /* LPC21xx definitions */#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 0x0800extern 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) { /* wait function */ unsigned long i;

i = timeval; while ((i +10 ) != timeval); /* wait 100ms */} 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){

Page 42: Embedded Sysytem  File

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 delay(unsigned int i){

unsigned int k=1000;while(i>0){

i--;}while(k>1)k--;

}

void delayms (unsigned int i) { /* Delay function */unsigned int n;while(i>1){

for(n=65535;n>1;n--);i--;

}}void delay1s(unsigned char i)

Page 43: Embedded Sysytem  File

{while(i>1){

i--;delayms(20);

}} void init_port(void) { //port initialized IODIR1=0xFFFF0000;// IODIR0=0xFF0F0F10;

IODIR0=0xFFFF017F; //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; //¶ÁP1while( 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);

Page 44: Embedded Sysytem  File

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);

Page 45: Embedded Sysytem  File

} 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;

Page 46: Embedded Sysytem  File

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;

Page 47: Embedded Sysytem  File

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;

elseab2=ab2+0x30;

}

void keysense(void){

if(ab1==0x0b) {

agg1: 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;

ab5=9+ab1;ab1=ab1+16;}

}

//Main Program/

int main (void)

Page 48: Embedded Sysytem  File

{ /* 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); /* 4800 Baud Rate @ 15MHz VPB Clock */ U1LCR = 0x03; /* DLAB = 0 */ init_port();

delayms(1);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"); //LCD UPPER LINE

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();

Page 49: Embedded Sysytem  File

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++) // Transmit Dataputchar(slct1[kk1]);

}}goto rpt1;

} //main


Recommended