t89c51 training board - v5

44
T89C51 Training Board Manual T89C51 Training Board.doc Page 1/44 T89C51 Training Board Manual

Upload: davidegrima

Post on 07-Apr-2015

264 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 1/44

T89C51 Training Board

Manual

Page 2: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 2/44

1.0 Introduction

Training boards allow a quick implementation of a software program design and successive downloadsof the program directly in circuit without the need to remove the microcontroller and place it in aprogrammer. This enables the software to be tested quickly and necessary modifications made easily,improving the project and product development times considerably. This board can also be used in amore fixed application, as a base or CPU board for a more complex system. Connections are providedto each of the microcontroller pins, and these connections can then be run to a auxiliary board, whereall the other IC’s are mounted to interface to the outside application. This allows easy swapping of theboards, if necessary and also the auxiliary board to be changed easily without affecting the main board.

The T89C51 Training Board uses the T89C51 as a base microcontroller. This IC is one of the newer 80series devices from Atmel, offering much larger program space and a range of peripherals to suit anumber of applications. The T89C51 includes a large 32kb of program flash memory, together with alarge RAM for storing temporary variables. A large 2k EEPROM is also included for retaining presetvalues while the power is disconnected. A 2k Flash Bootloader, is also included to allow the device tobe programmed using a standard RS232 connection, a special programmer is not required whenprogramming the microcontroller using this feature.

The T89C51 also includes a number of peripheral features which reduce the need for special auxiliaryIC’s. In particular the 5 channels of Pulse Width Modulation, enable this microcontroller to be used ina number of motor control functions, including standard motor control, together with roboticapplications. A total of 8 channels of Analog to Digital converters are also provided, with 10 bitaccuracy for each. This is ideal for an analogue system, where a large number of sensors are used.These could also be used as feedback sensors in the motor control application discussed earlier.Similarly a UART is provided for connecting to a PC, allowing information transfer between the PCand development board. This UART also enables multiprocessor communication, allowing a number ofboards to be connected together, with information passing between each. This would allow a morecomplex system, with a series of boards working together to monitor and control the equipment.

Figure 1: T89C51 Training Board

Page 3: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 3/44

Chapter 2 - Specifications

2.1 Board Specifications

Summary of board specifications and features

• T89C51 on-board with 18.432MHz Crystal- 32Kbytes of Flash Memory- 256 bytes of RAM Memory- 1Kbyte of ERAM- 2 Kbytes of EEPROM Memory- 32 + 2 Digital I/O pins- 3 16-bit Timers- 5 Channel 16-bit PCA with

- PWM (8-bit)- High-Speed Output- Timer and Edge capture

- 8 channels ADC with 10-bit accuracy- SPI Serial Interface

• In circuit programming via computer download cable (provided)• 5V regulator on-board with necessary power supply components• 34 Pin I/O connector for access to microcontroller port pins• Separate PWM Connectors• Adjustable Analogue Reference Trimpot• RS232 Communication with on-board MAX232 or equivalent• Real Time Clock (PCF8583)• EEPROM (24LCXX Series)• I/O Expansion IC (PCF8574)• Buzzer On-Board• LCD Connector and Contrast Trimpot Pre-installed• RS422 / RS485 Communication• Magnetic Card Reader Supported• Relay Socket• Keypad Connector• I2C Bus Expansion Socket• Test LED• Power-On LED• PSEN pushbutton• RESET pushbutton provided

Page 4: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 4/44

2.2 Microcontroller Specifications

The T89C51 includes a lot of new exciting features, beyond that of the previous 80 seriesmicrocontrollers. These include,

Self-programming In-System Programmable Flash Memory:

• 32K Bytes with 2K bytes Boot BlockEndurance – 10,000 Write / Erase Cycles

• 2K Bytes EEPROMEndurance – 100,000 Write / Erase Cycles

• 256 Bytes Internal SRAM• 1K Byte On-Chip ERAM• Programming Lock for Software Security

Peripheral Features:

• Three 16-bit Timer/Counters• Five Ports: 32 + 2 Digital I/O Lines• Five Channel 16-bit PCA with:

- PWM (8-Bit)- High Speed Output- Timer and Edge Capture

• 8-channel, 10-bit Analog to Digital Converter• Full Duplex UART Compatible 80C51

Special Microcontroller Features:

• On-Chip Emulation Logic• Double Data Pointer• 21-bit Watchdog Timer• Power Saving Modes: Idle Mode and Power-Down• 14-sources, 4-level Interrupts

Power Consumption at 8MHz, 5.5V and 25oC:

• Active 8.6mA• Idle Mode 6.8mA• Power-down Mode <160 µA

Page 5: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 5/44

Fig. 2 – T89C51 Pinout

Fig. 3 – T89C51 Block Diagram

2.3 80 Series Microcontrollers

The 80 Series was first released by Intel in the1980’s, and is now the most commonmicrocontroller series available. Many companies produce equivalents or upgraded versionsof the 8051 microcontroller, these include Dallas semiconductor, Philips and Atmel. Alsothere are a large number of compilers available to produce code for the 80 series. Basic, C,Fortran, and assembly language compilers are all available to produce hex formatted outputfiles suitable to load into this microcontroller.

Page 6: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 6/44

Chapter 3 - Set-Up and Programming The Training Board

3.1 Setting Up

Firstly connect the T89C51 Development Board to a suitable DC power supply. This shouldbe between 9-12Vdc and capable of at least 500mA. The jack can be either positive-negativeor negative-positive. Once the power supply is connected the red Vcc LED will illuminate.

Next connect the computer cable (ET-DOWNLOAD), that is included with the developmentboard. The 9 pin DB 9 connector is connected to the computer serial (RS232) port.

