Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Experiment-01

Object: Introduction to 8051 Microcontroller Board

Introduction:

Easy8051B development system is a full-featured development board for Atmel 8051


microcontrollers. It is designed to allow students and engineers to easily test and explore the
capabilities of the 8051 microcontrollers. It also allows 8051 microcontrollers to be interfaced
with external circuits and a broad range of peripheral devices, making it possible for the user to
concentrate on software development.

Figure 1 illustrates the development board. There are identification marks beside each component
on a silkscreen. These marks describe connections to the microcontroller, operation modes, and
provide additional information. Since all relevant information is provided on the board there is
almost no need for additional schematics.

1
Key Features:
1. External power supply 8-16 V AC/DC.
2. Choose between external and USB power supply.
3. Very fast and flexible USB programmer on board. The key feature is expandability. By
4. DS1820 temperature sensor allows to measure temperature with 0.5°C accuracy.
5. One RS232 port for communication with PC or another microcontroller.
6. 4-channel 12-Bit ADC (Analog-to-Digital Converter) with SPI interface.
7. 12-Bit DAC (Digital-to-Analog Converter) with SPI interface.
8. By setting jumper in the upper position the pins of the appropriate port are set to logical
one (pull-up). By setting jumper in the lower postion, the pins are set to logical zero (pull-
down). Select pull up to provide logical zero on pin’s inputs. Select pull down to provide
logical one on pin’s inputs
9. LCD connector allows easy connection of LCD in 4-bit mode.
10. Graphic LCD connector allows easy connection of GLCD or LCD in 8-bit mode.
11. Easy8051B supports microcontrollers in DIP14, DIP16, DIP20, DIP40, PLCC44 and
PLCC32 package.
12. 32 buttons allow control of every pin on the microcontroller.
13. By pressing the button select high/low state of the pins.
14. See all the signals - each pin has an LED.
15. 4.096V voltage reference is used for working with A/D and D/A Converters.
16. Upper four switches on the SW2 turns on/off the LEDs on PORT0, PORT1, PORT2 and
PORT3. Select port to connect LEDs to. By using lower four switches select which digit
on seven segment display are to be turned on.
17. Set LCD contrast according to display characteristics
18. Set GLCD contrast according to display characteristics.
19. On-Board peripherals are connected to the microcontroller via switches on the SW1.
20. Seven segment displays in multiplex mode for displaying values.
21. Reset circuit - if the reset button is pressed MCU will start executing from the beginning.
22. On-Board oscillator circuit for generating microcontroller’s clock input.

2
Pin Diagram of 8051 Microcontroller:

Block Diagram of 8051 Microcontroller:

3
Experiment-02

A. Write a program to show the addition of two numbers.


Program

MOV A,#10H
MOV B,#20H
ADD A,B
MOV P3,A

OUTPUT= 30H

B. Write a program to subtract two numbers.

Program

MOV A,#20H
MOV B,#10H
SUBB A,B
MOV P3,A

OUTPUT= 10H

C. Write a program to divide two numbers


Program:

MOV A,#95H
MOV B,#10H
DIV AB
MOV P3,A

OUTPUT
A= 09 H (QUOTIENT)
B= 05 H (REMAINDER)

4
D. Write a program to multiply two numbers
Program:

MOV A,#25H
MOV B,#65H
MUL AB
MOV P3,A

SOURCE FILE NAME : NNN.ASM


0000 7495 MOV A,#95H
0002 75F010 MOV B,#10H
0005 A4 MUL AB
0006 F5B0 MOV P3,A
No errors detected.

OUTPUT
E99
B=0E H A=99 H

5
Experiment -03

A. Write a program to perform multiplication without using MUL Instruction


Program:

MOV A,#00h
MOV B,#04h
MOV R0,#02h
L1: ADD A,R0
DJNZ B,L1
MOV P1,A

Output:-
00001000

B. Write a program to perform division without using DIV Instruction.


Program:

L2: MOV A,#09H


MOV R0,#02H
MOV R1,#00H
SUBB A,R0
JC L1
INC R1
SJMP L2
L1: CPL A
INC A
MOV R2,A

OUTPUT
R1=04H
R2= 01H

6
C. Write a program to add first ten natural numbers
Program

MOV A,#00H
MOV R2,#10
MOV R0,#00H
L1:INC R0
ADD A,R0
DJNZ R2,L1
MOV P3,A

SOURCE FILE NAME : ASM

0000 7400 MOV A,#00H


0002 7A0A MOV R2,#10
0004 7800 MOV R0,#00H
0006 08 L1:INC R0
0007 28 ADD A,R0
0008 DAFC DJNZ R2,L1
000A F5B0 MOV P3,A

SYMBOL TABLE :

L1 0006

No errors detected.
OUTPUT=37H

7
Experiment -04

A. Write a program to show alternate LED on/off


Program

MAIN:MOV A, #55H
MOV P0,A
ACALL DELAY
MOV A, #AAH
MOV P0,A
SJMP MAIN

DELAY: MOV R0,#255


L2: MOV R1,#13
L1: DJNZ R1,L1
DJNZ R2,L2
RET

B. Write a program to generate a pulse of width of 5ms.


Program

L3: MOV P3,#00H


LCALL DELAY
MOV P3,#0FFH
LCALL DELAY
SJMP L3
DELAY:MOV R0,#255
L2: MOV R1,#13
L1: DJNZ R1,L1
DJNZ R2,L2
RET

