You are on page 1of 82

8051 Development Board

User Manual

www.pantechsolutions.net 8051 Development Board User Manual


CONTENTS

1. Introduction
Technical/Customer Support .............................................................3
Package contains.............................................................................4
Board Introduction...........................................................................5
2. Connectors and Jumper Details................................................................7
3. Power Supply Block.............................................................................. 11
4. ZIF Socket Details ............................................................................... 11
5. Flash programming Utility ..................................................................... 12
6. Onboard Peripheral/Interface Details...................................................... 15
6.1 - Point LEDs ............................................................................ 16
6.2 - Push Buttons Switches ........................................................... 17
6.3 - LCD 2x16 in 8-bit mode.......................................................... 18
6.4 - Real Time Clock ..................................................................... 20
6.5 - ADC 8-Channel ..................................................................... 22
6.6 - 7 Segment LED ..................................................................... 24
6.7 - UART RS-232 Communication ................................................. 25
6.8 - Interrupts ............................................................................. 26
6.9 - DS1820 (Digital Thermometer)................................................ 27
6.10 - 32K SRAM/FLASH ................................................................ 28
6.11 - Matrix keypad...................................................................... 29
6.12 - Stepper Motor Driver ............................................................ 30
7. Board Layout.......................................................................................31
8. Example Programs ............................................................................... 33

www.pantechsolutions.net 8051 Development Board User Manual


Technical or Customer Support

E-mail questions to support@pantechsolutions.net

Send questions by mail to

Pantech Solutions Pvt Ltd.,


#3/2, Ramachandran Street,
Off: North Usman Road,
T.Nagar
Chennai 600 017.
Tamilnadu
India

Phone : +91-44-4260 6470


Fax : +91-44-4260 6480
Website : www.pantechsolutions.net

www.pantechsolutions.net 8051 Development Board User Manual


Package Contains

8051 Embedded Development module


Serial Port Cable
Printed User Manual
Board Schematic
CD contains
o Example Programs,
o User Manual
o Simple Projects

www.pantechsolutions.net 8051 Development Board User Manual


1. Introduction

Pantech Solutions Embedded Development module is an exclusive general-purpose


development board for the 8051 family. The intention of the design is to endorse the
engineers and students to exercise and explore the capabilities of 8051
microcontrollers with ease. At the heart of the development board is Atmel/Phillips
microcontrollers, Atmels AT89C5x/AT89S5x, Philipss P89C51RD2. The development
board is designed to support RS-232 interface and allows user to download program
to the uC directly from PC(Philips Microcontroller). Atmels devices can use separate
ISP programmer provided for Atmel. The embedded board and related software
routines help the system designers to rapidly design and prototype their designs
based on 8051. It provides a complete development platform with different modules
interface that accelerates the task of designers to run application software on target
8051 hardware, thereby paving a platform to benchmark their system, save time &
expense of building their own application test board and enabling them to get their
designs to market quickly.

www.pantechsolutions.net 8051 Development Board User Manual


Specifications

Compatible for MCS51 Family microcontrollers with 40 PIN ZIF socket.


AT89C51/52/55, AT89S51/52/55 (On board Flash Memory Capacity).
Philips P89C51RD2 (64K Flash with PWM output).
5V Operating voltage from 0 MHz to 25 MHz.
16/32/64KB of on-chip Flash user code memory with ISP(In-System Programming).
All I/O pins connected to 40 pin headers for easy external connections.
On-board FLASH ISP Programming for Philips microcontrollers.
Two pushbuttons for Interrupts study.
Reset switch.
Power ON status Indication LED.
8 Nos. General purpose Point LEDs.
8-way DIP Switch (Toggle Inputs).
4 Digits of common anode seven segment display.
2x16 Characters LCD.
Dallas DS1307 Real Time Clock with battery backup.
On board Buzzer (Alarm).
Dallas 1-wire DS1820 Digital Thermometer.
8-channel 10-bit ADC.
On-board Potentiometer for ADC input.
4x4 Matrix keyboard.
On-board 32K SRAM/FLASH.
Stepper Motor Driver Output.
4 Nos. Port I/O Connector.
User selectable jumpers.
UART for serial port communication through PC.
Onboard ISP Programmer for Atmel Microcontrollers.

www.pantechsolutions.net 8051 Development Board User Manual


2. Connectors and Jumper Details

CN1 - 10PIN Box Header ( PORT 0 )

CN1
P0_0 P0_1
P0_2 1 2 P0_3
P0_4 3 4 P0_5
P0_6 5 6 P0_7
7 8
9 10
P0

Connector MCU Pin Connector MCU Pin


Pin Name Pin Name
Numbers Numbers
1 P0.0 2 P0.1
3 P0.2 4 P0.3
5 P0.4 6 P0.5
7 P0.6 8 P0.7
9 NC 10 NC

CN2 - 10PIN Box Header ( PORT 1 )

CN2
P1_0 P1_1
P1_2 1 2 P1_3
P1_4 3 4 P1_5
P1_6 5 6 P1_7
7 8
9 10
P1

Connector MCU Pin Connector MCU Pin


Pin Name Pin Name
Numbers Numbers
1 P1.0 2 P1.1
3 P1.2 4 P1.3
5 P1.4 6 P1.5
7 P1.6 8 P1.7
9 NC 10 NC

www.pantechsolutions.net 8051 Development Board User Manual


CN3 - 10PIN Box Header ( PORT 2 )

CN3
P2_0 P2_1
P2_2 1 2 P2_3
P2_4 3 4 P2_5
P2_6 5 6 P2_7
7 8
9 10
P2

Connector MCU Pin Connector MCU Pin


Pin Name Pin Name
Numbers Numbers
1 P2.0 2 P2.1
3 P2.2 4 P2.3
5 P2.4 6 P2.5
7 P2.6 8 P2.7
9 NC 10 NC

CN4 - 10PIN Box Header ( PORT 3 )

CN4
P3_0 P3_1
P3_2 1 2 P3_3
P3_4 3 4 P3_5
P3_6 5 6 P3_7
7 8
9 10
P3

Connector MCU Pin Connector MCU Pin


Pin Name Pin Name
Numbers Numbers
1 P3.0 2 P3.1
3 P3.2 4 P3.3
5 P3.4 6 P3.5
7 P3.6 8 P3.7
9 NC 10 NC

www.pantechsolutions.net 8051 Development Board User Manual


CN6 - 40PIN Female Header

CN6
P1_0 P0_0
P1_1 1 2 P0_1
P1_2 3 4 P0_2
P1_3 5 6 P0_3
P1_4 7 8 P0_4
P1_5 9 10 P0_5
P1_6 11 12 P0_6
P1_7 13 14 P0_7
15 16
17 18
VCC

19 20
RST 21 22 PSEN
P3_0 23 24 P2_7
P3_1 25 26 P2_6
P3_2 27 28 P2_5
P3_3 29 30 P2_4
P3_4 31 32 P2_3
P3_5 33 34 P2_2
P3_6 35 36 P2_1
P3_7 37 38 P2_0
39 40
8051 BUS

Connector MCU Pin Connector MCU Pin


Pin Name Pin Name
Numbers Numbers
1 P1.0 2 P0.0
3 P1.1 4 P0.1
5 P1.2 6 P0.2
7 P1.3 8 P0.3
9 P1.4 10 P0.4
11 P1.5 12 P0.5
13 P1.6 14 P0.6
15 P1.7 s16 P0.7
17 VCC 18 GND
19 VCC 20 GND
21 VCC 22 GND
23 RESET 24 PSEN
25 P3.0 26 P2.7
27 P3.1 28 P2.6
29 P3.2 30 P2.5
31 P3.3 32 P2.4
33 P3.4 34 P2.3
35 P3.5 36 P2.2
37 P3.6 38 P2.1
39 P3.7 40 P2.0

www.pantechsolutions.net 8051 Development Board User Manual


Jumper for Enable Peripherals

The 8051-development board has many features if all the peripherals are enabled at
the same time, it consumes more current, and so the user has to select the
appropriate peripherals by using separate jumper. We need to check the jumpers or
the switches been properly set.

VCC
J8
1 2 SRAM
3 4 LCD
5 6 7_SEG_LED
7 8 I2C_RTC
9 10 ADC
11 12 KEYBOARD
13 14 DRIVER
15 16
VCC SLT

Jumpers, like switches, can break or establish a connection between two points. A
plastic, which is a metal contact, covers jumpers, it makes a connection when the
jumper is placed between two disconnected pins.

 Program Execution
While program execution short pin 1 & 2 of J2 for microcontrollers internal flash
memory or short pin 2 & 3 for external SRAM/FLASH memory execution.

VCC

J2
INT MEM
EA 1
2
EXT MEM 3
EA SLT

10

www.pantechsolutions.net 8051 Development Board User Manual


3. Power Supply

The external power can be AC or DC, with a voltage between (9V/12V,1A output) at
230V AC input. The 8051 board produces +5V using an LM7805 voltage regulator,
which provides supply to the entire device on the board.

D11 1N4007
2 1
1

JP26 D10
LM7805C/TO220 VCC
1 4 - + 2 1 3
1 2 IN U8 OUT
2 DB106

GND
R41

D12
9V DC

100uF/16V
C17 330E
3

C19

5V1
470uF/25V C18 0.1uF
D13
LED

GND

4. MCU ZIF Sockets

The 8051-development board is delivered with ATMELs 40-pin Microcontroller. User


can remove this and fit different microcontroller DIP40 packages of an adequate pin
out.

NOTE : Since all packages have parallel connections, there must not be more than
one
Microcontroller on the board at a time.

11

www.pantechsolutions.net 8051 Development Board User Manual


5. Flash Programming Utility
1. NXP (Philips)

NXP Semiconductors produce a range of Microcontrollers that feature both on-chip


Flash memory and the ability to be reprogrammed using In-System Programming
technology. Flash Magic is Windows software from the Embedded Systems
Academy (www.flashmagictool.com) that allows easy access to all the ISP features
provided by the devices. These features include:

Erasing the Flash memory (individual blocks or the whole device)


Programming the Flash memory
Modifying the Boot Vector and Status Byte
Reading Flash memory, Reading the signature bytes
Performing a blank check on a section of Flash memory
Reading and writing the security bits

12

www.pantechsolutions.net 8051 Development Board User Manual


Flash Magic provides a clear and simple user interface to these features and more as
described in the following sections. Under Windows, only one application may have
access the COM Port at any one time, preventing other applications from using the
COM Port. Flash Magic only obtains access to the selected COM Port when ISP
operations are being performed. This means that other applications that need to use
the COM Port, such as debugging tools, may be used while Flash Magic is loaded.

Note : Detailed Manual available at Flash Magic Help menu - Manual.

For NXP(Philips Microcontroller)

J1 PH-ISP
VCC
1 2 PSEN
3 4
5 6

D0
R3 330E

LED

J1, toggle switch is used to program NXP (Philips) microcontrollers.

Programming Mode
Switch Push to ON, MCU enters programming mode.

Execution Mode
Switch Push to OFF, MCU turns to execution mode.

13

www.pantechsolutions.net 8051 Development Board User Manual


2. ATMEL Microcontroller

VCC 330E R39 D9

P2 LED

20
1 ISP0 R30 1K U10
6 ISP0 2 18

VCC
2 ISP1 3 A1 Y1 17
7 R31 1K 4 A2 Y2 16 100E R35
ISP2 ISP1 A3 Y3 RST
3 5 15 100E R36
A4 Y4 P1_5