Figure 4: ET-Download cable

The 5 pin polarized connector, is connected to the development board, at the white socket(ET-DOWNLOAD) located at the bottom of the board. This connector will only go in, in asingle direction, the locking piece needs to match the white back in the polarized male header,as seen below.

Figure 5: Download Cable ConnectionThe board is now ready to program.

Page 7: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 7/44

3.2 Preparing Software

To download a program to the T89C51 board, it will be necessary to prepare and compile asuitable program, by using any of the many development tools that are available for thismicrocontroller. The compiled program needs to be in *.hex format prior to downloading.

A basic compiler is included with the accompanying CD. To prepare a sample program,follow these steps. It will first be necessary to prepare the code using a basic text editor suchas Windows Notepad. When this is complete, save the file as xxxx.asm. Then go to MS-Dosand run the Sxa51.exe program with the assembly file specified, i.e.

C:> Sxa51 test.asm

A number of options are available, as can be seen when running the program. Once theprogram is complete and there are no errors a hex file will be produced such as test.hex, whichis then ready for downloading.

3.3 Downloading to the Board

Atmel have made available an easy to use download program for Windows and Linux. Thisprogram is available from the Atmel website, we have also included a copy on theaccompanying CD. The Atmel FLIP (Flexible In-System Programmer) allows easy set-up ofthe computer and necessary parameters for downloading the compiled program to the targetmicrocontroller.

3.3a – Installing Atmel FLIP

Two versions of Atmel FLIP are included in the accompanying CD. Firstly FLIP forWindows, which is suitable for Windows 95,98, Me, NT and 2000. Secondly FLIP for Linux.To install either version is quite straightforward.

1. Either download the contents of the ZIP file to a temporary directory and click Setup. Ordouble click on Setup.exe from within the WinZIP archive.

2. The program will then commence installation.3. You will be required to accept the licence agreement by pressing ‘Yes’.4. Then you have the option to specify the directory where the program will be installed, or

to accept the default directory of Program Files\Atmel5. When the installation is complete a final Window will appear, with a Finish button to

complete the process.6. To run Atmel Flip, simply double click on the ‘FLIP 1.8.2’ icon in the program directory,

or select ‘FLIP 1.8.2’ from the Atmel section in the program browser.

3.3b – Downloading a program to the T89C51 Development BoardUsing Atmel FLIP

To down-load the compiled software to the board.

1. Connect the RS232 (ET-DOWNLOAD) connector between the computer and the T89C51Development Board. The socket on the board is marked ET-DOWNLOAD.

2. Connect a power supply, 9-12Vdc to the power connector on the board. The red ‘Power’LED should now illuminate.

3. Open or Run the Atmel FLIP program, this should already be installed on your computer,as per section 3.3a.

Page 8: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 8/44

4. On the Atmel FLIP program, click on the Device Menu and go to Select, a number ofdevices will now appear. Select the device ‘T89C51AC2’

Page 9: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 9/44

5. Now place the T89C51 Development board in Monitor mode for program download, thisis done by pressing the PSEN and RESET buttons in the following sequence

a. Press and hold the PSEN pushbutton on the development board.b. Now Press the RESET pushbutton on the development board, while

still holding the PSEN pushbuttonc. Release the RESET pushbuttond. Now release the PSEN pushbutton

This will place the board in Monitor mode for program download.

6. On the Atmel FLIP program, click on the settings menu, and select communicationRS232. Then select the appropriate communication port you are using, either COM1 orCOM2. Then select the speed at 115200 and press the ‘Connect’ button, at the bottom leftof this dialogue window. The FLIP program will now communicate with the T89C51, toreceive the various identification information and preset settings. This will appear in thedevice section of the program.

PSENPushbutton

RESETPushbutton

Page 10: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 10/44

7. Now load the Hex file that is to be downloaded to the board, by clicking on the File Menuand then ‘Load Hex’. The Hex file will then be loaded in the program buffer, ready fordownload to the device. Once the hex file has been loaded the information will appear onthe program in the buffer information section.

8. Now select the Operations Flow required. To program the device, we should select, Erase,Blank Check, Program and Verify. With these selected, now press the Run button at thebottom of the Operations Flow Section.

Page 11: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 11/44

9. As the program is being loaded, the progress bar will indicate the amount of the memorythat has been programmed. When the progress bar is 100%, and message will appearindicating the programming is complete.

10. Now reset the CPU, by pressing the RESET button on the T89C51 development board.The downloaded program will now run on the T89C51 Development Board.

3.4 Using the Software

Operation of the software is quite straightforward. A detailed manual is also included in pdf

Format, within the Atmel/Flip1.8.2/Doc directory. This details operation, configuration andtroubleshooting for the FLIP program. The Help command is also available from within theprogram, to allow easy access to the relevant sections of the Help Manual.

A configuration file can also be built for use when a number of devices are going to beprogrammed with identical parameters and hex file. This file can be built using FLIP or with atext file editor. Once the file is prepared, all that is required is to click on File and LoadConfiguration, the appropriate device is then selected, the communication port, speed andprotocol is set. The hex file is loaded and the device programmed. Examples of how toprepare configuration files and a sample configuration file is included in the pdf manual.

Page 12: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 12/44

3.5 Running My First Program – test_led.hex

A number of programs are included with the accompanying CD, that will demonstrate thefeatures of the board, and provide a number of ready to run solutions to test various parts ofthe board. In this section we will load and run the Led program, to flash the test LED at portposition P2.6. This is the green test LED, that is located just to the left of the T89C51.

