Documente Academic
Documente Profesional
Documente Cultură
User Manual
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
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
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
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
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
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
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
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
NOTE : Since all packages have parallel connections, there must not be more than
one
Microcontroller on the board at a time.
11
12
J1 PH-ISP
VCC
1 2 PSEN
3 4
5 6
D0
R3 330E
LED
Programming Mode
Switch Push to ON, MCU enters programming mode.
Execution Mode
Switch Push to OFF, MCU turns to execution mode.
13
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
15
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
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
17
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
18
2. Built-in Dot Matrix LCD controller with font 5X7 or 5X10 dots.
4. Character generator ROM, which provides 160, characters with font 5X7 dots and 32
5. Both display data and character generator RAMs can be read from the MPU.
Wide range of command functions: Clear displays, cursor home, display ON/OFF, cursor
19
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
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
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.
VCC
10K R27
3 1
J6
CH0
1
2
2
ADC INT I/P
22
11
CN14 U5
CH0 26 17
ADC
1 IN0 D0 ADC0
27 14
2 IN1 D1 ADC1
28 15
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
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
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
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
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
10uF 6 5
V-
C7 MAX232
15
SERIAL PORT
10uF
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
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
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
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.
28
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
R10 10K
RA1
SW5 SW6 SW7 SW8
R11 10K
RA2
SW9 SW10 SW11 SW12
R12 10K
RA3
SW13 SW14 SW15 SW16
R13 10K
RA4
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
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
31
33
//----------------------------
// 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
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
//----------------------------------
// 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
//----------------------------------
// 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
//----------------------------------
// LCD Main Program
//----------------------------------
void main(void)
{
lcd_init(); //LCD Initialization
DelayMs(50);
while(1); //Loop Forever
}
39
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
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
//------------------------------
// 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);
42
//------------------------------
// Main Program
//------------------------------
void main(void)
{
lcd_init(); //LCD Initialization
delay(3000);
while(1); //Loop Forever
}
43
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
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
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
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
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
7_SEG_LED
1
CA
CA
CA
CA
CA
CA
CA
48
//-----------------------------
// 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
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:
50
//----------------------
// 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
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
//---------------------------
// 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
//---------------------------------
// Delay Function
//---------------------------------
void DelayMs(unsigned int k)
{
unsigned int i;
for(i=0;i<=k;i++);
}
Output
54
//-------------------------------------------------
//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 */
}
Output
55
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
57
//------------------------------------------
//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
//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
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
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
//-----------------------------
// 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
61
//--------------------------
//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
while(1)
{
ch = READ_ADC(); //Get the value from Channel-0
printf("\rCH0 = %3bu",ch);
delay2(2);
}
}
62
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
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
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
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
//-------------------------------
// Key Scan Function
//-------------------------------
void Key_Scan(void)
{
unsigned int i = 0;
DelayMs(20);
66
//-------------------------------
// 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
//------------------------------------
// Second Line Message Display
//------------------------------------
//--------------------------
// DelayMs Function
//--------------------------
void DelayMs(int k)
{
unsigned int a,b;
for(a=0;a<=k;a++)
for(b=0;b<1275;b++);
}
68
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
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
R6 R7 R8 R9
10K 10K 10K 10K
R10 10K
RA1
SW5 SW6 SW7 SW8
R11 10K
RA2
SW9 SW10 SW11 SW12
R12 10K
RA3
SW13 SW14 SW15 SW16
R13 10K
RA4
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
//---------------------------
//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;
}
//-------------------------------------
//Main program
//-------------------------------------
void main()
{
serial(); //Serial initialization
71
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
//-----------------------------------------
// 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
//-----------------------------------------
// 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
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
//---------------------------------------
// 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);
}
}
76
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
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
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;
}
//-------------------------------------
//Main program
//-------------------------------------
void main()
{
serial(); //Serial initialization
while(1)
{
for(i=0;i<=16;i++)
{
b=a[i];
78
79
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.
80
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