74HCT541
8 6 14 100E R37
ISP3 A5 Y5 P1_6
4 R32 1K 7 13 100E R38
ISP2 A6 Y6 P1_7
9 8 12
5 ISP4 9 A7 Y7 11
R33 1K A8 Y8
ISP[0..4]

ISP3 1 10
DB9-ISP 19 G1 GND
VCC G2
R40 R34 100E
1 2 ISP0 ISP4
3 ISP1
4 ISP2
5 ISP3
C
SIP 5

Note : Atmel Microcontrollers (PGM mode), user can select switch settings to color
shaded position.(EXE Mode) disable switches to off position.
ISP PGM

RST
P1_5 RST
P1_6 P1_5
P1_7 P1_6
P1_7

SW DIP-4

14

www.pantechsolutions.net 8051 Development Board User Manual


6. On-board Peripherals

The Development board comes with many interfacing options


8 Nos. of Point LEDs
8-Input DIP Switch
2 Lines X 16 Character LCD Display.
Real Time Clock with battery backup.
8 Channel, 10- Bit Analog to Digital Converter.
4 Nos. of Seven-segment display.
RS232 Serial Interface.
Digital Temperature Sensor
32k External SRAM/Flash
4 X 4 Matrix keyboard.
Motor driver circuit.
Alarm interface

15

www.pantechsolutions.net 8051 Development Board User Manual


6.1 - Light Emitting Diodes

Light Emitting Diodes (LEDs) are the most commonly used components, usually
for displaying pins digital states.

The 8051 Development Board have 8 nos., of Point LED, user can interface the
point LEDs with any port. User can use P0, P1, P2 and P3 ports.

Connector CN9 for LED connector, when the High Level goes to the pin LED
glows.
1

C R4
470E
2
3
4
5
6
7
8
9
LED1

LED2

LED3

LED4

LED5

LED6

LED7

LED8

D1 D2 D3 D4 D5 D6 D7 D8

CN9
D1 1 2 D2
D3 3 4 D4
D5 5 6 D6
D7 7 8 D8
9 10
LED

16

www.pantechsolutions.net 8051 Development Board User Manual


6.2 - 8-Way DIP Switch

This is another simple interface, 8-way DIPswitch, mainly used to give an input to
the port lines, and for some control applications also.

The Development board has one no. of 8-way DIP switch, which can be used to
provide digital inputs to the microcontrollers ports.

User can change the level of digital inputs whatever they want, either high or low
by simply selecting the jumper J9. The switches are connected to +5V, in order to
detect a switch state, pull-up or pull-down resistors should be used.

R43 1K DS1

R44 1K DS2
VCC SW17
16 1 R45 1K DS3
J9 15 2
14 3 R46 1K DS4
3 13 4
2 12 5 R47 1K DS5
1 11 6
DIP SELECT 10 7 R48 1K DS6
9 8
R49 1K DS7

SW DIP-8 R50 1K DS8

17

www.pantechsolutions.net 8051 Development Board User Manual


6.3 - LCD 2x16 IN 8-BIT MODE

When using a character LCD in an 8-bit mode, the connector CN10 connects the LCD
to Microcontroller port lines. User can use LCD Data lines to Port P0, P1 and P2, not
P3, because P3 lines P3.5 (RS), P3.6(R/W) and P3.7 (Enable) connected by default.
The LCDs contrast can be adjusted by varying the trimpot.

Before using LCD insert the shunt or shorting link of jumper J8 mentioned to LCD
legend mark.

R5
JP14
LCD
1

47K 1
CN10
2 2
3 DP1 1 2 DP2
P3_5 4 DP3 3 4 DP4
P3_6 5 DP5 5 6 DP6
P3_7 6 DP7 7 8 DP8
DP1 7 9 10
3

DP2 8
LCD
DP3 9
DP4 10
DP5 11
DP6 12
DP7 13
DP8 14
15
LCD 16
2x16 LCD

Note: Possible ways to interface LCD (Not CN4).


LCD CON MCU CON
1. CN10 CN1
2. CN10 CN2
3. CN10 CN3

18

www.pantechsolutions.net 8051 Development Board User Manual


Features of LCD

1. Easy interface with a 4-bit or 8-bit MPU.

2. Built-in Dot Matrix LCD controller with font 5X7 or 5X10 dots.

3. Display data RAM for 80 characters.

4. Character generator ROM, which provides 160, characters with font 5X7 dots and 32

characters with font 5X10 dots.

5. Both display data and character generator RAMs can be read from the MPU.

6. Internal automatic reset circuit at power ON.

7. Built in oscillator circuit.

Wide range of command functions: Clear displays, cursor home, display ON/OFF, cursor

ON/OFF, cursor shift, display shift.

19

www.pantechsolutions.net 8051 Development Board User Manual


6.4 - Real Time Clock

The DS1307 Serial Real-Time Clock is a low power; full binary-coded decimal (BCD)
clock/calendar plus 56 bytes of NV SRAM. The DS1307 has a built-in power sense
circuit that detects power failures and automatically switches to the battery supply.
In Embedded modules DS1307 of pin SDA and SCL connected to the
Microcontrollers pin P3.3 and P3.4 respectively. Address and data are transferred
serially via a 2-wire, bi-directional bus. The clock/calendar provides seconds,
minutes, hours, day, date, month, and year information. The end of the month/ date
is automatically adjusted for months with fewer than 31 days, including corrections
for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM
indicator.

This RTC circuit is facilitated with Battery backup, when supply fails; battery voltage
goes to DS1307 RTC chip.

Note: Before using RTC insert the shunt or shorting link of jumper J8 mentioned near
RTC legend mark.
D14

I2C_RTC
1K R42

VCC
1N4148

1N4148
D15
D16

3.6V Battery
2 1 R28
R29 4K7
BT1 1N4148 U4 4K7
8

5 J4
I2C_RTC

3 SDA P3_3
X2 VBAT 1 2
1 6 3 4 P3_4
X1 SCLK RTC
32.768KHz 2 7
X2 SQW/OUT
DS1307

VCC
J8
1 2
3 4
5 6
7 8 I2C_RTC
9 10
11 12
13 14
15 16
VCC SLT

20

www.pantechsolutions.net 8051 Development Board User Manual


Features of DS1307

1. Real-time clock (RTC) counts seconds, minutes, hours, date of the month, month,
day of the week, and year with leap-year compensation valid up to 2100
2. 56-byte, battery-backed, nonvolatile (NV) RAM for data storage
3. Two-wire serial interface
4. Programmable square wave output signal
5. Automatic power-fail detects and switch circuitry
6. Consumes less than 500nA in battery backup mode with oscillator running
7. Optional industrial temperature range: 40C to +85C
8. Available in 8-pin DIP or SOIC
9. Underwriters Laboratory (UL) recognized

21

www.pantechsolutions.net 8051 Development Board User Manual


6.5 - Analog to Digital Converter unit (ADC 0809)

ADC 0809 is an 8-channel 10-bit ADC used for converting Analog Data into Digital
form. In ADC section a jumper is provided to select either external analog input from
signal conditioning as input source or can select internal 5V generator, which is
variable from 0-5V. The 8 bit digital output of the ADC can be connected to the any
of the port by using the Bus/connector. Reference voltage of 2.5V is given at the
reference input so that the analog input span is 5V. In a sample program provided
with the module the digital output of the ADC, which is given to the Microcontroller,
can be view on the hyper terminal of the PC.

Features of ADC0809

1. Resolution: 8 Bits.
2. Operates ratio metrically or with 5VDC, 2.5VDC, or analog span adjusted
voltage reference.
3. Differential analog voltage inputs
4. Works with 2.5V voltage reference.
5. On-chip clock generator.
6. 0V to 5V analog input voltage range with single 5V supply.
7. No zero adjusts required.

On-board ADC input

VCC
10K R27
3 1
J6
CH0
1
2

2
ADC INT I/P

22

www.pantechsolutions.net 8051 Development Board User Manual


ADC

11
CN14 U5
CH0 26 17

ADC
1 IN0 D0 ADC0
27 14
2 IN1 D1 ADC1
28 15

ADC EXT I/P


3 IN2 D2 ADC2
1 8
4 IN3 D3 ADC3
2 18
5 IN4 D4 ADC4
3 19
6 IN5 D5 ADC5
4 20
7 IN6 D6 ADC6
VCC 5 21
8 IN7 D7 ADC7
J5
U6A 74HC132 9 16 25
10 REF- A0 1 2 P2_7
24
A1 3 4 P2_6
1 23
A2 5 6 P2_5
3 10
CLK 7 8 P2_4
2 6
R26 12 START 22 CHNL SELECT
9 REF+ ALE 7
10K OE EOC
VCC ADC0809

C9
0.1uF
2 1

U7A
74LS04

ADC connector

CN13
ADC0 1 2 ADC1
ADC2 3 4 ADC3
ADC4 5 6 ADC5
ADC6 7 8 ADC7
9 10
ADC

Note:
User can use ADC Data lines to Port P0, P1 and P3 but not P2, because P2 lines
P2.7 (A0), P2.6 (A1) and P2.5 (A2) are connected by default.
Before using ADC insert the shunt or shorting link of jumper J8 mentioned to ADC
legend mark.
User can connect ADC Data lines by the following possible ways (Not CN3).
ADC CON MCU CON
------------------------------
1. CN13 CN1
2. CN13 CN2
3. CN13 CN4

23

www.pantechsolutions.net 8051 Development Board User Manual


6.6 - Seven Segment Display

In Embedded module 4 nos. of common anode seven segment displays are used. The
segment lines of seven segment LED is being terminated at connector CN11. The
digit select lines are connected to the port pins of 8051 by using BC547. All the
common anode displays consume very small amount of current. User can use
segment lines at any port P0, P1 and P3, by default digit select lines connected to
Port P2 of Pin2.0 to P2.3.
P2_0 P2_1 P2_2 P2_3

7_SEG_LED
R14 1K 1 R15 1K 1 R16 1K 1 R17 1K 1
2 Q1 2 Q2 2 Q3 2 Q4
3 3 3 3

330E R18 SEG0 U13 U14 U15 U16


A
3

8
330E R19 SEG1 SEG0 7 SEG0 7 SEG0 7 SEG0 7
CA

CA

CA

CA

CA

CA

CA

CA
B SEG1 6 A SEG1 6 A SEG1 6 A SEG1 6 A
330E R20 SEG2 SEG2 4 B SEG2 4 B SEG2 4 B SEG2 4 B
C SEG3 2 C SEG3 2 C SEG3 2 C SEG3 2 C
330E R21 SEG3 SEG4 1 D SEG4 1 D SEG4 1 D SEG4 1 D
D SEG5 9 E SEG5 9 E SEG5 9 E SEG5 9 E
330E R22 SEG4 SEG610 F SEG610 F SEG610 F SEG610 F
E SEG7 5 G SEG7 5 G SEG7 5 G SEG7 5 G
330E R23 SEG5 DP DP DP DP
F
7 SEG DISP 7 SEG DISP 7 SEG DISP 7 SEG DISP
330E R24 SEG6
G
330E R25 SEG7 SEG[0..7]
DP

7 Segment Display Connector

CN11
A 1 2 B
C 3 4 D
E 5 6 F
G 7 8 DP
9 10
7 SEG LED

Before using seven segment LED insert the shunt or shorting link of jumper J8
mentioned to 7-SEG legend mark.
User can connect ADC Data lines following possible ways (Not CN3).
7 SEG CON MCU CON
CN11 CN1
CN11 CN2
CN11 CN4

24