8
C. Write a program to toggle all the bits of p0, p1, p2 every ¼ of a second.
Program

BACK:MOV A,#55H
MOV P0,A
MOV P1,A
MOV P2,A
LCALL DELAY
MOV A,#0AAH
MOV P0,A
MOV P1,A
MOV P2,A
LCALL DELAY
SJMP BACK
DELAY:
MOV R1,#255
L3:MOV R2,#255
L2:MOV R3,#05
L1:DJNZ R3,L1
DJNZ R2,L2
DJNZ R1,L3
RET

9
Experiment -05

A. Write a program to display data 0-9 on seven segment display.

Program

START:MOV P0,#0C0H
ACALL DELAY
MOV P0,#F9H
ACALL DELAY
MOV P0,#0A4H
ACALL DELAY
MOV P0,#B0H
ACALL DELAY
MOV P0,#99H
ACALL DELAY
MOV P0,#92H
ACALL DELAY
MOV P0,#82H
ACALL DELAY
MOV P0,#0F8H
ACALL DELAY
MOV P0,#80H
ACALL DELAY
MOV P0,#98H
ACALL DELAY
SJMP START

DELAY:
MOV R7,#10
L3:MOV R5,#255
L2:MOV R6,#255
L1:DJNZ R6,L1
DJNZ R5,L2
DJNZ R7,L3
RET

10
B. Write a program to display data 0-99 on seven segment display.
Program

ORG 0100H
MOV A,00H
MOV P1,A
L4: CLR A
MOV R0,#10
MOV DPTR,#1000H
L3: MOV R1,#10
L2: MOV R2,#255
L1: CLR P1.1
SETB P1.0
MOV A,R1
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
CLR P1.0
SETB P1.1
MOV A,R0
MOVC A,@A+DPTR
MOV P0,A
ACALL DELAY
DJNZ R2,L1
DJNZ R1,L2
DJNZ R0,L3
SJMP L4

DELAY: MOV R3,#255


HERE: NOP
DJNZ R3,HERE
RET

ORG 1001H
DB 098H,080H,0F8H,082H,092H,099H,0B0H,0A4H,0F9H,0C0H

11
Experiment-06

Object: Introduction to PIC Microcontroller Board

PIC is the name for the Microchip microcontroller (MCU) family, consisting of a microprocessor,
I/O ports, timer(s) and other internal, integrated hardware. The main advantages of using the PIC
are low external part count, a wide range of chip sizes (now from 5-pin up!) available, nice choice
of compilers (assembly, C, Basic, etc.) good wealth of example/tutorial source code and easy
programming. Once bought, the PIC's program memory is empty, and needs to be programmed
with code (usually HEX files) to be usable in a circuit. For the purpose, a wide range of simple
programmer hardware docs and software is downloadable from the net.
PIC is a family of Harvard architecture microcontrollers made by Microchip Technology, derived
from the PIC1650 originally developed by General Instrument's Microelectronics Division. PICs
are popular with developers and hobbyists alike due to their low cost, wide availability, large user
base, extensive collection of application notes, availability of low cost or free development tools,
and serial programming (and re-programming with flash memory) capability.
If you are a beginner with PICs, a PIC 16F628 or 16F877 device is a good choice to start with.
The PIC microcontroller development platform Nvis 5002 is a very useful kit for the student. It
can be used as a teaching tool as well as learning tool. Nvis 5002 is a single board microcontroller
training development platform configured around the most popular microchip PIC16F877A; 8 bit
single chip microcontroller. Nvis 5002 is about the architecture, instruction set and capabilities of
PIC16F877A. PIC 16F877A provides Up to 8K x 14 words of Flash Program Memory, Up to 368
x 8 bytes of Data Memory (RAM), Up to 256 x 8 bytes of EEPROM Data Memory
The input/output structure of Nvis 5002 provides 33 I/O lines. It has 16 bit timer /counter. The kit
has onboard PIC JDM programmer to burn hex file into controller.
The development platform is used with different modules of interfacing given with this kit and
also used for own applications.

12
Features
• PIC16F877A MCU clocked at 4 MHz
• Expansion connectors for plug in modules and prototyping area
• On board programmer
• USB interface to PC for programming
• Every pin is marked in order to make work easier
• Master Reset/Restart Key for hardware reset
• Input/ Output & test points provided on board
• On board breadboard for connecting external components
• Self contained development platform with On board DC power supply
• CD with sample project code, Learning Material
• Programmer software & useful documents

Technical Specifications

• Communication : USB Port


• MCU : PIC16F877A
• Crystal Frequency : 4 MHz
• Size of Breadboard : 175 x 67 x 8 mm
• On board DC Supply : 12V and 5 V
• Interconnections : FRC Cables & ICSP Connector Cable
• Programmer Unit : Ready to run programmer will program PIC Devices
• Power Supply : 230V AC 10 %, 50Hz
• Dimensions : W 340 X D 260 X H 55
• Weight : 1.5 Kg (Approx)

Pin Configuration and Description PIC16F877A