Firstly connect the board to the computer and power supply as indicated previously. Alsoensure the jumper is in place next to this LED, which connects the LED to port pin P2.6.

Fig 6 – Test LED and Power LED

Then open the download software (FLIP), which should be installed on your computer. Now follow thesteps as below,

1. Click on the Device Menu and press ‘Select’, now choose ‘T89C51AC2’ from the dropdown menu.

2. Now place the T89C51 Development board in Monitor Mode by

a. Press and hold the PSEN pushbutton on the development board.b. Now Press the RESET pushbutton on the development board, while

still holding the PSEN pushbuttonc. Release the RESET pushbuttond. Now release the PSEN pushbutton

3. Then click on the Settings Menu and select Communications – RS232. There are now twobuttons, firstly the COMPORT button, for you to select either COM1 or COM2depending on which serial port is being used for the connection to the T89C51Development Board. The press the BAUDRATE button, to select a speed of 115200.

Page 13: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 13/44

Once this selection is complete, press the Connect button. If the connection is successful,a message will then appear in the bottom right of the program, indicating the COM portand the speed specified. Also the T89C51 default data will appear in the device section ofthe program.

If the connection timed out or a error message appeared. Check the power and RS232connection cables, that they are in place correctly and that the Red LED is illuminated onthe board. If this is okay, reset the board and follow step 2 again, to place the board inMonitor Mode.

4. The next step is to load the hex file in the buffer. To do this, click on the File menu andLoad Hex. Use the file browser to locate the program ‘test_led.hex’, which is located inthe examples section of the CD. Then press Load, as the program is being loaded theprogress bar at the bottom of the program window will display the percentage complete.Once the download is complete, the Buffer Information section will display the relevantfile data.

5. Now select, Erase, Blank Check, Program and Verify from the Operations Flow sectionof the FLIP program. Once these are selected press the Run button.

6. The program will now be downloaded into the T89C51 microcontroller, once this iscomplete a message will appear on the program, indicating the programming and verifyoperation is complete.

7. The program can now be started, by pressing the ‘RESET’ button on the T89C51Development Board.

3.6 Troubleshooting

Program Downloads But Will Not Run

1. Verify your code, has been downloaded correctly, by selecting Verify in the operationsflow and press the Run button.

2. Check your code or use a compiled program that is known to work.

Program Will Not Download

1. Check cable connections and power supply.2. Check port selection on the programming software, is correct according to the serial port

being used.3. Check T89C51 is in Monitor Mode prior to downloading of the software.

Page 14: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 14/44

Chapter 4 – Port 0 to Port 4

4.1 Introduction

The T89C51RD2 microcontroller has 4 ports for general I/O use. These consist of the following,

Port 0 – Identified as P0.0 to P0.7 – 8 Port PinsPort 1 – Identified as P1.0 to P1.7 – 8 Port PinsPort 2 – Identified as P2.0 to P2.7 – 8 Port PinsPort 3 – Identified as P3.0 to P3.7 – 8 Port PinsPort 4 – Identified as P4.0 to P4.1 – 2 Port Pins

These ports also have a number of ancillary functions, which can be selected by setting the variousregisters. These will be explained in greater detail in later section.

4.2 Port 1, Port 3 and Port 4

Ports 1,3 and 4 on the T89C51RD2 all have internal pull-ups and each of these pins can be configuredas general purpose I/O or for their alternate function. To use the pin for general purpose I/O set orclear the corresponding bit in the Px register of the port concerned. To use the port pin as an input thepin needs to be set to a 1 in this Px register. In the case of using the alternate port functions, this bit inthe Px register also needs to be set to a 1.

Port 1 on the T89C51RD2, is also used for ADC and PWM. These port pins have also been wired tothe ADC connector on the board and also the PWM connectors. For more information refer to theschematic and the relevant chapter in this manual.

Port 3 also serves a number of other functions. Port pins 3.0 and Port 3.1 are for the on-chip UART,and have been wired to the MAX232 as well as the RS422/Rs485 circuits on the board. The remainingpins P3.2 to P3.7 have been connected to the 34 pin connector as well as a number of other functions.P3.3 is used on the magnetic card reader connector, P3.4 for the RS422/RS485 circuit, to controlsending and receiving of data with RS485. P3.5 is also connected to the relay coil, for switching of therelay. P3.6 is used with the magnetic card reader circuit, for the data input/output. P3.7 for the clocksignal with the magnetic card reader.

Port 4 pins are wired for the I2C bus, with P4.0 as the clock line and P4.1 as the data line.

The internal arrangement within the microcontroller for these port pins is shown below.

Page 15: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 15/44

4.2 Port 0 and Port 2

Port 0 and 2 differ from the above ports, in that they do not have internal pull-ups. These ports can beused for general purpose I/O also or alternatively as the data/address bus in a microcomputer system.To use the various pins as I/O, again set the appropriate pin in the Px register to a 1 or a 0. For an input,set the Px register bit to a 1.

On the T89C51 Training Board, the Port 0 is connected directly to the 34 pin connector as well as KBI,the keypad input connector. For P0.7 this is also connected to the speaker. To select the speaker it isnecessary to place the jumper on the speaker side, and for the keypad to place the jumper at the “4x4”markings, on the board.

For Port 2, these pins are connected directly with the 34 pin connector as well as the LCD. For usingan LCD, the connections from the T89C51 are as follows,

P2.0 - D4 for LCD DataP2.1 - D5 for LCD DataP2.2 - D6 for LCD DataP2.3 - D7 for LCD DataP2.4 - EN for LCD signalP2.5 - RS for LCD signal

Page 16: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 16/44

Chapter 5 – 34 Pin 72IOZ80 Connector