www.pantechsolutions.net 8051 Development Board User Manual


6.7 - RS-232 Communication

RS-232 communication enables point-to-point data transfer. It is commonly used in


data acquisition applications, for the transfer of data between the microcontroller and
a PC.

The voltage levels of a microcontroller and PC are not directly compatible with those
of RS-232, a level transition buffer such as MAX232 be used.

VCC
C8 10uF
16

U9
13 12
V+
VCC

RXDIN 8 R1IN R1OUT 9 P1


11 R2IN R2OUT 14 RXD 1
10 T1IN T1OUT 7 TXDIN 6
TXD T2IN T2OUT RXDIN 2
C5 1 7
10uF 3 C+ TXDIN 3
4 C1- 8
5 C2+ 4
C6 C2- 9
GND

10uF 6 5
V-
C7 MAX232
15

SERIAL PORT
10uF

: Note : short pins 1 & 2 (RXD) and 3 & 4 (TXD) of J3.

J3
P3_0
RXD 1 2 P3_1
TXD INT0 3 4 P3_2
INT1 5 6 P3_3
7 8 P3_4
9 10 P3_5
11 12 P3_6
WE 13 14 P3_7
OE 15 16
MLT-P3

25

www.pantechsolutions.net 8051 Development Board User Manual


6.8 - Interrupts

Microcontrollers two external interrupts lines are terminated at switches SW32


(INT0) and SW33 (INT1).

SW32 INT0
INT0

SW33 INT1
INT1

INTERRUPTS

Note: While using interrupt short pins 5 & 6 of J3 header for Interrupt 0, 7 & 8 for
interrupt 1.

J3
P3_0
RXD 1 2 P3_1
TXD INT0 3 4 P3_2
INT1 5 6 P3_3
7 8 P3_4
9 10 P3_5
11 12 P3_6
WE 13 14 P3_7
OE 15 16
MLT-P3

26

www.pantechsolutions.net 8051 Development Board User Manual


6.9 - DS1820 Digital Thermometer

The DS1820 digital thermometer is well suited to environmental temperature


measurement, having a temperature range of 55C to 125C and an accuracy of +/-
0.5C.

It must be placed correctly in the 3-pin socket in the 8051; otherwise the DS1820
could be permanently damaged.

U11 DS1820
GND
Vdd

DQ

VCC
3

R52 4K7
J10
1 2
TEMP

Features
Unique 1-Wire interface requires only one port pin for communication
Multi-drop capability simplifies distributed temperature sensing applications
Can be powered from data line. Power supply range is 3.0V to 5.5V
Measures temperatures from -55C to +125C (-67F to +257F)
0.5C accuracy from -10C to +85C
9-bit thermometer resolution
Converts temperature in 750ms (max.)
Alarm search command identifies and addresses devices whose temperature is
outside of programmed limits (temperature alarm condition)

27

www.pantechsolutions.net 8051 Development Board User Manual


6.10 - External RAM/FLASH

User can use SRAM/FLASH upto 32KB. Port 0 Address/Data lines [AD0-AD7] are
terminated at connector CN7. Port 2 Higher Address lines are terminated at
connector CN8

SRAM SRAM

20

28
U2 U3
AD0 3 2 10 11 AD0

SRAM

SRAM
AD1 4 D0 Q0 5 9 A0 D0 12 AD1
AD2 7 D1 Q1 6 8 A1 D1 13 AD2
AD3 8 D2 Q2 9 7 A2 D2 15 AD3
AD4 13 D3 Q3 12 6 A3 D3 16 AD4
AD5 14 D4 Q4 15 5 A4 D4 17 AD5
AD6 17 D5 Q5 16 4 A5 D5 18 AD6
AD7 18 D6 Q6 19 3 A6 D6 19 AD7
D7 Q7 1 A7 D7
11 A14 A13 26 A14
ALE 1 G A12 2 A13
OC A11 23 A12
A10 21 A11
74LS373
A9 24 A10
A8 25 A9
A8
20
22 CE
OE 27 OE
MEM_WR WE
HM62256

CN7 CN8
AD0 AD1 A8 A9
AD2 1 2 AD3 A10 1 2 A11
AD4 3 4 AD5 A12 3 4 A13
AD6 5 6 AD7 5 6
7 8 7 8
9 10 9 10
AD0 - AD7 A8 - A15
MEM_WR

MEM_WR
A14

J3
A14

P3_0
RXD 1 2 P3_1 FLASH SRAM
TXD INT0 3 4 P3_2
INT1 5 6 P3_3 1 2
7 8 WR P2_6 WR 1 2 P2_6
P3_4 3 4 3 4
9 10 P3_5 5 6 5 6
11 12 P3_6
WE 13 14 CN5 CN5
P3_7
OE 15 16
MLT-P3

Note:
Its advised not to use Port-0 and Port-2 for others External peripherals while
using SRAM/FLASH.
Before using SRAM/FLASH insert the shunt or shorting link of jumper J8
mentioned to SRAM legend mark.
Short pins 13 & 14 (WE) for Write Enable and pin 15 & 16 (OE) of J3 Header.

Short pins SRAM( 3&5, 4&6) of CN5 or FLASH(1&3, 2&4).

28

www.pantechsolutions.net 8051 Development Board User Manual


6.11 - 4x4 Matrix keypad

Keypads arranged by matrix format, each row and column section pulled by high, all
row and column lines terminated at CN12.

+5v

R6 R7 R8 R9
10K 10K 10K 10K

SW1 SW2 SW3 SW4

R10 10K
RA1
SW5 SW6 SW7 SW8

R11 10K
RA2
SW9 SW10 SW11 SW12

R12 10K
RA3
SW13 SW14 SW15 SW16

R13 10K
RA4

CL1 CL2 CL3 CL4

Note:
Its advised not to use Port-0 & Port-2 for other External peripherals while using
SRAM/FLASH.
Before using keypads section insert the shunt or shorting link of jumper J8
mentioned to KBD legend mark.

29

www.pantechsolutions.net 8051 Development Board User Manual


6.12 - Motor / Driver Section

ULN2803 is used as a driver for port I/O lines, drivers output terminated to connector
CN17, there can interface relay/stepper motor or any driving source could need more
than 50mA.

U12
CN17
1 18
DI0 I1 O1 1
2 17
DI1 I2 O2 2
3 16
DI2 I3 O3 3
4 15
DI3 I4 O4 4
5 14
DI4 I5 O5 5
6 13
DI5 I6 O6 6
7 12
DI6 I7 O7 7
8 11
DI7 I8 O8 8
9 10
GND COMM 9
10
ULN2803A
+5V DRV O/P

CN15
DI0 1 2 DI1
DI2 3 4 DI3
DI4 5 6 DI5
DI6 7 8 DI7
9 10
DRV I/P

Note:
Before using Motor/Driver section insert the shunt or shorting link of jumper J8
mentioned to Driver legend mark.

30

www.pantechsolutions.net 8051 Development Board User Manual


7. Board Layout

31

www.pantechsolutions.net 8051 Development Board User Manual


32

www.pantechsolutions.net 8051 Development Board User Manual


8. Example Programs

1. Program for scrolling LED's


2. Program to Display Message in LCD 8 Bit Mode
3. Program to Display Message in LCD 4 Bit Mode
4. Program to Display counts from 0-1000 in 7Segment Display
5. Program to interface Buzzer with 8051
6. Program for DIP Switch Interface
7. Program to Receive Data Serially
8. Program to Send Data Serially
9. Stepper Motor Interface
10. Program to read 4-Channel values from ADC
11. Program for 4X4 Matrix Keyboard
12. Program to Display I2C RTC(DS1307) to LCD
13. DS1820 Digital Temp Sensor output displayed in Serial Window
14. Program to store data in SRAM and display in serial port

33

www.pantechsolutions.net 8051 Development Board User Manual


34

www.pantechsolutions.net 8051 Development Board User Manual


/*------------------------------------------------------------------------------*/
/* Example :Program for scrolling LED's */
/*------------------------------------------------------------------------------*/
/* Filename :scrollled.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*------------------------------------------------------------------------------*/
/* Note :The Led is connected to the Port1 and it will blink from 0th bit */
/* to 7th bit. */
/*------------------------------------------------------------------------------*/
#include<reg51.h> //Define 8051 Registers
void DelayMs(); //Delay Function

//----------------------------
// Main Function
//----------------------------
void main()
{
int i;

while(1)
{
for(i=0x01;i<=0x80;i<<=1) //shift led one position
{
P1=i; //Initialize Port1
DelayMs(); //wait
}
}

//---------------------------------
// Delay Function
//---------------------------------
void DelayMs()
{
unsigned int i;
for(i=0;i<=5;i++)
{
TMOD=0X01; //Timer0 Mode1
TL0=0X00; //Timer Lower Byte initialized to 00h
TH0=0X00; //Timer Higher Byte Initialized to 00h
TR0=1; //Timer0 ON
while(TF0==0); //Wait until Timer Flag gets Set
TR0=0; //Stop Timer
TF0=0; //Disable Timer Flag
}
}

35

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

VCC
C1 0.1uF

U1

40

20
1 39

VCC

GND
2 P1.0 P0.0/AD0 38
3 P1.1 P0.1/AD1 37
4 P1.2 P0.2/AD2 36
5 P1.3 P0.3/AD3 35
6 P1.4 P0.4/AD4 34
7 P1.5 P0.5/AD5 33
8 P1.6 P0.6/AD6 32
P1.7 P0.7/AD7
10 31
11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1
SW0

14
15 P3.4/TO 28
P3.5/T1 P2.7/A15
C4

10uF

16 27
P3.6/WR P2.6/A14
RST

17 26
P3.7/RD P2.5/A13 25
9 P2.4/A12 24
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

In this program 8 LEDs were connected to the port1. After some delay each LED gets blink one
after another. Here the delay program is written with timer. Here the time delay for each an every bit to get
set is 71ms. If a single bit in the port gets set then the LED connected to the corresponding port bit will
glow.

Here the Timer0 is running under mode-1 and the lower byte and higher byte of timer-0 is loaded
with 00h and 00h respectively. In this mode we have to reload the timer. But in mode-2 the timer gets
reloaded automatically. Then the number of counts for the rollover is found out by FFFFH (Maximum
value) 0000H (loaded value) is 65,535.

th
The crystal frequency is 11.0592MHz and the Timer frequency is found out by 1/12 of the crystal
frequency. (i.e) 11.0592MHz/12 = 921.6 KHz. Then the time period for each clock is T = 1/f = 1/921.6 KHz
= 1.085us. Then the delay created by this delay function is 65,535 x 1.085us = 71ms. So, after 71ms in
th
the port1 0 bit gets set. Hence with the delay of 71ms the adjacent bit gets set and goes on.

36

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example :Program to Display Message in LCD 8 Bit Mode */
/*--------------------------------------------------------------------------*/
/* Filename :lcd8bit.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :To display a message in LCD 8 bit mode. */
/*--------------------------------------------------------------------------*/
#include <reg51.h> //Define 8051 Registers
#include <stdio.h> //Define I/O Functions
#define DATA P1 //Define DATA to Port1

//Define control pins


sbit RS = P3^5; //Register Select
sbit RW = P3^6; //LCD Read/Write
sbit lcd_e = P3^7; //LCD Enable

code unsigned char msg[] = ("8051 DEVELOPMENT"); //Display the message


code unsigned char msg1[] = (" BOARD ");

//----------------------------------
// LCD Functions
//----------------------------------
void lcd_init(void);
void lcd_cmd(unsigned char);
void lcd_display(unsigned char);

void DelayMs(int);

//----------------------------------
// LCD command Function
//----------------------------------
void lcd_cmd(unsigned char cmnd)
{
DATA = cmnd;
RS = 0;
RW = 0;
lcd_e = 1;
DelayMs(35);
lcd_e = 0;
}

37

www.pantechsolutions.net 8051 Development Board User Manual


//----------------------------------
// LCD Data Function
//----------------------------------
void lcd_display(unsigned char dat)
{
DATA = dat;
RS = 1;
RW = 0;
lcd_e = 1;
DelayMs(35);
lcd_e = 0;
}

//----------------------------------
// LCD Delay Function
//----------------------------------
void DelayMs(int k)
{
unsigned int a;
for(a=0;a<=k;a++);
}

//----------------------------------
// LCD Initialization
//----------------------------------
void lcd_init(void)
{
unsigned char i;
lcd_cmd(0x38); //2x16 Character 5x7 dot
DelayMs(15); //matrix LCD,8-bit format
lcd_cmd(0x0c); //Display On, cursor off
DelayMs(15);
lcd_cmd(0x06); //Shift Cursor to right
DelayMs(15);
lcd_cmd(0x01); //Clear display screen
DelayMs(15);

//-------------------------------------------
// First Line Message Display
//-------------------------------------------
lcd_cmd(0x80); //First Line Initialization
DelayMs(35);
i=0;

38

www.pantechsolutions.net 8051 Development Board User Manual


while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}
DelayMs(50);
//-------------------------------------------
// Second Line Message Display
//-------------------------------------------
lcd_cmd(0xc0); //Second Line Initialization
DelayMs(35);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}
DelayMs(50);
while(1);
}