13
The first pin is the master clear pin of this IC. It resets the microcontroller and is active low,
meaning that it should constantly be given a voltage of 5V and if 0 V are given then the
controller is reset. Resetting the controller will bring it back to the first line of the program that
has been burned into the IC.
PIC16F877A reset
A push button and a resistor is connected to the pin. The pin is already being supplied by constant
5V. When we want to reset the IC we just have to push the button which will bring the MCLR
pin to 0 potential thereby resetting the controller.
PIN 2: RA0/AN0
PORTA consists of 6 pins, from pin 2 to pin 7, all of these are bidirectional input/output pins. Pin
2 is the first pin of this port. This pin can also be used as an analog pin AN0. It is built in analog
to digital converter.
PIN 3: RA1/AN1
This can be the analog input 1.
PIN 4: RA2/AN2/Vref-
It can also act as the analog input2. Or negative analog reference voltage can be given to it.
PIN 5: RA3/AN3/Vref+
It can act as the analog input 3. Or can act as the analog positive reference voltage.
PIN 6: RA0/T0CKI
To timer0 this pin can act as the clock input pin, the type of output is open drain.
PIN 7: RA5/SS/AN4
This can be the analog input 4. There is synchronous serial port in the controller also and this pin
can be used as the slave select for that port.
PIN 8: RE0/RD/AN5
PORTE starts from pin 8 to pin 10 and this is also a bidirectional input output port. It can be the
analog input 5 or for parallel slave port it can act as a ‘read control’ pin which will be active low.
PIN 9: RE1/WR/AN6
It can be the analog input 6. And for the parallel slave port it can act as the ‘write control’ which
will be active low.
PIN 10: RE2/CS/A7
It can be the analog input 7, or for the parallel slave port it can act as the ‘control select’ which
will also be active low just like read and write control pins.
PIN 11 and 32: VDD
These two pins are the positive supply for the input/output and logic pins. Both of them should be
connected to 5V.
PIN 12 and 31: VSS
These pins are the ground reference for input/output and logic pins. They should be connected to
0 potential.
PIN 13: OSC1/CLKIN
This is the oscillator input or the external clock input pin.
PIN 14: OSC2/CLKOUT
This is the oscillator output pin. A crystal resonator is connected between pin 13 and 14 to
provide external clock to the microcontroller. ¼ of the frequency of OSC1 is outputted by OSC2
in case of RC mode. This indicates the instruction cycle rate.
crystal interfacing with PIC16F877A
PIN 15: RC0/T1OCO/T1CKI

14
PORTC consists of 8 pins. It is also a bidirectional input output port. Of them, pin 15 is the first.
It can be the clock input of timer 1 or the oscillator output of timer 2.
PIN 16: RC1/T1OSI/CCP2
It can be the oscillator input of timer 1 or the capture 2 input/compare 2 output/ PWM 2 output.
PIN 17: RC2/CCP1
It can be the capture 1 input/ compare 1 output/ PWM 1 output.
PIN 18: RC3/SCK/SCL
It can be the output for SPI or I2C modes and can be the input/output for synchronous serial
clock.
PIN 23: RC4/SDI/SDA
It can be the SPI data in pin. Or in I2C mode it can be data input/output pin.
PIN 24: RC5/SDO
It can be the data out of SPI in the SPI mode.
PIN 25: RC6/TX/CK
It can be the synchronous clock or USART Asynchronous transmit pin.
PIN 26: RC7/RX/DT
It can be the synchronous data pin or the USART receive pin.
PIN 19, 20, 21, 22, 27, 28, 29,30.
All of these pins belong to PORTD which is again a bidirectional input and output port. When the
microprocessor bus is to be interfaced, it can act as the parallel slave port.
PIN 33-40: PORT B
All these pins belong to PORTB. Out of which RB0 can be used as the external interrupt pin and
RB6 and RB7 can be used as in-circuit debugger pins.

15
Experiment-07

Object: Write a program to Interfacing of LED Bar Graph with PIC Microcontroller
Program:
#include <PIC.H>
//__CONFIG(WDTDIS & LVPDIS & PWRTEN & XT);
__CONFIG(FOSC_HS & PWRTE_ON & WDTE_OFF & CP_OFF & LVP_OFF);
/* LED Bar Graph data and clock pin define at port C */
#define ROW_data RC0
#define ROW_Clock RC1
#define COL_data RC2
#define COL_Clock RC3
#define Enable RC4
/********************* Function Prototype****************************************/
void row_Clock();
void col_Clock();
void out_enable();
void N_data();
void DelayMs(unsigned int count);
/*********************************Main Program*****************************/
void main()
{
unsigned int k;
TRISC = 0x00;
PORTC = 0x00;
Enable = 0;
while(1) // Loop will work for Infinite times
{
N_data();
}
}
/************************** SUBROUTINES******************************/
/**************************N character display***************************/
void N_data()
{
// first Column
COL_data = 1; col_Clock(); COL_data = 1; col_Clock();COL_data = 1;
col_Clock();COL_data = 1;col_Clock();COL_data = 0; col_Clock();
ROW_data = 0;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 1;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 1;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 0;row_Clock();
out_enable();
// second column
COL_data = 1;col_Clock();COL_data = 1;col_Clock();COL_data = 1;col_Clock();
COL_data = 0;col_Clock();COL_data = 1;col_Clock();
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
ROW_data = 1;row_Clock();ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
out_enable();
// third column
COL_data = 1;col_Clock();COL_data = 1;col_Clock();COL_data = 0;
col_Clock();COL_data = 1;col_Clock();COL_data = 1;col_Clock();
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
ROW_data = 0;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
out_enable();
// forth column
COL_data = 1;col_Clock(); COL_data = 0;col_Clock();
COL_data = 1;col_Clock();COL_data = 1;col_Clock();COL_data = 1;col_Clock();

16
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
ROW_data = 1;row_Clock();ROW_data = 0;row_Clock();
ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();ROW_data = 0;row_Clock();
out_enable();
//fifth column
COL_data = 0;col_Clock();COL_data = 1;col_Clock();COL_data = 1;col_Clock();
COL_data = 1;col_Clock();COL_data = 1;col_Clock();
ROW_data = 0;row_Clock();ROW_data = 1;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 1;row_Clock();ROW_data = 1;row_Clock();ROW_data = 1;row_Clock();
ROW_data = 0;row_Clock();
out_enable();
}
/****** Row clock *****/
void row_Clock()
{
ROW_Clock = 0;
ROW_Clock = 1;
}
/**** Column clock ****/
void col_Clock()
{
COL_Clock = 0;
COL_Clock = 1;
}
/**** Enable pin *****/
void out_enable()
{
Enable = 0;
DelayMs(1);
Enable = 1;
DelayMs(35);
}
/************This function generates delay for (count X 1milisecond)**************/
void DelayMs(unsigned int count)
{
unsigned int Del;
while(count)
{
for(Del=0;Del<=5;Del++);
count--;
}
}
/****************************END*******************************************/
Result Analysis:
Step 1:-
Switch ON Nvis 5002
Burn Program LED Bar Graph Interface.hex file in PIC16F877A Microcontroller using
Nvis 5002.
Step 2:- Connections:
Connect FRC cable Nvis 5002 port C to LED Bar Graph Interface Block socket (MC04).
Step 3:-
Place Microcontroller on ZIF Socket
Switch on the Power supply
Press Reset Switch
Step 4:-
Output:
"N" will display on LED Bar Graph.