5.1 Introduction

All port pins are conveniently brought out to this 34 pin connector, together with the GND and Vccconnections. The configuration of the pins can be seen in the below diagram. A standard 34 pin IDCCconnector can be used to connect to this socket, these are available on the Futurlec website,www.futurlec.com

This connection is ideal when another board is used as an interface board or as a connection to morecomplex circuitry. In this case the T89C51 Board can be used as a main processor board, andconnected to ancillary boards as required. The ancillary board can then easily be changed and modifiedaway from the main board, and a simple plug connection is all that is required to separate the boards.

Fig 7 - Diagram of 34 Pin IO Connector

Page 17: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 17/44

Diagram 1 – 34 pin Connector

Page 18: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 18/44

Chapter 6 – Keypad Connector

6.1 Introduction

A keypad connection has been provided at P0 (KBI) Connector, this can be used with standard 4x4 or4x3 matrix keypads. Sample programs are provided on the accompanying CD. For sensing, one side ofthe matrix can be raised to a high, and the bottom outputs, monitored or scanned for a high signal,indicating a key has been pressed. Once a press is detected, each side input signal can be alternativelyraised and lowered to detect which key has been pressed. By following the sample program a betterunderstanding of this operation can be deduced.

A standard 10 pin IDCC connector can be used to connect to this socket, the wired accordingly to thekeypad signals. A diagram of the connection of the keypad is seen below,

Fig. 8 - Keypad Connector

Diagram 2 – Keypad Connector

Page 19: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 19/44

Chapter 7 – ADC Connector

7.1 Introduction

The PORT1 ADC port pins are all brought out to the ADC socket for ease of connection to monitoringequipment. It is always good practice to separate the analog signals/circuit from the digital circuit. Thusthese connections can then be taken to a separate board or circuit area for isolation of the inputs. Theseport 1 pins also have dual functions and it is necessary to select the ADC operation prior to using theinputs. By setting the various bits within the ADCF register of the T89C51, we can select which pinsare to be used for ADC and which can be used for standard I/O.

To perform an A/D conversion, first select the port pin the conversion is to take place on. This is doneby setting the SCH0 to SCH2 bits, within the ADCON register. Refer to Table 56 of the technical datasheet. An actual A/D conversion on the selected pin, is triggered by setting the ADSST bit. This islocated within the ADCON register. When the conversion is complete, this bit will be cleared by themicrocontroller. An easier way to monitor the completion of the conversion is to use the end ofconversion flag, ADEOC, in the ADCON register. When this flag is set the value is available at theADDH and ADDL registers.

When the input signal is equal to the A/D reference voltage VAREF, the result will be 3FFh. For avalue between the VAGND ground reference voltage and the VAREF high reference. The result willbe a linear conversion between these upper and lower limits. It is important to ensure the input voltagedoes not exceed, the VAREF voltage, as this may lead to damage of the IC.

The arrangement of the ADC connection can be seen below.

Fig 9 – Diagram ADC Connector

Page 20: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 20/44

Diagram 3 – ADC Connector

Page 21: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 21/44

Chapter 8 – I2C Connector

8.1 Introduction

The connections from the PCF8574A are available on the IDCC Connector. The layout of thisconnection is as show below.

Diagram 3 – I2C Bus Socket

8.2 I2C Bus Expand

A further I2C connector is provided for expansion of the I2C bus. This bus can then be taken from thisboard and connected to another board, to allow other devices to be connected to this bus. It is importantto remember the connection should not be too long, as this can affect the operation of the bus. Alsoother devices connected to the bus, will require different addresses to those devices already on the bus.For more information regarding the I2C bus, refer either to the T89C51 data sheet or to PhilipsSemiconductor, who were the original designers of this bus concept, a number of information datasheets are available on the Philips website.

Diagram 4 – I2C Bus Expansion Socket

Page 22: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 22/44

Fig 10 - Diagram of I2C Bus expand Connector

Page 23: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 23/44

Chapter 9 – Magnetic Card Reader

9.1 Introduction

The T89C51 Training Board is designed to work directly with the MCR-B02TTL Magnetic cardreader. The connector from this device, can be plugged directly into the T89C51 board. This is an idealstarting point for a restricted area access system, or employee identification logging system. The datafrom the card, will be passed to the board, which can then log the information or pass it via the board’sRS232 connection to a computer, for card identification, recording and enabling access to the area asrequired. A electronic latch could be connected to one of the port pins, to open a door or gate, onceaccess is authorised.

Several software examples are provided on the CD. There are two ways to work with this card, the firstone, is to constantly monitor the output of the card reader, to identify as soon as a card is present.Alternatively the INT1 jumper can be connected on the board, this will connect the card readerPRESENT signal to the INTERRUPT input of the microcontroller. A present signal will then generatean interrupt within the microcontroller, which can then perform an interrupt routine to read the card andprocess the data accordingly.

Diagram 5 – Magnetic Card Reader Connector

Figure 11 – Magnetic Card Reader

Page 24: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 24/44

Chapter 10 – Output Relay

10.1 Introduction

An output relay is provided on the board, for the control and switching of various devices. The coil ofthe relay is connected via a transistor to port pin P3.5. Although the relay output is rated for mainsvoltage, we do not recommend any voltage greater than 24Vdc be connected to the output. If it isrequired to switch mains appliances, the relay output could be used to switch a triac or other device,that was suitably isolated from the mains voltage, to switch the device.

To use the relay, the jumper relay needs to be connected. This will connect the port3.5 pin to the relaycircuit. By setting this pin to 1, the relay will switch on or close. By setting the pin to 0, the relay willopen or switch off. This pin needs to be set as an output also for the circuit to work.