//----------------------------------
// LCD Main Program
//----------------------------------
void main(void)
{
lcd_init(); //LCD Initialization
DelayMs(50);
while(1); //Loop Forever
}

39

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

VCC
C1 0.1uF

U1

40

20
VCC R5
1 39 JP14

VCC

GND
D0 P1.0 P0.0/AD0

1
2 38 47K
D1 P1.1 P0.1/AD1 1
3 37
D2 P1.2 P0.2/AD2 2
4 36 2
D3 P1.3 P0.3/AD3 3
5 35
D4 P1.4 P0.4/AD4 P3_5 4
6 34
D5 P1.5 P0.5/AD5 P3_6 5
7 33
D6 P1.6 P0.6/AD6 P3_7 6
8 32
D7 P1.7 P0.7/AD7 D0 7

3
D1 8
RXD 10 31
P3.0/RXD EA/VPP D2 9
TXD 11 30
P3.1/TXD ALE/PROG D3 10
VCC 12 29
P3.2/INTO PSEN D4 11
13
P3.3/INT1 D5 12
SW0

14
P3.4/TO D6 13
15 28
P3_5 P3.5/T1 P2.7/A15 D7 14
C4

10uF

16 27
P3_6 P3.6/WR P2.6/A14 15
RST

17 26
P3_7 P3.7/RD P2.5/A13 VCC 16
25
9 P2.4/A12 24 2x16 LCD
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

This circuit consists of a Microcontroller and a LCD. This LCD is operating with an 8-bit data bus.
So totally 11 lines are required (8 Data lines and 3 control lines). The 8 bit data lines are connected to the
Port1 and 3 control lines to (Port3.5-Port3.7). The EN line is called "Enable." This control line indicates to
the LCD that we are sending it data. To send data to the LCD, the EN should be low (0) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely ready, bring
EN high (1) and wait for the minimum amount of time required by the LCD datasheet (this varies from LCD
to LCD), and end by bringing it low (0) again.

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data
being sent is text data, which should be displayed on the screen. For example, to display the letter "T" on
the screen we would set RS high.

The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus
is being written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD.
Only one instruction ("Get LCD status") is a read command.

40

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example: Program to Display Message in LCD 4 Bit Mode */
/*--------------------------------------------------------------------------*/
/* Filename: lcd4bit.c Date:29/05/06 */
/* */
/* Company: PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note: To display a message in LCD 4 bit mode. */
/*--------------------------------------------------------------------------*/

#include <reg51.h> //Define 8051 Registers


#include <stdio.h> //Define I/O Functions

#define DATA P1 //Define DATA to Port1

//Define control pins


sbit RS = P3^5; //LCD Register Select
sbit RW = P3^6; //LCD Read/Write
sbit lcd_e = P3^7; //LCD Enable

code unsigned char msg[] = ("8051 DEVELOPMENT"); //Display the message


code unsigned char msg1[] = (" BOARD ");

void lcd_init(void);
void lcd_cmd(unsigned char);
void lcd_display(unsigned char);
void delay(int);
void lcd_sendchar(unsigned char );

//------------------------------
// LCD command Function
//------------------------------
void lcd_cmd(unsigned char cmnd)
{
DATA=cmnd;
RS = 0;
RW = 0;
lcd_sendchar(cmnd);
}

41

www.pantechsolutions.net 8051 Development Board User Manual


//------------------------------
// LCD Data Function
//------------------------------
void lcd_display(unsigned char dat)
{
DATA=dat;
RS = 1;
RW = 0;
lcd_sendchar(dat);
}
//------------------------------
// LCD Delay Function
//------------------------------
void delay(int k)
{
unsigned int a;
for(a=0;a<=k;a++); }

//------------------------------
// LCD Initialization
//------------------------------
void lcd_init(void)
{
unsigned char i;
lcd_cmd(0x28); //2x16 Character 5x7 dot
delay(1000); //matrix LCD,4-bit format
lcd_cmd(0x0c); //Display On, cursor off
delay(1000);
lcd_cmd(0x06); //Cursor shift right
delay(1000);
lcd_cmd(0x01); //Clear display screen
delay(1000);

// First Line Message Display


//--------------------------------
lcd_cmd(0x80); //First Line Initialization
delay(1000);
i=0;
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}delay(3000);

42

www.pantechsolutions.net 8051 Development Board User Manual


//---------------------------------
// Second Line Message Display
//---------------------------------
lcd_cmd(0xc0); //Second Line Initialization
delay(2000);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}delay(3000);
while(1);
}

void lcd_sendchar(unsigned char x)


{
DATA = 0xf0&x; //Masking lower 4 Bits
lcd_e = 1;
delay(2000);
lcd_e = 0;
DATA=x*16; //Masking higher 4 Bits
lcd_e = 1;
delay(2000);
lcd_e = 0;
delay(2000);
}

//------------------------------
// Main Program
//------------------------------
void main(void)
{
lcd_init(); //LCD Initialization
delay(3000);
while(1); //Loop Forever
}

43

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

VCC
C1 0.1uF

U1

40

20
VCC R5
1 39 JP14

VCC

GND
P1.0 P0.0/AD0

1
2 38 47K
3 P1.1 P0.1/AD1 37 1
4 P1.2 P0.2/AD2 36 2 2
5 P1.3 P0.3/AD3 35 3
D4 P1.4 P0.4/AD4 P3_5 4
6 34
D5 P1.5 P0.5/AD5 P3_6 5
7 33
D6 P1.6 P0.6/AD6 P3_7 6
8 32
D7 P1.7 P0.7/AD7 7

3
RXD 10 31 8
TXD 11 P3.0/RXD EA/VPP 30 9
VCC 12 P3.1/TXD ALE/PROG 29 10
P3.2/INTO PSEN D4 11
13
P3.3/INT1 D5 12
SW0

14
P3.4/TO D6 13
15 28
P3_5 P3.5/T1 P2.7/A15 D7 14
C4

10uF

16 27
P3_6 P3.6/WR P2.6/A14 15
RST

17 26
P3_7 P3.7/RD P2.5/A13 VCC 16
25
9 P2.4/A12 24 2x16 LCD
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

This circuit consists of a Microcontroller and a LCD. This LCD is operating with a 4-bit data bus.
So totally 7 data lines are required (4 Data lines and 3 control lines). The 4 bit data lines are connected to
the Port1.0 to Port1.3 and the 3 control lines to the Port3.5-Port3.7. Since we have only 4 data lines we
can display a character by masking the lower 4 bits and then masking the higher 4 bits. The EN line is
called "Enable". This control line indicates to the LCD that we are sending it data. To send data to the
LCD, the EN should be low (0) and then set the other two control lines and/or put data on the data bus.
When the other lines are completely ready, bring EN high (1) and wait for the minimum amount of time
required by the LCD datasheet (this varies from LCD to LCD), and end by bringing it low (0) again.

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1), the data
being sent is text data, which should be displayed on the screen. For example, to display the letter "T" on
the screen we would set RS high.

The RW line is the "Read/Write" control line. When RW is low (0), the information on the data bus is being
written to the LCD. When RW is high (1), the program is effectively querying (or reading) the LCD. Only
one instruction ("Get LCD status") is a read command.

44

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program to Display counts from 0-1000 in 7Segment Display */
/*--------------------------------------------------------------------------*/
/* Filename :7Seg.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :The 7Segment display are interfaced to the Port2.The counting of */
/* numbers from (0-1000) are displayed in 7Segment display. */
/*--------------------------------------------------------------------------*/
#include<stdio.h>
#include<reg51.h>

unsigned char SetDisplay(unsigned char);


void delay(void);

sbit eseg1000 = P2^0;


sbit eseg100 = P2^1;
sbit eseg10 = P2^2;
sbit eseg1 = P2^3;
sbit buzzer = P0^0;

unsigned char d0,d1,d2,d3;

unsigned char SetDisplay(unsigned char value)


{
unsigned char segment[]={0xc0
,0xf9,0xa4,0xb0,0x99,0x92,0x83,0xf8,0x80,0x98,0x08,0x00,0xa7,0xa1,0x86,0x8e};

if(value<=10)
return segment[value];
else
return 0;
}

//Delay Function
//--------------
void delay()
{
int i;
for(i=0; i<500; i++)
i = i + 0;
}

45

www.pantechsolutions.net 8051 Development Board User Manual


//--------------
//Main Program
//--------------
void main(void)
{
unsigned char count = 0;
unsigned long timer = 0;
int turn = 1;

while(1)
{
if(turn==1) //7-Seg Display 0
{
eseg1000=0;
eseg100=0;
eseg10=0;
eseg1=1;
P1=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2) //7-Seg Display 1
{
eseg1=0;
eseg1000=0;
eseg100=0;
eseg10=1;
P1=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3) //7-Seg Display 2
{
eseg10=0;
eseg1=0;
eseg1000=0;
eseg100=1;
P1=SetDisplay(d2);
turn = 0;
delay();
}

46

www.pantechsolutions.net 8051 Development Board User Manual


else //7-Seg Display 3
{
eseg100=0;
eseg10=0;
eseg1=0;
eseg1000=1;
P1=SetDisplay(d3);
turn = 1;
delay();
}
buzzer = 0;

if(timer == 100){
d0++;
buzzer=1;
timer=0;
if(d0>=10){
d0=0;
d1++;
if(d1>=10){
d1=0;
d2++;
if(d2>=10){
d2=0;
d3++;
if(d3>=10){
d3=0;
}
}
}
}
}
timer++;
}
}

47

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

The Seven Segment Display is nothing but a combination of 7 LEDS combined into one case to
make a convenient device for displaying numbers and letters. The Seven Segment used is common
anode since the positive legs of the seven segment is connected to a common point. The four seven
segments enable lines are connected to the Port2.0-Port2.3.
VCC
C1 0.1uF

U1

40

20
1 39

VCC

