0% found this document useful (0 votes)
7 views38 pages

Et 3491 Emb&iot

The document is a laboratory manual for the Embedded Systems and IoT Design course at Mangayarkarasi College of Engineering, detailing practical exercises and experiments using the 8051 and ARM microcontrollers. It includes a list of experiments such as arithmetic operations, waveform generation, and various IoT mini-projects like garbage segregation and smart lock systems. The manual outlines the aims, required apparatus, algorithms, and procedures for each experiment, ensuring students can effectively perform and verify their tasks.

Uploaded by

muthurajharini67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views38 pages

Et 3491 Emb&iot

The document is a laboratory manual for the Embedded Systems and IoT Design course at Mangayarkarasi College of Engineering, detailing practical exercises and experiments using the 8051 and ARM microcontrollers. It includes a list of experiments such as arithmetic operations, waveform generation, and various IoT mini-projects like garbage segregation and smart lock systems. The manual outlines the aims, required apparatus, algorithms, and procedures for each experiment, ensuring students can effectively perform and verify their tasks.

Uploaded by

muthurajharini67
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

MANGAYARKARASI COLLEGE OF ENGINEERING

(Approved by AICTE, New Delhi & Affiliated to Anna


University, Chennai)
MANGAYARKARASI NAGAR, PARAVAI, MADURAI – 625 402
Website: http://mce-madurai.ac.in E-Mail: : [email protected]

DEPARTMENT OF ELECTRONICS AND


COMMUNICATION ENGINEERING
LABORATORY MANUAL

Sub.Code: ET3491

Sub.Name: EMBEDDED SYSTEMS AND IOT DESIGN


Regulation:R-21

Prepared By, Approved By,


Mr.V.Mohanadas, AP/ECE HOD-ECE

1
SYLLABUS

PRACTICAL EXERCISES
Experiments using 8051
1. Programming Arithmetic and Logical Operations in 8051
2. Generation of Square Waveform using 8051
3. Programming using On-Chip ports in 8051
4. Programming using Serial Ports in 8051
5. Design of a Digital Clock using Timers/Counters in 8051

Experiments using ARM


6. Interfacing ADC and DAC
7. Blocking of LEDs and LCD
8. Interfacing keyboard and Stepper Motor

Mini-projects for IoT


9. Garbage Segregator and Bin Level Indicator
10. Colour based Product Sorting
11. Image Processing based Fire Detection
12.. Vehicle Number Plate Detection
13. Smart Lock System

2
LIST OF EXPERIMENTS

S.No Experiment Pg.No

1 Arithmetic and Logical Operations in 8051

2 Generation of Square Waveform using 8051

3 Programming using On-Chip ports in 8051

4 Programming using Serial Ports in 8051

5 Design of a Digital Clock using Timers/Counters in


8051

6 Interfacing ADC and DAC

7 Blocking of LEDs and LCD

8 Interfacing keyboard and Stepper Motor

9 Garbage Segregator and Bin Level Indicator

10 Colour based Product Sorting

11 Image Processing based Fire Detection

12 Vehicle Number Plate Detection

13 Smart Lock System

3
EX NO:
1 Programming Arithmetic and Logical Operations
in 8051

AIM:
To perform arithmetic, logical, and bit manipulation operations using 8051.

APPARATUS REQUIRED:
1. 8051 KIT

A) 8-BIT ADDITION
ALGORITHM:
 Clear Program Status Word.
 Select Register bank by giving proper values to RS1 & RS0 of PSW.
 Load accumulator A with any desired 8-bit data.
 Load the register R 0 with the second 8-bit data.
 Add these two 8-bit numbers.
 Store the result.
 Stop the program.

4
P ROGRAM

OUTPUT:

INPUT OUTPUT

MEMORY DATA MEMORY DATA

9000 9004

9001 9005

9002

9003

5
(B) 8-BIT SUBTRACTION
ALGORITHM:
➢ Clear the carry flag.
➢ Initialize the register for borrowing.

➢ Get the first operand into the accumulator.

➢ Subtract the second operand from the accumulator.

➢ If a borrow results increment the carry register.

➢ Store the result in memory.

P
ROGRAM

OUT P UT

INPUT OUTPUT

Memory Data Memory Data

9000 9004

9001 9005

9002

9003

6
(C) 8-BIT MULTIPLICATION

ALGORITHM:
➢ Get the multiplier in the accumulator.
➢ Get the multiplicand in the B register.