Note: Port pin 3.5 is also connected to the 34 pin connector, these pins cannot be used simultaneously.So if Port pin 3.5 is required at the 35 pin IDC connector, it will be necessary to open the jumper at therelay circuit.

Fig 11 - Diagram of Relay Connector

Pin 1 – Normally OpenPin 2 – Common

Pin 3 – Normally Closed

Page 25: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 25/44

Chapter 11 – Buzzer

11.1 Introduction

The on-board buzzer/speaker is an ideal warning device, for a dangerous or attention signal. The buzzeris connected via an interface transistor to port pin P0.7. By selecting this pin as an output, the buzzercan be turned on or off, by setting the pin to a 1 or 0. To operate the buzzer it is also necessary that thejumper at 4X4/SPK is set to the speaker position to connect the port pin to the buzzer.

Fig 12 – Jumper Selector for Keypad or Speaker

Note: The port pin P0.7 is also connected to the 34 pin IDCC connector. If the port pin is required atthis connector, it is necessary to disconnect the jumper for the buzzer. The port pin cannot worksimultaneously with the 34 pin connector and the buzzer. It is also possible to connect another port pinto the buzzer, by connecting between the port pin and the buzzer input.

Page 26: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 26/44

Chapter 12 – LCD

12.1 Introduction

The T89C52 Training Board is designed to connect directly with a standard character based LCD. Thiscan be of any size from 16x1 to 40x4. A 14 pin IDCC socket is provided on the board, together with acontrast adjustment trimpot for adjusting the brightness of the display. The data transfer to the LCD isset up for 4-Bit transfer thus reducing the number of I/O pins used for connecting to the LCD.

Fig 13 – LCD Connection and Contrast Trimpot

12.2 Connecting to an LCD

For the LCD connection a 14 pin IDCC connector is provided on the training board, this is configuredas below.

Page 27: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 27/44

Diagram 7 – LCD Connector

To connect to the board, a 14 pin IDCC connector will be needed together with some ribbon cable. Thegrey ribbon cable available from Futurlec is ideal for this purpose. Place the end of the cable in theIDCC connector and crimp accordingly.

For the LCD connection, there are basically two types of connections available on LCD’s currently.These are either a single row of 16 connections on the top or bottom of the display. Or a double row oneither side of the display. Connection to either type will now be explained separately,

Single Row: Here is will be necessary to cross each pairs of the wires. Thus in the case of wire 2, thiswill run to LCD connection 1, and wire 1 will run to LCD connection 2. Then wire 4 will run to LCDconnection 3, and so on. This can be seen in the diagram below. Take special care, the connection isstarted at pin 1, not at pin 14 or pin 16 of the LCD.

Diagram 8 - LCD Connection

Page 28: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 28/44

Double Row: For the double row, this can sometimes be easier depending on the position of the holes.In some cases it is possible to mount a male IDCC socket on the back of the LCD, thus allowing asimple cable connection between the board and LCD. In most cases, though it will be necessary to wiredirectly to the LCD. As per the above diagram, take care to ensure the correct connections are made tothe LCD, as it can be very difficult to rewire this connection.

Note: In the case of a backlit LCD, if the backlight is required, it will be necessary to run a separate+5V and ground supply to the backlight. The backlight is connected to pin 15 and 16 of the LCD.

12.2 Running the LCD

A number of sample programs have been included on the accompanying CD for running an LCDroutine. Basically, it will be necessary to first set-up the LCD, by following a pre-determined sequencefor initialisation. After this is complete, data can then be sent to the LCD. It is recommended a dataarea be allocated in the T89C51 microcontroller, for the LCD. The values to appear on the LCD canthen be written to this area. The download process to the LCD, will then simply transfer the contents ofthis area to the LCD. The size of the data area, should be identical to the number of characters availableon the LCD.

Important: Use the contrast adjustment first for the LCD, such that the dots of the LCD are visible. Thisis a common source of errors, as the characters on the LCD will not be seen unless the contrastadjustment is set correctly.

Page 29: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 29/44

Chapter 13 – I2C Bus

13.1 Introduction

The T89C51 Training Board has a pre-installed I2C bus for communication with a number of devices.The I2C bus was originally developed by Philips Semiconductor as an easy means to connect withdifferent devices on a single bus connection by using a simple 2 wire bus. Today there are a number ofmanufacturers producing products that comply with this bus specification and can be connected ontothis bus. Also many microcontroller manufacturers, incorporate a master receiver as a special featurewithin the microcontroller to control and send data using this bus. On the T89C51 Training board, thereare 3 devices connected to the I2C bus, this is the Real Time Clock, a PCF8583 from Philips. AEEPROM IC, which can be any device from the 24LCXX range. As well as a special I/O device, thePCF8574 from Philips. Each of these devices have a different address, which is used when sending orreceiving data, thus allowing the microcontroller to act as a master and identify each device. For themicrocontroller, Pin P4.1 is used as the data line (SDA) and P4.0 as the clock line (SCL). Operationand message transmission will be covered in a later section.

13.2 Basics

The T89C51RD2 microcontroller does not have dedicated hardware internally to control the I2C Bus,thus it is necessary to implement this in software and use 2 I/O pins for this bus. On the board the pinP4.1 is used as the SDA line or data line for sending and receiving data. When data is to be sent the pinis set as an output pin and when it is necessary to receive or read incoming data, the pin is set to aninput. For the SCL line, this is slightly different as the microcontroller will act as a master and issue allthe clock signals, to which the various devices will respond. Thus this pin is set as an output pin.

