8051 ADB Board Manual
Transcript of 8051 ADB Board Manual
1
www.pantechsolutions.net 8051 Advanced Development Board User Manual
8051 Advanced Development Board
User Manual
2
www.pantechsolutions.net 8051 Advanced Development Board User Manual
CONTENTS
1. Introduction
Technical/Customer Support ............................................................. 3
Package contains ............................................................................. 4
Board Introduction ........................................................................... 5
2. Connectors and Jumper Details................................................................ 9
3. Power Supply Block .............................................................................. 12
4. ZIF Socket Details ............................................................................... 12
5. Flash programmers .............................................................................. 13
6. Onboard Peripheral/Interface Details ...................................................... 17
6.1 - Point LEDs ............................................................................ 18
6.2 – Digital Inputs Toggle Switches ................................................ 21
6.3 - LCD 2x16 in 8-bit mode .......................................................... 23
6.4 - GLCD 128x64 ....................................................................... 27
6.5 - UART RS-232 Communication ................................................. 32
6.6 - Real Time Clock ..................................................................... 36
6.7 – I2C EEPROM ......................................................................... 43
6.8 - 7 Segment LED ..................................................................... 48
6.9 - Interrupts ............................................................................. 52
6.10 - DS1820 (Digital Thermometer) .............................................. 53
6.11 - Matrix keypad ...................................................................... 57
6.12 - Stepper Motor Driver ............................................................ 62
6.13 - Relay Driver ........................................................................ 64
6.14 – SPI DAC ............................................................................. 66
6.15 – RS-485 .............................................................................. 68
6.16 – PS/2 ................................................................................. 70
6.17 – Ethernet ............................................................................ 73
6.18 – ADC On-Chip ...................................................................... 76
6.19 – CAN .................................................................................. 79
7. Board Layout....................................................................................... 81
9. Easy Programming Steps ...................................................................... 82
3
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Technical or Customer Support
E-mail questions to [email protected]
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
4
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Packages
• 8051 ADB Development module
• Serial Port Cable (Dallas/Philips Controller Program)
• Parallel to Serial Cable (Atmel ISP)
• 10-pin FRC Cables
• Printed User Manual
• CD contains
o Software (Programmers, IDE)
o Example Programs
o User Manual
o Simple Projects
5
www.pantechsolutions.net 8051 Advanced Development Board User Manual
1. Introduction
Pantech Solutions’ Embedded Advanced Development module is proposed to smooth
the progress of developing and debugging of various designs encompassing 8051
Microcontrollers from Philips / Atmel/ Dallas. The intention of the design is to endorse
the engineers to exercise and explore the capabilities of 8051 microcontrollers with
many communication protocol ease. The board is compatible with 40-DIP/44-PLCC
pin Microcontrollers. The kit is designed so as to facilitate separate On-board ISP
Programmer for Atmel microcontrollers and Philips Microcontroller through ISP on
serial port. Programming can be done without detaching the Microcontroller from the
ZIF socket.
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. Many real world applications can be tested on the board.
RS485, RTC, DAC, Digital Temperature controllers, Motor drivers, Memory
interfacing, counters, timers...
6
www.pantechsolutions.net 8051 Advanced Development Board User Manual
General Block Diagram
AT89SXX AT89C51CC0X
DS89C4XX P89C51RD2
PS/2
Keyboard
10-bit ADC
(AT89C51CC03)
SPI – DAC MCP4921
I2C
EEPROM
128x64 GLCD
2x16 LCD
I2C
Real Time Clock
CAN 2.0
(MCP2551)
Stepper Motor Termination
8 Nos.
Point LEDs
Two
Ext Interrupts
PWM
(AT89C51CC03)
2XRS232
10Mbps Ethernet
9V AC/DC Input
5V Regulator
Two Relay Outputs
4x4 Matrix
Keypad
1-Wire
Temp Sensor
RS485
Parallel/Serial
ISP Programmer
3.3V Regulator Ethernet supply
4 Nos. Seven
Segment Display
8 Nos.
Digital Inputs
7
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Specifications
• Supported Microcontrollers :
SOCKET1 (40-DIP)
Atmel : AT89S51/52/8252 and AT89Sxx
NXP : P89V51Rxx
Dallas : DS89C420/430/450
SOCKET2 (44-PLCC)
Atmel : AT89S51/52/8252 and AT89Sxx MCUs
NXP : P89V51Rxx
Dallas : DS89C420/430/450
SOCKET3 (44-PLCC)
Atmel : AT89C51CC01/02/03 (CAN Controllers)
T89C51CC01/02/03
• External Peripheral Modules
� 128X64 GLCD Interface
� 2x16 Character LCD with Contrast adjust
� 10Mbps Ethernet Interface.
� 4-Nos. of common anode seven segment display.
� 8-Nos. General purpose Point LEDs.
� 8-Nos. of Toggle switches (Digital Inputs).
� 4x4 Matrix keypad.
� Stepper Motor Driver Output.
� Two Nos. of 5V Relay with termination.
� PS/2 keyboard Interface.
• Communication Protocols
� CAN (2.0A and 2.0B) (Bosch)
� I2C Two Wire Interface (Philips-NXP)
� SPI (Motorola)
� 1-wire Technology (Maxim-Dallas)
� Two Full Duplex UART (EIA)
� RS485 (EIA)
8
www.pantechsolutions.net 8051 Advanced Development Board User Manual
• Other Features
� Digital to Analog Converter.
� Real Time Clock with Battery Backup.
� Serial EEPROM memory.
� Digital Temperature sensor
� RS485 serial communication through long distance(>200m)
� Two UART for serial port communication through PC.
� ISP In-System Programming for NXP, Dallas and Atmel CAN controllers.
� Parallel programmer for Atmel AT89S5X family controllers.
� Two pushbuttons for Interrupts study.
� Two Nos. of On-board potentiometer for ADC input testing of Atmel AT89C51CC03
controller
� Easy to mount 40-pin DIP Devices (ZIF socket).
� MCU Socket selectable jumpers.
� Controlling of multifunction through DIP Switch.
9
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2. Connectors and Jumper Details
CN3 - 10PIN Box Header ( PORT 0 )
VCC
P0.1
P0.5P0.6
CN3
PORT 0
1 23 45 67 89 10
P0.4P0.2P0.0
P0.7
P0.3
P0.[0..7]P0.[0..7]
Connector
Pin
Numbers
MCU Pin
Name
Connector
Pin
Numbers
MCU Pin
Name
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 VCC 10 GND
CN2 - 10PIN Box Header ( PORT 1 )
P1.[0..7]P1.[0..7]
VCC
CN2
PORT 1
1 23 45 67 89 10
P1.3P1.5P1.7
P1.1
P1.4
P1.0
P1.6
P1.2
Connector
Pin
Numbers
MCU Pin
Name
Connector
Pin
Numbers
MCU Pin
Name
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 VCC 10 GND
10
www.pantechsolutions.net 8051 Advanced Development Board User Manual
CN4 - 10PIN Box Header ( PORT 2 )
P2.0 P2.1
P2.5P2.7
P2.3
P2.[0..7]
VCC
CN4
PORT 2
1 23 45 67 89 10
P2.6P2.4P2.2
P2.[0..7]
Connector
Pin
Numbers
MCU Pin
Name
Connector
Pin
Numbers
MCU Pin
Name
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 VCC 10 GND
CN5 - 10PIN Box Header ( PORT 3 )
P3.4
P3.[0..7]P3.[0..7]
VCC
P3.1
P3.5P3.3
P3.7
CN5
PORT 3
1 23 45 67 89 10
P3.6
P3.0P3.2
Connector
Pin
Numbers
MCU Pin
Name
Connector
Pin
Numbers
MCU Pin
Name
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 VCC 10 GND
11
www.pantechsolutions.net 8051 Advanced Development Board User Manual
JP2 – 6pin Header (Power select for MCU)
CAN_VCC
JP2PWRSLT_MC
246
135
MC1_VCCMC2_VCC
VCC
Jumper for Enable Power to MCU
• Short Pin 1&2 of JP2(+5V, to MCU1 socket)
• Short Pin 3&4 of JP2(+5V, to 44pin plcc socket MCU)
• Short Pin 5&6 of JP2(+5V, to 44pin plcc AT89C51CC03 CAN controller)
Connector
Pin
Numbers
Signal
Name
Connector
Pin
Numbers
Signal
Name
1 VCC 2 MCU1(40-Dip)-8051
3 VCC 4 MCU2(44-PLCC)-8051
5 VCC 6 MCU3(AT89C51CC03CAN
Note : short jumpers only one at a time, otherwise it executes fault operation.
12
www.pantechsolutions.net 8051 Advanced 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. USB socket meant for power
supply only, user can select either USB or Ext power supply through JP1. Separate
On/Off Switch for controlling power to the board.
JP1POWER
1 2 3
C30.1uf
D2
5V1
- +
D1BRIDGE
1
4
3
2
C2470uf
U1 78XX/TO
VIN1
VOUT3
GN
D2
J1
POWER JACK
12
CN1USB
VC
C1
D-
2
D+
3
GN
D4
GND5
GND6
SW3
SW KEY-SPST
1 2
R1330E
D3LED
4. MCU Sockets
• The 8051-development board is delivered with ATMEL’s 40-pin & 44pin CAN
Controller 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.
13
www.pantechsolutions.net 8051 Advanced 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.
SW4
SW DIP-10
M_TXD0M_RXD0P3.1
P3.0
Programming Mode
SW4 (pin 9) make it ‘on’
(PSEN low), program
mode NXP (Philips)
microcontrollers.
Execution Mode
SW4 (pin 9) make it ‘off’
(PSEN nil), execution
mode NXP (Philips)
microcontrollers.
Note : Detailed Manual available at “Flash Magic” Help menu - Manual.
14
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2. ATMEL Microcontroller ISP
Note : Atmel Microcontrollers (PGM mode), user can select switch settings to color
shaded position.(EXE Mode) disable switches to off position.
P1.5P1.7
P1.6
SW32
SW DIP-4
MC_RST
Note : Detailed Manual available for
\8051ADB\Softwares\Programmers\AT89ISP\User Manual.pdf
15
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2. Dallas Microcontroller ISP
MC_RST
SW4
SW DIP-10
R24K7
VCC
R34K7
VCC
EA
R4330E
VCC D4LED
PSEN
M_TXD0M_RXD0P3.1
P3.0
Note : Dallas Microcontrollers (PGM mode), user can select switch settings to color
shaded position.(EXE Mode) disable switches to off position.
16
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2. ATMEL CAN Microcontroller ISP
SW4
SW DIP-10
R24K7
VCC
R34K7
VCC
EA
R4330E
VCC D4LED
PSEN
M_TXD0M_RXD0
P3.0P3.1
Note : Atmel CAN Microcontrollers (PGM mode), user can select switch settings to
color shaded position(EXE Mode) disable switches to off position.
17
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6. On-board Peripherals
The Development board comes with many interfacing options
• 8-Nos. of Point LED’s (Digital Outputs).
• 8-Nos. of Toggle switches (Digital Inputs).
• 2 Lines X 16 Character LCD Display.
• 128X64 GLCD Interface
• Real Time Clock with battery backup.
• 4 Nos. of Seven-segment display.
• Digital Temperature Sensor
• 4 X 4 Matrix keypad.
• Relay / Stepper Motor driver circuit.
� Digital to Analog Converter.
� Serial EEPROM memory.
� RS485 serial communication through long distance(>200m)
� Two UART for serial port communication through PC.
� PS/2 keyboard Interface.
� 10Mbps Ethernet Interface.
18
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.1 - Light Emitting Diodes
• Light Emitting Diodes (LEDs) are the most commonly used components, usually
for displaying pin’s 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 CN8 for LED connector, when High Level goes to the pin LED glows.
CN8
LED
1 23 45 67 89 10
LED
1
LED
2
LED
3
LED
4
LED
5
LED
6
LED
7
LED
8
C R11
470E
12 3 4 5 6 7 8 9
D2D3 D4
D8D5D7
D6
D1
D1
D5D4D3 D7 D8D6D2
19
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/
/* Example : Program to shift LED’s Left and Right */
/*------------------------------------------------- -------------------------*/
/* Filename :LED_Flash.c Date:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*------------------------------------------------- -------------------------*/
/* LED Port(CN8) : Port1 P1(CN2) */
/*------------------------------------------------- -------------------------*/
#include <stdio.h>
#include <REG51.H>
#define LED P1 //define prot for LED
void delay(void); //Delay function
void led_left(void); //LED_Left
void led_right(void); //LED_Right
unsigned int j;
//----------------------------------
//LED LEFT FUNCTIONS
//----------------------------------
void led_left()
{
for (j=0x01; j<=0x80; j<<=1)
{
LED = j;
delay();
}
}
//----------------------------------
//LED RIGHT FUNCTIONS
//----------------------------------
void led_right()
{
for (j=0x40; j>=0x01; j>>=1)
{
LED = j;
delay();
}
}
20
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//----------------------------------
//Delay Functions
//----------------------------------
void delay(void)
{
unsigned int i;
for (i=0;i<10000;i++)
{;}
}
//----------------------------------
// Main Program Starts
//----------------------------------
void main (void)
{
LED = 0x00; //Initialize to 0x00
while (1) //Loop forever
{
led_left(); //scroll left
delay();
led_right(); //scroll right
}
}
21
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.2 – Digital Inputs Toggle Switch
• This is another simple interface, 8-Nos. of toggle switch, mainly used to give an
input to the port lines, and for some control applications also.
• User can change the level of digital inputs whatever they want, either high or low
by simply selecting the jumper J3. The switches are connected to +5V, in order to
detect a switch state, pull-up or pull-down resistors should be used.
R1010K
12 3 4 5 6 7 8 9
J3
CON3
123
VCC
GND
SW
181
2
SW
191
2
SW
201
2
SW
211
2
SW
221
2
SW
231
2
SW
241
2
SW
251
2
SS3SS5
SS1SS4
SS7SS6
SS2
SS8
CN6
SLIDE_SWITCH
1 23 45 67 89 10
SS
1
SS
2
SS
3
SS
4
SS
5
SS
6
SS
7
SS
8
22
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/
/* Example : Program for DIP Switch Interface */
/*------------------------------------------------- -------------------------*/
/* Filename :DIPswitch.c D ate:29/05/06 */
/* */
/* Company :PANTECH SOLUTIONS */
/*------------------------------------------------- -------------------------*/
/* Note : The DIP switch is connected to the port-2 active low '0' */
/* and the LED to the port-0. */
/*------------------------------------------------- -------------------------*/
#include<reg51.h> //Define 8051 Registers
#define SW P2 //Define Switch to Port2
#define Led P0 //Define Led to Port0
//----------------------
// Main Function
//----------------------
void main()
{
P2=0xff; //Port-2 as input to FFh
P0=0x00; //Port-0 as output to 00h
while(1) //Loop Forever
{
Led=SW; //Assign the Switch value to Led
}
}
23
www.pantechsolutions.net 8051 Advanced 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 LCD’s contrast can be adjusted by varying the trimpot (R13).
• Before using LCD insert the shunt or shorting link of jumper J5 mentioned to CHAR
legend mark.
• Place 2x16 Character LCD to proper place, mentioned legend in PCB.
R19 10EVCC
VCC
J4
GLCD128X64
123456789
1011121314151617181920
GD3GD2GD1
GD4GD6 GD7
GD5
CN10
GLCD
1 23 45 67 89 10
GD4
GD0
GD2
GD6GD5
GD7
GD3
GD1
VCCGNDR13
10K
13
2
P3.7P3.6P3.5
RST
GD0
J5
CON3
123
2x1
6 L
CD
CHAR
GLCD
Note: Possible ways to interface LCD (Not CN5).
LCD CON MCU CON
1. CN10 CN2
2. CN10 CN3
3. CN10 CN4
24
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/
/* Example :Program to Display Message in LCD 8 Bi t 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> //Def ine 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 Enab le
code unsigned char msg[] = (" 8051 ADVANCED "); //Display the message
code unsigned char msg1[] = (" ADB 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;
}
25
www.pantechsolutions.net 8051 Advanced 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 o ff
DelayMs(15);
lcd_cmd(0x06); //Shift Cursor to right
DelayMs(15);
lcd_cmd(0x01); //Clear display scree n
DelayMs(15);
//-------------------------------------------
// First Line Message Display
//-------------------------------------------
lcd_cmd(0x80); //First Line Initiali zation
DelayMs(35);
i=0;
26
www.pantechsolutions.net 8051 Advanced Development Board User Manual
while(msg[i]!='\0')
{
lcd_display(msg[i]);
i++;
}
DelayMs(50);
//-------------------------------------------
// Second Line Message Display
//-------------------------------------------
lcd_cmd(0xc0); //Second Line Init ialization
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 Initial ization
DelayMs(50);
while(1); //Loop Forever
}
27
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.4 - 128X64 Graphic LCD
• When using a Graphic LCD, the connector CN10 connects the LCD to Microcontroller
port lines. User can use GLCD Data lines to Port P0, P1 and P2, not P3, because P3
lines P3.3(CS1), P3.4(CS2), P3.5(RS), P3.6(R/W) and P3.7 (Enable) connected by
default. The LCD’s contrast can be adjusted by varying the trimpot(R13).
• Before using LCD insert the shunt or shorting link of jumper J5 mentioned to GLCD
legend mark. Adjust(R13) for GLCD Negative Voltage
• Place GLCD to proper place, mentioned in PCB.
R19 10EVCC
VCC
J4
GLCD128X64
123456789
1011121314151617181920
GD3GD2GD1
GD4GD6 GD7
GD5
CN10
GLCD
1 23 45 67 89 10
GD4
GD0
GD2
GD6GD5
GD7
GD3
GD1
VCCGND
R1310K
13
2
P3.7P3.6P3.5
RST
GD0
J5
CON3
123
GL
CD
12
8x6
4
GLCD
CS1CS2
Note: Possible ways to interface LCD (Not CN5).
LCD CON MCU CON
1. CN10 CN2
2. CN10 CN3
3. CN10 CN4
28
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example :Program to Display Picture in GLCD 128 x64 */ /*------------------------------------------------- -------------------------*/ /* Filename :GLCD.c Date:10/01/08 */ /* */ /* Company :PANTECH SOLUTIONS * / /*------------------------------------------------- -------------------------*/ /* Note :To display a image in page0 & 1 */ /*------------------------------------------------- -------------------------*/ #include <reg51.h> //Define 8051 Registers #include <stdio.h> //Define I/O Functions #define DATA P2 //Define DATA to Port1 //Define control pins sbit CS1 = P3^3; //CS1 select LCD IC1 sbit CS2 = P3^4; //CS2 select LCD IC2 sbit RS = P3^5; //Register Select sbit RW = P3^6; //LCD Read/Write sbit lcd_e = P3^7; //LCD Enable //sbit RST = P3^7; //#define size 1024 void GLCD_PutPicture(const unsigned char *); //For method 3 void Select_page(unsigned char); int i; code unsigned char carsun_bmp[1024] ={ 0, 0, 0, 0, 4, 10, 58, 62,122,210,208,208,208,208,208, 48, 188, 60,172,172,246,247,255,110,254,190,126,126, 9 2,152, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,128,128,128, 0,129,129,141,143,136,192, 80,208,200, 8, 8, 140, 12, 58, 58, 71,130,135, 0,161,208,112,240,16 0,166,166,153, 139,142,141,143, 15, 27, 23, 23, 27, 15, 15,143,190,187,191,159, 204,140,143,246,246,246,230,189,255,177,189,238,19 5, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, 28,222,126,123, 57, 63,125,120, 15, 15, 3, 3, 65,193,225,193,192,192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 98, 99, 29, 153,192, 66,199,132,132,133,135, 0, 0,128, 80,120, 81,113, 118, 126, 63, 31, 22,227,253,248,224,192,193,194,194,19 4,195,129, 0, 1,131,131,191,191,230,234,234,188,248,241,195, 66, 71,129,133, 133,174,255,255,247,255,255,254,254,255,251,253,21 0,208, 0, 0, 0, 0, 0, 0, 32, 60, 52,247,254,241,245,239,255,188,182,254, 252,230,243,233,247,151,153,255,247,243,223,221,25 2,120,120,248, 104,120,248,112,112, 48, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 1 6, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 31, 31, 31, 31, 17, 17, 17, 17, 1 7, 17, 17, 18, 18, 25, 25, 44, 15, 31, 63, 63,111,127, 58, 63,119,119,255,191, 53, 22, 31, 11, 31, 31, 47, 63, 63,255,207,255,25 5, 47, 37, 0, 0, 0, 0, 0, 0, 0, 32,251,255,255,255,255,255,131,129,193,
29
www.pantechsolutions.net 8051 Advanced Development Board User Manual
227,227, 51, 55,229,199, 7, 15, 11, 27, 31, 28, 5 6,240, 96, 96, 97, 97, 97, 97, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96,224, 96, 96, 96, 96, 96, 9 6, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 9 6, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 99, 98,102,108,248,240, 96, 96, 0,255,255,255,25 5, 0, 0, 0, 0, 0, 0, 0, 2, 23, 29, 33, 33,255,255,255,255,167,167, 58, 24,120,248,232,121,123,122,158,144, 0,252,158,15 9,127, 96,128, 14, 10, 10, 10, 10, 10, 10, 14, 0, 0, 0, 14, 10, 10, 10, 10, 10, 14, 14, 0, 0,128,255,248,232,192,192,254,25 4,254, 34, 34, 34, 34, 34, 34,254, 34, 34, 34, 34, 34, 34, 34,254,254,254, 50, 0, 0, 0,254,130,186, 58, 58, 98, 98, 98, 98, 2,254, 0, 0, 0,254,254,254,254, 34, 34, 34, 34,254,254, 34, 34, 34, 34, 34, 254,254,254,224,127,255,194,222,126,255,255,255,25 5, 0, 0, 0, 0, 0, 0, 0, 0,128,128,128, 96,191,255,127,255,255,225,195, 207,140,137, 8, 8, 8, 8, 25, 63, 59, 11, 79, 7 9, 73,233,254, 168,160,160, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 63, 39, 47, 63, 63,125, 73, 9,225, 64, 72, 120,120,120,121, 73, 65, 77, 81, 25,121, 73,121, 49,113, 73, 73, 200,200,120,127, 80, 81, 64, 64, 64, 80, 80,240,22 4,127, 24,152, 144,201,233,249,249, 56,136, 8,144,241,121,120,160,248,240,112, 9,121, 63,127,120,104, 77, 76,124,255,255,255,25 5,248, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 3, 3, 6, 6, 12, 12, 24, 24, 16, 48, 32, 96, 96, 192,192,128,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 2, 6, 6, 0, 0, 4, 0, 0, 2, 2, 34, 98, 98,208,209,145, 145, 16, 16, 16, 8, 8, 8, 4, 6, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,128,192,192,224,224,248,231,239,255,11 9, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,128, 0,192,192,192,192,192,192, 192,192,192,192,192,192,192,192,192,192,192,192,19 2, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 96, 64, 64, 65, 65, 99, 99, 98,102,102,108,108,120,12 0,120,112,112, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 3, 2, 6, 6, 12, 12, 24, 24, 48, 48, 4 8, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 16, 16, 0, 0, 0, 0, 0, 0,}; //---------------------------------- // LCD Functions //---------------------------------- void GLCD_Init(); void GLCD_Data(unsigned char); void GLCD_Comd(unsigned char); void DelayMs(int);
30
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//---------------------------------- // LCD command Function //---------------------------------- void GLCD_Comd(unsigned char cmnd) { DATA = cmnd; //send command to port RS = 0; //make it RS to Low RW = 0; //make it RW to low lcd_e = 1; //enable high DelayMs(10); lcd_e = 0; //enable low } //---------------------------------- // LCD Data Function //---------------------------------- void GLCD_Data(unsigned char dat) { DATA = dat; //send command to port RS = 1; //make it RS to high RW = 0; //make it RW to low lcd_e = 1; //enable high DelayMs(10); lcd_e = 0; //enable low } //---------------------------------- // LCD Delay Function //---------------------------------- void DelayMs(int k) { unsigned int a; for(a=0;a<=k;a++); } //---------------------------------- // GLCD Initialization Function //---------------------------------- void GLCD_Init() { unsigned char Comd[5]={0xc0,0xb8,0x40,0x3f};//LCD Command list Select_page(1); //send commands to page1 for(i=0;i<4;i++) GLCD_Comd(Comd[i]); Select_page(0); //send commands to page0 for(i=0;i<4;i++) GLCD_Comd(Comd[i]); }
31
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//---------------------------------- // Page Selection //---------------------------------- void Select_page(unsigned char Page) { if(Page) { CS1=0; //Page 0 LCD IC1 CS2=1; } else { CS1=1; //Page 1 LCD IC2 CS2=0; } } //------------------------------------- // Display Picture for page0 & page1 //------------------------------------- void GLCD_PutPicture(const unsigned char *ip) //Cha nge here for method 1,2 & 3 { int Page=0,i=0; int Column=0; for (Page = 0; Page < 8; Page++) { Select_page(1); //Display part of image to Page 1 GLCD_Comd(0xb8 | Page); GLCD_Comd(0x40); for (Column = 0; Column < 128; Column++) { if (Column == 64) { Select_page(0); //Display part of image to Page0 GLCD_Comd(0xb8 |); GLCD_Comd(0x40); } GLCD_Data(*ip++); } } } //------------------------ // Main Program //----------------------- void main(void) { GLCD_Init(); //Initialize GLCD DelayMs(10); GLCD_PutPicture(carsun_bmp); //Display Image while(1); //wait forever }
32
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.5 - 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.
CANH
C15 10uF
TX0_OUT
M_TXD0
M_RXD0
M_TXD1
M_RXD1
RX0_IN
VCCP1
COM1
594837261
U10
MAX232/DIP
GN
D15
VC
C16
R1IN13
R2IN8
T2IN10 T1IN11
C1+1
C1-3
C2+4
C2-5
V+2
V-6
R1OUT12
R2OUT9
T1OUT14
T2OUT7 TX1_OUT
RX1_IN
TX0_OUT
RX0_IN
RX1_IN
TX1_OUT
C11 100n
P2
COM2
594837261
C12
10uF
C14
10uF
C13 10uF
CANL
�: Note : Make switch positions below this UART0(P1).
P3.0P3.1
P1.2P1.3
M_TXD1M_RXD1
M_RXD0M_TXD0
SW4
SW DIP-10
33
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Program to send data serially through serial port */ /*------------------------------------------------- -------------------------*/ /* Filename :send.c Date:29/05/06 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* Note : output can view by system's hyper termina l window */ /* set baudrate to 9600 */ /*------------------------------------------------- -------------------------*/ #include <REG51.H> /*special functio n register declarations */ #include <stdio.h> /*prototype decla rations 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 UAR T, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mod e 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 se nd first char of UART */ } //Main Program Starts Here //-------------------------- void main(void) { serial_init(); while (1) printf ("Hello! World\n"); /* Print "Hello World" */ }
Output
34
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Program to send data serially through serial port 0 & 1 */ /*------------------------------------------------- -------------------------*/ /* Filename :UART0_1.c Date:25/01/08 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* Connection - Only Dallas MCU89c4xx */ /* ---------------------------------- */ /* P3.0 - RXD0 (UART-0) P1.2 - RXD1 (UART-1) */ /* P3.1 - TXD0 (UART-0) P1.3 - TXD1 (UART-1) */ /* Note : PORT0(P1) - 9600 Baudrate */ /* PORT1(P2) - 4800 Baudrate */ /*------------------------------------------------- -------------------------*/ #include <reg420.H> #include <stdio.h> code unsigned char msg1[]={"Dallas UART-0"}; code unsigned char msg2[]={"Dallas UART-1"}; void DelayMs(unsigned int); //--------------------------------- // Delay Function //--------------------------------- void DelayMs(unsigned int n) { unsigned int i,j; for(j=0;j<n;j++) for(i=0;i<1000;i++); } //------------------------------------------------- -------------------- // This function initializes serial port 0&1 to run at 9600 , 4800 // baud rate using the timer 1 auto-reload mode wit h a 11.0592MHz XTAL //------------------------------------------------- -------------------- void serial_init(void) { PCON |= 0xC0; SCON0 = 0x50; //serial-0 conn mode 1 - start, 8- data, 1 stop bit SCON1 = 0x52; //serial-1 conn mode 1 - start, 8- data, 1 stop bit TMOD |= 0x21; //Timer 1 mode 2, 8-bit auto re load mode TH1 = -6; //serial-0(9600), serial-1(4800) ba ud rate. TCON = 0x50; TI_0 = 1; //Enable Transmit bit of serial 0 TI_1 = 1; //Enable Transmit bit of serial 1 }
35
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//-------------------------- //Main Program Starts Here //-------------------------- void main(void) { int i,j; serial_init(); while (1) { while(msg1[i]!='\0') //UART0(9600 baudrate) msg { SBUF0 = msg1[i++]; DelayMs(10); } DelayMs(10); while(msg2[j]!='\0') //UART1(4800 Baudrate) msg { SBUF1 = msg2[j++]; DelayMs(10); } } }
Note : Dallas MCU User can’t set 9600 baud rate for both the UART0 and UART1
PORT0(P1) - 9600 baudrate
PORT1(P2) – 4800 baudrate
Output
36
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.6 - 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 module’s DS1307 of pin SDA and SCL connected to the
Microcontroller’s pin P2.1 and P2.0 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.
VCC
I2C_SCL
I2C_SDA
U17
DS1307
SQW/OUT7
SDA5
X11
X22
SCLK6
VBAT3
I2C
_RT
C8
X3
32.768KHz
BT1
3.6V Battery12
D7
1N4148
D9
1N4148
VCC
D8
1N4148
R40
1K
R434K7
R424K7
I2C_SDAP2.1P2.0 I2C_SCL
SW31
SW DIP-8
12345678
161514131211109
P2.[0..7]
Note: Before using RTC make switch settings like above mentioned.
37
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Program to Display I2C RTC(DS1307) to Hyper terminal window */ /*------------------------------------------------- -------------------------*/ /* Filename :I2CRTC_Serial.c Date:29/05/06 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* RTC(DS1307) */ /* ----------- */ /* SCL : P2.0 */ /* SDA : P2.1 */ /* Output : Port0(P1) ...Hyper terminal, 9600baud r ate */ /*------------------------------------------------- -------------------------*/ #include<reg51.h> #include<stdio.h> #include<intrins.h> //------------------- // DS1307 driver //------------------- #define ACK 1 #define NO_ACK 0 #define SLAVE 0xD0 #define WRITE 0x00 #define READ 0x01 #define ERR_ACK 0x01 unsigned char i; const unsigned char * DayStr[7] = {{"Sun"}, {"Mon"}, {"Tue"}, {"Wen"}, {"The"}, {"Fri"}, {"Sat"}}; const unsigned char * MonthStr[12] ={{"Jan"}, {"Feb"}, {"Mar"}, {"Apr"}, {"May"}, {"Jun"}, {"Jul"}, {"Aug"}, {"Sep"}, {"Oct"}, {"Nov"}, {"Dec"}};
38
www.pantechsolutions.net 8051 Advanced Development Board User Manual
sbit SCL = P2^0; // connect to SCL pin (Clock) sbit SDA = P2^1; // connect to SDA pin (Data) unsigned char RTC_ARR[7]; // Buffer for second,mi nute,.....,year unsigned char p; //--------------------------------------- // Initialize serial port //--------------------------------------- void InitSerial(void) { SCON = 0x52; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.0559 2MHZ) TH1 = 0xFD; // TH1 TR1 = 1; // Timer 1 on } //---------------------------------- // Convert BCD 1 byte to HEX 1 byte //---------------------------------- unsigned char BCD2HEX(unsigned int bcd) { unsigned char temp; temp=((bcd>>8)*100)|((bcd>>4)*10)|(bcd&0x0f); return temp; } //------------------------------- // start I2C //------------------------------- void Start(void) { SDA = 1; SCL = 1; _nop_();_nop_(); SDA = 0; _nop_();_nop_(); SCL = 0; _nop_();_nop_(); } //------------------------------- // stop I2C //------------------------------- void Stop(void) { SDA = 0; _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SDA = 1; }
39
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//------------------------------- // Write I2C //------------------------------- void WriteI2C(unsigned char Data) { for (i=0;i<8;i++) { SDA = (Data & 0x80) ? 1:0; SCL=1;SCL=0; Data<<=1; } SCL = 1; _nop_();_nop_(); SCL = 0; } //------------------------------- // Read I2C //------------------------------- unsigned char ReadI2C(bit ACK_Bit) { unsigned char Data=0; SDA = 1; for (i=0;i<8;i++) { SCL = 1; Data<<= 1; Data = (Data | SDA); SCL = 0; _nop_(); } if (ACK_Bit == 1) SDA = 0; // Send ACK else SDA = 1; // Send NO ACK _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SCL = 0; return Data; }
40
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//------------------------------- // Read 1 byte form I2C //------------------------------- unsigned char ReadBYTE(unsigned char Addr) { unsigned char Data; Start(); WriteI2C(0xD0); WriteI2C(Addr); Start(); WriteI2C(0xD1); Data = ReadI2C(NO_ACK); Stop(); return(Data); } //------------------------------- // Write 1 byte to I2C //------------------------------- void WriteBYTE(unsigned char Addr,unsigned char Dat a) { Start(); WriteI2C(0xD0); WriteI2C(Addr); WriteI2C(Data); Stop(); } //------------------------------- // Read RTC (all real time) //------------------------------- void ReadRTC(unsigned char * buff) { Start(); WriteI2C(0xD0); WriteI2C(0x00); Start(); WriteI2C(0xD1); *(buff+0)=ReadI2C(ACK); // Second *(buff+1)=ReadI2C(ACK); // Minute *(buff+2)=ReadI2C(ACK); // hour *(buff+3)=ReadI2C(ACK); // Day *(buff+4)=ReadI2C(ACK); // date *(buff+5)=ReadI2C(ACK); // month *(buff+6)=ReadI2C(NO_ACK); // year Stop(); }
41
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//------------------------------- // Write RTC //------------------------------- void WriteRTC(unsigned char *buff) { Start(); WriteI2C(0xD0); WriteI2C(0x00); WriteI2C(*(buff+0)); WriteI2C(*(buff+1)); WriteI2C(*(buff+2)); WriteI2C(*(buff+3)); WriteI2C(*(buff+4)); WriteI2C(*(buff+5)); WriteI2C(*(buff+6)); Stop(); } //------------------------------- // Convert date (BCD) to string of Day // 1=Sanday // 2=Monday // And so on //------------------------------- char * Int2Day(unsigned char day) { return DayStr[day-1]; } //------------------------------- // Convert month (BCD) to string of Month // 0x01=January // 0x02=February // ........... // 0x12 = December // And so on //------------------------------- char * Int2Month(unsigned char month) { return MonthStr[BCD2HEX(month)-1]; } // 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--; } }
42
www.pantechsolutions.net 8051 Advanced Development Board User Manual
// DELAY at 11.0592MHz crystal. // Calling the routine takes about 22us, and then // each count takes another 17us. //--------------------------------------------- void DelayUs(int us) { int i; for (i=0; i<us; i++); } /*************************************** // Main program /***************************************/ void main(void) { InitSerial(); // Initialize serial port // Setup time and enable oscillator //----------------------------------- ReadRTC(&RTC_ARR[0]); RTC_ARR[0] = RTC_ARR[0] & 0x7F; // enable oscillato r (bit 7=0) RTC_ARR[1] = 0x59; // minute = 59 RTC_ARR[2] = 0x23; // hour = 05 ,24-hour mode(bit 6=0) RTC_ARR[3] = 0x04; // Day = 1 or sunday RTC_ARR[4] = 0x31; // Date = 30 RTC_ARR[5] = 0x10; // month = August RTC_ARR[6] = 0x08; // year = 05 or 2008 WriteRTC(&RTC_ARR[0]); // Set RTC while(1) { ReadRTC(&RTC_ARR[0]); putchar(0x0C); // clear Hyper terminal printf("Day : %s\r\n",Int2Day(RTC_ARR[3])); printf("Time : %02bX:%02bX:%02bX\r\n",RTC_ARR[2],RT C_ARR[1],RTC_ARR[0]); printf("Data : %02bX-%s-20%02bX",RTC_ARR[4],Int2Mon th(RTC_ARR[5]),RTC_ARR[6]); DelayMs(1000); // delay about 1 second } } Output
43
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.7 – Serial EEPROM
The AT24C01A/02/04/08/16 provides 1024/2048/4096/8192/16384 bits of serial
electrically erasable and programmable read-only memory (EEPROM) organized as
128/256/512/1024/2048 words of 8 bits each. The device is optimized for use in
many industrial and commercial applications where low-power and low-voltage
operation are essential. The AT24C01A/02/04/08/16 is available in space-saving 8-
pin PDIP.
Features of AT24Cxx:
• Internally Organized 128 x 8 (1K), 256 x 8 (2K), 512 x 8 (4K)
• 2-wire Serial Interface
• Schmitt Trigger, Filtered Inputs for Noise Suppression
• Bi-directional Data Transfer Protocol
• 100 kHz (1.8V, 2.5V, 2.7V) and 400 kHz (5V) Compatibility
• Write Protect Pin for Hardware Data Protection
• 8-byte Page (1K, 2K), 16-byte Page (4K, 8K, 16K) Write Modes
• Partial Page Writes are Allowed
• Self-timed Write Cycle (10 ms max)
• High-reliability
– Endurance: 1 Million Write Cycles
– Data Retention: 100 Years
P2.0P2.1
SW31
SW DIP-8
12345678
161514131211109
P2.[0..7]
I2C_SCLI2C_SDA
U18
AT24CXX
A01
A12
A23
GN
D4
VC
C8
WP7SCL
6 SDA5
VCC
44
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Program to write and read EEPROM data through serial port */ /*------------------------------------------------- -------------------------*/ /* Filename :I2CEEPROM_Serial.c Date:29/05/06 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* EEPROM(AT24C04) */ /* ----------- */ /* SCL : P2.0 */ /* SDA : P2.1 */ /* Output : Port0(P1) ...Hyperterminal, 9600baud ra te */ /*------------------------------------------------- -------------------------*/ #include<reg51.h> #include<stdio.h> #include<serial.h> #include<delay.h> #include<intrins.h> #define ACK 1 #define NO_ACK 0 unsigned char i; unsigned char EData[5]; unsigned char Data; void WriteI2C(unsigned char); void Start(void); void Stop(void); void ReadBYTE(unsigned int); void WriteBYTE(unsigned int); unsigned char ReadI2C(bit); sbit SCL = P2^0; // connect to SCL pin (Clock) sbit SDA = P2^1; // connect to SDA pin (Data) //--------------------------------------- // Main program //--------------------------------------- void main(void) { InitSerial(); // Initialize serial port putchar(0x0C); // clear hyper terminal DelayMs(5); WriteBYTE(0x0000); WriteI2C('A'); WriteI2C('B'); WriteI2C('C'); WriteI2C('D'); WriteI2C('E');
45
www.pantechsolutions.net 8051 Advanced Development Board User Manual
WriteI2C('F'); Stop(); DelayMs(10); ReadBYTE(0x0000); EData[0] = ReadI2C(NO_ACK); EData[1] = ReadI2C(NO_ACK); EData[2] = ReadI2C(NO_ACK); EData[3] = ReadI2C(NO_ACK); EData[4] = ReadI2C(NO_ACK); EData[5] = ReadI2C(NO_ACK); for(i=0;i<6;i++) { printf("value = %c\n",EData[i]); // display data DelayMs(100); } while(1); } //--------------------------------------- // Initialize serial port //--------------------------------------- void InitSerial(void) { SCON = 0x52; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.0592M HZ) TH1 = 0xFD; // TH1 TR1 = 1; // Timer 1 on } //------------------------------- // start I2C //------------------------------- void Start(void) { SDA = 1; SCL = 1; _nop_();_nop_(); SDA = 0; _nop_();_nop_(); SCL = 0; _nop_();_nop_(); }
46
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//------------------------------- // stop I2C //------------------------------- void Stop(void) { SDA = 0; _nop_();_nop_(); SCL = 1; _nop_();_nop_(); SDA = 1; } //------------------------------- // Write I2C //------------------------------- void WriteI2C(unsigned char Data) { for (i=0;i<8;i++) { SDA = (Data & 0x80) ? 1:0; SCL=1;SCL=0; Data<<=1; } SCL = 1; _nop_();_nop_(); SCL = 0; } //------------------------------- // Read I2C //------------------------------- unsigned char ReadI2C(bit ACK_Bit) { Start(); WriteI2C(0xA1); SDA = 1; for (i=0;i<8;i++) { SCL = 1; Data<<= 1; Data = (Data | SDA); SCL = 0; _nop_(); } if (ACK_Bit == 1) SDA = 0; // Send ACK else SDA = 1; // Send NO ACK
47
www.pantechsolutions.net 8051 Advanced Development Board User Manual
_nop_();_nop_(); SCL = 1; _nop_();_nop_(); SCL = 0; Stop(); return Data; } // Read 1 byte form I2C //------------------------------- void ReadBYTE(unsigned int Addr) { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); WriteI2C((unsigned char)Addr&0xFF); } // Write 1 byte to I2C //------------------------------- void WriteBYTE(unsigned int Addr) { Start(); WriteI2C(0xA0); WriteI2C((unsigned char)(Addr>>8)&0xFF); // send a ddress high WriteI2C((unsigned char)Addr&0xFF); // send addre ss low } // 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--; } } OUTPUT
48
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.8 - Seven Segment Display
In Embedded module 4 nos. of common anode seven segment displays are used. The
segment lines of seven segments LED is being terminated at connector CN9. 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 P2, by default digit select lines connected to Port P3 of Pin3.4
to P3.7.
U7
7 SEG DISP
E1 D2
CA
3
C4
DP5
B6 A7
CA
8
F9
G10
U8
7 SEG DISP
E1 D2
CA
3
C4
DP5
B6 A7
CA
8
F9
G10
Q1
1
2
3
Q2
1
2
3
Q3
1
2
3
Q4
1
2
3
SEG0
VCC
SEG1
R14 1K R15 1K R16 1K R17 1K
SEG2SEG3SEG4
SEG6SEG5
SEG7
SEG0SEG1
SEG4
SEG2SEG3
SEG6SEG7
SEG5
SEG0SEG1SEG2
SEG4SEG5
SEG3
SEG6
SEG0
SEG7
SEG1
SEG3SEG2
SEG4SEG5SEG6SEG7
A
D
B
C
F
E
DP
G
R18330E
R20330E
R21330E
R22330E
R23330E
R24330E
R25330E
R26330E
SEG0
SEG1
SEG2
SEG3
SEG4
SEG5
SEG6
SEG7
P3.
4
P3.
5
P3.
6
P3.
7
SEG[0..7] SEG[0..7] SEG[0..7]
A
EC
G
D
DP
B
F
CN9
7 SEG LED
1 23 45 67 89 10
SEG[0..7]
U5
7 SEG DISP
E1 D2
CA
3
C4
DP5
B6 A7
CA
8
F9
G10
U6
7 SEG DISP
E1 D2
CA
3
C4
DP5
B6 A7
CA
8
F9
G10
• User can connect 7-seg Data lines following possible ways (Not CN5).
7 SEG CON MCU CON
CN9 CN2
CN9 CN3
CN9 CN4
49
www.pantechsolutions.net 8051 Advanced 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 */
/*------------------------------------------------- -------------------------*/
/* Data Line : P2 */
/* Digit1 : P3.4 */
/* Digit2 : P3.5 */
/* Digit3 : P3.6 */
/* Digit4 : P3.7 */
/*------------------------------------------------- -------------------------*/
/* Note :The 7Segment display are interfaced to th e Port2.The counting of */
/* numbers from (0-1000) are displayed in 7Segmen t display. */
/*------------------------------------------------- -------------------------*/
#include<stdio.h>
#include<reg51.h>
unsigned char SetDisplay(unsigned char);
void delay(void);
sbit eseg1000 = P3^7;
sbit eseg100 = P3^6;
sbit eseg10 = P3^5;
sbit eseg1 = P3^4;
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};
if(value<=10)
return segment[value];
else
return 0;
}
//Delay Function
//--------------
void delay()
{ int i;
for(i=0; i<500; i++)
i = i + 0;
}
50
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//--------------
//Main Program
//--------------
void main(void)
{
unsigned char count = 0;
unsigned long timer = 0;
int turn = 1;
P2 = 0xff;
while(1)
{
if(turn==1) //7-Seg Display 0
{
eseg1000=0;
eseg100=0;
eseg10=0;
eseg1=1;
P2=SetDisplay(d0);
turn = 2;
delay();
}
else if(turn==2) //7-Seg Display 1
{
eseg1=0;
eseg1000=0;
eseg100=0;
eseg10=1;
P2=SetDisplay(d1);
turn = 3;
delay();
}
else if(turn==3) //7-Seg Display 2
{
eseg10=0;
eseg1=0;
eseg1000=0;
eseg100=1;
P2=SetDisplay(d2);
turn = 0;
delay();
}
51
www.pantechsolutions.net 8051 Advanced 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++;
}
}
52
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.9 - Interrupts
Microcontroller’s two external interrupts lines are terminated at switches SW1 (INT0)
and SW2 (INT1).
SW1 INT0
INTERRUPTS
SW2 INT1
INT0
INT1
Note: While using interrupt P3.2 make high (on) to SW4 for Interrupt 0, P3.3
make(on) to SW4 for interrupt 1.
P3.0
P3.2P3.3
P3.1
P1.2P1.3
M_TXD1M_RXD1
M_RXD0M_TXD0
INT1INT0
SW4
SW DIP-10
53
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.10 - 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.
SW31
SW DIP-8
12345678
161514131211109
P2.2 1_WIRE
P2.[0..7]
VCC
U12 DS1820
Vdd
3
DQ
2
GN
D1
R34 4K7
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 -55°C to +125°C (-67°F to +257°F)
• ±0.5°C accuracy from -10°C to +85°C
• 9-bit thermometer resolution, Converts temperature in 750ms (max.)
54
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : DS1820 Digital Temp Sensor output dis played 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 } //----------------------------------------- // 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; }
55
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//----------------------------------------- // 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 tem p into Dout = Dout >> 1; } DelayUs(5); } //----------------------------------------- // Read temperature //----------------------------------------- void ReadTemp(unsigned char * buff) {
unsigned char n; EA=0; // disable all interrupt ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0x44); // perform temperature conv ersion while (ReadByte()==0xff); // wait for conversi on complete ResetDS1820(); WriteByte(0xcc); // skip ROM WriteByte(0xbe); // read the result
for (n=0; n<9; n++) // read 9 bytes but, use on ly one byte {
buff[n]=ReadByte(); // read DS1820 } EA=1; }
56
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//--------------------------------------- //Serial Port Initialization //--------------------------------------- void InitSerial(void) { SCON = 0x52; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.055 92MHZ) 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--; } } //------------------------------------------------- ------ // DELAY at 11.0592MHz crystal. // Calling the routine takes about 22us, and then // each count takes another 17us. test with KEIL C5 1 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); } }
57
www.pantechsolutions.net 8051 Advanced 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 CN7.
R1
C1R3
C3
R4
C4
R2
C2
CN7
KEYPAD
1 23 45 67 89 10
SW6
SW7 SW8 SW9
SW10 SW11 SW12 SW13
SW14 SW15 SW16 SW17
SW26 SW27 SW28 SW29
R1
R3
R2
C2C1
R4
C3 C4
R12
10K12
3456789
J2
CON3
1 2 3
VCC GND
58
www.pantechsolutions.net 8051 Advanced 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(CN2) */ /* Keypads : Port P2(CN4) */ /* Note :Getting a key value from a 4X4 Matrix K eypad (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 LCD void lcd_init(void); //LCD Initialization void lcd_cmd(unsigned char); //LCD Command Functi on void lcd_display(unsigned char); //LCD Display Fun ction 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', //Matri x 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);
59
www.pantechsolutions.net 8051 Advanced 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); }
60
www.pantechsolutions.net 8051 Advanced 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++; } DelayMs(20);
61
www.pantechsolutions.net 8051 Advanced Development Board User Manual
// 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++); }
62
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.12 - Motor / Driver Section
The ULN2803A is a high-voltage, high-current Darlington transistor array. The device
consists of eight npn Darlington pairs that feature high-voltage outputs with
common-cathode clamp diodes for switching inductive loads. The collector-current
rating of each Darlington pair is 500 mA. The Darlington pairs may be connected in
parallel for higher current capability.
ULN2803 is used as a driver for port I/O lines, drivers output terminated to connector
CN11, there can interface relay/stepper motor or any driving source could need more
than 50mA. Motor can connect JP8 or J6 connector.
Note : User select Internal Vcc or External through JP10 header.
J7
HEADER 2
12EXT_VCC
STM_C
U9
ULN2803A
I11
I22
I33
I44
I55
I66
I77
I88
GND9
O118
O217
O316
O415
O514
O613
O712
O811
COMM10
DR5DR3
DR7
DR4DR1 DR2
DR6DR8
CN11
MOTOR/RELAY
1 23 45 67 89 10
DR1DR2DR3DR4DR5DR6DR7DR8
STM_A
STM_B
STM_B
JP8
HEADER 6
123456
STM_A
STM_C
JP10
MOTOR/RELAY
123
STM_D
VCCULN_PWR
RL1STM_B
ULN_PWRSTM_DSTM_C
J6
HEADER 6
123456
STM_A
EXT_VCC
RL2
STM_D
ULN_PWR
ULN_PWR
63
www.pantechsolutions.net 8051 Advanced 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 */ /*------------------------------------------------- -------------------------*/ #include <reg51.h> //Define 8051 registers #include<stdio.h> void DelayMs(unsigned int); //Delay function //---------------------------------- // Main Program //---------------------------------- void main (void) { P2 = 0; //Initialize Port2 while(1) //Loop Forever { P2 = 0x01;DelayMs(20); //Delay 20msec P2 = 0x02;DelayMs(20); P2 = 0x04;DelayMs(20); P2 = 0x08;DelayMs(20); } } //--------------------------------- // Delay Function //--------------------------------- void DelayMs(unsigned int n) { unsigned int i,j; for(j=0;j<n;j++) { for(i=0;i<1000;i++); } }
64
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.13 - Relay Section
In ADB Board two no. Of SPDT relays are used. Both the relays operate on 5V DC.
The outputs of both the terminals of the relay are taken out on the connecter to
connect the external circuitry. The relay can be connected to the Microcontroller
through any of the selected port (P0.4 & P0.5) or (P1.4 & P1.5) or (P2.4 & P2.5) by
using the FRC connecter.
JP6
RE
LAY
O/P
1
123R
1_N
OR
1_C
R1_
NC
LS1
RELAY SPDT
35
412
R1_NC
R1_NOR1_C
R45 330E
R46 330E
JP7
RE
LAY
O/P
2
123R
2_N
O
R2_
NC
R2_
C
LS2
RELAY SPDT
35
412
R2_C
RL2
R2_NO
R2_NC
RL1
RL2
D14
LED
D13
LED
VCC
RL1ULN_PWR ULN_PWR
65
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Relay Example Program */ /*------------------------------------------------- -------------------------*/ /* Filename :Relay.c Date :29/05/06 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* Note :Each Relay will on/off some intervals */ /*------------------------------------------------- -------------------------*/ #include <reg51.h> //Define 8051 registers #include<stdio.h> sbit relay1 = P2^4; sbit relay2 = P2^5; void DelayMs(unsigned int); //Delay function //---------------------------------- // Main Program //---------------------------------- void main (void) { P2 = 0; //Initialize Port2 while(1) //Loop Forever { relay1 = 1; //Relay1 - ON relay2 = 0; //Relay2 - Off DelayMs(200); //Delay 20msec relay1 = 0; //Relay1 - Off relay2 = 1; //Relay2 - ON DelayMs(200); //Delay 20msec } } //--------------------------------- // Delay Function //--------------------------------- void DelayMs(unsigned int n) { unsigned int i,j; for(j=0;j<n;j++) { for(i=0;i<1000;i++); } }
66
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.14 - SPI DAC
The Microchip Technology Inc. MCP492X are 2.7 – 5.5V, low-power, low DNL, 12-Bit
Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI
interface.
The MCP492X are DACs that provide high accuracy and low noise performance for
industrial applications where calibration or compensation of signals (such as
temperature, pressure and humidity) are required. The MCP492X are available in the
extended temperature range and PDIP, SOIC, MSOP and TSSOP packages.
Features
• 12-Bit Resolution
• ±0.2 LSB DNL (typ), ±2 LSB INL (typ)
• Single or Dual Channel
• SPI™ Interface with 20 MHz Clock Support
• Simultaneous Latching of the Dual DACs w/LDAC
• Fast Settling Time of 4.5 µs
• Selectable Unity or 2x Gain Output
• 450 kHz Multiplier Mode
• External VREF Input
• Extended Temperature Range: -40°C to +125°C
DAC_CS
DAC_SDIDAC_SCK
SW31
SW DIP-8
12345678
161514131211109
P2.5P2.6P2.7
P2.[0..7]U19
MCP4291
VDD1
/C/S2
SCK3
SDI4
VOUTA8
AVSS7VREFA6
LDAC5
J11
HEADER 2
12DAC_CS
DAC_SCKDAC_SDI
VCCC18
0.1D
C21100nF
VCC
67
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : SPI Based DAC */ /*------------------------------------------------- -------------------------*/ /* Filename : DAC_SPI.c Da te:25/01/08 */ /*------------------------------------------------- -------------------------*/ /* Connections [I2C/1-wire/DAC section] */ /* ----------- */ /* SW31 : P2.5 - DAC_CS */ /* P2.6 - DAC_SCK */ /* P2.7 - DAC_SDI */ /* Output : J11 - view results in oscilloscope o r multi meter */ /*------------------------------------------------- -------------------------*/ #include<reg51.h> sbit CS =P2^5; //chip select port pin P2.5 sbit SCK=P2^6; //SCK Port pin 2.6 sbit SDI=P2^7; //SDI port pin P2.7 void SPI_out(unsigned char); unsigned char x=0x80,i; //---------------------- // Main program Starts //---------------------- void main() {
unsigned int Data=0x37FF; //Assign Data Here e.g 0x 33ff, //0x37ff, 0x3fff
unsigned char data1; SCK = 0; //sck pull to low while(1) //loop forever { CS=0; //make cs to low data1=(Data>>8); //shift and send to spiout SPI_out(data1); //send high byte data1=Data; SPI_out(data1); //send low byte CS=1; //make cs to high } } // SPI Data out routine //------------------------ void SPI_out(unsigned char Data_val) { for(i=0;i<8;i++) { SDI=(Data_val & x)?1:0; SCK=1; //make sck high Data_val=Data_val<<1; SCK=0; //make sck low } }
68
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.15 - RS485
The Max485 is a differential line transceiver suitable for high speed bidirectional data
communication on multipoint bus transmission lines. It is designed for balanced data
transmission and complies with EIA Standards RS-485 and RS-422. The part contains
a differential line driver and a differential line receiver. Both the driver and the
receiver may be enabled independently.
Features
• Meets EIA RS-485 Standard
• 5 Mbps Data Rate
• Single 5 V Supply
• –7 V to +12 V Bus Common-Mode Range
• High Speed, Low Power BiCMOS
• Thermal Shutdown Protection
• Short-Circuit Protection
• Driver Propagation Delay: 10 ns
• Receiver Propagation Delay: 15 ns
• High Z Outputs with Power Off
SW30
SW DIP-8
12345678
161514131211109
P3.1P3.0
TXD_485
P3.2
RXD_485
P3.[0..7] RT_485
U13
MAX485
RO1
DI4
GN
D5
VC
C8
RE2 DE3
A6
B7
RT_485RXD_485
TXD_485
R32 56E
R33 56E
J8
HEADER 2
12
VCC
R64 4k7
R63 4k7
69
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Application Schematic
U13
MAX485
RO1
DI4
GN
D5
VC
C8
RE2
DE3
A6
B7
RT_485R32 56E
R33 56E
RS485
VCC
R64 4k7
R63 4k7
8051 Board1shielded pair
RS485
RS485-RS232 Adaptor
U1
AT89S51
RST9
XTAL218
XTAL119
GN
D20
PSEN29ALE/PROG30EA/VPP31
VC
C40
P1.01
P1.12
P1.23
P1.34
P1.45
P1.56
P1.67
P1.78
P2.0/A821P2.1/A922P2.2/A1023P2.3/A1124P2.4/A1225P2.5/A1326P2.6/A1427P2.7/A1528
P3.0/RXD10
P3.1/TXD11
P3.2/INTO12
P3.3/INT113
P3.4/TO14
P3.5/T115
P3.6/WR16
P3.7/RD17
P0.0/AD039
P0.1/AD138
P0.2/AD237
P0.3/AD336
P0.4/AD435
P0.5/AD534
P0.6/AD633
P0.7/AD732
C1
0.1uFVCC
SW
1R
ST C2
10uF
R2
8K2
X1
11.0592MHz
C333PF
C433PF
VCC
TXD_485
RXD_485RXD_485TXD_485RT_485
U13
MAX485
RO1
DI4
GN
D5
VC
C8
RE2
DE3
A6
B7
RT_485R32
56E
R33 56E
VCC
R64 4k7
R63 4k7
RXD_232
TXD_232
U1
MAX232
R1IN13
R2IN8
T1IN11
T2IN10
C+1
C1-3
C2+4
C2-5
V+
2
V-6
R1OUT12
R2OUT9
T1OUT14
T2OUT7
VC
C16
GN
D15
TXD_232
RXD_232
P1
SE
RIA
L P
OR
T
594837261
VCC
C3
10uF
C4
10uF
C5
10uF
C110uF
RT_485
Exemple Code
\Examples Code\RS485\send\out\send.hex
\Examples Code\RS485\receive\out\receive.hex
70
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.16 - PS/2 Interface
User can connect PS/2 Devices like keyboard, mouse to the 8051 ADB board. PS/2’s
DATA(P2.1) and CLK(P2.0) lines connected to MCU’s Port Lines. for example
keyboard connected to the ADB board it act as a pc keyboard, pressed key code
displayed in LCD or PC’s Hyperterminal window.
P2.0
VCC
J3
11
22
33
55
66
88R28 270
R27 270
P2.1
JP11
HEADER 2X2
1 23 4
P2.
[0..
7]
71
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example :PC Keyboard Interface */ /*------------------------------------------------- -------------------------*/ /* Filename :ps2.c Date:10/01/08 */ /* */ /* Company :PANTECH SOLUTIONS * / /*------------------------------------------------- -------------------------*/ /* Note :set HyperTerminal window @ 9600baud rate */ /*------------------------------------------------- -------------------------*/ #include<reg51.h> #include<stdio.h> sbit PS2_CLK = P2^1; //PS2 Clock sbit PS2_DATA = P2^0; //PS2 Data code unsigned char Key[]={"0F FFFFF FFFFt` as cQ1 ZSAW2 CXDE43 VFTR5 NBHGY6 MJU78 ,KIO09 ./L;P- ' [=\\"}; unsigned char KeyVal,KeyVal2,i=0; void Serial_init(); //serial initialization unsigned char Scan_Data(); //scan data void putch(unsigned char); void DelayMs(unsigned int); /***************************/ /*Main Program Starts Here /***************************/ void main() { P2=0xff; Serial_init(); //serial init DelayMs(50); while(1) { while(PS2_CLK==1); KeyVal=Scan_Data(); if(KeyVal>85 || KeyVal<20 || KeyVal==0x0e) //scan keypressed { if(KeyVal==0x0e) printf("`"); if(KeyVal==0x5d || KeyVal==0x5b) { if(KeyVal==0x5b)printf("]"); if(KeyVal==0x5d)printf("\\"); } } else putch(Key[KeyVal]); //print scanned key to seria l port DelayMs(50); P2=0xff; } }
72
www.pantechsolutions.net 8051 Advanced Development Board User Manual
//--------------------- // Scan keyboard //--------------------- unsigned char Scan_Data() { unsigned char Data=0,temp; while(PS2_CLK==0); for(i=0;i<10;i++) { while(PS2_CLK==1); temp=PS2_DATA; temp<<=i; Data|=temp; while(PS2_CLK==0); } DelayMs(50); P2=0x00; return(Data); } //----------------- // serial init //----------------- void Serial_init() { SCON = 0x52; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.05592 MHZ) TH1 = 0xFD; // TH1 TR1 = 1; // Timer 1 on putch(0x0c); putch('R'); } // putchar //----------------- void putch(unsigned char dat) { while(TI==0); SBUF=dat; } // Delay Routine //----------------- void DelayMs(unsigned int del) { int j; while(del>0) { del--; for(j=0;j<306;j++); } }
73
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.17 - Ethernet
The ENC28J60 is a stand-alone Ethernet controller with an industry standard Serial
Peripheral Interface (SPI™). It is designed to serve as an Ethernet network interface
for any controller equipped with SPI.
The ENC28J60 meets all of the IEEE 802.3 specifications. It incorporates a number of
packet filtering schemes to limit incoming packets. It also provides an internal DMA
module for fast data throughput and hardware assisted IP checksum calculations.
Communication with the host controller is implemented via two interrupt pins and the
SPI, with data rates of up to 10 Mb/s. Two dedicated pins are used for LED link and
network activity indication.
Ethernet Controller Features
IEEE 802.3 compatible Ethernet controller
• Integrated MAC and 10BASE-T PHY
• Receiver and collision squelch circuit
• Supports one 10BASE-T port with automatic polarity detection and correction
• Supports Full and Half-Duplex modes
• Programmable automatic retransmit on collision
• Programmable padding and CRC generation
• Programmable automatic rejection of erroneous packets
• SPI™ Interface with speeds up to 10 Mb/s
74
www.pantechsolutions.net 8051 Advanced Development Board User Manual
3.3V Unit
R47
330E
D10
LED
VCC U21 REG1117/SOT
VIN3
VOUT2
GN
D1 C25
10UFC240.1uF
+3.3V
ENC28J60 Section
C2710UF
C340.1uF
+3.3V+3.3V
TD
+
INT*_ETH
C300.1uF
+3.3V
WOL*_ETH
+3.3V
C310.1uF
MISO_ETH
C320.1uF
+3.3V
C330.1uF
+3.3V
MOSI R56 100ESCK
R58 100E
R54 1KR53 1K
CS
U23
ENC28J60
VCAP1
VS
S2
CLKOUT3
/I/N/T4
/WO/O/L5
SO6
SI7
SCK8
/C/S9
RESET10
VS
SR
X11
TPIN-12
TPIN+13
RBIAS14
VDD28
LEDA27
LEDB26
VDDOSC25
OSC224
OSC123
VS
SO
SC
22
VS
SP
LL21
VDDPLL20
VDDRX19
VS
ST
X18
TP
OU
T+
17T
PO
UT
-16
VDDTX15
R51330E
RST*
R52330E
Y1
25M
Hz
D11LED
D12LED
A1 A2
C28 22pf
TD
-
RD+
C29 22pf
RD-
CN13
8051/AVR
1 23 45 67 89 10
INT*
SCK
CS*
MISO
RST*
MOSIWOL*
75
www.pantechsolutions.net 8051 Advanced Development Board User Manual
RJ-45 connector with In-built transformer
U24
RJ45
TD+1
CT4
TD-2
RD+3
CT5
RD-6
K2
11
A2
12K
110
A1
9
GND8
A1
A2
R59 56E
R60 56E
TD+
TD-
C360.1uF
C350.1uF
L1F-BEAD
R6156E
R62 56E
RD+
RD-
+3.3V
U22
74LS245
A02
A13
A24
A35
A46
A57
A68
A79
G19 DIR1
B018
B117
B216
B315
B414
B513
B612
B711
VC
C20
GN
D10
WOL*_ETHINT*_ETH
MISO_ETH
CS
INT*
MISOWOL*
R55 100E
R57 10E
VCC
CS*
C260.1uF
VCC
J12
HEADER 3X2
246
135
76
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.18 - On-Board ADC (AT89C51CC03)
This sect ion describes the on-chip 10 bit analog- to-digital converter of the
AT89C51CC03. Eight ADC channels are available for sampling of the external sources
AN0 to AN7. An analog multiplexer allows the single ADC converter to select one from
the 8 ADC channels as ADC input voltage (ADCIN). ADCIN is converted by the 10-bit
cascaded potentiometric ADC
Features
• 8 channels with multiplexed inputs
• 10-bit cascaded potentiometric ADC
• Conversion time 16 micro-seconds (typ.)
• Zero Error (offset) ± 2 LSB max
• Positive External Reference Voltage Range (VREF) 2.4 to 3.0Volt (typ.)
• ADCIN Range 0 to 3Volt
• Integral non-linearity typical 1 LSB, max. 2 LSB
• Differential non-linearity typical 0.5 LSB, max. 1 LSB
• Conversion Complete Flag or Conversion Complete Interrupt
• Selectable ADC Clock
P1.1P1.0
U2
AT89C51CC0X
VA
RE
F2
P1.0/AN03P1.1/AN14P1.2/AN25P1.3/AN3/CEX06
VA
GN
D1
P1.4/AN4/CEX17P1.5/AN5/CEX28P1.6/AN6/CEX39P1.7/AN7/CEX410
P3.0 (RXD)12
VC
C42
P3.1 (TXD)13
P3.2 (INT0)14
P3.3 (INT1)15
P3.4 (T0)16
P3.5 (T1)17
P3.6 (WR)18
P3.7 (RD)19
XT
AL2
40
XT
AL1
41G
ND
43
(RX
D_C
AN
)P4.
121
P2.
0 (A
8)29
P2.
1 (A
9)28
P2.
2 (A
10)
27
P2.
3 (A
11)
26
P2.
4 (A
12)
25
P2.
5 (A
13)
24
P2.
6 (A
14)
23
P2.
7 (A
15)
22
PSEN38
(TX
D_C
AN
) P
4.0
20
(PROG) ALE39
EA11
(AD
7) P
0.7
37(A
D6)
P0.
636
(AD
5) P
0.5
35(A
D4)
P0.
434
(AD
3) P
0.3
33(A
D2)
P0.
232
(AD
1) P
0.1
31(A
D0)
P0.
030
RESET44
R810K
13
2
JP4
ADC1
123
JP3
ADC0
123
R710K
13
2
+3.3V
+3.3V P1.0
P1.1
77
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*------------------------------------------------- -------------------------*/ /* Example : Program to Read AD0 Value to display serial port */ /*------------------------------------------------- -------------------------*/ /* Filename :adcmain.c Date:10/01/08 */ /* */ /* Company :PANTECH SOLUTIONS */ /*------------------------------------------------- -------------------------*/ /* ADC0 : P2.0, ADC1 : P2.1 */ /* */ /* Output : Port0(P1) ...Hyperterminal, 1200baud ra te */ /*------------------------------------------------- -------------------------*/ #include <stdio.h> sfr ADCON = 0xF3; sfr ADCF = 0xF6; sfr ADCLK = 0xF2; sfr ADDH = 0xF5; sfr ADDL = 0xF4; sfr SCON = 0x98; sfr TMOD = 0x89; sfr TH1 = 0x8D; sbit TR1 = 0x88^6; sbit TI = 0x98^1; /*================================================= ========================== This function initializes the serial port 1200 baud rate at 12Mhz clock. =================================================== =========================*/ void serial_init(void) { SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit r eload */ TH1 = 0xfd; /* TH1: reload value for 1200 ba ud @ 12MHz */ TR1 = 1; /* TR1: timer 1 run */ TI = 1; /* TI: set TI to send first cha r of UART */ } /*================================================= ========================== This function initializes the A/D Converter on the Atmel CC01 using 10-bits. =================================================== =========================*/ void init_ADC (void) { ADCF = 0xFF; // Setup P1 as 8 ADC inputs ADCLK = 0x1F; // Set AD Clock divisor to 32 (the maximum) ADCON |= 0x20; // Enable the A/D Converter }
78
www.pantechsolutions.net 8051 Advanced Development Board User Manual
/*================================================= ========================== This function sets the A/D channel to convert and s tarts a conversion. The 10-bit value is returned. =================================================== =========================*/ unsigned read_ADC (unsigned char channel) { ADCON &= ~0x07; // Clear channel bit s ADCON |= 0x07 & channel; // Set channel to co nvert ADCON |= 0x08; // Start a Conversio n while( ADCON & 0x8 ); //Wait for conversio n to end return (((unsigned) ADDH << 2) | (ADDL & 3)); } /*================================================= ==========================*//Main Program Starts Here /*================================================= ==========================* void main(void) { unsigned char i; serial_init(); //Initialize serial port init_ADC (); //Initialize the A/D Converter /*------------------------------------------------- -- Loop thru each channel and output the converted val ue. --------------------------------------------------- -*/ printf ("\n---------------------------------------- --------\n"); printf (" AD89C51CC03 On-Chip ADC Demo AN0 and A N1 \n"); printf (" AN0 - Adjust R7 POT | AN1 - Adjust R 8 POT \n"); printf ("------------------------------------------ ------\n"); while (1) { printf ("\r ADC0.0 : %u", read_ADC (0)); //read channel 0 printf (" ADC0.1 : %u", read_ADC (1)); //r ead channel 1 } } Output
79
www.pantechsolutions.net 8051 Advanced Development Board User Manual
6.19 - CAN Microcontroller (AT89C51CC03)
The CAN Controller provides all the features required to implement the serial
communication protocol CAN as defined by BOSCH GmbH. The CAN specification as
referred to by ISO/11898 (2.0A and 2.0B) for high speed and ISO/11519-2 for low
speed. The CAN Controller is able to handle all types of frames (Data, Remote, Error
and Overload) and achieves a bit-rate of 1-Mbit/sec at 8 MHz1 Crystal frequency in
X2 mode.
CAN Transceiver
The MCP2551 is a high speed CAN fault tolerant device that serves as the interface
between a CAN protocol controller and the physical bus. The MCP2551 provides
differential transmit and receive capability for the CAN protocol controller and is fully
compatible with the ISO 11898 standard, including 24 V requirements. It will operate
at speeds of up to 1 Mb/s.
Features
• Supports 1 Mb/s operation
• Implements ISO 11898 standard physical layer requirements
• Suitable for 12 V and 24 V systems
• Externally controlled slope for reduced RFI emissions
• Detection of ground fault (permanent dominant) on TXD input
• Power-on reset and voltage brown-out protection
• An un powered node or brown-out event will not disturb the CAN bus
• Low current standby operation
• Protection against damage due to short circuit conditions.
• Protection against high voltage transients
• Automatic thermal shutdown protection
• Up to 112 nodes can be connected
• High noise immunity due to differential bus implementation
80
www.pantechsolutions.net 8051 Advanced Development Board User Manual
CAN
U14
PCA82C250
TXD1 G
ND
2
VC
C3
RXD4
RS8
CANH7
CANL6
VREF5
R30330E
R29330E
D6CRX
D5CTX
R3150E
VCC
J9
HEADER 2
12
VCC
P2
COM2
594837261
U2
AT89C51CC0X
VA
RE
F2
P1.
0/A
N0
3P
1.1/
AN
14
P1.
2/A
N2
5P
1.3/
AN
3/C
EX
06
VA
GN
D1
P1.
4/A
N4/
CE
X1
7P
1.5/
AN
5/C
EX
28
P1.
6/A
N6/
CE
X3
9P
1.7/
AN
7/C
EX
410
P3.0 (RXD)12
VC
C42
P3.1 (TXD)13
P3.2 (INT0)14
P3.3 (INT1)15
P3.4 (T0)16
P3.5 (T1)17
P3.6 (WR)18
P3.7 (RD)19
XT
AL2
40
XT
AL1
41G
ND
43
(RXD_CAN)P4.121
P2.
0 (A
8)29
P2.
1 (A
9)28
P2.
2 (A
10)
27
P2.
3 (A
11)
26
P2.
4 (A
12)
25
P2.
5 (A
13)
24
P2.
6 (A
14)
23
P2.
7 (A
15)
22
PSEN38
(TXD_CAN) P4.020(PROG) ALE
39
EA11
(AD7) P0.737(AD6) P0.636(AD5) P0.535(AD4) P0.434(AD3) P0.333(AD2) P0.232(AD1) P0.131(AD0) P0.030
RESET44
81
www.pantechsolutions.net 8051 Advanced Development Board User Manual
7. Board Layout
82
www.pantechsolutions.net 8051 Advanced Development Board User Manual
8. Easy Programming Steps - Philips/NXP Microcontrollers
Hardware Settings
SW4
SW DIP-10
M_TXD0M_RXD0P3.1
P3.0
Software Settings
1. open “Flashmagic” isp software
Step 0 : Go to “Options” Menu, then choose “Advanced Options”, Advanced
options windows appears.
Choose “Hardware Config” tab, Deselect “Use DTR to Control RST”
checkbox.
Step1 :
• Select Com Port E.g COM1 or COM2
• Set baud rate “9600”
• Select Device “89V51RD2”
Interface “None(ISP)”
P1.5
P1.6
P1.7
SW32
SW DIP-4
MC_RST
ONOFF
83
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Step2 :
Check “Erase all Flash”
Step3 : Load or locate your Hex files
…JNTU_Pantech\JNTU_Lab_Examples\EX1_LED\1_LED Blink\Out\LedBlink.hex
Step4 : select options you want like above figure, verify, erase, security bit.
Step 5: press “Start” button
Press Hardware “RST” Button SW5. Now it starts, Erasing, Program &
Verifying.
84
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2 - Atmel Microcontrollers
Hardware Settings
P1.5P1.7
P1.6
SW32
SW DIP-4
MC_RST
Software Settings
1. “Options” - Menu
Select Port
-LP1
Device Selection
AT89S51
Clock : 12MHz
2. “File” Menu – “Load Buffer” Load your hex file
…\Examples Code\LED Blink\Out\LEDBlink.hex
85
www.pantechsolutions.net 8051 Advanced Development Board User Manual
3. “Instructions” – “Auto Program”
In Lock Bit settings
Executions
“Instructions” Menu
“Run Target” – Your program Now executes
Note : “Options” – Menu
“Initialize” – It comes to program mode
86
www.pantechsolutions.net 8051 Advanced Development Board User Manual
3 - Dallas Microcontrollers
Hardware Settings
MC_RST
SW4
SW DIP-10
R24K7
VCC
R34K7
VCC
EA
R4330E
VCC D4LED
PSEN
M_TXD0M_RXD0P3.1
P3.0
Select Dallas mcu “DS89C450”
1. “Options” – Menu
Select com port and set baud rate to 9600
87
www.pantechsolutions.net 8051 Advanced Development Board User Manual
2. “Target” – Menu
1. Open Com1at 9600
2. Connect to Loader
We get window like this
3. “File” – Load Flash
…\Examples Code\LED Blink\Out\LEDBlink.hex
Execution Mode
Set DIPSWITCH SW4 – ‘EXE’ Mode
88
www.pantechsolutions.net 8051 Advanced Development Board User Manual
ATNEL CAN Microcontroller
Hardware Settings
SW4
SW DIP-10
R24K7
VCC
R34K7
VCC
EA
R4330E
VCC D4LED
PSEN
M_TXD0M_RXD0
P3.0P3.1
Software Settings
“Device” Menu
“Settings” – menu
“Communication” – RS232
Serial Port ‘COM ‘ & Baud rate ‘38400’
89
www.pantechsolutions.net 8051 Advanced Development Board User Manual
Press ‘Reset” key from Hardware ADB Board
Press “connect” button
‘File’ – menu
Load Hex files
\Examples Code\AT89C51CC03 Examples\UART\OUT\UART.hex
Press “RUN” Button
Execution mode
• Uncheck – ‘BLJB’ check box
• Check – ‘Reset’ check box
• Press “Start Application”