GND
DP1 2 P1.0 P0.0/AD0 38
DP2 3 P1.1 P0.1/AD1 37
DP3 4 P1.2 P0.2/AD2 36
DP4 5 P1.3 P0.3/AD3 35
DP5 6 P1.4 P0.4/AD4 34
DP6 7 P1.5 P0.5/AD5 33
DP7 8 P1.6 P0.6/AD6 32
DP8 P1.7 P0.7/AD7
10 31
11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1
SW0

14
P3.4/TO
10uFC2

15 28
P3_5 16 P3.5/T1 P2.7/A15 27
P3_6 P3.6/WR P2.6/A14
RST

17 26
P3_7 P3.7/RD P2.5/A13 25
RST P2.4/A12 24
P2.3/A11 23 P2_3
9 P2.2/A10 22 P2_2
R2 18 RST P2.1/A9 21 P2_1
8K2 19 XTAL2 P2.0/A8 P2_0
11.0592MHz XTAL1
X1
C4 C3 AT89S51
33PF
33PF

P2_0 P2_1 P2_2 P2_3

7_SEG_LED
1

R14 1K R15 1K R16 1K R17 1K


2 Q1 2 Q2 2 Q3 2 Q4
3

330E R18 SEG0 U13 U14 U15 U16


DP1
3

330E R19 SEG1 SEG0 7 SEG0 7 SEG0 7 SEG0 7


CA

CA

CA

CA

CA

CA

CA

CA

DP2 SEG1 6 A SEG1 6 A SEG1 6 A SEG1 6 A


330E R20 SEG2 SEG2 4 B SEG2 4 B SEG2 4 B SEG2 4 B
DP3 SEG3 2 C SEG3 2 C SEG3 2 C SEG3 2 C
330E R21 SEG3 SEG4 1 D SEG4 1 D SEG4 1 D SEG4 1 D
DP4 SEG5 9 E SEG5 9 E SEG5 9 E SEG5 9 E
330E R22 SEG4 SEG610 F SEG610 F SEG610 F SEG610 F
DP5 SEG7 5 G SEG7 5 G SEG7 5 G SEG7 5 G
330E R23 SEG5 DP DP DP DP
DP6
7 SEG DISP 7 SEG DISP 7 SEG DISP 7 SEG DISP
330E R24 SEG6
DP7
330E R25 SEG7 SEG[0..7]
DP8

48

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program to interface Buzzer with 8051 */
/*--------------------------------------------------------------------------*/
/* Filename :Buzzer.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :Buzzer is interfaced in Port0,0th bit and it will raise alarm */
/* for 426 milli Seconds */
/*--------------------------------------------------------------------------*/

#include<reg51.h> //Define 8051 Registers


sbit alarm =P0^0; //Buzzer connected to Port0 0th bit
void DelayMs(); //Delay Function

//-----------------------------
// Main Function
//-----------------------------
void main()
{
P0=0x00; //Initialize Port0 to 00h
alarm=1; //Buzzer ON
DelayMs(); //Delay Function
alarm=0; //Buzzer OFF
}

//---------------------------------------
// Delay Function for 426mS
//---------------------------------------
void DelayMs()
{
unsigned int i;
for(i=0;i<=5;i++)
{
TMOD=0X01; //Timer0 Mode1
TL0=0X00; //Timer Lower Byte initialized to 00h
TH0=0X00; //Timer Higher Byte Initialized to 00h
TR0=1; //Timer0 ON
while(TF0==0); //Wait until Timer Flag gets Set
TR0=0; //Stop Timer
TF0=0; //Disable Timer Flag
}
}

49

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

VCC LS1 BUZZER


C1 0.1uF VCC
1
U1

40

20
R2 1K 2
1 39 Q1

VCC

GND
2 P1.0 P0.0/AD0 38
3 P1.1 P0.1/AD1 37 BC547
4 P1.2 P0.2/AD2 36
5 P1.3 P0.3/AD3 35
6 P1.4 P0.4/AD4 34
7 P1.5 P0.5/AD5 33
8 P1.6 P0.6/AD6 32
P1.7 P0.7/AD7
10 31
11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1
SW0

14
15 P3.4/TO 28
P3.5/T1 P2.7/A15
C4

10uF

16 27
P3.6/WR P2.6/A14
RST

17 26
P3.7/RD P2.5/A13 25
9 P2.4/A12 24
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

th
The buzzer is interfaced in 0 bit of port0. The aim of this program is to raise the alarm from the
buzzer up to the desired delay. Here the delay program is written for 426ms. The buzzer will raise alarm
up to 426ms and turns OFF. The delay program is written using the timer not by using any loops. The
value 0000h is loaded into the timer0 and the timer overflow flag sets, when the timer0 reaches FFFFh
and rolls over to 0000h. By this, the loop runs for six times. And the obtained delay is 426ms.
Moreover you can connect the buzzer to any of the I/O pins. In the above described program you can
change the connection to your desired port, by changing P0^0 as any other pin in the following line:

sbit alarm =P0^0;

50

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program for DIP Switch Interface */
/*--------------------------------------------------------------------------*/
/* Filename :DIPswitch.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note : The DIP switch is connected to the port1 active low '0' */
/* and the LED to the port0. */
/*--------------------------------------------------------------------------*/
#include<reg51.h> //Define 8051 Registers

#define SW P1 //Define Switch to Port1


#define Led P2 //Define Led to Port2

//----------------------
// Main Function
//----------------------
void main()
{
P1=0xff; //Initialize Port1 to FFh
P2=0x00; //Initialize Port2 to 00h
while(1) //Loop Forever
{
Led=SW; //Assign the Switch value to Led
}
}

51

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

VCC
C1 0.1uF

U1

40

20
VCC SW1 SW DIP-8
16 1 R2 1K 1 39

VCC

GND
J1 15 2 R3 1K 2 P1.0 P0.0/AD0 38
14 3 R4 1K 3 P1.1 P0.1/AD1 37
3 13 4 R5 1K 4 P1.2 P0.2/AD2 36
2 12 5 R6 1K 5 P1.3 P0.3/AD3 35
1 11 6 R7 1K 6 P1.4 P0.4/AD4 34
DIP SELECT 10 7 R8 1K 7 P1.5 P0.5/AD5 33
9 8 R9 1K 8 P1.6 P0.6/AD6 32
P1.7 P0.7/AD7
10 31
11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1
SW0

14
15 P3.4/TO 28
P3.5/T1 P2.7/A15
C4

10uF

16 27
P3.6/WR P2.6/A14
RST

17 26
P3.7/RD P2.5/A13 25
9 P2.4/A12 24
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

The DIP switch is connected to the Port1 and the LED is connected to the Port2. Initially all the
bits in Port1 is kept low, and if any of a switch is pressed then the corresponding LED glows. As usual the
Port connections for DIP switch can be changed for your needs. The resistors connected prior to the
Port1 are current limiters. One can configure the DIP-switch, whether it has to act for Logic 0 or Logic 1,
by configuring the jumper J1, in the above circuit.

52

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example :Program to Receive Data Serially */
/*--------------------------------------------------------------------------*/
/* Filename :Receive.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :Transmission and Reception takes place via Serial Buffer only. */
/* The TI bit gets set during transmission and RI bit gets set only
/* after receiving the stop bit. */
/*--------------------------------------------------------------------------*/

#include<reg51.h> //Define 8051 Registers

void serial(void); //Serial Communication Register initialization


void DelayMs(unsigned int); //Delay Function

unsigned int i,j;


unsigned char b[25],d;

//---------------------------
// Main Program
//---------------------------
void main()
{
EA=1; //Enable All Interrupt
ES=1; //Enable Serial Port Interrupt
serial(); //Serial Communication Initialization
while(1); //Loop Forever
}

//----------------------------------------------------------
// Serial Communication Register Initialization
//----------------------------------------------------------
void serial(void)
{
TMOD=0X20; //Timer1, Mode2
SCON=0X50; //Serial Mode1, Receive Enable
TH1=0XFD; //Baud Rate 9600bps
TR1=1; //Timer1 ON
}

53

www.pantechsolutions.net 8051 Development Board User Manual


//-----------------------------------------
// Serial Interrupt Function
//-----------------------------------------
void serin (void) interrupt 4 //Serial Port Interrupt
{
if(RI==1) //Receive Interrupt Gets Enabled
{ //after Stop Bit get Received
d=SBUF; //Serial Buffer value moved to a variable
b[j]=d;
SBUF=b[j];
DelayMs(20); //Delay Function
j++;
}
SCON=0X50; //Initializing Receive, Transmit interrupt
}

//---------------------------------
// Delay Function
//---------------------------------
void DelayMs(unsigned int k)
{
unsigned int i;
for(i=0;i<=k;i++);
}

Output

54

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program to send data serially through serial port */
/*--------------------------------------------------------------------------*/
/* Filename :DS18S20.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note : output can view by system's hyper terminal window */
/* set baudrate to 9600 */
/*--------------------------------------------------------------------------*/
#include <REG51.H> /*special function register declarations */
#include <stdio.h> /*prototype declarations for I/O functions*/
void serial_init(void);

//-------------------------------------------------
//Setup the serial port for 9600 baud at 11.0592MHz.
//-------------------------------------------------
void serial_init(void)
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; /* TH1: reload value for 9600 baud,11.0592MHz*/
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
}

//Main Program Starts Here


//--------------------------
void main(void)
{
serial_init();
while (1)
printf ("Hello! World\n"); /* Print "Hello World" */
}

Output

55

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details
VCC
C1 0.1uF

U1

40

20
1 39

VCC

GND
2 P1.0 P0.0/AD0 38
3 P1.1 P0.1/AD1 37
4 P1.2 P0.2/AD2 36
5 P1.3 P0.3/AD3 35
6 P1.4 P0.4/AD4 34 VCC
7 P1.5 P0.5/AD5 33 C5 10uF P1
8 P1.6 P0.6/AD6 32 5
P1.7 P0.7/AD7 9

16

SERIAL PORT
RXD 10 31 U2 4
TXD 11 P3.0/RXD EA/VPP 30 11 14 8

V+
VCC
VCC 12 P3.1/TXD ALE/PROG 29 TXD 10 T1IN T1OUT 7 3
13 P3.2/INTO PSEN T2IN T2OUT 7
P3.3/INT1
SW0

14 12 8 2
15 P3.4/TO 28 RXD 9 R1OUT R2IN 13 6
P3.5/T1 P2.7/A15 R2OUT R1IN
C4

10uF

16 27 1
P3.6/WR P2.6/A14
RST

17 26 1
P3.7/RD P2.5/A13 25 C6 C+
9 P2.4/A12 24 MAX232
18 RST P2.3/A11 23 10uF 3
XTAL2 P2.2/A10 C1-
12MHz

R1 X1 22
8K2 P2.1/A9 21 4 6
P2.0/A8 C7 C2+ V- C8
19

GND
C3 C2 XTAL1 10uF 5 10uF
AT89S51 C2-
33PF 33PF

15
Serial Communication is a form of I/O in which the bits of a byte being transferred appear one
after other in a timed sequence on a single wire. Serial Communication uses two methods, asynchronous
and synchronous. The Synchronous method transfers a block of data at a time, while the asynchronous
method transfers a single byte at a time. In Synchronous Communication the data get transferred based
on a common clock signal. But in Asynchronous communication, in addition to the data bit, one start bit
and one stop bit is added.