The I2C bus floats or is pulled to +5V by 2 pull-up resistors on each bus. When a message is to betransmitted the data line (SDA) is first pulled low, followed by the clock line (SCL). Transfers aremade with 9 bit words, this consists of an 8 bit data work and 1 bit acknowledge, which is issued by thereceiver. A typical message sent on the bus, consists of firstly the start condition. Followed by theaddress of the device to which the message is to be sent, this address is 7 bits in length, an additionalbit, the 8th bit, is used to indicate whether this is to be a read or a write. The receiving device will thenacknowledge receipt of the message. The address of the read or write is then sent as an 8 bit address.

The following data will depend on whether this is to be a read or a write. In the case of a write, the datais sent one byte at a time until a stop condition is issued or detected. The receiver can stop thetransmission, by failing to acknowledge the byte. In the case of a read, the microcontroller will firstsend a start condition, followed by the receivers address, and then the receiving device will place thedata on the bus that was requested from the master. The master will now acknowledge receipt of eachbyte. This can be seen in more detail in the diagram below.

Page 30: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 30/44

Diagram 9 – I2C Bus Communication

13.3 Using The Interrupts from the I2C Bus IC’s

To use the interrupt signals from the various I2C devices, it is necessary to connect these to the INT0pin on the microcontoller. It is possible to connect from 3 sources to the INT0 pin. These are

a) Connect an interrupt signal to INT0 (P3.2) on the 34 pin Connectorb) Connect from the RTC (PCF8583) pin 7 to the INT0 pinc) Connect from the I/O Port IC (PCF8574) pin 13 to the INT0 pin

Only one of these sources can be used at one time. To connect either of the INT signals from the I2Cbus devices, the I/O Port IC or the RTC, it is necessary to connect the jumper on the board. To connectthe RTC INT signal, place a jumper at the RTC to INT0 header pins. These are located at the top rightof the board. Similarly to connect the I/O interrupt to the microcontroller interrupt, connect the jumperbetween the I/O pin and the INT0 pin. This can be seen in the photo below. Do not connect both theRTC and I/O simultaneously.

Fig 14 – INT0 Connector for Microcontroller Interrupt

Page 31: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 31/44

13.4 Adding Additional Devices to the I2C Bus

Provision has been made on the board to expand the I2C bus, onto another series of devices or anotherboard. A couple of precautions are necessary if this is to be implemented. Firstly it is necessary toensure the devices added to the bus do not have the same address as the devices already on the bus. Inthe case of some IC’s it is not possible to change the address, however for others, this address can bemodified by connection to the various address input pins of the device, for example the 24 serieseeproms. Similarly for the PCF8574 I/O IC, up to 8 devices can be connected on the same bus, byadjusting the address of each.

Secondly, the amount of current consumption needs to be considered, as the microcontroller I/O pincan only supply or source up to 15mA. If there are a large number of devices, each consuming a smallamount of current, the signal will become degraded, and it will not be possible to recognise clearly thesignals on the bus.

Fig 15 – I2C Bus Expansion Socket

Page 32: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 32/44

13.5 Real Time Clock (PCF8583)

The PCF8583 real time clock from Philips Semiconductor is a flexible I2C bus clock/calender IC. TheIC features many useful functions including standard 12hour or 24 hour clock. Alarm function, withprogrammable alarm. Free RAM for use as a scratchpad for storing of parameters. The IC can also beused as an event counter, which will count the number of input pulses and sound an alarm when thenumber of the count, matches the alarm value stored within the IC.

Fig 16 – Real Time Clock IC Socket and Crystal

Fig 17 – Battery Back-Up For Real Time Clock

Page 33: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 33/44

Use of this IC is quite simple and it is recommended to read the datasheet on the accompanying CD,for more detailed information.

Firstly to address the PCF8583, the address for this device is ‘1010001X’ the 7th bit is actuallyadjustable by setting a +5V or 0V at pin 3 of the IC. On the T89C51 Training Board, the control supply+5V has been tied to this pin, configuring this bit to be a 1. The X bit as discussed above is for a reador write and is specified when sending the address information, for a data write this will be ‘10100010’.After this byte is sent from the microcontroller, the PCF8573 will acknowledge. The address of theregister to be written to or read is then sent. This register address can be the starting point and a seriesof data sent to the device.

Normally the control register at location 00 will be the first register to be written to. The controlregister is used to set up the device and specify the operation. For the unit to operate as a normal clock,the function mode at bit 4 and 5, will need to be set to ‘00’, alternatively to set the IC as a eventcounter, these bits will be set to ‘10’. The time can then be sent to the device to initialise it. The time isstored in BCD format, and the initial data will need to be sent in an identical format. There is no needto start the clock, once the data has been written, the IC will automatically update the count.

For specifying the operation of the alarm, register 08 will need to be set with the appropriate values.The alarm is enabled or disabled by using the Alarm Enable Bit, which exists in bit 2 of the controlregister. Setting this bit to a 1 will enable the alarm. The value the alarm is to trigger at, is then placedin registers 09h to 0bh.

Page 34: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 34/44

13.6 EEPROM (24LCXX)

The EEPROM is used to store data and it necessary initialisation parameters. A number of differentEEPROM devices can be used for this socket, namely the 24LCXX series from Microchip or the24CXX series from Atmel, these parts are all available from Futurlec, www.futurlec.comIn this section we will discuss in detail the Microchip range of devices, for which are datasheet isincluded in the accompanying CD. These EEPROM’s can store data for up to 200 years and it ispossible to write and erase to these devices up to 1 Million times. A range of sizes are available fromthe 24LC32 up to the 24LC256. These devices have an I2C bus address of ‘1010XXX’. With the lastthree values determined by the settings at A2, A1 and A0 on pins 1,2 and 3 of the IC. A +5V controlvoltage at these pins will set the address value to a ‘1’. By setting these pins to different values, it ispossible to include up to 8 devices on a single bus. For the T89C51 Training Board, these values havebeen preset to ‘100’, thus the complete address for the on-board eeprom is ‘1010100X’, with the last bitbeing the read/write bit. To include additional EEPROM on the external I2C bus, it is necessary to setthese bits A2,A1 and A0 to different values than the on-board EEPROM.