17
Experiment-08

Object: Write a program to Interfacing of 16x2 LCD with PIC Microcontroller

Program:
#include<pic.h>
__CONFIG(FOSC_HS & PWRTE_ON & WDTE_OFF & CP_OFF & LVP_OFF);
#define LCD_Port PORTD /* LCD data pin(D0-D7) to port D*/
#define LCD_rs RB5 /* LCD RS (Register select) pin RB5 */
#define LCD_rw RB6 /* LCD R/W (Read/ Write)pin RB6 */
#define LCD_en RB7 /* LCD Enable pin RB7 */
/**********************Function Prototypes**********************/
void LCD_Init();
void LCD_Cmd(unsigned char);
void LCD_Data(unsigned char ASCII);
void LCD_Disp(unsigned char Loc,unsigned char *String);
/******************************* Company Name******************************/
void Display_CompanyName()
{
LCD_Disp(0x80," Nvis");
LCD_Disp(0xC0," Technologies ");
}
/*******************************Delay*********************************/
void Delay(unsigned int rTime)
{
unsigned int x,y;
for(x=0;x<=rTime;x++)
for(y=0;y<=500;y++);
}
/************************** Main Function*********************************/
void main()
{
TRISB = 0x00; /* Port B initialized as output port */
TRISD = 0x00; /* Port D initialized as output port */
LCD_Init(); /* LCD Control Command Initialized */
LCD_Cmd(0x01); /* Clear Display */
Display_CompanyName(); /* Display Company Name */
while(1);
}
/********************** Subroutines*************************************/
/********** Initialize LCD Routine *****************/

18
void LCD_Init()
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots */
Delay(2);
LCD_Cmd(0x0E); /* Display On curser Off */
Delay(2);
LCD_Cmd(0x01); /* Clear Display */
Delay(2);
LCD_Cmd(0x06); /* Entry Mode */
Delay(2);
}
/**************** LCD Cmds Routine **************/
void LCD_Cmd(unsigned char Cmd)
{
LCD_Port = Cmd; /* Write Command to LCD */
LCD_rs = 0; /* Clear bit P3.5 */
LCD_rw = 0; /* Clear bit P3.6 */
LCD_en = 1;
Delay(5); /* Set bit P3.7 */
LCD_en = 0;
}
/*************** Write Charactor to LCD ***************/
void LCD_Data(unsigned char ASCII)
{
LCD_Port = ASCII; /* Write data to LCD in ascii
value*/
LCD_rs = 1;
LCD_rw = 0;
LCD_en = 1;
Delay(5);
LCD_en = 0;
}
/*************** Write String to LCD *****************/
void LCD_Disp(unsigned char Loc,unsigned char *String)
{
LCD_Cmd(Loc);
while(*String)
{
LCD_Data(*String++); /* write data to LCD */
}

19
}
/************************** END ***************************/
Result Analysis:
Step 1:-
Swith ON NV5002
Burn Program LCD Interface.hex file in PIC16F877A Microcontroller using Nvis5002
Step 2:-
Connections:
Connect FRC cable Nvis 5002 port RD to LCD_Data (MC04).
Connect FRC cable Nvis 5002 port RB to LCD_Control (MC04).
Step 3:-
Place MicroController on ZIF Socket
Switch on the Power supply
Press Reset Switch
Step 4:-
Output:
A message "Nvis Technologies" will display on LCD screen.

20
Experiment-09

Object: Write a program to Interfacing of seven segment display with PIC Microcontroller
Program:

#include<pic.h>
__CONFIG(FOSC_HS & PWRTE_ON & WDTE_OFF & LVP_OFF & CP_OFF);
#define Seg_Data PORTC /* Seven Segment data pins initialized at port C */
#define Segment_A_cntrl RD0 /* Seven Segment control pins initialized at port D */
#define Segment_B_cntrl RD1
#define Segment_C_cntrl RD2
#define Segment_D_cntrl RD3
/************************Delay Function********************************/
void Delay(unsigned int rTime)
{
unsigned int x,y;
for(x=0;x<=rTime;x++)
for(y=0;y<=500;y++);
}
/****Segment_Disp* Description : This function generates digit 0 to 9*************/
void Segment_Disp()
{
Seg_Data=0x3F; /* '0' */
Delay(100);
Seg_Data=0x06; /* '1' */
Delay(100);
Seg_Data=0x5B; /* '2' */
Delay(100);
Seg_Data=0x4F; /* '3' */
Delay(100);
Seg_Data=0x66; /* '4' */
Delay(100);
Seg_Data=0x6D; /* '5' */
Delay(100);
Seg_Data=0x7D; /* '6' */
Delay(100);
Seg_Data=0x07; /* '7' */
Delay(100);
Seg_Data=0x7F; /* '8' */
Delay(100);

21
Seg_Data=0x6F; /* '9' */
Delay(100);
}
/****************************Main Function*******************************/
void main()
{
TRISD = 0X00; /* Port D initialized as output port */
TRISC = 0X00; /* Port C initialized as output port */
Segment_A_cntrl = 0; /* Clear All Control Pins for Seven segment */
Segment_B_cntrl = 0;
Segment_C_cntrl = 0;
Segment_D_cntrl = 0;
while(1) /* Forever loop */
{
Segment_A_cntrl=1; /* High All Control Pins for all Seven segment */
Segment_B_cntrl=1;
Segment_C_cntrl=1;
Segment_D_cntrl=1;
Segment_Disp(); /* Display digits from 0 to 9 */
}
}
/*****************************End************************************/.
Output Analysis:
Step 1:-
Swith ON Nvis 5002
Burn Program Seven Segment Interface.hex file in PIC16F877A Microcontroller
using Nvis 5002
Step 2:- Connection:
Connect an FRC cable from Nvis 5002 Port RC to the data pins of segment(7-Seg_Data)
(MC04)
Connect an FRC cable fromNvis 5002 Port RD to the transistor input of the
segments (7-Seg_Control) (MC04)
Step 3:-
Place MicroController on ZIF Socket
Switch on the Power supply
Press Reset Switch
Step 4:-

Output:
All 4 segments will display 0 to 9 digits simultaneously.

22
Experiment-10

Object: Write a program to Interfacing of hex keypad with PIC Microcontroller and output
display on LCD.

Program:

#include<pic.h>
__CONFIG(FOSC_HS & PWRTE_ON & WDTE_OFF & BOREN_OFF & LVP_OFF &
CP_OFF);
#define _XTAL_FREQ 4000000
/*********************Global function and Variable Declearation********************/
unsigned char KeyVal;
/* Defined LCD Data Pin on PORT D */
#define LCD_Port PORTD /* LCD data pin(D0-D7) to port P0 */
/* Defined LCD Control Pin on Port C */
#define LCD_rs RC5 /* LCD RS (Register select) pin */
#define LCD_rw RC6 /* LCD R/W (Read/ Write)pin */
#define LCD_en RC7 /* LCD Enable pin */
#define Buzzer RC0
#define Led RC1
/* Defined Keypad Pin on Port B */
#define COL0 RB0
#define COL1 RB1
#define COL2 RB2
#define COL3 RB3
#define ROW3 RB4
#define ROW2 RB5
#define ROW1 RB6
#define ROW0 RB7

/********************* Function Prototypes*******************************/