➢ Multiply A with B.

➢ Store the product in memory.

PROGRAM

OUTPUT:

INPUT OUTPUT

Memory Data Memory location Data


Location

9000 9000

9001 9003

7
(D) 8-BIT DIVISION
ALGORITHM:
➢ Get the Dividend in the accumulator.
➢ Get the Divisor in the B register.

➢ Divide A by B.

➢ Store the Quotient and Remainder in memory.

PROGRAM:

OUTPUT

INPUT OUTPUT

Memory Data Memory Data


Location location

9000 9002

9001 9003

8
RESULT:

Thus the arithmetic, logical, and bit manipulation operations using 8051 has
been performed.

9
EX NO: 2
Generation of Square Waveform in 8051

AIM:
To perform Generation of square waveform using 8051.

APPARATUS REQUIRED:
1. 8051 KIT

ALGORITHM:

 Clear Program Status Word.


 Select Register bank by giving proper values to RS1 & RS0 of PSW.
 Load accumulator A with any desired 8-bit data.
 Load the register R 0 with the second 8-bit data.
 Add these two 8-bit numbers.
 Store the result.
 Stop the program.

10
Program

RESULT:

Thus the Generation of square wave using 8051 has been performed

11
EX.NO:3 Programming using On-Chip ports in
8051

AIM:

To perform programming using On-chip ports using 8051

APPARATUS REQUIRED:
1. 8051 KIT

ALGORITHM FOR ADC:

1. Set the port you connected to the output lines of the ADC as an input port.
2. Make the Port connected to EOC pin high. The reason for doing this is that the ADC
sends a high to low signal when the conversion of data is complete.
3. Clear the data lines which are connected to pins ALE, START, and OE as all these pins
require a Low to High pulse to get activated.
4. Select the data lines according to the input port you want to select.
5. Now that we have selected the analog input pin, we can tell the ADC to start the
conversion by sending a pulse to the START pin.
6. Wait for the High to low signal by polling the EOC pin.
7. Wait for the signal to get high again.
8. Extract the converted data by sending a High to low signal to the OE pin.

12
13
ALGORITHM FOR DAC:

1. Connect the P1 of 8051 with D0-D7 pins of DAC


2. Give +5v to VCC & Vref of DAC
3. Connect -12v to VEE of DAC
4. Connect OPAMP to OUT pin of the DAC With 5K resistor
5. Connect the oscilloscope to the OPAMP to View the output

14
RESULT: Thus the programming in On-Chip ports board using 8051 is verified successfully

Ex.no: Programming using Serial Ports in 8051

AIM:

To perform programming programming using serial port using 8051

APPARATUS REQUIRED:
1. 8051 KIT
2. Stepper motor

ALGORITHM:

1. Connect the first four input pins to the microcontroller


2. Connect the four output pins to the stepper motorConnect two pins to the 12V
supply
3. Connect the remaining pins to the stepper motor's output
4. Use the ULN2003A to connect the coils' four ends to port 2's first four
pinsGive the stepper motor's four wires 0 and 1,
5. depending on the mode you want to run the stepper motor inConnect the
remaining two wires to a 12V supply

15
RESULT: Thus the programming in serial port using 8051 is verified success

16
Interfacing ADC and DAC

AIM :

To write a program for Analog to Digital Conversion (On chip ADC,DAC)


and verify the output using Nvis 5004B board.

Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable
4. DSO/Oscilloscope
5. 2mm Patch Chord

Procedure for ADC:


1. Connect the USB cable to USB port of your PC and UART0( B
Type USB) port of the board (in PC interface & ISP section)
provided on the board.
2. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
4. Connect the power cable to the board and switch ‘ON’ the power switch.
5. Start the Flash Magic (available in the all programs on the Start menu of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “ADC_Interfacing.hex” file from the folder you have
saved.
7. Switch ‘OFF’ the power supply and change the position of
Run/ISP switch placed in “PC Interface & ISP Section” block
on the RUN mode.
8. Put all the switches provided in the ‘LED Interface’ block in the
OFF position.
9. Put all the switches provided in the ‘LCD Interface’ block in the ON
position.
10. Put 6,7,8 switches provided in the ‘Motor Module’ block in the
ON position
11. Put 6,7 Dip switches provided in the ‘ADC Interface’ block in the
ON position
12. Connect the DC Voltage potentiometer provided in the
‘ADC Interface’ block with the AIN1 pin using a patch chord.
13. Turn ON the switch no 5 of the switch provided in the
‘ADC Interface’
14. Switch ‘On’ the supply, then press reset switch.
15. Rotating the potentiometer will provide the analog input to
the controller and its digitally converted values could be seen on
LCD.

17
Procedure for DAC:
1. Connect the USB cable to USB port of your PC and UART0( B
Type USB) port of the board (in PC interface & ISP section)
provided on the board.
2. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
4. Connect the power cable to the board and switch ‘ON’ the power switch.
5. Start the Flash Magic (available in the all programs on the Start menu of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “DAC Square generation .hex” file from the folder
you have saved. 7. Switch ‘OFF’ the power supply and change the
position of Run/ISP switch placed in “PC Interface & ISP
Section” block on the RUN mode.
8. Put 4 Dip switches provided in the ‘ADC Interface’ block in the
ON position
9. Switch ‘On’ the supply, then press reset switch.
10. Observe Signal on “Aout” with DSO/Oscilloscope.

Program //ADC

#include <LPC214x.H> /* LPC214x definitions */ #define


CR 0x0D
#define PLOCK 0x400
void ADC_Init(void); /* ADC Init Function */ void
ADC_Convert(unsigned int); /* ADC Display Function */

unsigned int ADC_Val; /* ADC Result (HEX) */ unsigned int


FirstBit,SecondBit,ThrdBit,FourthBit;
void LCD_Init(void); /* LCD Init Function */ void LCD_Delay(unsigned int);
/* LCD LCD_Delay Function */
void LCD_Cmd(unsigned long); /* LCD Command Function */
voidLCD_Data(unsigned long); /* LCD Data Function */
void LCD_Disp(unsigned char,unsigned char *); /* LCD Display Function */ void
LCD_Delay(unsigned int Time)
{
unsigned int i,j;

18
for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}

void LCD_Init(void)
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots
*/ LCD_Cmd(0x0C); /* Display On curser Off */
LCD_Cmd(0x01); /* Clear Display */
LCD_Cmd(0X06); /* Entry Mode */
}

void LCD_Cmd(unsigned long Cmd)


{
unsigned long Shifted_Cmd;
Shifted_Cmd = Cmd << 16; /* because We have selected P1.16 to
P1.23 as LCD data line */

RS_Clr; /* RS Pin Clear */


LCD_Delay(10); /* LCD_Delay for Clock*/ EN_Set;
/* Enable Pin SET */
LCD_Delay(10);
IO1SET = Shifted_Cmd; /* Write Command Value to LCD Data Pin
*/ LCD_Delay(20); /* LCD_Delay for enable Clock*/
EN_Clr; /* Enable Pin Clear */
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}

void LCD_Data(unsigned long Data)


{

RS_Set; /* RS Pin Clear */


LCD_Delay(10); /* LCD_Delay for
Clock*/ EN_Set; /* Enable Pin SET */
LCD_Delay(10);
IO1SET = Data << 16; /* Write Command Value to LCD Data Pin */
LCD_Delay(20); /* LCD_Delay for enable Clock*/ EN_Clr; /* Enable
Pin Clear */

19
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}

void LCD_Disp(unsigned char Loc, unsigned char *String)


{
LCD_Cmd(Loc); /* Send Command to LCd */ while(*String) /* Wait untill
Null char come */ {
LCD_Data(*String++); /* Write data to LCD
*/ IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
}

void Delay(unsigned int Time)


{
unsigned int i,j;

for(i=0;i<=Time;i++)
for(j=0;j<110;j++);
}

static void feed(void)


{
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
}

void PLL_Init()
{
PLL0CFG = 0x24;
feed(); /* Enabling the PLL */ PLL0CON = 0x01;
feed(); /* Wait for the PLL to lock set frequency */ while(!(PLL0STAT &
PLOCK)); /* Connect the PLL as the clock source */ PLL0CON = 0x3;
Enabling MAM and setting number of clocks used for Flash memory fetch
(4 cclks in this
case) */
MAMTIM = 0x04;
MAMCR = 0x02; /* Setting peripheral Clock (pclk) to System
Clock (cclk)*/
VPBDIV = 0x01;

20
}

void ADC_Init()
{
PINSEL0 = 0x00030000; /* channel AD1.1 */
AD1CR = 0x01210402; /* Setup A/D: 10-bit AIN1 @ 3MHz */
}
void ADC_Convert(unsigned int ADC_Value)
{
unsigned int X,Y,Z; /* Intermidiate Variables */
FirstBit=0,SecondBit=0,ThrdBit=0,FourthBit=0
; X = ADC_Value/10;
FirstBit = ADC_Value%10;
FirstBit = 0x30|FirstBit; /* First Byte(LSB)
*/ Y = X/10;
SecondBit = X % 10;
SecondBit = 0x30|SecondBit; /* Second Byte
*/ Z = Y/10;
ThrdBit = Y % 10;
ThrdBit = 0x30|ThrdBit; /* Third Byte
*/ FourthBit = Z; /* Last Byte(MSB) */
FourthBit=0x30|FourthBit;
}

int main (void) /* program exec. starts here */ {

IO1DIR = 0x00FF0000; /* Set LCD_DATA pin as out put */ IO0DIR =


0x00E00000; /* Set LCD_Control pin as out put */ LCD_Init(); /* Initialize
LCD */ Delay(100);
LCD_Disp(0x80, " NVIS "); /* Display "NVIS" */
LCD_Disp(0xC0, " Technologies "); /* Display "Technologies"
*/

Delay(5000);
LCD_Cmd(0x01);
ADC_Init(); /* ADC Initialize*/
while(1)
{
AD1CR |= 0x01000000; /* start of ADC conversion */ do
{
ADC_Val = AD1DR1; /* 10 bit value */
21
}
while ((ADC_Val & 0x80000000) == 0); /* Wait ADC
Conversion Complete*/
AD1CR &= ~0x01000000; /* Again start ADC */ ADC_Val =
(ADC_Val >> 6) & 0x03FF;
ADC_Convert(ADC_Val); /* Convert ADC value into ASCII
for LCD Display */
LCD_Disp(0x83, "ADC Value");
LCD_Cmd(0xC5);
LCD_Data(FourthBit);
LCD_Cmd(0xC6);
LCD_Data(ThrdBit);
LCD_Cmd(0xC7);
LCD_Data(SecondBit);
LCD_Cmd(0xC8);
LCD_Data(FirstBit);

Delay(40000);
}
}

Program//DAC

#include<LPC214x.H>
void msdelay(unsigned long);
int main(void)
{
unsigned int DAC_Val;
IO1DIR = 0xFFFF0040;
IO0SET = 0x00000000;
VPBDIV = 0x01;
PINSEL0 = 0x00030000; //channel AD1.1
PINSEL1 = 0x00080000; //ENABLE DAC PIN
AD1CR = 0x01210402 ; /* Setup A/D: 10-bit AIN0 @ 3MHz */

while (1) /*START FIRST WHILE*/


{
DAC_Val = 0x03FF;
DACR=DAC_Val<<6;
msdelay(200);

22
DAC_Val = 0x00;
DACR =DAC_Val<<6;
msdelay(200);
}
}

void msdelay (unsigned long a) // DELAY ROUTINE


{
while (--a!=0);
}

Result

Thus the programs for Analog to Digital Conversion (On chip ADC), (On
chip DAC) were written and its output were verified using Nvis 5004 boar
23
EX.NO:
Blocking of LEDs and LCD

Aim:
To write a program for LED and LCD Interface and verify the output
using
Nvis 5004B board.

Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable

Procedure for LED:


1. Connect the USB cable to USB port of your PC and UART0( B
Type
USB) port of the board (in PC interface & ISP section) provided on
the
board.
2. Change the position of Run/ISP switch placed in “PC Interface &
ISP
Section” block on the ISP
mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ”
block.
4. Connect the USB cable (supplied along with the board) to USB port
of
your PC and UART0( B Type USB) port of the board (in PC interface
& ISP section) provided on the board.
5. Change the position of Run/ISP switch placed in “PC Interface &
ISP Section” block on the ISP mode.
6. Turn ON switch no 1, 2 placed in “I2C & SPI ”
block.
7. Connect the power cable to the board and switch ‘ON’ the power
switch.
8. Start the Flash Magic (available in the all programs on the Start menu
of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
9. Program “LED_Interface.hex” file from the folder you have
saved.
10. Switch ‘OFF’ the power supply and change the position
of Run/ISP switch placed in “PC Interface & ISP Section” block on
the RUN mode.
11. Put all the switches provided in the ‘LED Interface’ block in the
ON
position.
12. Put all the switches provided in the ‘LCD Interface’ block in the
OFF
position.

24
13. Switch ‘On’ the supply, then press reset
switch.
14. Observe the LED glowing according to
program

Procedure for 16X2 LCD Display:


1. Connect the USB cable (supplied along with the board) to USB
port
of your PC and UART0( B Type USB) port of the board (in
PC
interface & ISP section) provided on the
board.
2. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ”
block.
4. Connect the power cable to the board and switch ‘ON’ the power
switch.
5. Start the Flash Magic (available in the all programs on the Start menu
of

25
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “LCD_Interface.hex” file from the folder you have
saved. 7. Switch ‘OFF’ the power supply and change the
position of Run/ISP switch placed in “PC Interface & ISP
Section” block on the RUN mode.
8. Put all the switches provided in the ‘LED Interface’ block in the
OFF position.
9. Put all the switches provided in the ‘LCD Interface’ block in the ON
position.
10. Put 6,7,8 switches provided in the ‘Motor Drive ’ block in the ON
position.
11. Switch ‘On’ the supply, then press reset switch.
12. Observe the LCD Display according to program.

Program for LED

void MSdelay(unsigned int rTime)


{
unsigned int i,j;
for(i=0;i<=rTime;i++)
for(j=0;j<4867;j++);
}

int main(void)
{
IO1DIR = 0x00070000; /* Define Port1 pin P1.16 to P1.23 as output
*/
while (1)
{
IO1SET = 0x00070000; /* Glow All LEDs */
MSdelay (100); /* Delay */
IO1CLR = 0x00070000;
MSdelay (100); /* Delay */

26
Program for LCD

void LCD_Init(void); /* LCD Init Function */ void LCD_Delay(unsigned int);


/* LCD LCD_Delay Function */
void LCD_Cmd(unsigned long); /* LCD Command Function */
void LCD_Data(unsigned long); /* LCD Data Function */
void LCD_Disp(unsigned char,unsigned char *); /* LCD Display Function */
#define RS_Set IO0SET = 0x00200000;
#define RS_Clr IO0CLR = 0x00200000;
#define EN_Set IO0SET = 0x00800000;
#define EN_Clr IO0CLR = 0x00800000;
void LCD_Delay(unsigned int Time)
{
unsigned int i,j;
for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}
void LCD_Init(void)
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots
*/ LCD_Cmd(0x0C); /* Display On curser Off */
LCD_Cmd(0x01); /* Clear Display */
LCD_Cmd(0X06); /* Entry Mode */
}
void LCD_Cmd(unsigned long Cmd)
{
unsigned long Shifted_Cmd;
Shifted_Cmd = Cmd << 16; /* because We have selected P1.16 to P1.23 as
LCD data line */
RS_Clr; /* RS Pin Clear */
LCD_Delay(10); /* LCD_Delay for Clock*/ EN_Set;
/* Enable Pin SET */
LCD_Delay(10);
IO1SET = Shifted_Cmd; /* Write Command Value to LCD Data Pin */
LCD_Delay(20); /* LCD_Delay for enable Clock*/ EN_Clr; /* Enable Pin
Clear
*/
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }
void LCD_Data(unsigned long Data)
{

RS_Set; /* RS Pin Clear */


LCD_Delay(10); /* LCD_Delay for Clock*/ EN_Set; /* Enable Pin
SET */
LCD_Delay(10);

27
IO1SET = Data << 16; /* Write Command Value to LCD Data Pin */
LCD_Delay(20); /* LCD_Delay for enable Clock*/ EN_Clr; /* Enable Pin
Clear
*/
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }
void LCD_Disp(unsigned char Loc, unsigned char *String)
{
LCD_Cmd(Loc); /* Send Command to LCd */ while(*String) /*
Wait untill Null char come */ {
LCD_Data(*String++); /* Write data to LCD */
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
}
int main(void)
{
IO1DIR = 0x00FF0000; /* Set LCD_DATA pin as out put */
IO0DIR = 0x00FF0000; /* Set LCD_Control pin as out put
*/ LCD_Init(); /* Initialize LCD */ while(1)
{
LCD_Disp(0x80, " NVIS "); /* Display "NVIS" */
LCD_Disp(0xC0, " Technologies "); /* Display "Technologies" */
}
}

Result

Thus the programs for LED and 16x2 LCD Display Interface were
written and its output were verified using Nvis 5004 board.
28
EX.NO
Interfacing keyboard and StepperMotor

Aim:
To write a program for a 4x4 Hex Keypad Stepper Motor Interface and
verify the output using Nvis 5004B board.

Equipment Needed:
1. Nvis 5004B board
2. Adapter 5volt/1Amp
3. USB Cable

Procedure for 4X4 hex Keyboard:


1. Connect the USB cable (supplied along with the board) to USB port
of your PC and UART0( B Type USB) port of the board (in PC
interface & ISP section) provided on the board.
2. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
4. Connect the USB cable (supplied along with the board) to USB port
of your PC and UART0( B Type USB) port of the board (in PC
interface & ISP section) provided on the board.
5. Change the position of Run/ISP switch placed in “PC Interface
& ISP Section” block on the ISP mode.
6. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
7. Connect the power cable to the board and switch ‘ON’ the power switch.
8. Start the Flash Magic (available in the all programs on the Start menu of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
9. Program “LED_Interface.hex” file from the folder you have
saved. 10. Switch ‘OFF’ the power supply and change the position
of Run/ISP switch placed in “PC Interface & ISP Section” block
on the RUN mode.
11. Put all the switches provided in the ‘LED Interface’ block in the OFF
position. 12. Put all the switches provided in the ‘LCD Interface’
block in the ON position. 13. Put 6,7,8 switches provided in the
‘Motor
Module’ block in the ON position 14. Put all the switches provided
in the ‘4x4 Hex Keypad’ block in the ON position 15. Switch ‘On’
the
supply, then press reset switch.
16. Observe the Character display on LCD when user press
Keypad according to program.

Program for keyboard

#include <LPC214x.H> /* LPC214x definitions


29
#define RS_Set IO0SET = 0x00200000;
#define RS_Clr IO0CLR = 0x00200000;

#define EN_Set IO0SET = 0x00800000;


#define EN_Clr IO0CLR = 0x00800000;
void LCD_Delay(unsigned int Time)
{
unsigned int i,j;

for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}
void LCD_Init(void)
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots
*/ LCD_Cmd(0x0C); /* Display On curser Off */
LCD_Cmd(0x01); /* Clear Display
*/ LCD_Cmd(0X06); /* Entry Mode
*/
}

void LCD_Cmd(unsigned long Cmd)


{
unsigned long Shifted_Cmd;

Shifted_Cmd = Cmd << 16; /* because We have selected P1.16 to


P1.23 as LCD data line */

RS_Clr; /* RS Pin Clear */


LCD_Delay(10); /* LCD_Delay for Clock*/ EN_Set;
/* Enable Pin SET */
LCD_Delay(10);
IO1SET = Shifted_Cmd; /* Write Command Value to LCD Data Pin
*/ LCD_Delay(30); /* LCD_Delay for enable Clock*/ EN_Clr; /*
Enable Pin Clear */
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }

void LCD_Data(unsigned long Data)


{
RS_Set; /* RS Pin Clear */
LCD_Delay(10); /* LCD_Delay for Clock*/ EN_Set; /* Enable Pin
SET */
LCD_Delay(10);

IO1SET = Data << 16; /* Write Command Value to LCD Data Pin
*/ LCD_Delay(30); /* LCD_Delay for enable Clock*/ EN_Clr; /*
30
Enable Pin Clear */
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */ }
void LCD_Disp(unsigned char Loc, unsigned char *String)

31
{
LCD_Cmd(Loc); /* Send Command to LCd */ while(*String) /*
Wait untill Null char come */ {
LCD_Data(*String++); /* Write data to LCD */
IO1CLR = 0x00FF0000; /* Clear All pins of LCD
*/
}
}

int main(void)
{
IO0DIR = 0x00E00000; /* defined as Outputs for LCD P0.21,22,23*/
IO1DIR = 0x0FFF0000; /* defined as Outputs for keypad P1.23 to P1.17
LCD_Init();
LCD_Disp(0x80, " Nvis "); /* Display "NVIS" */ LCD_Disp(0xC0,
" Technologies "); /* Display "Technologies" */; LCD_Delay(5000);
LCD_Cmd(0x01); /* Clear Display */ LCD_Disp(0x82," Key Pressed");
while(1)
{
IO1SET = 0x01000000; /* Set Row 1 */

if((IO1PIN & 0xF0000000)!= 0xF0000000)


{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/
{
LCD_Disp(0xC8,"1"); /* Set Curser at
'0xC6' */
IOCLR1 = 0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000) /*Row1, Column2*/
{ LCD_Disp(0xC8,"4");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,
Column3*/
{ LCD_Disp(0xC8,"7");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000) /*Row1,

Column4*/ { LCD_Disp(0xC8,"0");
IOCLR1 = 0x80000000;

32
}
LCD_Delay (100);
}
IO1CLR = 0x01000000; /* Clear Row 1 */ IO1SET = 0x02000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"2"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000) /*Row1,
Column2*/
{ LCD_Disp(0xC8,"5");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,

Column3*/ { LCD_Disp(0xC8,"8");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000) /*Row1,

{ LCD_Disp(0xC8,"A");
Column4*/ IOCLR1 = 0x80000000;
}
LCD_Delay (100);

}
IO1CLR = 0x02000000; /* Clear Row 1 */ IO1SET = 0x04000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"3"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000)
/*Row1, Column2*/
{ LCD_Disp(0xC8,"6");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,

33
Column3*/
{ LCD_Disp(0xC8,"9");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000)
/*Row1, Column4*/
{ LCD_Disp(0xC8,"B");
IOCLR1 = 0x80000000;
}
LCD_Delay (100);
}
IO1CLR = 0x04000000; /* Clear Row 1 */ IO1SET = 0x08000000; /* Set
Row 1 */ if((IO1PIN & 0xF0000000)!= 0xF0000000)
{
if((IO1PIN & 0x10000000) == 0x10000000) /*Row1,
Column1*/ {
LCD_Disp(0xC8,"F"); /* Set Curser at '0xC6' */ IOCLR1 =
0x10000000; /* Clear pins */
}
else if((IO1PIN&0x20000000) == 0x20000000) /*Row1,
Column2*/
{ LCD_Disp(0xC8,"E");
IOCLR1 = 0x20000000;
}
else if((IO1PIN&0x40000000) == 0x40000000) /*Row1,

Column3*/ { LCD_Disp(0xC8,"D");
IOCLR1 = 0x40000000;
}
else if((IO1PIN&0x80000000) == 0x80000000) /*Row1,

{ LCD_Disp(0xC8,"C");
Column4*/ IOCLR1 = 0x80000000;
}
LCD_Delay (100);

}
IO1CLR = 0x08000000; /* Clear Row 1 */ }
}

34
Procedure for Stepper Motor Interface:

1. Connect the USB cable to USB port of your PC and UART0( B


Type USB) port of the board (in PC interface & ISP section)
provided on the board.
2. Change the position of Run/ISP switch placed in “PC Interface &
ISP Section” block on the ISP mode.
3. Turn ON switch no 1, 2 placed in “I2C & SPI ” block.
4. Connect the power cable to the board and switch ‘ON’ the power switch.
5. Start the Flash Magic (available in the all programs on the Start menu of
Windows OS: Start menu/All programs/Flash Magic/Flashmagic.exe.)
and select the appropriate port settings (use baud rate 9600).
6. Program “DAC Square generation .hex” file from the folder you
have saved
7. Switch ‘OFF’ the power supply and change the position of
Run/ISP switch placed in “PC Interface & ISP Section” block on
the RUN mode.
8. Put 1,2,3,4,5, Dip switches provided in the ‘Motor Module’ block
in the ON position
9. Connect a patch cord from+5volt to Vcc in Motor Drive block
10. Connect Stepper Motor wire connection according to read me file.
11. Switch ‘On’ the supply, then press reset switch.
12. Observe rotation of Stepper motor.

Program

void MSdelay(unsigned int rTime)


{
unsigned int i,j;
for(i=0;i<=rTime;i++)
for(j=0;j<1275;j++);
}

int main(void)
{
IO0DIR = 0x001F0000;
IO0SET = 0x00010000;

while (1)
{
IO0SET = 0x00020000;
MSdelay(150);

35
IO0CLR = 0x00020000;

IO0SET = 0x00040000;
MSdelay(150);
IO0CLR = 0x00040000;

IO0SET = 0x00080000;
MSdelay(150);
IO0CLR = 0x00080000;

IO0SET = 0x00100000;
MSdelay(150);
IO0CLR = 0x00100000;
}
}

Result
Thus the program for Keyboard and Stepper Motor Interface were
written and its output were verified using Nvis 5004 board.

36
30

You might also like