To write to the EEPROM, this can be either a single byte write or a page write. The difference beingthat the stop bit, is sent at the completion of the transmission. To write to a single byte, the device

address ‘10101000’ is sent, followed by the register address the byte is to be written to. In the case ofthe 24LC256, as the memory size is quite large, the register address will consist of 2 bytes, the firstbyte being the high address and the next byte being the low address. Following this the data is sent.

To read from the EEPROM, it is necessary to first set the register address to the correct address withinthe EEPROM. This is done by first sending the device address followed by the register address for thedata to be read. This is sent as a write instruction, not a read instruction. After sending the address, themicrocontroller generates a start condition and then resends the control byte or device address again,but this time with the read/write bit set to a read ‘1’. The EEPROM will then place the byte value onthe bus for receiving by the microcontroller. A sequential read for reading a number of bytes is similarwith the exception that the stop bit is generated at the completion of the reading of the data.

Page 35: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 35/44

Fig 18 – EEPROM Socket

Page 36: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 36/44

13.7 I/O Port (PCF8574A)

The PCF8574 is designed to expand the number of I/O points available on the system. If a lot of themicrocontroller I/O pins are being used for ancillary functions, such as communication and as A/Dports. It is possible to use this device to add another 8 I/O points, which can be read or written to. Up to8 of these devices can be used on a single I2C bus, enabling a large increase in the number of I/Opoints available for a more complex system.

Fig 19 – PCF8574 IC Socket and Connector

The address for the PCF8574 is ‘0100XXX’ or for the PCF8574A this is ‘0111XXX’. The value ofXXX is set by pins A2, A1 and A0 on the PCF device. In the case of the T89C51 Training Board, thesehave all been set to 0, thus for a PCF8574A, the address will be ‘0111000’. Each of the I/O points onthe PCF8574 can act as either an input or output. To act as an output, simply write either a 0 or a 1 tothe port pin. This is achieved similarly to the above IC’s. Firstly send the address with a writeindicated, i.e. ‘01110000’. Then write the write the value to be written to the output port. The data issent as P7 to P0. The output at the port will not change until the complete byte has been sent and thePCF8574 acknowledges. Thus the entire port changes state at the same time, on completion ofreceiving the entire byte. To read values from the port, simply send the device address with a readinstruction, i.e. ‘01110001’, the PCF8574 will then send the data, following the acknowledge signal.

Interrupts can also be set up on the device, such that an interrupt is generated, if the input changes state.To use this, the interrupt pin can be connected to the INT pin of the microcontroller, as discussed in theprecious section. Once an interrupt is generated, the microcontroller can then initiate a read of thedevice, to obtain the new information.

Page 37: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 37/44

Fig 20 - Writing Data to PCF8574

Fig 21 – Reading Data from PCF8574

Page 38: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 38/44

Chapter 14 – Communication

14.1 Introduction

The T89C51 Training Board is equipped with a number of communication channels to communicatewith high-level devices, such as computers and control systems. These are connected to themicrocontrollers internal UART, which is used to read and send these signals. To set up the UART, aseries of communication registers exist within the microcontroller, these need to be set correctly priorto using the communication channels. Three options exist for communication with the microcontroller,these are RS232, RS422 and RS485.

The RS232 port is designed to communicate directly with a computer, by connecting the RS232connection to the computers serial port. Data can then be sent and received from the board. This isideal for setting up a control and monitoring system on the computer, using either Visual Basic, C orDelphi, to display and record the various values. The high level system can also be used to comtrol theboard, such that a more sophisticated control system is developed using this software and commandsare then sent to the T89C51 board as required.

For the RS422/RS485 ports, these are designed for setting up communication either in a one-to-oneformat, between two devices. Or for a multi-board system where a number of boards are connected tothe RS485 bus, and data is placed on this bus, for the entire system to read and monitor.

It is only possible to use one communication option, either the RS232, RS422 or RS485communication port.

14.2 RS232

Within the T89C51 Training board the necessary RS232 IC’s and support parts are already included,for RS232 communication with a computer. It is however necessary to set-up the microcontroller, forthe correct baud rate, data bit, parity and other values. This information is available in the T89C51 datasheet and a thorough understanding of this is recommended prior to using this port. One of the mostcommon causes of problems with this communication, is using or setting the incorrect communicationspeed, resulting in lost data or simply no communication.

Included on the T89C51 Training Board, is the MAX232 level conversion IC. This is used to convertthe RS232 signals to a TTL level signal suitable for the microcontroller. RS232 signals are ± 12, whilstTTL signals are +5V, connecting the RS232 signals directly to the microcontroller’s UART wouldresult in damage to the IC.

For two-way communication between the board and a computer, it is necessary to cross the wires. Suchthat the TXD or transmission signal from the board is connected to the RXD (receiving) input of thecomputer. Similarly the TXD (transmission) signal from the computer is connected to the receivinginput of the microcontroller board. It is also possible to arrange one-way communication byconnecting only the TXD transmission signal to the computer, or alternatively only the TXD signalfrom the computer to the board. This is however not recommended, especially in the case of commandsbeing sent, as it is important these signals are acknowledged, by issuing a confirmation from thereceiving device.