void LCD_Init(void);
void LCD_Cmd(unsigned char Cmd);
void LCD_Data(unsigned char ASCII);
void Delay(unsigned int rTime);
void LCD_Disp(unsigned char Loc,unsigned char *String);
void Display_CompanyName(void);
/****** Delay Subroutine ******/
void Delay(unsigned int rTime)
{

23
unsigned int x,y;
for(x=0;x<rTime;x++)
for(y=0;y<500;y++);
}
/********** Initialize LCD Routine *****************/
void LCD_Init()
{
LCD_Cmd(0x38); /* Function Set 8bit : 2 Line 5x7 Dots */
Delay(5);
LCD_Cmd(0x0C); /* Display On curser Off */
Delay(5);
LCD_Cmd(0x01); /* Clear Display */
Delay(5);
LCD_Cmd(0x06); /* Entry Mode */
Delay(5);
}
/**************** LCD Commands Routine **************/
void LCD_Cmd(unsigned char Cmd)
{
LCD_Port = Cmd; /* Write Command to LCD */
LCD_rs = 0; /* Clear bit P3.5 */
LCD_rw = 0; /* Clear bit P3.6 */
LCD_en = 1; /* Set bit P3.7 */
Delay(2);
LCD_en = 0;
}
/*************** Write Srting to LCD ***************/
void LCD_Disp(unsigned char Loc,unsigned char *String)
{
LCD_Cmd(Loc);
Delay(2);
while(*String)
{
LCD_Data(*String++); /* write data to LCD */
Delay(1);
}
}
/*************** Write Charactor to LCD ***************/
void LCD_Data(unsigned char ASCII)
{

24
LCD_Port=ASCII; /* Write data to LCD in ascii
value*/
LCD_rs=1; /* Set bit P3.5 */
LCD_rw=0; /* Clear bit P3.6 */
LCD_en=1; /* Set bit P3.7 */
Delay(2);
LCD_en=0;
}
/********************Company Name***********************************/
void Display_CompanyName()
{
LCD_Disp(0x80," Nvis");
LCD_Disp(0xC2,"Technologies");
}
/************************Keypad subroutine*****************************/
unsigned char Scan_Keypad(void)
{
PORTB = 0xFF;
while(1)
{
// Row0 Scan
ROW0 = 1;
if(COL0 != 1)
{
KeyVal='1';
return KeyVal;
}
if(COL1 != 1)
{
KeyVal='2';
return KeyVal;
}
if(COL2 != 1)
{
KeyVal='3';
return KeyVal;
}
if(COL3 != 1)
{
KeyVal='F';

25
return KeyVal;
}
ROW0 = 0;
// Row1 Scan
ROW1 = 1;
if(COL0 != 1)
{
KeyVal='0';
return KeyVal;
}
if(COL1 != 1)
{
KeyVal='A';
return KeyVal;
}
if(COL2 != 1)
{
KeyVal='B';
return KeyVal;
}
if(COL3 != 1)
{
KeyVal='C';
return KeyVal;
}
ROW1 = 0;
// Row2 Scan
ROW2 = 1;
if(COL0 != 1)
{
KeyVal='7';
return KeyVal;
}
if(COL1 != 1)
{
KeyVal='8';
return KeyVal;
}
if(COL2 != 1)
{

26
KeyVal='9';
return KeyVal;
}
if(COL3 != 1)
{
KeyVal='D';
return KeyVal;
}
ROW2 = 0;
// Row3 Scan
ROW3 = 1;
if(COL0 != 1)
{
KeyVal='4';
return KeyVal;
}
if(COL1 != 1)
{
KeyVal='5';
return KeyVal;
}
if(COL2 != 1)
{
KeyVal='6';
return KeyVal;
}
if(COL3 != 1)
{
KeyVal='E';
return KeyVal;
}
ROW3 = 0;
}
return KeyVal;
}
void main()
{
OPTION_REG = 0X00;
TRISC = 0x00;
TRISB = 0x0F; //

27
TRISD = 0x00; //
ADCON1 = 0x06;
Buzzer = 0;
Led = 0;

LCD_Init(); /* Initialize LCD */


Delay(20);
LCD_Cmd(0x01); /* Clear Display */
Delay(20);
Display_CompanyName(); /* Display Company Name*/
Delay(50);
LCD_Cmd(0x01);
LCD_Disp(0x83,"Key Pressed");
while(1)
{
Scan_Keypad(); /* Keypad Sence */
LCD_Cmd(0xC8); /* if key is pressed select LCD Location */
LCD_Data(KeyVal); /* Display the Key value */
}
}
/*****************************End************************************/
Output Analysis:
Swith ON Nvis 5002

Burn Program Keypad Interface.hex file in PIC16F877A Microcontroller using Nvis 5002

Connections:
Connect 20 Pin FRC cable in following manner:
Nvis 5002 Port RD with "LCD_Data" Connector of MC10.
Nvis 5002 Port RB with "Keypad" Connector of MC10.
Nvis 5002 Port RC with "LCD_Control" Connector of MC10
Output:
Initially on LCD "Nvis Technologies" will display then after some delay "Key
Pressed" is showing. Now whenever you will press any key
the same character will display on LCD second row.

28
Experiment-11

Object: Introduction to ARM7 Development Board

Nvis Technologies ARM 7 Development Board (Nvis 5004A) serves as a 32 bit development
platform and provides means for code development. This trainer designed for students to explore
ARM architecture and on board supporting peripherals provide an ideal platform for extensive
embedded development. The trainer provides serial and USB connection both that can be used to
download and run code on any standard IDE. This trainer allows users to evaluate, prototype and
create application specific designs.

29
Features:

• LPC2148 ( ARM 7 TDMI 32 Bit ) MCU clocked at 12MHz


• Expansion connectors for plug in modules and prototyping area
• 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
• On board Flash download utility (programmer) for Philips microcontrollers
• USB interface given for programming
• 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
• Every pin is marked in order to make work easier
• Master Reset/Restart Key for hardware reset
• On board UART 1 Interface
• On board ADC (10 Bit ) Interface
• On board 10-bit DAC provides variable analog output
• On board PWM Interface
• On board facility to connect JTAG debugger
• On board GPIO Connectors
• 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
• Input/ Output & test points provided on board
• On board four external interrupts interface
• Self contained trainer with On board DC Power Supply
• CD with sample project code, Programmer software & useful documents
• Learning Material

Technical Specifications:
• MCU : LPC2148
• Crystal Frequency : 12 MHz
• LED’s : 8
• ADC : Two Internal 10 bit ADC (14 Channel)
• DAC : Single 10 Bit Internal DAC
• Interrupts : Four External Interrupts on Board
• RTC : 3.3 Volt CMOS Battery
• PWM : Three No’s on Board
• GPIO’s : All GPIO Pins on Board
• Communication Interfaces : USB 2.0 Full speed device control
• Serial Communication : RS 232 Port
• Programmer : USB
• Programmer Mode Selection : Run/ISP Switch
• Baud Rate : 9600 bps (for both USB/Serial Ports)
• Interconnections : 2 mm Patch Chords & FRC Cables
• Main Supply : 230 V ±10 %, 50 Hz