The 8051 has two pins that are used specifically for transferring and receiving data serially. These
two pins are called TXD and RXD and are part of the Port-3 group (Port-3.0 and Port-3.1). Pin 11 of the
8051 is assigned to TXD and pin 10 is designated as RXD. These pins are TTL compatible; therefore they
require a line driver to make them RS232 compatible. The line driver chip is MAX232. The MAX232 uses
+5v power source, which is same as the source voltage for 8051.

The 8051 transfers and receives data serially at different baud rates via serial buffer only. The
baud rate in the 8051 is programmed into the timers. In this program baud rate is defined in timer1 at a
baud rate of 9600bps and character has been transferred to the microcontroller via serial buffer (SBUF)
and it is received from the microcontroller via serial buffer (SBUF) and it is displayed in the serial window.
In our program in the serin interrupt function definition the value 4 indicates the priority of the serial
communication interrupt. To do a function in a serial interrupt we have to set the ES and EA bit to 1. The
microcontroller will receive the data only when RI bit gets set. (i.e)The RI bit gets sets only after receiving
the stop bit of the transmitted data.

56

www.pantechsolutions.net 8051 Development Board User Manual


Hyper Terminal Window Setup

57

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Stepper Motor Interface */
/*--------------------------------------------------------------------------*/
/* Filename :Stepper.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :To rotate the stepper motor in clockwise direction and */
/* anti-clockwise direction. */
/*--------------------------------------------------------------------------*/
#include<reg51.h> //Define 8051 registration
#include<stdio.h> //Define I/O functions

//------------------------------------------
//Initialization
//------------------------------------------
void clockwise();
void Anticlockwise();
void serial();
void delay();

//-----------------------------------------
//Main
//-----------------------------------------
void main(void)
{
P0=0x00; //Ports initialization
serial();
printf(Type A-clockwise or Type B-Anticlockwise \n);
while(1)
{
SBUF=getchar(); //Getting value from the user
if(SBUF=='A')
clockwise();
if(SBUF=='B')
Anticlockwise ();
}
}

58

www.pantechsolutions.net 8051 Development Board User Manual


//Clockwise
//----------------
void clockwise()
{
int j;
for(j=0;j<8;j++)
{
P0=0x01;delay();
P0=0x02;delay();
P0=0x04;delay();
P0=0x08;delay();
}
}

//Anticlockwise
//----------------
void Anticlockwise()
{
int j;
for(j=0;j<8;j++)
{
P0=0x08;delay();
P0=0x04;delay();
P0=0x02;delay();
P0=0x01;delay();
}
}
//Serial initialization
//------------------------
void serial()
{
TMOD=0X20; //Timer1, Mode2
SCON=0X50; //Serial Mode1, Receive Enable
TH1=0XFD; //Baud Rate 9600bps
TR1=1; //Timer1 ON
TI=1; //Transmit Interrupt Enable
}
//Delay
//-----------------
void delay()
{
unsigned int i;
for(i=0;i<1000;i++);}

59

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Diagram

VCC
C1 0.1uF

U1

40

20
1 39

VCC

GND
2 P1.0 P0.0/AD0 38
3 P1.1 P0.1/AD1 37
4 P1.2 P0.2/AD2 36
5 P1.3 P0.3/AD3 35
6 P1.4 P0.4/AD4 34
7 P1.5 P0.5/AD5 33
8 P1.6 P0.6/AD6 32
P1.7 P0.7/AD7
RXD 10 31
TXD 11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1 U2
SW0

14
P3.4/TO
10uFC2

15 28 1 16
16 P3.5/T1 P2.7/A15 27 2 IN1 OUT1 15
17 P3.6/WR P2.6/A14 26 3 IN2 OUT2 14
RST

P3.7/RD P2.5/A13 25 4 IN3 OUT3 13


RST P2.4/A12 24 5 IN4 OUT4 12
P2.3/A11 23 6 IN5 OUT5 11
9 P2.2/A10 22 7 IN6 OUT6 10
R2 18 RST P2.1/A9 21 8 IN7 OUT7 9
8K2 19 XTAL2 P2.0/A8 GND VCC
11.0592MHz XTAL1
ULN2003
X1
C4 C3 AT89S51
33PF
33PF

This program is to rotate a stepper motor in clockwise and anti-clockwise direction by means of issuing a
command from serial port. Here if we give the character A from the serial port the motor rotates in
clockwise direction and for the character B the motor rotates in anti-clockwise direction. The serial port
has to be initialized as usual. The stepper motor is connected in port-2 via ULN 2003. The ULN 2003 is a
seven pair Darlington array package. The Darlington amplifier is a powerful amplifier to drive wide loads
like Solenoids, Relays, Thermal print heads and high power buffers. The sequence of the stepper motor is
defined as reference to the data sheet of the corresponding motor.

60

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program to read CH0 value from ADC */
/*--------------------------------------------------------------------------*/
/* Filename :1channel.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :The ADC data lines are interfaced in the Port1 and the obtained*/
/* value in Port1 is converted to decimal value */
/*--------------------------------------------------------------------------*/
#include<stdio.h> //Define I/O Functions
#include <reg51.h> //Define 8051 Registers
#include <ctype.h>

//-----------------------------
// ADC Control Lines
//-----------------------------
sbit A0 = P2^7; //Address lines Initialization
sbit A1 = P2^6;
sbit A2 = P2^5;
sbit CS = P2^4; //Chip Select Pin

void serial(); //Serial Port Initialization


void delay1(int);
void delay2(int);
unsigned char READ_ADC(void);

unsigned char ch;


unsigned int i;
//-----------------------------
//Delay Function
//-----------------------------
void delay1(int n)
{
int i;
for(i=0;i<n;i++);
}
void delay2(int n)
{
int i;
for(i=0;i<n;i++)
delay1(1000);
}

61

www.pantechsolutions.net 8051 Development Board User Manual


//-------------------------------------
//Serial Port Initialization
//-------------------------------------
void serial()
{
SCON=0x50; //Serial Mode-1, REN enable
TMOD=0x20; //Timer1, Mode2, 8-bit (Auto Remode)
TH1=0xfd; //9600 Baud rate at 11.0592MHz
TR1=1; //Timer 1 ON
TI=1; //Transmit Interrupt Enable
}

//--------------------------
//ADC Function
//--------------------------
unsigned char READ_ADC()
{
unsigned char ADC_DATA;
CS = 0; delay2(1); //Trigger ADC by Chip Selectt Pin
CS = 1; delay2(1);
CS = 0; delay2(1);
CS = 1; delay2(1);
ADC_DATA = P1; //Get the value from Port1
return(ADC_DATA);
}
//--------------------------
// Main Program
//--------------------------
void main(void)
{
P1=0xFF;
serial(); //Serial port Initialization
A0 = 0; A1 = 0; A2 = 0; // channel '0' ADJ Trimpot

printf("ADC Demo - Channel '0' Adjust (R27) Trimpot\n");


printf("--------------------------------------------\n");

while(1)
{
ch = READ_ADC(); //Get the value from Channel-0
printf("\rCH0 = %3bu",ch);
delay2(2);
}
}

62

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details
VCC
C1 0.1uF

U1

40

20
11
U5 D0 1 39

VCC

GND
CH0 26 17 D0 D1 2 P1.0 P0.0/AD0 38

ADC
CH1 27 IN0 D0 14 D1 D2 3 P1.1 P0.1/AD1 37
CH2 28 IN1 D1 15 D2 D3 4 P1.2 P0.2/AD2 36
CH3 1 IN2 D2 8 D3 D4 5 P1.3 P0.3/AD3 35
CH4 2 IN3 D3 18 D4 D5 6 P1.4 P0.4/AD4 34
CH5 3 IN4 D4 19 D5 D6 7 P1.5 P0.5/AD5 33
CH6 4 IN5 D5 20 D6 D7 8 P1.6 P0.6/AD6 32
VCC CH7 5 IN6 D6 21 D7 P1.7 P0.7/AD7
IN7 D7 RXD 10 31
U6A 74HC132 16 25 TXD 11 P3.0/RXD EA/VPP 30
REF- A0 P2_7 P3.1/TXD ALE/PROG
24 VCC 12 29
A1 P2_6 P3.2/INTO PSEN
1 23 13
A2 P2_5 P3.3/INT1

SW0
3 10 14
2 CLK 6 15 P3.4/TO 28
START P3.5/T1 P2.7/A15 P2_7

C4

10uF
R26 12 22 16 27
REF+ ALE P3.6/WR P2.6/A14 P2_6

RST
9 7 17 26
OE EOC P3.7/RD P2.5/A13 P2_5
10K 25
P2.4/A12 P2_4
VCC ADC0809 9 24
18 RST P2.3/A11 23
XTAL2 P2.2/A10

12MHz
C9 R1 X1 22
0.1uF 8K2 P2.1/A9 21
2 1 P2_4 P2.0/A8
19
U7A C3 C2 XTAL1
74LS04 AT89S51
33PF 33PF

VCC
C5 10uF P1
5
9
16

SERIAL PORT
U2 4
11 14 8
V+
VCC

TXD 10 T1IN T1OUT 7 3


T2IN T2OUT 7
12 8 2
RXD 9 R1OUT R2IN 13 6
R2OUT R1IN 1
1
C6 C+
MAX232
10uF 3
C1-
4 6
C7 C2+ V- C8
GND

10uF 5 10uF
C2-
15

This circuit consists of a Microcontroller and an ADC. The ADC reads the Temperature value from
the sensor and the obtained value is an analog value and it is converted to digital value. The digital value
is fed into the Microcontroller because the Microcontroller reads only the digital value. The data lines of
ADC are connected to the Port1 of Microcontroller. The Address lines and Chip Select Pin is connected to
the Port2.7-Port2.5 and Port2.4 respectively.

63

www.pantechsolutions.net 8051 Development Board User Manual


The ADC0809 has 8 channels, so we can interface 8 parameters to the ADC. But in this program
we are considering four parameters, which is the Voltage value from four Channels.

The obtained value in Microcontroller is hexadecimal. So to display the Voltage in real time we
cant leave it as hexadecimal, we have to convert the hexadecimal to decimal. . If you intend to display the
temperature value in LCD, convert the hexadecimal value to decimal and then display it.

Here we have 8-channels, the desired channel can be selected. The purpose of CS pin is to
trigger the ADC chip. The ADC converts the analog input to its binary equivalent and holds it in an internal
register. RD (active low pin) is used to get the converted data out of the chip. If CS=0 and when the WR
pin comes from low to high transition the ADC starts converting the analog input value to the digital value.
When the conversion is over, the INTR pin is forced low by the ADC chip.