Diagram 9 – RS232 Connector

Page 39: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 39/44

14.3 RS422

In the case of RS422 communication, a 75176 or MAX3088 IC is required to convert these signals toTTL signals. For 2 way communication, i.e. sending and receiving, 2 IC’s are required, one for sendingand one for receiving, these are installed in the sokcets as shown below,

Fig 22 - 75176 IC sockets and Full/Half Duplex Jumpers, together with RS422/RS485 Jumper

Similarly if only one-way communication is required, only a single IC is required either at thereceiving socket or at the transmission socket, refer to the schematic diagram for this information.

The advantage of RS422, is that it can communicate over much greater distances than RS232, up to1200metres. Shielded wire however is required for the link between the devices. RS422 is mainlydesigned for communication between two devices, whilst RS485, can be used on a bus system withmany devices on the single bus.

It is however possible to connect a series of devices together, however only one unit can be atransmission unit and the remainder are receiving units. Up to 32 receiving units can be connected inthe case of using the 75176 IC and up to 256 points when using the MAX3088 IC. A standard RS422connector, consists of 6 pins, 4 of these wires are used for signal wires, i.e. RXA and RXB forreceiving and TXA and TXB for transmission. It is necessary as in RS232 to cross these wires also,such that the transmission wires of one device are connected to the receiving wires of the other device.

Diagram 10– RS422 Connector

Page 40: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 40/44

14.4 RS485

RS485 communication offers a lot more flexibility than the previous methods, in that signals can besent and received on the same bus. Also a number of devices can be connected to the same bus, to forma network. In the case of the 75176 IC, up to 32 connection points/devices can be connected to a singlebus, whilst for the MAX3088 up to 256 devices can be connected. To implement a network system aform of addressing needs to be set up to identify each device. Similarly software control needs toensure only one device is sending at one time, to avoid signal collisions, and corrupted data.

Only 2 wires are required for sending and receiving data, the direction is controlled by themicrocontroller at port pin PD7. To send data, set PD7 to a 1 and to receive data set PD7 to 0. Toimplement RS485, the board needs to be set up as follows,

a) Insert either a 75176 IC or MAX3088 IC in the RS422/RS485 socket.b) Set the RS422/RS485 jumper to the RS485 side.c) Set the F/H jumper to the H (Half Duplex) sided) Short the jumper for the fail safe resistor at position TLe) Short the jumper for the fail safe resistor at position THf) Connect the 2 wire bus to terminal TXB (TX-) and TXA (TX+)

It is now necessary to set up the software, to control this communication. A sample program is includedon the CD, it is worthwhile before implementing a system to study this and other literature to get agood understanding of controlling and sending messages on such a network.

Fig 23 – RS422/RS485 Connector

Page 41: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 41/44

Diagram 11 – RS485 Connector

Page 42: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 42/44

14.5 Communication Jumpers

RS422/RS485 Jumper: - This is to set the IC Line driver at the position TXD/485 to work either forRS422 or RS485 communication. Setting the jumper to the TXD position, will enable the IC to workfor RS422 communication and to send/transmit data only. When the jumper is in the 485 position, itwill enable the socket for RS485 communication. This will allow data to be sent and received by thisIC, under the control of the PD7 pin from the microcontroller.

F/H Jumper: - This allows communication in either half or full duplex formats. Full duplex, is whendata is sent and received simultaneously on two separate bus wires as in RS422. Half duplex is whendata is sent and received on the same bus, by alternatively sending and receiving information. This isthe method for RS485 communication and this jumper needs to set accordingly for either RS422 orRS485 communication.

RL Jumper: - This connects the termination resistor into the RXB (RX-) circuit. This resistor willstabilise the bus voltages, when signals are sent out and provide a stiff impedance for signal. For shortbuses, it is not necessary to include this resistor, however at least one point on the bus a terminationresistor should be included.

RH Jumper: - As above this jumper connects the resistor into the RXA (RX+) circuit.

RZ Jumper: - This connects an impedance between the RX+ and RX- lines. This will also help toreduce signal reflections for long distance lines and is recommended to jumper this connection in thecase of long distance bus wiring.

TX Jumper: - This connects the termination resistor into the TXB (TX-) circuit. This resistor willstabilise the bus voltages, when signals are sent out. For short buses, it is not necessary to include thisresistor, however at least one point on the bus a termination resistor should be included.

TH Jumper: - As above this jumper connects the resistor into the TXA (TX+) circuit. It is important toinclude this jumper such that this resistance is at least connected at one point on the bus.

TZ Jumper: - This connects an impedance between the TX+ and TX- lines. This will also help toreduce signal reflections for long distance lines and is recommended to jumper this connection in thecase of long distance bus wiring.

Fig 24 – Communication Jumpers

Page 43: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 43/44

Chapter 15 – Power Supply

15.1 Power Supply Connection

The power supply circuit on the Development Board has been designed for heavy duty, andwill maintain a 5V supply to the circuit under quite high load conditions. A standard plugpack can beused to supply power to the board, the plugpack pin and shield can be either polarity as a full waverectifier is used in the circuit.

The power supply can be connected to either the poarized header or the plugpack connection,as shown in the photo below. The DC input voltage can be between 9 and 12 V, and should be capableof supplying at least 500mA.

The red LED will come on to indicate the supply is okay.

Output voltage of 5Vdc is available at several points around the board.

Figure 25: Power Supply Connections

PlugpackConnection

Polarized HeaderConnector

Power LED

Page 44: T89C51 Training Board - V5

T89C51 Training Board Manual

T89C51 Training Board.doc Page 44/44

4 Board Layout