30
Block Diagram:

31
Pin out and description:

32
General procedure to operate ARM7 Controller Board
Equipments Needed:
1.SMPS Supply
2.USB Cable
3.Mains Cord
Procedure:
1. Connect the USB cable (supplied along with the board) to any functional USB port of
your PC and ISP (USB) port provided on the right side of the board (in PC interface & ISP
section).
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 “PC Interface & ISP Section” block.
4. Connect the SMPS Supply to the trainer and switch ‘ON’ the supply.
5. Start the Philips flash utility (available in the all programs on the Start menu of Windows
OS: Start menu/All programs/Philips semiconductor/Flash utility/ Launch LPC210x_ISP.exe.) &
select the appropriate port settings (use baud rate 9600).
6. Program LED_Interface.hex files (CD-drive\On Board Experiments\LED
Interface\LED_Intarfc hex).
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 ON position.
9. Switch ‘On’ the supply and then press reset switch.
10. Observe the result/ blinking of LED's according to program.

33
Experiment- 12

Objective: Study and analysis of interfacing of LED's with ARM7 Controller

Program:

#include <LPC214X.H>
/* LED Bar Graph data and clock pin define at port B */
#define ROW_data_Clr IO1CLR = 0x00010000;
#define ROW_Clock_Clr IO1CLR = 0x00020000;
#define COL_data_Clr IO1CLR = 0x00040000;
#define COL_Clock_Clr IO1CLR = 0x00080000;
#define ROW_data_Set IO1SET = 0x00010000;
#define ROW_Clock_Set IO1SET = 0x00020000;
#define COL_data_Set IO1SET = 0x00040000;
#define COL_Clock_Set IO1SET = 0x00080000;
#define Enable_Clr IO1CLR = 0x00100000;
#define Enable_Set IO1SET = 0x00100000;
/************************************************
* Function Prototype
************************************************/
void row_Clock();
void col_Clock();
void out_enable();
void Display_Char_N();
void DelayMs(unsigned int count);
/******Main Program************************************/
int main()
{
IO1DIR = 0x001F0000;
IO1SET = 0x00100000;

while(1) // Loop will work for Infinite times


{
Display_Char_N();
}
}

/******************SUBROUTINES*********************************************/

/*********************** N character display *************************/


void Display_Char_N()
{
// first Column
COL_data_Set; col_Clock(); COL_data_Set; col_Clock();COL_data_Set;
col_Clock();COL_data_Set;col_Clock();COL_data_Clr; col_Clock();

34
ROW_data_Clr;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Set;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Set;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Clr;row_Clock();
out_enable();
// second column
COL_data_Set;col_Clock();COL_data_Set;col_Clock();COL_data_Set;col_Clock();
COL_data_Clr;col_Clock();COL_data_Set;col_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
ROW_data_Set;row_Clock();ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
out_enable();
//third column
COL_data_Set;col_Clock();COL_data_Set;col_Clock();COL_data_Clr;
col_Clock();COL_data_Set;col_Clock();COL_data_Set;col_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
ROW_data_Clr;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
out_enable();
// fourth column
COL_data_Set;col_Clock(); COL_data_Clr;col_Clock();
COL_data_Set;col_Clock();COL_data_Set;col_Clock();COL_data_Set;col_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
ROW_data_Set;row_Clock();ROW_data_Clr;row_Clock();
ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();ROW_data_Clr;row_Clock();
out_enable();
//fifth column
COL_data_Clr;col_Clock();COL_data_Set;col_Clock();COL_data_Set;col_Clock();
COL_data_Set;col_Clock();COL_data_Set;col_Clock();
ROW_data_Clr;row_Clock();ROW_data_Set;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Set;row_Clock();ROW_data_Set;row_Clock();ROW_data_Set;row_Clock();
ROW_data_Clr;row_Clock();
out_enable();
}
/****** Row clock *****/
void row_Clock()
{
ROW_Clock_Clr;
ROW_Clock_Set;
}
/**** Column clock ****/
void col_Clock()
{
COL_Clock_Clr;
COL_Clock_Set;

35
}

/**** Enable pin *****/


void out_enable()
{
Enable_Clr;
DelayMs(200);

Enable_Set;
DelayMs(50);
}

/*********************************************************************
This function generates delay for (count X 1milisecond)
**********************************************************************/
void DelayMs(unsigned int count)
{
unsigned char Del;
while(count)
{
for(Del=0;Del<=10;Del++);
count--;
}

/**************************END***********************************/

Step 1:-
Swith ON Nvis 5004A
Turn the toggle switch in ISP Mode
Burn Program LED Bar Graph Interface.hex file in LPC2148 Microcontroller
Turn the toggle switch in RUN Mode
Step 2:-
Connections:
Connect FRC cable Nvis 5004A P1.16-P1.23 LED Bar Graph Interface Block socket (MC04)
Step 3:-
Turn on the supply
Press Reset Switch
Step 4:-

Output:
"N" will display on LED Bar Graph

36
Experiment- 13

Objective: Study and analysis of interfacing of LCD with ARM7 Controller

Program:

#include<lpc214x.h>
/*************************FunctionPrototypes *****************/
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 */
/**************************LCD Pin Out Discription ******************/
#define RS_Set IO1SET = 0x20000000;
#define RS_Clr IO1CLR = 0x20000000;
#define EN_Set IO1SET = 0x80000000;
#define EN_Clr IO1CLR = 0x80000000;
/****************** LCD_Delay******/
void LCD_Delay(unsigned int Time)
{
unsigned int i,j;

for(i=0;i<=Time;i++)
for(j=0;j<1275;j++);
}
/*****************
*LCD initialization
* Description : This function initializes the LCD module by the following steps:
* 1. Set 8bit : 2 Line 5x7 Dots (0x38)
* 2. Display On curser Off (0x0C)
* 3. Clear Display (0x01)
* 4. Entry Mode (0x06)
* Note : This function should be called once before any of the other functions
****************************************************************************/
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 */
}
/**************************************************************************
* LCD Command (Shifting is done here)
* Description : This function initializes the LCD module by the following steps:
* Note : Here we have selected Pin P1.16 to P1.23 as LCD data line,

37
* thats why we need to shift data by 16.************************************/