64

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : Program for 4X4 Matrix Keyboard with LCD */
/*--------------------------------------------------------------------------*/
/* Filename :Keypad_LCD.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* LCD Data Lines : Port P1 */
/* Keypads : Port P2 */
/* Note :Getting a key value from a 4X4 Matrix Keypad (based on the Row */
/* and Column value of corresponding Key) and displaying it in the*/
/* LCD. */
/*----------------------------------------------------------------------------
#include <stdio.h> //Define I/O Functions
#include <reg51.h> //Define 8051 Registers

#define DATA P1 //Define DATA to Port1

void lcd_init(void); //LCD Initialization


void lcd_cmd(unsigned char); //LCD Command Function
void lcd_display(unsigned char); //LCD Display Function
void Key_Scan(void); //KeyScan Function
void DelayMs(int); //DelayMs Function

sbit RS = P3^5; //Register Select


sbit RW = P3^6; //LCD Read/Write
sbit lcd_e = P3^7; //LCD Enable

unsigned char R,C,ch,d=0x81;


unsigned int i=0;
unsigned char Key[4][4] = {'C','D','E','F', //Matrix Keypad Character
'8','9','A','B', //Initialization
'4','5','6','7',
'0','1','2','3',};

code unsigned char msg[] = ("KEYPAD TEST PGM "); //Display the Message
code unsigned char msg1[] = ("PRES ANY KEY... "); //in LCD

//-------------------------------
// Main Program
//-------------------------------
void main()
{
lcd_init();
DelayMs(20);
lcd_cmd(0x01);
lcd_e=0;
lcd_cmd(0x80);

65

www.pantechsolutions.net 8051 Development Board User Manual


while(1)
{
Key_Scan();
lcd_e=1;
DelayMs(5);
ch = Key[R][C]; //Assign Key value to ch;
DelayMs(5); //and Row Value of Keypad
lcd_display(ch);
lcd_cmd(d++);
DelayMs(10);
P2=0xFF;
}
}

//-------------------------------
// Key Scan Function
//-------------------------------

void Key_Scan(void)
{
unsigned int i = 0;

//Scanning for Row Value

P2 = 0x0F; //Initialize Port2 to 0Fh


while(P2 == 0x0F);

if(P2 == 0x0E) //Checking for Row0


R = 0;
else if(P2 == 0x0D) //Checking for Row1
R = 1;
else if(P2 == 0x0B) //Checking for Row2
R = 2;
else if(P2 == 0x07) //Checking for Row3
R = 3;

//Scanning for Column Value

P2 = 0xF0; //Initialize Port2 to F0h


while(P2 == 0xF0);

if(P2 == 0xE0) //Checking for Column0


C = 0;
else if(P2 == 0xD0) //Checking for Column1
C = 1;
else if(P2 == 0xB0) //Checking for Column2
C = 2;
else if(P2 == 0x70) //Checking for Column3
C = 3;

DelayMs(20);

66

www.pantechsolutions.net 8051 Development Board User Manual


//-------------------------------
// LCD command Function
//-------------------------------
void lcd_cmd(unsigned char cmnd)
{
DATA = cmnd;
RS = 0; //RS:Register Select
RW = 0; //RW:Read/Write
lcd_e = 1; //LCD Enable
DelayMs(15);
lcd_e = 0;
}

//-------------------------------
// LCD Data Function
//-------------------------------
void lcd_display(unsigned char dat)
{
DATA = dat;
RS = 1; //RS:Register Select
RW = 0; //RW:Read/Write
lcd_e = 1;
DelayMs(15);
lcd_e = 0;
}

//-------------------------------
// LCD Initialization
//-------------------------------
void lcd_init(void)
{
unsigned char i;
lcd_cmd(0x38); //2x16 Character 5x7 dot
DelayMs(15); //matrix LCD,8-bit format
lcd_cmd(0x0c); //Display On, cursor off
DelayMs(15);
lcd_cmd(0x06); //Shift Cursor to right
DelayMs(15);
lcd_cmd(0x01); //Clear display screen
DelayMs(15);

//------------------------------------
// First Line Message Display
//------------------------------------
lcd_cmd(0x80); //First Line Initialization
DelayMs(15);
i=0;
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}

67

www.pantechsolutions.net 8051 Development Board User Manual


DelayMs(20);

//------------------------------------
// Second Line Message Display
//------------------------------------

lcd_cmd(0xc0); //Second Line Initialization


DelayMs(15);
i=0;
while(msg1[i]!='\0')
{
lcd_display(msg1[i]);
i++;
}
DelayMs(30);
}

//--------------------------
// DelayMs Function
//--------------------------
void DelayMs(int k)
{
unsigned int a,b;
for(a=0;a<=k;a++)
for(b=0;b<1275;b++);
}

68

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

The 4X4 Matrix Keyboard circuit diagram is given below:

R5
+5v JP14

1
47K 1
2 2
3
P3_5 4
P3_6 5
P3_7 6
DP1 7
3

DP2 8
DP3 9
DP4 10
DP5 11
DP6 12
DP7 13
DP8 14
+5v 15
16
2x16 LCD

VCC
C1 0.1uF

U1
40

20

1 39
VCC

GND

DP1 2 P1.0 P0.0/AD0 38


DP2 3 P1.1 P0.1/AD1 37
DP3 4 P1.2 P0.2/AD2 36
DP4 5 P1.3 P0.3/AD3 35
DP5 6 P1.4 P0.4/AD4 34
DP6 7 P1.5 P0.5/AD5 33
DP7 8 P1.6 P0.6/AD6 32
DP8 P1.7 P0.7/AD7
10 31
11 P3.0/RXD EA/VPP 30
VCC 12 P3.1/TXD ALE/PROG 29
13 P3.2/INTO PSEN
P3.3/INT1
SW0

14
P3.4/TO
10uFC2

15 28
P3_5 P3.5/T1 P2.7/A15 CL4
16 27
P3_6 P3.6/WR P2.6/A14 CL3
RST

17 26
P3_7 P3.7/RD P2.5/A13 CL2
25
P2.4/A12 CL1
RST 24
P2.3/A11 RA4
23
P2.2/A10 RA3
9 22
RST P2.1/A9 RA2
R2 18 21
XTAL2 P2.0/A8 RA1
8K2 19
11.0592MHz XTAL1
X1
C4 C3 AT89S51
33PF
33PF

69

www.pantechsolutions.net 8051 Development Board User Manual


+5v

R6 R7 R8 R9
10K 10K 10K 10K

SW1 SW2 SW3 SW4

R10 10K
RA1
SW5 SW6 SW7 SW8

R11 10K
RA2
SW9 SW10 SW11 SW12

R12 10K
RA3
SW13 SW14 SW15 SW16

R13 10K
RA4

CL1 CL2 CL3 CL4

Circuit Description

This circuit comprises of a LCD, 4X4 Keyboard and a microcontroller. In this program we have
assigned a character to each key. The microcontroller scans the key value and it will be displayed in the
LCD. The lines DP1-DP8 are the data lines of the LCD. The control lines RS, RW, EN pins are connected
to the Port lines P3.5, P3.6 and P3.7 respectively. The 4X4 Matrix keyboard is connected to the Port2.
RA1-RA4 is the row of the keyboard and it is connected to the port lines P2.0-P2.3 and CL1-CL4 is the
column of the keyboard and it is connected to the Port lines P2.4-P2.7. The microcontroller assigns the
row value to the lower four bits of Port2 and the column values to the higher four bits of Port2. (For
Example if the value in the Port2 is EE means the character displayed in the LCD is 1).

When a key is pressed a row and a column make a contact; otherwise there is no connection
between rows and columns. To detect a pressed key, the microcontroller grounds all columns by providing
0 to the port2 higher 4 bits, and then it checks for rows. If the data read from the rows is F, no key has
been pressed and the process continues until a key press is detected. If a 0 is detected in the four bits of
the row (lower four bits of port2) then a key press is detected. After the key press got detected the
microcontrollers check the column value. If any of the higher four bits in port2 becomes 0 the column
value was got detected. Then based on the port2 value it checks with the program (Key scan function is to
detect the key value) and moves the correct value to port1 and it will be displayed in the LCD.

70

www.pantechsolutions.net 8051 Development Board User Manual


/*-------------------------------------------------------------------------*/
/* Example : Program to Display I2C RTC(DS1307) to LCD */
/*-------------------------------------------------------------------------*/
/* Filename :I2C_RTC.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*-------------------------------------------------------------------------*/
/* LCD contrl Lines RTC(DS1307) */
/* ---------------- ----------- */
/* LCD RS : P3.5 SCL : P3.4 */
/* LCD RW : P3.6 SDA : P3.3 */
/* LCD EN : P3.7 */
/* LCD Data : P1 */
/*-------------------------------------------------------------------------*/
#include<reg51.h> //Define 8051 registration
#include<stdio.h> //Define I/o Functions

//---------------------------
//Initialization
//---------------------------
void serial(void);
void delay(int);
unsigned char a[17]="This is from SRAM",b,c,i;
unsigned char xdata *add=0xfff0;

//--------------------------------------
//Sram
//--------------------------------------
void flash_wr(unsigned char xdata *addr,unsigned char val)
{
*addr=val;
}

unsigned char flash_rd(unsigned char xdata *addr)


{
return *addr;
}