void LCD_Cmd(unsigned long Cmd)


{
unsigned long Shifted_Cmd;
Shifted_Cmd = Cmd << 16; /* 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 */
}

/**********************************************************************
* LCD Data
*
* Description : This function initializes the LCD module by the following steps:
* 1. Set Register select (RS) to High
* 2. Set enable pin high to low
* 3. Send data to LCd data pin
* Note : Here we have selected Port 1 Pin P1.16 to P1.23 as LCD data line
*****************************************************************************/
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 */
LCD_Delay(10);
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
/********* LCD Display
* Description : This function initializes the LCD module by the following steps:
* 1. Send Loc from where data needs to write
* 2. Display string on LCD
************************************************************************/
void LCD_Disp(unsigned char Loc, unsigned char *String)
{
LCD_Cmd(Loc); /* Send Command to LCd */

38
while(*String) /* Wait untill Null char come */
{
LCD_Data(*String++); /* Write data to LCD */
IO1CLR = 0x00FF0000; /* Clear All pins of LCD */
}
}
/*************** Main Routine*************************************/
int main(void)
{
IO1DIR = 0xFFFF0000; /* Set LCD pin as out put */
LCD_Init(); /* Initialize LCD */
while(1)
{
LCD_Disp(0x80, " Nvis "); /* Display "NVIS" */
LCD_Disp(0xC0, " Technologies "); /* Display "Technologies" */
}
}
/***********************************End************************************/

Result Analysis:

Step 1:-
Switch ON Nvis 5004A
Turn the toggle switch in ISP Mode
Burn Program "LCD Interface.hex" file in LPC2148 Microcontroller using Nvis 5004A
Turn the toggle switch in RUN Mode
Step 2:-
Connection:
Connect P1.24-P1.31 of " Nvis 5004A board" to "LCD_Control" connector present on
the board "MC04 Display Module" Module.
Connect P1.16-P1.23 of "Nvis 5004A board" to "LCD_Data" connector present on the
board "MC04 Display Module" Module.
Step 3:-

OUTPUT:
"Nvis Technologies" Display on 16x2 LCD display

39
Experiment- 14
Objective: Study and analysis of Seven Segment Display Interface with ARM7 Controller

Program:

#include<lpc214x.h>
/********Delay Description: This function provide Delay in Mili Sec.*******************/
void MSdelay(unsigned int rtime)
{
unsigned int i,j;
for(i=0;i<=rtime;i++)
for(j=0;j<1275;j++);
}
/***************************MainFunction************************************/
int main(void)
{
IO0DIR = 0x00000FFF; /* Define Port as Output */
IO0SET = 0x00000F00; /* Set all Control Pins */
while(1)
{
IO0SET = 0x3F; /* Display '0' on Seven Segment */
MSdelay(2000); /* Delay - A small pause to display*/
IO0CLR = 0x3F; /* Clear '0' on Seven Segment */
IO0SET = 0x06;
MSdelay(2000);
IO0CLR = 0x06;
IO0SET = 0x5B;
MSdelay(2000);
IO0CLR = 0x5B;
IO0SET = 0x4F;
MSdelay(2000);
IO0CLR = 0x4F;
IO0SET = 0x66;
MSdelay(2000);
IO0CLR = 0x66;
IO0SET = 0x6D; /* Display '5' on Seven Segment */
MSdelay(2000); /* Delay - A small pause to display*/
IO0CLR = 0x6D; /* Clear '5' on Seven Segment */
IO0SET = 0x7D;
MSdelay(2000);
IO0CLR = 0x7D;
IO0SET = 0x07;
MSdelay(2000);
IO0CLR = 0x07;
IO0SET = 0x7F;
MSdelay(2000);

40
IO0CLR = 0x7F;
IO0SET = 0x6F;
MSdelay(2000);
IO0CLR = 0x6F;
}
}
/***********************************End************************************/

Result Analysis:

Step 1:-
Switch ON Nvis 5004A
Turn the toggle switch in ISP Mode
Burn Program "LCD Interface.hex" file in LPC2148 Microcontroller using Flash Utility
Turn the toggle switch in RUN Mode
Step 2:-
Connection:
Connect an FRC cable from Nvis 5004A port P0.0 - P0.7 to (7-Seg_Data) MC04
Connect another FRC cable from Nvis 5004A port P0.8- P0.15 to (7-Seg_Control) MC04

Step 3:-

OUTPUT: 0000 to 9999 all four seven segment display.

41

You might also like