//-------------------------------------
//Main program
//-------------------------------------
void main()
{
serial(); //Serial initialization

71

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details

Note: Before using RTC insert the shunt or shorting link of jumper J8 mentioned near RTC legend
mark.

VCC
C1 0.1uF

U1

40

20
VCC R5
1 39 JP14

VCC

GND
D0 P1.0 P0.0/AD0

1
2 38 47K
D1 P1.1 P0.1/AD1 1
3 37
D2 P1.2 P0.2/AD2 2
4 36 2
D3 P1.3 P0.3/AD3 3
5 35
D4 P1.4 P0.4/AD4 P3_5 4
6 34
D5 P1.5 P0.5/AD5 P3_6 5
7 33
D6 P1.6 P0.6/AD6 P3_7 6
8 32
D7 D0

3
P1.7 P0.7/AD7 7
RXD D1 8
10 31
TXD P3.0/RXD EA/VPP D2 9
11 30
P3.1/TXD ALE/PROG D3 10
VCC 12 29
P3.2/INTO PSEN D4 11
13
P3_3 P3.3/INT1 D5 12
SW0

14
P3_4 P3.4/TO D6 13
15 28
P3_5 P3.5/T1 P2.7/A15 D7 14
C4

10uF

16 27
P3_6 P3.6/WR P2.6/A14 15
RST

17 26
P3_7 P3.7/RD P2.5/A13 VCC 16
25
9 P2.4/A12 24 2x16 LCD
18 RST P2.3/A11 23
XTAL2 P2.2/A10
12MHz

R1 X1 22
8K2 P2.1/A9 21
P2.0/A8
19
C3 C2 XTAL1
AT89S51
33PF 33PF

D14

I2C_RTC
1K R42

VCC
1N4148

1N4148
D15
D16

3.6V Battery
2 1 R28
R29 4K7
BT1 1N4148 U4 4K7
8

5 J4
I2C_RTC

3 SDA P3_3
X2 VBAT 1 2
1 6 3 4 P3_4
X1 SCLK RTC
32.768KHz 2 7
X2 SQW/OUT
DS1307

VCC
J8
1 2
3 4
5 6
7 8 I2C_RTC
9 10
11 12
13 14
15 16
VCC SLT

72

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example : DS1820 Digital Temp Sensor output displayed Serial Window */
/*--------------------------------------------------------------------------*/
/* Filename :DS18S20.c Date:29/05/06 */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Data : P2.2 */
/*--------------------------------------------------------------------------*/
#include<reg52.h>
#include<stdio.h>

sbit DQ = P2^2; // connect with DS1820 Data pin


unsigned char MyTemp[9];
void DelayUs(int);
//----------------------------------------
// Reset DS1820
//----------------------------------------
bit ResetDS1820(void)
{
bit presence;
DQ = 0; //pull DQ line low
DelayUs(29); // leave it low for about 490us
DQ = 1; // allow line to return high
DelayUs(3); // wait for presence 55 uS
presence = DQ; // get presence signal
DelayUs(25); // wait for end of timeslot 316 uS
return(presence); // presence signal returned
} // 0=presence, 1 = no part

//-----------------------------------------
// Read one bit from DS1820
//-----------------------------------------
bit ReadBit(void)
{
unsigned char i=0;
DQ = 0; // pull DQ low to start timeslot
DQ=1;
for (i=0; i<3; i++); // delay 17 us from start of timeslot
return(DQ); // return value of DQ line
}

73

www.pantechsolutions.net 8051 Development Board User Manual


//-----------------------------------------
// Write one bit to DS1820
//-----------------------------------------
void WriteBit(bit Dbit)
{
unsigned char i=0;
DQ=0;
DQ = Dbit ? 1:0;
DelayUs(5); // delay about 39 uS
DQ = 1;
}

//-----------------------------------------
// Read 1 byte from DS1820
//-----------------------------------------
unsigned char ReadByte(void)
{
unsigned char i;
unsigned char Din = 0;
for (i=0;i<8;i++)
{
Din|=ReadBit()? 0x01<<i:Din;
DelayUs(6);
}
return(Din);
}

//-----------------------------------------
// Write 1 byte
//-----------------------------------------
void WriteByte(unsigned char Dout)
{
unsigned char i;
for (i=0; i<8; i++) // writes byte, one bit at a time
{
WriteBit((bit)(Dout & 0x1)); // write bit in temp into
Dout = Dout >> 1;
}
DelayUs(5);
}

74

www.pantechsolutions.net 8051 Development Board User Manual


//-----------------------------------------
// Read temperature
//-----------------------------------------
void ReadTemp(unsigned char * buff)
{
unsigned char n;
EA=0; // disable all interrupt
ResetDS1820();
WriteByte(0xcc); // skip ROM
WriteByte(0x44); // perform temperature conversion
while (ReadByte()==0xff); // wait for conversion complete
ResetDS1820();
WriteByte(0xcc); // skip ROM
WriteByte(0xbe); // read the result

for (n=0; n<9; n++) // read 9 bytes but, use only one byte
{
buff[n]=ReadByte(); // read DS1820
}
EA=1;
}

//---------------------------------------
//Serial Port Initialization
//---------------------------------------
void InitSerial(void)
{
SCON = 0x52; // setup serial port control
TMOD = 0x20; // hardware (9600 BAUD @11.05592MHZ)
TH1 = 0xFD; // TH1
TR1 = 1; // Timer 1 on
}
//---------------------------------------
// Delay mS function
//---------------------------------------
void DelayMs(unsigned int count)
{ // mSec Delay 11.0592 Mhz
unsigned int i; // Keil v7.5a
while(count) {
i = 115;
while(i>0) i--;
count--;
}
}

75

www.pantechsolutions.net 8051 Development Board User Manual


//-------------------------------------------------------
// DELAY at 11.0592MHz crystal.
// Calling the routine takes about 22us, and then
// each count takes another 17us. test with KEIL C51 V7.5
// -----------------------------------------------------
void DelayUs(int us)
{
int i;
for (i=0; i<us; i++);
}

//---------------------------------------
// Main program
//---------------------------------------
void main(void)
{
unsigned char tp,tpd,i;
InitSerial(); // Initialize serial port
while(1)
{
ReadTemp(&MyTemp[0]);
tp = MyTemp[0] >> 1;
tpd = ((MyTemp[0] >> 1)&1) ? 5:0;
putchar(0x0C); // clear Hyper terminal
printf("%bu Temperature : %2bu.%bu\r\n",i++,tp,tpd);
DelayMs(200);
}
}

Output (Hypter Terminal)

76

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details
DS1820 is a temperature sensor which is small sensor. The output of sensor converted to digital that easy
connecting with microcontroller.

VCC
C1 0.1uF

U1

40

20
J3 1 39

VCC

GND
P3_0 2 P1.0 P0.0/AD0 38
RXD 1 2 P3_1 3 P1.1 P0.1/AD1 37
TXD 3 4 4 P1.2 P0.2/AD2 36
5 6 5 P1.3 P0.3/AD3 35
7 8 6 P1.4 P0.4/AD4 34 U11 DS1820
9 10 7 P1.5 P0.5/AD5 33
11 12 8 P1.6 P0.6/AD6 32
13 14 P1.7 P0.7/AD7

GND
15 16

Vdd
P3_0

DQ
10 31
MLT-P3 P3_1 11 P3.0/RXD EA/VPP 30
12 P3.1/TXD ALE/PROG 29 VCC

1
13 P3.2/INTO PSEN
VCC 14 P3.3/INT1
15 P3.4/TO 28
P3.5/T1 P2.7/A15
SW0

16 27
P3.6/WR P2.6/A14
10uFC2

17 26
P3.7/RD P2.5/A13 25 R52 4K7
P2.4/A12
RST

24
P2.3/A11 23
9 P2.2/A10 22
18 RST P2.1/A9 21
19 XTAL2 P2.0/A8
R2 11.0592MHz XTAL1
8K2 X1
C4 C3 AT89S51
33PF
33PF

VCC
P1
C5 10uF 5
9
16

SERIAL PORT

U2 4
11 14 8
V+
VCC

TXD 10 T1IN T1OUT 7 3


T2IN T2OUT 7
12 8 2
RXD 9 R1OUT R2IN 13 6
R2OUT R1IN 1
1
C6 C+
MAX232
10uF 3
C1-
4 6
C7 C2+ V- C8
GND

10uF 5 10uF
C2-
15

Note : Connect DS18s20 Data line to P2.2, short jumpers rxd and txd line, set baud rate of systems
HyperTerminal window to 9600bps, 8-Data bits, parity-none, 1-stob bit, flow controlnone.

77

www.pantechsolutions.net 8051 Development Board User Manual


/*--------------------------------------------------------------------------*/
/* Example :Program to store data in SRAM and display in serial port */
/*--------------------------------------------------------------------------*/
/* Filename :SRAM.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*--------------------------------------------------------------------------*/
/* Note :Transmission and Reception takes place via Serial Buffer only. */
/* The TI bit gets set during transmission and RI bit gets set only */
/* after receiving the stop bit, SRAM is connected to Port 1&2. */
/*--------------------------------------------------------------------------*/
#include<reg51.h> //Define 8051 registration
#include<stdio.h> //Define I/o Functions

void serial(void);
void delay(int);
unsigned char a[17]="This is from SRAM",b,c,i;
unsigned char xdata *add=0xfff0;

//--------------------------------------
// SRAM
//--------------------------------------
void flash_wr(unsigned char xdata *addr,unsigned char val)
{
*addr=val;
}

unsigned char flash_rd(unsigned char xdata *addr)


{
return *addr;
}

//-------------------------------------
//Main program
//-------------------------------------
void main()
{
serial(); //Serial initialization
while(1)
{
for(i=0;i<=16;i++)
{
b=a[i];

78

www.pantechsolutions.net 8051 Development Board User Manual


flash_wr(add,b); //Writing data to the SRAM
c=flash_rd(add); //Reading data from the SRAM
SBUF=c; //Passing the value to SBUF
delay(10);
add++;
}
SBUF='\n';
delay(10);
}
}
//---------------------------------------
//Serial Initialization
//---------------------------------------
void serial()
{
TMOD=0X20; //Timer1, Mode2
SCON=0X50; //Serial Mode1, Receive Enable
TH1=0XFD; //Baud Rate 9600bps
TR1=1; //Timer1 ON
TI=1; //Transmit Interrupt Enable
}
//---------------------------
// Delay
//---------------------------
void delay(int m)
{
int i ,j;
for(j=0;j<m;j++)for(i=0;i<=1000;i++);
}

79

www.pantechsolutions.net 8051 Development Board User Manual


Circuit Details
SRAM SRAM

20

28
U2 U3
AD0 3 2 10 11 AD0

SRAM

SRAM
AD1 4 D0 Q0 5 9 A0 D0 12 AD1
AD2 7 D1 Q1 6 8 A1 D1 13 AD2
AD3 8 D2 Q2 9 7 A2 D2 15 AD3
AD4 13 D3 Q3 12 6 A3 D3 16 AD4
AD5 14 D4 Q4 15 5 A4 D4 17 AD5
AD6 17 D5 Q5 16 4 A5 D5 18 AD6
AD7 18 D6 Q6 19 3 A6 D6 19 AD7
D7 Q7 1 A7 D7
11 A14 A13 26 A14
ALE 1 G A12 2 A13
OC A11 23 A12
A10 21 A11
74LS373
A9 24 A10
A8 25 A9
A8
20
22 CE
OE 27 OE
MEM_WR WE
HM62256

CN7 CN8
AD0 AD1 A8 A9
AD2 1 2 AD3 A10 1 2 A11
AD4 3 4 AD5 A12 3 4 A13
AD6 5 6 AD7 5 6
7 8 7 8
9 10 9 10
AD0 - AD7 A8 - A15
MEM_WR

MEM_WR
A14

J3
P3_0 A14
RXD 1 2 P3_1 FLASH SRAM
TXD INT0 3 4 P3_2
INT1 5 6 P3_3 1 2
7 8 WR P2_6 WR 1 2 P2_6
P3_4 3 4 3 4
9 10 P3_5 5 6 5 6
11 12 P3_6
WE 13 14 CN5 CN5
P3_7
OE 15 16
MLT-P3

Note:
Its advised not to use Port-0 and Port-2 for others External peripherals while using
SRAM/FLASH.
Before using SRAM/FLASH insert the shunt or shorting link of jumper J8 mentioned to SRAM
legend mark.
Short pins 13 & 14 (WE) for Write Enable and pin 15 & 16 (OE) of J3 Header.

Short pins SRAM( 3&5, 4&6) of CN5 or FLASH(1&3, 2&4).

80

www.pantechsolutions.net 8051 Development Board User Manual


VCC
C1 0.1uF

U1

40

20
1 39

VCC

GND
2 P1.0 P0.0/AD0 38
3 P1.1 P0.1/AD1 37
4 P1.2 P0.2/AD2 36
5 P1.3 P0.3/AD3 35
6 P1.4 P0.4/AD4 34 VCC
7 P1.5 P0.5/AD5 33 C5 10uF P1
8 P1.6 P0.6/AD6 32 5
P1.7 P0.7/AD7 9

16

SERIAL PORT
RXD 10 31 U2 4
TXD 11 P3.0/RXD EA/VPP 30 11 14 8

V+
VCC
VCC 12 P3.1/TXD ALE/PROG 29 TXD 10 T1IN T1OUT 7 3
13 P3.2/INTO PSEN T2IN T2OUT 7
P3.3/INT1
SW0

14 12 8 2
15 P3.4/TO 28 RXD 9 R1OUT R2IN 13 6
P3.5/T1 P2.7/A15 R2OUT R1IN
C4

10uF

16 27 1
P3.6/WR P2.6/A14
RST

17 26 1
P3.7/RD P2.5/A13 25 C6 C+
9 P2.4/A12 24 MAX232
18 RST P2.3/A11 23 10uF 3
XTAL2 P2.2/A10 C1-
12MHz

R1 X1 22
8K2 P2.1/A9 21 4 6
P2.0/A8 C7 C2+ V- C8
19

GND
C3 C2 XTAL1 10uF 5 10uF
AT89S51 C2-
33PF 33PF

15
The 8051 has two pins that are used specifically for transferring and receiving data serially. These
two pins are called TXD and RXD and are part of the Port-3 group (Port-3.0 and Port-3.1). Pin 11 of the
8051 is assigned to TXD and pin 10 is designated as RXD. These pins are TTL compatible; therefore they
require a line driver to make them RS232 compatible. The line driver chip is MAX232. The MAX232 uses
+5v power source, which is same as the source voltage for 8051.

Output

81

www.pantechsolutions.net 8051 Development Board User Manual


82

www.pantechsolutions.net 8051 Development Board User Manual