0% found this document useful (0 votes)
1K views

89S52 Micro Controller Interfacing

The document provides instructions for testing the functionality of the CKIT-06 microcontroller development kit using an 89S51 microcontroller. The steps are: 1. Write a simple blinking LED program in ASM51 assembly language and save it as p41.asm. 2. Assemble the program to create an object file p41.obj using the ASM51 assembler. 3. Convert the object file to a binary file p41.bin to write to the microcontroller's program memory using the LPT port. 4. Write the binary file to the microcontroller's program memory using the LPT port to run the program and test that the LED blinks as expected.

Uploaded by

Hafiz Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

89S52 Micro Controller Interfacing

The document provides instructions for testing the functionality of the CKIT-06 microcontroller development kit using an 89S51 microcontroller. The steps are: 1. Write a simple blinking LED program in ASM51 assembly language and save it as p41.asm. 2. Assemble the program to create an object file p41.obj using the ASM51 assembler. 3. Convert the object file to a binary file p41.bin to write to the microcontroller's program memory using the LPT port. 4. Write the binary file to the microcontroller's program memory using the LPT port to run the program and test that the LED blinks as expected.

Uploaded by

Hafiz Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Golam Mostafa : http://www.krdcbd.com/ : 01726341559 ; mostafagb@yahoo.

com

89S52 Microcontroller Intefacing

Introduction

There are many topics that we need to study, understand and then verify to acquire the capability of designing and building microcontroller based systems such as: a 24-Hr Clock or a
Taximeter or a Digital Weighing Machine or a Prepaid KWH Meter or a similar.

Now, the question is: Which topics to study and verify first? It is a difficult question and there exits no straightforward answer! However, like many successful people, I have found that the following guidelines could help getting quick interest into the works involving microcontrollers.
i. ii. Let us take an example program from Chpater-5 or Chpater-6 of this book. Follow the steps as outlined in the example and observe the results. Open the source code of the program. Let us try to understand the need of every instructions of the program. While studying the program codes, we must remember that the program instructions are closely related with the hardware on which it works. Let us now, try to rewrite the program in our own ways and observe that the new program still provides the same result. This is the beginning point of learning the procedures of microcontroller based system design.

iii. iv.

To design, develop and build a microcontroller-based system, we need a learning/development tool similar to MicroTalk-8051, which has been pictured at the back of the cover sheet of this book. A development tool is equipped with all kinds of commonly used peripheral controllers, RAM, local hexadecimal keyboard, serial link, breadboard, edge connectors and a good number of ROM and CD-based subroutines. A user places the interface circuitry on the breadboard; connect these with the MCU using the edge connectors and the hookup wires. The user then develops the control program using IBMPC and the assembler. The binary codes are then transferred into the RAM of the trainer using the serial link of the PC. The program could be easily edited and modifies using the local keyboard and the PC. MCU based system design becomes a matter of enjoyment using development system like Microtalk-8951 and the similar. Unfortunately, the development tools are costly items and are not within the reach of the students and the amateur designers. The solution is the development of a student version of the MicroTalk-8051, which is: CKIT-06A. The CKIT-06A is a very low cost miniature microcontroller learning/development system using Atmel 8-bit CISC microcontrollers of type: 89S51, 89S52 and 89S8252. The CKIT-06B supports Atmel 8-bit 20-pin RISC microcontroller of type: AT90S2313. The CKIT-06C supports 8-bit 40-pin RISC MCU of type: AT90S8515. The CKIT is equipped with edge connectors, breadboard, +5V supply and a Line Printer (LPT) cable. A user can develop his circuitry on the breadboard; develop the control program using the IBMPC and assembler. The binary cods are then written into the code memory (EEPROM) of the MCU using the LPT port of the IBMPC and a driver, which has been supplied with the CD that accompanies the CKIT. It is very annoying to develop MCU based system using CKIT because it does not provide any facility to debug a program. If the program works its fine; otherwise the modified or the extended codes of the program required to be re-written into the MCU, which reduces the endurance of the EEPROM of the MCU. However, the MCU supports 1000 times write operations within its EEPROM and it is sure that a user would be able to develop his working control program within 100 attempts.

Component Layout of CKIT-06A

R2

J1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

J2
P10 P11 P12 P13 P14 P15 P16 P17 RST P30 P31 P32 P33 P34 P35 P36 P37 XT1 XT2 GND Vcc P00 P01 P02 P03 P04 P05 P06 P07 EA/ ALE PSEN/ P27 P26 P25 P24 P23 P22 P21 P20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

D1

C3
1

D4

Microcontroller 89S51, 89S52, 89S8252

U5

C2

T1
C1 + -

Y1

U1

CKIT-06 Karighar R&D Center

D3

D2

+5V Power Supply

CKIT

Figure-2.1(a): Component Layout Diagram of CKIT-06A

D3

1 + -

7805 2

+5V

220V

6V
0V

C1 U5 1000uF

6V
T1 LV D2

C3 0.1uF

+ C2 220uF 0V

Figure-2.1(b): Schematic Diagram for +5V Power Supply

Circuit Diagrams

3.1 Connection Diagram Between LPT Port and 40-Pin ZIF Socket

LPTCR (037Ah)
CR0

LPT Port
14

U1: 40 Pin ZIF (89S51)


9

1 2 3 4 5 6 7 8
`

RST

15

18 Y1 11.0592MHz

XT2

CR2

16
` 17

19
20 40

XT1
GND Vcc

COM

18 19 20

+5V

LPTDR (0378h)
DB7

21
22 23 24

9 10 11 12 13

Data In

Clock In

6 7 8

MOSI (P15) MISO (P16) SCK (P16)

D1
Data Out

LPTSR (0379h)
SR4

25

0V

P10

1001x: GM : 02-05

Figure-3.1: Connection Diagram between LPT Port and 40-pin ZIF Socket

As indicated in the diagram of Fig-3.1, the pins of the 40-pin ZIF socket (assuming that the ZIF contains 89S51 MCU) are permanently connected with the indicated pins of the LPT port of the IBMPC.

The P10-pin of the 89S51 is directly connected with the LED, D1. The internal pullup resistor of P10 limits the current. The LED (D1) would be helpful to monitor the status of the functionality of programs.

3.2 Connection Diagram Between 89S51, J1 and J2 Edge Connectors


D1
+5V

J1
0V

U1: 40 Pin ZIF (89S51)


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
Y1

J2
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

P10 P11 P12 P13 P14 P15-MOSI P16-MISO P17-SCK RST P30-RxD P31-TxD P32-INT0/ P33-INT1/ P34-T0/ P35-T1/ P36-WR/ P37-RD/ XT2 XT1 GND

Vcc AD0-P00 AD1-P01 AD2-P02 AD3-P03 AD4-P04 AD5-P05 AD6-P06 AD7-P07 Vpp-EA/ PROG/-ALE PSEN/ A15-P27 A14-P26 A13-P25 A12-P24 A11-P23 A10-P22 A9-P21 A8-P20

20

1001

Figure-3.2: Connection Diagram between 89S51, J1 and J2 Edge Connectors

The power up reset circuit for the 89S51 is not included in the CKIT-06. Therefore: i. ii. After storing the program codes in the code memory (the flash) using the LPT port, the RST-pin could be activated MCU using the LPT port and software instructions. The following reset circuits could be built on the breadboard of the CKIT and be connected with the appropriate reset pins of the MCUs. The LPT cable should be open.
+5V + 100uF

K1
4k7 0V

Pin-9 of 89S51

3.3 Connection Diagram Between 89S8252, J1 and J2 Edge Connectors


D1
J1
0V
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

+5V

U1: 40 Pin ZIF (89S8252)


P10-T2 P11-T2EX P12 P13 P14-SS/ P15-MOSI P16-MISO P17-SCK RST P30-RxD P31-TxD P32-INT0/ P33-INT1/ P34-T0/ P35-T1/ P36-WR / P37-RD/ XT2 XT1 GND Vcc AD0-P00 AD1-P01 AD2-P02 AD3-P03 AD4-P04 AD5-P05 AD6-P06 AD7-P07 Vpp-EA/ PROG/-ALE PSEN/ A15-P27 A14-P26 A13-P25 A12-P24 A11-P23 A10-P22 A9-P21 A8-P20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

J2
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

Y1

20

1004

Figure-3.3: Connection Diagram between 89S8252, J1 and J2 Edge Connectors

After storing program codes within the MCU, the following reset circuitry (same as for 89S51) should be included. The EA/-pin should also be tied to LH. And then activate the reset switch to run the stored program. Connect the following reset the with the reset pin of the 89S8252 microcontroller.
+5V

+ 100uF
Pin-9 of 89S8252

K1

4k7 0V

Quick Functional Check of CKIT-06

4.1 Familiarization with ASM51 Assembler and Quick Function Check of the 89S51 CISC (Compact Instruction Set Controller) Microcontroller
In this functional check, we would store a small program inside the code memory of the 89S51 microcontroller. When the program is executed, the LED-D1 connected at the P10-pin would start blinking. Let us now carry out the following steps:
1. 2. 3. 4. 5. Read the diagram of Fig-3.1 and 3.2 for the electrical connections between the LPT port, 89S51 MCU and the J1 and the J2 edge connectors of the CKIT. Copy the contents of the folder CKIT of the CD that has been supplied with CKIT in the hard disk in the path: C:\CKIT Boot the IBMPC in pure DOS mode and then enter into the path: c:\ckit. Type EDIT at the DOS prompt and then hit the carriage return. A screen would appear called DOS screen. Now, type the following program statements and save it as: c:\ckit\p41.asm. This program could be found in the CD that accompanies the CKIT.

$MOD51 ; this file includes the definitions of various symbolic names ; you may open the mode51 file and read the contents ; you may open the asm51.doc file to read about the asm51 assembler $OBJECT(c:\CKIT\p41.OBJ) ; P41.OBJ file contains the Intel-Hex formatted code ; for the Binary code of the program P41.asm. ; read the CKIT manual for the detailed structure of the Intel-Hex ; formatted file. ORG DB DB DB ORG MOV MOV L1: SETB LCALL LCALL LCALL LCALL LCALL CLR LCALL LCALL LCALL LCALL LCALL LJMP TDELAY: MOV AGN1: MOV AGN2: DJNZ DJNZ RET END 0000H 02H ; after power up the MCU looks for instruction at 0000H 00H 10H ; the program execution now begins at: 0010H: 0010H SP, #70H ; stack pointer set. See MCU data structure PSW, #00H ; Bank-0 Selection. Fig-21 of the PSPKIT Manual P1.0 ; TDELAY ; TDELAY TDELAY ; TDELAY ; TDELAY P1.0 ; TDELAY ; TDELAY TDELAY ; TDELAY TDELAY ; L1 ; R5, #0FFH R6, #0FFH R6, AGN2 R5, AGN1 LED1 is ON calling Time Delay calling Time Delay calling Time Delay LED1 is OFF calling Time Delay calling Time Delay calling Time Delay repeat

6. 7.

Save the program and exit to DOS. Now convert the P41.asm program into P41.obj file. The p41.obj file would automatically be saved in the path: c:\ckit\p41.obj as per declaration with the include directive $ at the top of the program. Procedures: i. Type ASM51 and hit the carriage return. ii. Type C:\ckit\p41.asm in response to: Source File drive and name [.ASM]: iii. The program would terminate to DOS prompt with zero errors. Now convert the P41.obj program into P41.bin. Why? The P41.obj program is an Intel-Hex formatted file, which is suitable to transfer over COM port of the IBMPC. The ISP programming technique of the 89S51 demands that the program codes should be in the Binary format. The P41.obj file would now be converted into P41.bin using the EPW512.exe program (a third party program being used freely with no obligation). The procedures are: i. ii. iii. iv. v. vi. vii. Type EPW512 at the DOS prompt. A DOS menu would appear. Follow the menu and load the file: c:\ckit\p41.obj Type I in response of: < B > in, < I > ntel Hex, < M > otorola S Hex Type 0000 in response of: File start seg. (0000) : Type 2 in response of: Unused bytes will be < 1 > 00, < 2 > FF, < 3 > Dont care: Note down the end address as: 0047 (it may vary program to program) Follow the menu.

8.

9. 10. 11. 12. 13.

Follow the menu and save the converted file as: c:\ckit\p41.bin. Be careful to type the correct start and end addresses. Quit the DOS menu and exit to DOS prompt. Connect the LPT cable with the LPT port of the IBMPC. The EA/-pin is already tied with +5V Build the following reset circuit on the breadboard and connect it with the RST pin (pin-9) of the 89S51 +5V MCU. You may omit this circuit if you wish.
+ 100uF 4k7 0V

K1

Pin-9 of 89S51

14. 15.

Apply power to the CKIT. Let us now store the codes of the program p41.bin on to the code memory of the 89S51 MCU. The procedures are: i. At the DOS prompt, type 89S51 and hit carriage return. ii. Follow the menu iii. Erase the Chip. Write the chip. [type small letter y for Yes and n for No]. Type: Capital letters for digits. Execute the downloaded program by executing P89s51.exe from the path: C:\ckita The LED-D1 should statrt5 blinking.

16. 17. 18.

Example Programs and Interfacing Circuits

5.1 Functionality Check of INT0/-pin of 89S51 MCU of the CKIT-06A In this example, we configure Pin-12 of the MCU to operate as Interrupt Input Line.
Interrupting Device (K1) 12

Inernal Pullup (5k)

+5V

cngm et\ch8n\8-9n

EA=1

EX0=1 IRQ : 0003H

INT0/ (P32)
SWA

0 1

IT0=0,1

IE0

SWB

SW C

IE1 IT1 IE0 IT0

TCON (88H)
1100

EX0

EA

IE (A8H)

Figure-5.1: Structure of the INT0/ Interrupt Pin of 89S51

Working Principles:
a. b. c. d. e. f. Assume that the SWA is at position 1, which could be done by writing LH at IT0-bit of the TCON register. When a High-to-Low going signal appears at Pin-12, the IE0-bit of TCON register is set to LH. Assume that the switches SWB and SWC are closed. These switches could be opened and closed as required by manipulating the relevant bit of the IE register. The MCU would be automatically interrupted. The MCU would suspend the mainline program and would jump to the Interrupt Service Routine due to INTO (ISURINT0) at the address: 0003H. This is known as Vectored Interrupt. If the switches SWB and SWA are opened, then the user can still detect the occurrence of an activating signal at Pin-12 by reading the IE0-bit and the user can deliver the interrupt services. This is known as Polling Interrupt.

Functional Check:
a. b. c.

Mainline Program (MLP) located at: 0000H 0010H. Output: The LED-D1 would be continuously blinking. The ISURINTO program is located at: 0003H 0030H Output: The LEDD1 would blink for 5 times with a long gap in between them. At the end of the execution of ISURINT0, the MLP would normally be resumed.

Procedures:
a. b. c. d. e. f. g. h. Use the LPT port and store the program C:\CKITA\P51.bin into the 89S51 MCU. Run the downloaded program either by activating the LPT port or the RST switch. The MLP should start normally. After a while, take apiece of hookup wire and gently touch Pin-12 to ground potential. The MLP should be suspended. The ISURINT0 should start and comes to an end. The MLP should resume. Repeat the process.

5.2 Functionality Check of Pin-14 as External Event Counter In this example, we configure Pin-14 of the MCU to operate as an External Event Counter. The Pin-14 would receive external LH-to-LL transitions and the internal Counter-0 would count them.
18 XT2
OSC

1/12

f1=921.6KHz

Counter-0
SW2 SW1

19 XT1 Y1 11.0592 MHz

Address:8AH
TL0
TF0

C 0-T0/=1

14

P34

TH0 (8-bit)
534b

Address:8C H

Figure-5.2: Structure of Counter-0 of MCU in Mode-2 (8-Bit Auto Reload) Operation

Working Principles:
1. Timer/Counter-0 of MCU operates as Counter-0 when the internal switch SW1 is connected to Pin14 and the mode of operation is configured properly with the help of TMOD register. We say that the there is a Timer-0 operation when the SW1 is internally connected with the internal oscillator signal. The open/close condition of SW2 is controlled by TCON register. Initially both TL0 and TH0 are loaded with some user defined values. The counter-0 counts an external event and increments the TL0. And when the content of TL0 rolls over from all 1s to all 0s, the TF0-bit of the TCON register is set to LH. At the same time, the TL0 is automatically loaded with the content of TH0 register. A user can poll the TF0-bit to know that the counter has been filed up. If interrupt structure is enabled then the setting of the TF0-bit can be brought to the attention of the MCU through vectored interrupt.

2. 3.

4.

Functional Check:
We intend to count the negative zero crossing points of the ac line frequency. The counter-0 would be employed to count 50 (fifty) ve crossing points, which would amount to 1-sec time delay. After each 1-sec time delay, the MCU can drive an external 7-segment display device to indicate amount of time elapsed.

Procedures:
1. 2. Refer to Fig-5.3, build the following zero crossing circuit and the 7-segment display unit on the breadboard of the CKIT. Download and execute program: C:\CKITA\P52.bin. The DP0 would count the time and be advancing by 1-sec.
+5V

+5V
20m S

D3 (on C KIT)

MCU
14 T0/(P34)

8x560R
P07

DP0
p

R1 : 1k5

R2 1k5

Q1: C 828
P00
0V

P20

a cc

1003x : GM : 03-05

Figure-5.3: Circuit to Detect and Display 1-sec Time Tick from AC Line Frequency

5.3 Functionality Check of P30, P31 Pins as Serial Ports


In this example, we configure Pin-10 (P30) and Pin-11 (P31) to operate as serial communication port. The functionality of the serial port would be verified by connecting the MCU with the IBMPC using a 9-pin serial cable as per circuit diagram of Fig-5.4. 4800-Bd, NP, -SPB, 1-STB,8-Ch.
CKIT-06A
U1: 89S51 Microcontroller
Address: 99H
Rx Buffer

RS<-->TTL
U2 : MAX232
RXTTL
RxD

9-Pin Cable
4 5

IBMPC
Pins
1

C2
+ 1uF
TXRS

Holes
1 6 2 7

CD/ DSR/

10
P30

12 R1OU T

R1IN 13

2 7

RXRS
RTS/

+5V

Address: 99H
Tx Buffer

TxD

TXTTL
11

8x560R
DP0 p

11 T1IN

T1OUT 14

Port-3 : B0H
P07 P00
P30 P31 P32 P33 P34 P35 P36 P37

P31

+ 1uF

1 3

3
8

TXRS

cc

P2.0

C1 12 13 14 15 16 17

16 2 6

C3 RXRS
1uF + C4 1uF +
15 0V

CTS/ DTR/

4 9 5

4 9

+5V
5

COM

0V
753x : GM : 10-05

GND 15

VCC 16

+5V

COM1 Port of IBMPC

Figure-5.4: Connection Setup to Check Functionality of Serial Port of MCU

Setup Procedures:
1. 2. 3. 4. Place the zero crossing circuitry and the 7-segment display device (DP0) on the breadboard and connect it with the MCU as per diagram of Fig-5.4. Place the MAX232 chip (RS TTL Converter) on the breadboard and connect it with the MCU as per diagram of Fig-5.4. Also install the capacitors C1-C4 in correct polarity as per diagram of Fig-5.4. Obtain a 9-pin serial port cable and short the lines: 7,8 and 1,4,6 as per circuit diagram of Fig-5.4. Attach the hole-side of the 9-pin connector with the COM1 port of the IBMPC. The other side of the 9pin cable should be connected with the MAX232 chip as per circuit diagram of Fig-5.4.

Functional Check:
1. 2. 3. 4. Boot the IBMPC in the pure DOS mode and enter into path: C:\CKITA Download (write) the program C:\CKITA\P53.bin into the MCU and execute the program. From the DOS prompt of the PC, execute the program: c:\CKITA\SERCHK.EXE. Press any key from 0-9 in the keyboard of IBMPC and it would be instantly displayed on DP0 of the trainer.

Working Principles:
1. The MCU keeps polling the receiver port and looks for the arrival of a character. The ASCII code of the character is read from the receiver buffer. It is converted to CC-code and is then displayed on DP0. The MCU also sends the received character back to the IBMPC. The PC displays the character on CRT. The IBMPC receives the ASCII code from the buffer and displays them on the CRT monitor. The IBMPC keeps polling the keyboard and whenever a close key is found, the corresponding ASCII code is instantly transmitted to the MCU.

3. 4.

10

5.4 Interfacing 2x16 Character LCD with MCU as a Bus-operated Device


Let us interface a 2x16 character LCD unit with the 89S51 MCU of the CKIT-06A. The LCD would be accessed as a Bus Operated device. In a bus-operated device, the data read/write operations are carried out using the bus signals (Address, Data and Control), which are automatically generated at the time the instructions are executed. The disadvantage of a busoperated system is that there is wastage of Port Lines of the MCU, which cannot be tolerated in a Single Chip solution. In Section-5.5, we would operate the LCD device as a port-operated device in which the bus-signals (Address, Data and Control) are generated artificially using instructions. The advantage of port-operated device is that there is a savings of many port lines, which could be easily used for some other purposes.

89S51

U14
DP0
DP10

2x16 Charracter LCD


DPF
DP1F

D7 D6 D5 D4 D3 D2 D1 D0

R-W /

D-I/

VA

Vdd

Vss L+ L-

14 13 12 11 10 9 8 7

A9(P21) A8(P20) 0V +5V 0V

R10:1k5

Viewing Angle

A14(P27)
A10(P22) 0V R D/(P17) W R/(P16)

6 5 4 3 Y2/ 2 Y1/ 1 Y0/

13 14 15

2 1

LC DIR: 4000H LC DSR : 4200H LC DDR : 4100H LC DCR : 4300H


3

U15: 74LS138

U16: 7486

747x-05:GM

Figure-5.5: Interfacing Circuit for Bus-operated LCD Device

Setup:
1. 2. 3. 4. 5. Refer to Fig-5.5 and place the device U14 (LCD), U15 (74LS138) and U15 (7486) on the breadboard of the CKIT and connect them together along with 89S51 MCU using the hookup wires. Use LPT and then store the program c:\ckitA\P54a.bin into 89S51. Execute the program P55a.bin, the LCD should show character 3 at DP0 position of 1st Line. Erase the MCU and store c:\ckita\p54b.bin. Execute the program, the LCD shows: 2 at DP2 position of the 2nd line. Erase and store the program C:\CKITA\P54c.bin. Execute the program. The LCD shows the following message:

Karighar R&D C Tel: 7161846

11

To See at Dark
0V

AD7/P07 AD6/P06 AD5/P05 AD4/P04 AD3/P03 AD2/P02 AD1/P01 AD0/P00

15 16
+5

K1

5.5 Interfacing 2x16 Character LCD with MCU as a Port-operated Device (8-Bit Data)
Let us interface a 2x16 character LCD unit with the 89S51 MCU of the CKIT-06A. The LCD would be accessed as a Bus Operated device. In a bus-operated device, the data read/write operations are carried out using the bus signals (Address, Data and Control), which are automatically generated at the time the instructions are executed. The disadvantage of a busoperated system is that there is wastage of Port Lines of the MCU, which cannot be tolerated in a Single Chip solution. In Section-5.5, we would operate the LCD device as a port-operated device in which the bus-signals (Address, Data and Control) are generated artificially using instructions. The advantage of port-operated device is that there is a savings of many port lines, which could be easily used for some other purposes.

89S51

U14
DP0
DP10

2x16 Charracter LCD


DPF
DP1F

D7 D6 D5 D4 D3 D2 D1 D0

R-W /

D-I/

VA

Vdd

Vss L+ L-

14 13 12 11 10 9 8 7

A9(P21) A8(P20) 0V +5V 0V

R10:1k5

Viewing Angle

8x4k7 +5V
A10(P22)

747y : 05:GM

Figure-5.6: Interfacing Circuit for Port-operated Device (8-Bit Data Line)

Setup:
1. 2. 3. 4. 5. Refer to Fig-5.6 and place the device U14 (LCD) and resistor network RN1 on the breadboard of the CKIT and connect them together along with 89S51 MCU using the hookup wires. Use LPT and then store the program c:\ckitA\P55a.bin into 89S51. Execute the program P55a.bin, the LCD should show character 7 at DP0 position of 1st Line. Erase the MCU and store c:\ckita\p55b.bin. Execute the program, the LCD shows: A at DP2 position of the 2nd line. Erase and store the program C:\CKITA\P55c.bin. Execute the program. The LCD shows the following message:

Karighar R&D C Tel: 7161846


6. The readers may study program p55c.asm in consultation with the data sheet-timing diagram of LCD.

12

To See at Dark
0V

AD7/P07 AD6/P06 AD5/P05 AD4/P04 AD3/P03 AD2/P02 AD1/P01 AD0/P00

15 16
+5

K1

5.6 Interfacing 2x16 Character LCD with MCU as a Port-operated Device (4-Bit Data)
89S51
U14
DP0
DP10

2x16 Charracter LCD


DPF
DP1F

D7 D6 D5 D4 D3 D2 D1 D0

R-W /

D-I/

VA

Vdd

Vss L+ L-

14 13 12 11 10 9 8 7

4x4k7
A9(P21) A8(P20) 0V +5V 0V

+5V
R10:1k5
Viewing Angle

A10(P22)

748y : 06:GM

Figure-5.7: Interfacing Circuit for Port-operated Device (4-Bit Data Line)

Setup:
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Place the LCD and RN1 on the breadboard of the CKIT. Use hookup wire and connect the LCD and RN1 with the 89S51 MCU as per circuit diagram of Fig-5.7. Store the program c:\ckita\p56a.bin into the MCU and execute it. The LCD should shoe character 7 at DP0 position of the 1st line. Erase the chip and then store program p56b.bin. Execute the program p56b.bin. The LCD should show the character C at DP2 position of the 2nd line. Erase the MCU. Store the program c:\ckita\p56c.bin. Execute the program: C:\ckita\p56c.bin. The LCD should show the following message on the display:

Karighar R&D C Tel: 7161846

13

To See at Dark
0V

AD7/P07 AD6/P06 AD5/P05 AD4/P04

15 16
+5

K1

5.7 Interfacing 7-Segment Display Devices and Walking 1s Keyboard using 8279 Controller In any microcomputer system, the display unit and the keyboard are the two most important IO devices. The display is usually built using 7-segment display devices and the keyboard is made using PCB mountable ON/OFF keys. The 8279 are a MPU/MCU bus compatible versatile IO controller that allows interfacing both the 7-sement display devices and the ON/OFF keys. However, in MCU applications, the display and the keyboard are driven using the built-in port lines, as we will find in Section-5.8.
89S51
AD7/P07 D7 D6 D5 D4` D3 D2 D1 D0

U12: 8279
A3 A2 A1 A0 B3 B2 B1 B0 h g f e d c b a

DP0

DP7

DP8

DPF

AD0/P00

cc0

cc7

cc8

ccF

S7/

En/ C B A S0/

S7/

A14(P27) A8(P21)

CS/ A (C -D/)

ALE

CLK

SL3 SL2 Sl1 SL0

U13: 74138

U14: 74138

U15: 74138
A B C
IRQ
0V RST

R L0 R L1 R L2 R L3 R L4 R L5 R L6 R L7

K00

K07

Figure-5.8: 8279-Driven 7-Segment Display Unit and Keyboard

Setup:
1. 2. 3. 4. Consult data sheets for 8279, 74138 to get their pin numbers and signal names. Place the U12, U13, U14, U15 , CC-type 7-Segment devices and the keyboard on the breadboard. use hookup wire and connect the devices of the breadboard with the 89S51 MCU as per circuit diagram of Fig-5.8. Store the program C:\ckita\p57a.bin into the MCU and execute it. The display should the changing pattern of: blank, 0, 1, 2, 3,,E,F , ., 0, 1.. Erase the chip and then store the program c:\ckita\p57b.bin. Execute the program. Press the keys and find that the DP0DP1 positions show the Scan Code of the pressed down key.

5. 6.

14

En C B A S0/
1200: Gm : 03-06

W R/(P36) R D/(P37)

WR/ RD/

S0/

S7/

5.8 Interfacing 7-Segment Display Devices and Walking 1s Keyboard using MCU Port Lines
+5V 8x4k7

89S51
P07

DP0
h g f e d c b a
cc0

DP7

DP8

DPF

P00

cc7

cc8

ccF

S0/

P23 P22 P21 P20 P24 P25 P26

U13: 74138
P10 P11 K00

D C B A

U12: 74154

K07

P17 1200x: Gm : 03-06

Figure-5.9: Port Line Driven 7-Segment Display Unit and Keyboard

Setup:
1. 2. 3. 4. Consult data sheets for 8279, 74154 and 74138 to get their pin numbers and signal names. Place the U12, U13 and CC-type 7-Segment devices and the keyboard on the breadboard. Use hookup wire and connect the devices of the breadboard with the 89S51 MCU as per circuit diagram of Fig-5.8. Store the program C:\ckita\p58a.bin into the MCU and execute it. The display should the changing pattern of: blank, 0, 1, 2, 3,,E,F , ., 0, 1.. Erase the chip and then store the program c:\ckita\p58b.bin. Execute the program. Press the keys and find that the DP0DP1 positions show the Scan Code of the pressed down key.

5. 6.

15

SF/

A B C

S0/

S7/

5.9 Generation of PWM (Pulse Width Modulated) Signal using Port-operated 8253
MCU
ALE 30

ALE of 8951 : 1.10592MHz

PIT
1 2 3 4 5 6 7 8 21 20 19 23 22 24 12

50Hz Line
GT0 C K0 OT0 GT1 C K1 OT1 GT2 C K2 OT2
11 9 10 14 15 12 16 18 17

P07 P06 P05 P04 P03 P02 P01 P00


P23 P21 P20 P25 P24

32 33 34 35 36 37 38 39
24 22 21 26 25

D7 D6 D5 D4 D3 D2 D1 D0
C S/ A1 A0 WR/ R D/ Vcc GND

CT0 (00B) CT1 (01B) CT2 (02B)


CT2 (03H)

C h1
y

One Shot

x 20m S

C h2

+5V

Oscilloscoipe

R 2: 1k5 D3 R 1: 1k5
Q1 : C 828
0V

Vcc 40 GND 20

U1 : 89S51

GM: 03-05: 744x

8253

C 1: 104

Figure-5.10: Generation of PWM Signal using Port-operated 8253 Programmable Timer

Theory: Pulse Width Modulation means Changing the ON Time (Mark) Width of a Pulse. In Fig-5.10, let us see that the period of the signal of Ch-2 of the oscilloscope is fixed and it is 20mS. But the OFF Time (Space), x is variable and hence the ON Time (Mark) y is also variable. Here, we have a pulse of variable width, which could be used (and of course after suitable conditioning) to control the rotating speed of a fan, the luminescence of a dim light and so on. In this example, we will learn and practice the procedures of generating a PWM signal using the Timer-0 of the 8253. Brief Architecture of 8253: There are 3 identical timers/counters inside the 8253 chips, which could be configured to operate in various mode of operation. In this example, we would initialize Timer-0 as a Programmable One-shot to produce a PWM signal similar to one as shown in Fig-5.10. A square wave signal (SWS) of 20mS duration is obtained from the ac line frequency using a Zero Crossing Circuit consisting of D3, C1, R1, R2 and Q1. When a rising edge of the SWS arrives at the GATE0-pin of Timer-0, the OUT0-pin immediately assumes LL state and remains Low until the content of the internal Counter-0 is emptied. Here, we see that a PWM signal could be obtained by writing variable data inside the 16-bit Counter-0 of the 8253. The readers are referred to data sheet for the detailed study of the architecture and programming of the 8253. Setup:
1. Gently solder a piece of wire with the anode of the D3 of the CKIT-06A. Place the components R1, R2 and Q1 on the breadboard and connect them together using hookup wires as per circuit diagram of Fig-5.10. This circuit is known as Zero Crossing Detector (ZCD). Place an 8253 chip on the breadboard and connect it various pins with the ZCD and the MCU of CKIT. Connect an oscilloscope with the 8253 as per directions of the diagram of Fig-5.10. Store the program c:\ckita\p59.bin inside the 89S51 MCU and execute it. Observe in the oscilloscope that the width of the oneshot pulse is continuously changing. Open the program C:\CKITA\P59.ASM and study it with the assistance of a teacher.

2. 3. 4. 5. 6.

7.

Operate Timer-1 as a 20KHz square wave generator.

16

5.10 Interfacing Multiple 8253 as Bus-operated Devices


In Section-5.9, we operated a single 8253 as a port-operated device in which the address, data and control signals for the 8253 have been generated artificially using the port lines of the MCU. In a bus-operated device, the address, data and control (RD/ and WR/) signals are automatically asserted by the MCU concurrently with the execution of program instructions.
MCU
ALE 30

ALE of 8951 : 1.10592MHz

PIT-1
1 2 3 4 5 6 7 8 21 20 19 23 22 24 12

50Hz Line
11 9 10 14 15 12 16 18 17

P07 P06 P05 P04 P03 P02 P01 P00 A15(P27) A14(P27) A9(P21) A8(P20)
WR /(P37) R D/(P36)

32 33 34 35 36 37 38 39 28 27 22 21
17 16

D7 D6 D5 D4 D3 D2 D1 D0
C S/ A1 A0

GT0 CT0 C K0 (8000H) OT0 GT1 CT1 C K1 (8100H) OT1 GT2 CT2 C K2 (8200H) OT2

C h1
y

One Shot

x 20m S

C h2

+5V

Oscilloscoipe

WR/ R D/ (8300H) Vcc GND

CT2

R 2: 1k5 D3 R 1: 1k5
Q1 : C 828
0V

Vcc 40 GND 20

U2: 8253
PIT-2
1 2 3 4 5 6 7 8 21 20 19 23 22
24 12

C 1: 104

D7 D6 D5 D4 D3 D2 D1 D0 C S/ A1 A0

GT0 CT0 C K0 (4000H) OT0 GT1 CT1 C K1 (4100H) OT1 GT2 CT2 C K2 (4200H) OT2

11 9 10 14 15 12 16 18 17

WR/ R D/ (4300H) Vcc GND

CT2

U1 : 89S51

U3: 8253

Figure-5.11: Interfacing Multiple 8253 as Bus-operated Devices

Working Principles: The 8253 devices are interfaced with the 89S51 MCU as bus-operated devices. The U2 and U3 are assigned the following addresses for their various internal registers:
Register Name Counter-0 Counter-1 Counter-2 Mode Register Address for U1 8000H 8100H 8200H 8300H Address for U2 4000H 4100H 4200H 4300H

When the MCU asserts address 8000H on the bus, the A15-pin assumes LH and A14-pin assumes LL. The device U1 is selected and U2 is deselected. The opposite occurs at address 4000H

17

5.11 Converting 6-Digit BCD-to-BINary


In many situations relating to instrument design such as Weighing Machine, we would be required to convert BCD number into Binary and vice versa. The readers may study the Fig-63.10 for the applications of BCD2BIN, BIN2BCD and BMULT subroutines. In this section we would practice the procedures of converting 6-digit BCD number into equivalent BINary number. The input (000000 999999) and the output (000000H 0F423FH) numbers would be displayed on a LCD display. Setup:
1. 2. Install a 2x16 character LCD panel on the breadboard and connect it with the MCU of the CKIT-06A as per circuit diagram of Fig-5.7. Open the program c:\ckita\p518.asm and find that the input BCD and output BIN values are associated with RAM locations as follows: L1X: MOV 54H, #12H ; Input BCD Higher Byte MOV 53H, #34H ; next Byte of BCD MOV 52H, #56H ; lowest byte of BCD L2x: MOV 48H, #00H ; to hold Higher Byte of BINary MOV 47H, #00H ; to hold next byte of BINary MOV 46H, #00H ; to hold lower byte of BINary Store the program C:\CKITA\p518.bin into MCU and execute it. The as: InpBCD : 123456 OtpBIN : 01E240 4. Change the input BCD to 999999. Assemble the program P518.asm and convert to P518.bin. Store the program P518.bin into MCU and execute it. The LCD should show as: InpBCD : 999999 OtpBIN : 0F423F

3.

Working Principles of P518.asm


512

Input BCD (000000-999999)


Internal RAM Input BCD 54 x5x4 53 x3x2 x1x0 52
Data Order M SDigits LSDigits

Calling at: ............. SDBCD2BIN

Ouput BINar y (000000H-0F423FH)


Internal RAM Input BC D 48 y5y4 y3y2 47 46 y1y0
Data Order MSDigits LSDigits

Figure-5.12: Data Structure for Converting Six Digit BCD Number into Binary 1. 2. 3. 4. 5. 6. Extract x0 in the form of 0X0 from x1x0 and get (00H 09H) taking positional weight as: 01H for 1. Update output binary table: 48 - 46 Extract x1 in the form of 0x1 from x1x0 and get (00H 5AH) taking positional weight as: 0AH for 10. Update output binary table : 48 - 46. Extract x2 in the form of 0X2 from xx3x2 and get (0000H 0384H) taking positional weight as: 64H for 100. Update output binary table: 48 - 46 Extract x3 in the form of 0x3 from x3x2 and get (0000H 2328H) taking positional weight as: 03E8H for 1000. Update output binary table : 48 - 46. Extract x4 in the form of 0X4 from x5x4 and get (000000H 015F90H) taking positional weight as: 2710H for 10000H. Update output binary table: 48 - 46 Extract x5 in the form of 0x5 from x5x4 and get (000000H 0DBBA0HH) taking positional weight as: 0186A0H for 100000. Update output binary table : 48 - 46.

18

5.12 Converting 40-Bit BINary Number into Equivalent BCD using Horner Rule
Setup:
1. 2. Install a 2x16 character LCD panel on the breadboard and connect it with the MCU of the CKIT-06A as per circuit diagram of Fig-5.7. Open the program c:\ckita\p519.asm and find that the input BIN and output BCD values are associated with RAM locations as follows: LOAD: BIN2BCD: MOV 68H, #12H ; Input BIN Hbyte MOV 5DH, #00H ; to hold BCD HByte MOV 67H, #34H ; MOV 5CH, #00H MOV 66H, #56H ; MOV 5BH, #00H MOV 65H, #78H MOV 5AH, #00H MOV 64H, #90H ; Input BIN Lbyte MOV 59H, #00H MOV 58H, #00H ; to hold BCD LByte Store the program C:\CKITA\p519.bin into MCU and execute it. The as: Bin: 1234567890 Bcd: 078187493520 4. Change the input BIN to FFFFFFFF. Assemble the program P519.asm and convert to P519.bin. Store the program P51.bin into MCU and execute it. The LCD should show as: Bin: FFFFFFFFFF Bcd: 099511627775

3.

Working Principles:
Input BINary (0000000000H - FFFFFFFFH)
Internal RAM Input BCD 68 x9x8 67 x7x6 66 x5x4 65 x3x2 x1x0 64
39
68H 66H 67H 32 31 24 23

Calling at: .............

Ouput BCD (000000000000- 099511627775)

Data Order M SDigits

LSDigits
15
65H

16

64H

Internal RAM Input BC D Data Order 5D MSDigits y11y10 5C y9y8 BIN2BCD y7y6 5B y5y4 5A y3y2 59 LSDigits y1y0 58 BIN2BCD 5DH 5C H 59H 58H 5BH 5AH 0 0 2 1 8 7 6 5 4 3 11 10 9
Ouput: 12-Digits BCD Data

514x

Input : 40-Bit Binary Data

Figure-5.13 : Data Structure for 40-Bit Binary to BCD Conversion Input BINary Output BCD = b39b38,.,b1b0 = b39x239 + b38 x 238 + . + b1 x 21 + b0 x 20 = (((((( ((((b39)2 + b38)2 + + b3)2 + b2) 2 +b0

When we carefully observe the above expression while moving from right to left, we notice that the bit values (say b0) are always added with something, which is multiplied by 2. This feature is not seen for bit b39. To offer the same feature to the bit b39, we may rewrite the above expression as: Output BCD = (((((( ((((IBCDx2 + b39)2 + b38)2 + + b3)2 + b2) 2 +b0 Where, IBCD (Initial Partial BCD) is assigned the value of 00.

This expression is known as Horner Rule due to W.G. Horner, who used it in the year of 1819 (the original rule belongs to Isaac Newton in 1711) for algebraic simplification. This is a particular case of the generalpurpose polynomial of the form: A(x) = anxn + an-1xn-1 + ..+ a1x1+ a0 x0 Golam Mostafa (the author) of Ahsanullah University of Science and Technology (AUST), Dhaka for the 1st time in Bangladesh in the year of 1998, carried out the low-level implementation of the Horner Rule to convert a 32-bit BINary number into equivalent BCD number in connection with the design of Digital Weighing Machine using 8085/8086/8051 architectures.

19

5.13 16-Bit by 16-Bit Unsigned Binary Multiplication (BMULT)


Setup:
1. 2. Install a 2x16 character LCD panel on the breadboard and connect it with the MCU of the CKIT-06A as per circuit diagram of Fig-5.7. Open the program c:\ckita\p520.asm and find that the input and output numbers are associated with RAM locations as follows: INPUT_1: OUTPUT: MOV 59H, #78H ; Input1 Hbyte MOV 5FH, #00 ; to hold Output HByte MOV 58H, #56H ; Input1 LByte MOV 5EH, #00H MOV 5DH, #00H INPUT_2: MOV 5CH, #00H MOV 5BH, #12H ; Input2 Hbyte MOV 5AH, #34H ; Input2 LByte Store the program C:\CKITA\p520.bin into MCU and execute it. The as: Inputs: 7856,1234 Output: 088E7D78 4. Change the inputs to FFFFH and FFFFH. Assemble the program P520a.asm and convert to P520a.bin. Store the program P520a.bin into MCU and execute it. The LCD should show as: Inputs: FFFF,FFFF Output: FFFE0001

3.

Working Principles:
Input-2: Multiplicand (0000H - FFFFH)
Internal RAM Input BIN 5B x3x2 x1x0 5A

Calling at: .............

4B 4A
Ouput; Product (00000000H- FFFE0001H)
Internal RAM Input BCD Data Order 5F r7r6 MSDigits 5E r5r4 r3r2 5D r1r0 5C LSDigits

c3c2 c1c0

Data Order MSDigits LSDigits

BIN2BCD

Internal RAM Input BIN 59 y3y2 y1y0 58

Data Order MSDigits LSDigits

Input-1: Multiplier (0000H - FFFFH)


5BH x3x2 y3y2 59H 5AH x1x0 y1y0 58H

BMULT

Carry

Carry

Carry

X
519
519

519

5CH

5DH

5EH

5FH

47 46 45 44 43 42 41 40

r7''''r6'''' r5''''r4'''' r5'''r4''' r3'''r2''' r5''r4'' r3''r2'' r3'r2' r1'r0'

Figure-5.14: Data Structure to Compute 16-Bitx16-Bit Binary Multiplication


B-reg
xx

B-reg

x3x2 x1x0 y3y2 y1y0


r5''r4'' r5'''r4''' r3''r2'' r3'''r2'''
r3r2 c1c0 r1r0

: Multiplicand : Multiplier

MUL AB
yy

High Low 8-Bits 8-Bits

`r3'r2' r1'r0' = (x1x0) x (y1y0) : L1 = (x3x2) x (y1y0) : L2 = (x1x0) x (y3y2) : L3 = (x3x2) x (y3y2) :L4

A-reg

r7''''r6''''
r7r6

r5''''r4''''
r5r4 c3c2

A-reg

Figure-5.15: 8051 Register Model for BMULT

Figure-5.16: Computing Mechanism for BMULT

20

5.14 Performing m-Bit by n-Bit Division using GCR-Method on 8-Bit Machine


Introduction: There may be occasions where we might need to divide an m-bit (say 40-it, 00576E7BFFHH) number by an n-bit (say 32-bit, 19B24DE6H) number using an 8-bit architecture machine such as 8051. The author encountered such situation while developing a Prepaid KWH Meter using ADE7756/89S8252 devices. The energy measurement chip ADE7756 outputs a 40bit code, as a basic measure of energy while the 89S8252 is an 8-bit machine. To extract the quanta (nx0.01) kwh, the author had to find a way of dividing m-bit by n-bit without violating the allowable % error. The result is the GCR-Method (Count Residual method due to Golam Mostafa), whose working principle is explained briefly with the help of an experimentally verified example:
1. 2. 3. Assume 140w electric load is ON for 5-sec The 5-sec accumulated energy is: 576E7BFFH = 1466858495 = X Assume 40w load is ON 5-sec and accumulated energy is: 19A5516EH = 430264686 = Y Y1 = FF x FF x FF x 1A = 19B24DE6H = 431115750 % error = (Y-Y1)/Y = (430264686 431115757)/ (430264686) = 0.20% Quanta (nx0.01) kwh: = {(Reading of Step-2)/ (Reading of Step-3)} x {(0.01/36000) x (40x5)} = (X / Y1) x (0.01/B4H) = (X/FF) x (1/FF) x (1/FF) x (1/B4) x 0.01 kwh X/FF(z8) = q1 z9 1AH ;divider is Z8, remainder is named z9 and is saved in 1AH. : 57C642 - 41 q1/FF(z6) = q2 z7 1BH : 581E - 60 q2/FF(z4) = q3 z5 1CH : 58H 76H q3/B4(z2) = q4 z3 1DH : 00 B4H q4/1A = q5 z1 1EH ; : 00 1AH The quanta kwh is q5 The integrated Residual is: R = ((((z1) z2 + z3) z4 + z5) z6 + z7) Z8 + z9 = z1z2z4z6z8 + z3z4z6z8 + z5z6z8 + z7z8 + z9 For the given data of Step-4, we should have: q5 = quanta = 00H R = 00H + 56F907A8H + 751476H + 5FA0H + 41H = 576E7BFFH

4.

5.

6. 7.

8.

Binary Division Process using GCR-Method:


RAM Loc

T1

Con

Variable

RAM Loc

T2

Con

Variable

RAM Loc

T3

Con

Variable

Dividend
0D 0C 0B 0A 09 08

BDIV

x9x8 x7x6 x5x4 x3x2 x1x0 y1y0 Divisor

764x : GM : 10-05

17 16 15 14 13 12 11 10 0F 0E 0D

C9 C8 C7 C6 C5 C4 C3 C2 C1 C0 R

Quuotient as Counts in the form of: 0X (00 - 0F)

MERG
0D 0C 0B 0A 09 08 C9C8 C7C6 C5C4 C3C2 C1C0

Quuotient as Packed Hex

Residue

Figure-5.17: Data Structure for 40-Bit by 8-Bit Binary Division using GCR-Method

21

5.15 Read/Write with Data EEPROM of 89S8252 using Program Instructions


Looking at Fig-A.5, we find that the AT89S8252 MCU contains 2K Data EEPROM along with security bit. The DATA EEPROM occupies the space: 0000H 07FFH. A user may store System Confidential Data inside the data EEPROM and then set the security bit. Once the security bit is set, there is no way left to access the content of the data EEPROM using the Conventional Programmer or the ISP Port. This feature of the 89S8252 allows it for building Prepaid Energy Meter and the similar products. There are three ways of writing data inside the data EEPROM and these are:
1. 2. 3. Using conventional ROM Programmer putting the MCU OFF-line (not running). Using Program Instructions of the MCU itself keeping the MCU ON-line (running). Using ISP Port of the MCU keeping the chip OFF-line.

Writing into Data EEPROM using Program Instructions:


1. 2. 3. Install the AT89S8252 MCU on the CKIT-06A. Install the LCD on the breadboard of the CKIT as per circuit diagram of Fig-5.5. The LCD is an output device, which allows a user to monitor the input and output variables. Let us store the program C:\ckita\P522a.bin into the MCU and execute it. The program does the following: a. It writes 12H, 34H , 56H into locations 00EAH, 00EBH and 00ECH respectively. b. It reads back the locations 00EAH, 00EBH and 00ECH. c. The LCD shows as follows: Write: 12,34,56 Read: 12,34,56

Data Structure:
Immediate Data
56H 34H 12H
1201:GM :03-06

RAM Locations
0A 09 08

EEPROM Locations
00EC 00EB 00EA

RAM Locations
EC EB EA

LCD
Write:12,34,56 Read: 12,34,56

Figure-5.18: Data Structure for the Process of Writing into EEPROM of 89S8252 MCU

Working Principles:
Let us open the program c:\ckit\p522a.asm and we find that the writing process into the EEPROM of the 89S8252 MCU involves the following steps: 1. 2. The data 12H, 34H and 56H are written into RAM locations 08H 0AH for matter of convenience. However, the data could be directly written into the EEPROM. The rules for performing data read/write operations into the EEPROM of the MCU are clearly stated into the data sheets of the MCU. We follow the data sheets and copy the contents of RAM locations 08H-0AH into EEPROM locations 00EAH-00ECH. The 3-byte data are read back from the EEPROM and are saved into RAM locations EAH-ECH. The content of the locations EAH-ECH are displayed on the LCD to visualize that the data have been correctly written/retrieved into/from of the EEPROM of the MCU.

3. 4.

22

5.16 Functionality Check of the SPI (Serial Peripheral Interface) Port of 89S8252.
The four port pins (P1.4-P1.7) of the 89S8252 microcontroller could be configured to operate as a High Speed Synchronous Serial Peripheral Interface Port (SPI Port) to exchange data with compatible devices like:
i. ii. iii. Another 89S8252 microcontroller AT25040 Serial EEPROM ADE7756 Energy Measurement Chip (EMC)

In this section, we shall carry out a functional test of the SPI port of the 89S8252 MCU using an ADE7756 EMC chip. The set up consists of:
i. ii. iii. Placing the EMC chip on the breadboard of the CKIT-06A. Placing an 89S8252 MCU into the 40-pin socket of the CKIT And then connecting the 89S8252 and the ADE7756 as per circuit diagram of Fig-5.19.
89S8252 MCU
P14(SS/) 5 1

ADE7756 EMC
RST/

AVdd AVdd

3 2

+5V

0V

17

NC
MOSI(P15) MISO(P16) SCK(P17) 6 7 8 20 19 18

REFIN/REFOUT CS/ SAG/ IRQ/ ZX AGND CF DGND


DIN DOUT SCK

8 10

C2 0.1

+ C1 47uF

CLKOUT CLKIN

16 15

Y1 3.58M Hz

V2P V2N

7 6

Vol Channel

V1P V1N

4 5

Curr Channel

867 : GM : 03-05

Figure-5.19: Connection Diagram of MCU and EMC to Test SPI Port

To be sure that the SPI Port of the MCU is functioning properly, we shall perform data read/write operations on the Mode Register of the ADE7756 chip. The particulars of the Mode Register are:
i. ii. iii. Size Operation Mode Content after Power up Reset : 16-bit : Read and Write : 000CH

Reading Mode Register after Power UP: (c:\ckita\p523a.asm)


Store the binary codes of the program c:\ckita\p523a.bin into the 89S8252 MCU and execute it. The LCD should show: MR_Read:000CH

Writing 1234H (New Data) into Mode Register and Reading it Back (p523b.asm)
Download program p523b.bin and execute it. The LCD should show: MR_Read:1234H.

23

6.1 24-Hr Clock


Procedures:
1. Use telephone hook up wires and build the following circuit on the breadboard and connect them with the MCU as per diagram of Fig-6.1. i. 20mS TT (Time Tick) acquisition circuit from the line frequency ii. Time Display Unit using CC-type 7-Sement Display devices
+5V

DP0

DP1

DP2

DP3

DP4

DP5

8x560R
P07

HRS
p

M IN

SEC

+5V

P00
20m S

a cc

cc

cc

cc

cc

cc

D3 (on C KIT)

R1 : 1k5

R2 1k5

14

T0/(P34)

Q1: C 828
0V

P20 P21 P22 P23 P24 P25

1002x : GM : 03-05

MCU

Figure-6.1: CKIT-06A Based Circuit for the 24-Hr Clock System 2. 3. 4. 5. 6. A: Boot the PC in pure DOS mode and enter in the path: C:\CKITA Connect the CKIT with the PC using the LPT port. Store the program C:\CKITA\CK24HR.BIN in the code memory of the MCU. Execute the program: CK24HR. The 24-Hr Clock should run. If the clock does not work, adjust the time delay of the program. Data Structure

Design Analysis of the 24-Hr Clock System:

BCD_TIME
54 HRS

SUR: BCD2CC

CC_TIME
3F

3E

HR S

SUR: CCX7S

Display

53

MIN

BCD2CC Converter

3D 3C 3B 3A

MIN

52

SEC

SEC

1002x : GM : 03-05

Figure-6.2: Data Structure for 24-Hr Clock System

24

Development of Taximeter using PSPKIT


998X

Chapter-6.2
Vehicle

CKIT-06A

Taximeter

Mileage
Fare
Wheel
Gear Box

Km
Tk

Wheel

Waiting

Mn

Sensor

K W K TO ISP R ST : Karighar R&D : Bangladesh : CARMET-35LED W-CentreCentre : Bangladesh : Karighar ST ERR TST TST PA Y HRD T R&D

Figure-62.1: Conceptual Design Layout of Taximeter using CKIT-06A

62.1 Introduction The author has already designed, developed, built and field tested taximeters that are really commercially feasible. These taximeters are now on the road of getting in into the market. However, the author wishes that the interested readers should come forward with new ideas of building exciting taximeters having extraordinary features like remote telemetry, graphic display and etc. In the following pages, the author has presented the design concepts (both hardware and software) in modular forms. It is hoped that the readers would work on these modules and convert these into functional objects. At the end, all these modules could be integrated together to realize the Actual Taximeter. The University students may take it as theses/project works. And if so, the author may sometimes arrange a National Competition on Design of Microcontroller Based Digital Taximeter. 62.2 Brief Working Principles of CARMET Karighar R&D Center has, for the 1st time in Bangladesh, successfully designed, developed and prototyped a Metering System for the Taxi/CNG Cabs. The Company has given the name CARMET-35, which stands for Metering System for the Taxi Cars developed in the month of May of the year 2003. The design layout of the CARMET is depicted below in Fig-61.1. The CARMET is built around an 8x51 Microcontroller and an 8279 peripheral controller (Fig15.7). The 8x51 receives status signal of the Wheel (running or not) through a sensor, which is attached with the gearbox of the engine. It then computes the Distance, Fare and Waiting Time/Speed according to some predefined algorithm. The 8279 drive the Digital Fare Meter (DFM), Digital Distance Meter (DDM) and the Digital Wait Meter (DWM). The DFM, DDM and DWM have been built using CC-type 7-segment display devices. The DDM is incremented by 10m and the corresponding increase in the DFM is (for the CNG auto): a. Tk 1.00 for 200m distance traveled or b. Tk 1.00 for 2min waiting time or c. Tk 1.00 for the combination of distance and waiting making an equivalence of 200m.

25

Functions of the Front Panel Keys of the Taximeter


Front Panel Switch RST LED TST HRD Full Name Reset Led Test Hired Function To reset the meter To check that the 7Segment devices are OK To indicate that the Taxi is hired by a passenger. The fare field shows the flat fare. The meter is enabled to acquire distance, compute fare and waiting time. When the taxi arrives at the final destination, the taxi driver pushes this switch to freeze all the activities of the meter. The meter shows: Total Fare, Distance and Waiting Time. This switch is only active when the taxi is in the waiting state. K-Factor is the value that corresponds to the number of pulses that the speed transducer generated when it was first installed in the taximeter and the taxi was moved over 1Km distance (We used Highway Km Posts). With the help of the W TST switch, an inspector can time to time check the functional condition of the: : Meter itself, : Speed pulse carrying cable, : Tire (Excessive Wear, Not Fully inflated) In this test, the taxi is moved over known 1km distance and the transducer counts are recorded. To certify that the meter and the wheel of the vehicle are in operational condition, then the difference between W- and KFactors must be less than 1%. Pressing of the W-K Error switch would compute the percentage of errors and display it on the 7Segment display. The Vehicle Ordinances of GOB may time to time change the fare rates. ISP Programming Port allows updating new data within the meter without removing the MCU from the meter itself.

TO PAY

Journey Ends Make Payment

K TST

Examine K Factor of Meter

W TST

Determine W (Wheel) Factor of Taximeter

W-K ERR

Determine Error between W and K Factors

ISP

In System Programming Port

62.3

Taximeter Setup using CKIT-06A


M7
M4
+5V

1006: GM:02=2005

M1 B+
12V

M5

Fare

Distance

Waiting

Vcc

B-

0V Voltage R egulator

0V

GND

CS/

User Data

p,...,a

A D C

A D C
DR : 2000H CR: 2100H
SL3-SL0

M2

M3
P11 Q2 Q1/ INT0/ T0/

+5V 0V SPulse

DP0-DP5

DP6-DP11

DP12-DP15

Transducer

`Pulse Shaper & C onditioning Logic Generator

M8

INT1

IRQ

SL3-SL0

Decoders: 2x138

M9
6MHz

S2-SL0 S0/

Decoders:1x138

S1/ LED PAY K W-K

S2/

RL2 RL3
Microcontroller : 89S51

HRD W

Display Controller : 8279

M10

Keyboard

Figure-62.2: Taximeter Setup using PSPKI

26

62.4 Hardware Module-1 (Installing One-shot Circuit) Let us build the one-shot circuit of Fig-62.3 on the breadboard. It is left as an exercise for the readers to explore the working principles of the one-shot circuit.
+5V

R4 : 1k5 R3: 1k5

G F

INT1(P33)
IRQ

Q1 : C828
0V
S peed Pulses
A
+5V
R1=1K 6 C1= 0. 1u 7

D
C2= 1000uF 14

T0(P34)

+5V

R2=3k3

+ 15

11 CLR/ Q1 5 16 Vcc 10 9 K1 8

CLR/ Q2 13

Waiting
2 1

INT0(P32)

P1.1

Q1/ 12
GND

Q2/ 4
GND 0V 8
755x

1/2U1 74LS 123

Figure-62

2/2U1 74LS 123

C3 = 0.1uF

0V

Figure-62.3: One-shot Circuit to Condition the Speed Pulses

The One-shot Circuit: The package contains two pieces of identical re-triggerable one shots. The schematics and its connection with the transducer and microcontroller are shown in Fig-62.3. The duration of the transducer signal Sig varies with the speed of the vehicle (See Example62.1). To produce the same type of pulse out-of-Sig, the Sig information is pulse-shaped by passing it through the one shot circuit of 1/2Uz. The low-going edge of the signal Sig of the transducer fires the one shot 1/2U1 to produce a pulse of duration 0.15mS (=150uS). The inverted output of 1/2U1 is labeled as speed Pulses and is connected at T0(P34) terminal of the MCU Considering the CNG vehicle, the transducer produces about 1500-1700 pulses for 1km of distance traveled. As long as the wheel is turning, there is always presence of speed pulses at P34-pin. The MCU receives the pulses, calibrate these, computes the fare and then display the fare and the distance. The absence of the Speed Pulses (let us call it WTP) indicates that the wheel of the vehicle is not turning and the MCU must recognize that the Waiting Event has started. Is it always true? Not necessarily! It is true that there will be no speed pulse when the vehicle enters into Waiting State. But the absence of the speed pulse does not necessarily mean that the wheel of the vehicle is not turning. There may be occasions when the vehicle is moving at a very slow speed, and in that case, the occurrence of the speed pulse would also be very rare. Therefore, the event of the absence of the speed pulse cannot be used as an input to the MCU for triggering the Waiting Cycle. The valid waiting state of the vehicle is recognized in the following way: The speed pulse signals are converted to High Level Logic by re-triggering the 2/2U1 one shot by the falling edge of every speed pulse. The width of the Q2 output is chosen in such a way so

27

that the 2/2U1 always receives re-triggering pulses even at the acceptable slowest speed of the vehicle (See Example-62.1). This arrangement allows the MCU to recognize the valid waiting state or wheel turning state by monitoring the Logic State of the status signal at a the port pin, P1.1. If the vehicle moves at a speed, which is lower than the acceptable limit, there will be no speed pulse at the appropriate time to re-trigger the 2/2U1 one shot. As a result, the status signal will drop to Logic Low State and the MCU will be interrupted at the INT0 pin. The MCU will jump to the ISUBINT0 to start with the processing of the waiting cycle, which involves (i) counting of the current waiting time, (ii) fare calculation and updating by combining the current waiting time with the distance traveled (iii) monitoring the end of the waiting time.
Example-62.1: A CNG auto is moving at a speed of 10km/hour. The transducer of this particular CNG produces 1500 WTP for 1km of mileage. (a) Show that the CARMET will not trigger the waiting cycle. (b) Calculate the minimum speed of the CNG at which the waiting cycle of the meter will be activated. Solution: (a) Average WTP/Sec = (1500x10) / (60x60) = 4 WTP pulses. Assuming smooth speed of the CNG, the WTP separation time is = 0.25 S The 1st WTP will trigger the 2/2U1 to assert 1.5S pulse at Q2. The 2nd WTP will re-trigger the 2/2U1 at the elapse of only 0.25S of the 1st Q2 pulse. Because the 2/2U1 is a re-triggerable one shot, the Q2 will begin with a fresh 1.5S pulse. After 0.25S, the 3rd WTP arrives and so on Thus, we see that the Q2 will never drop to low state and the MCU will never execute the waiting cycle. (b) For the MCU to activate the waiting cycle, the Q2 of 2/2Uz must drop to low state. This requires a speed of the CNG, which fails to re-trigger the 2/2U1 at the appropriate time (before the expiry of the 1.5S width of the Q2). Therefore, the time separation between the two successive WTP pulses must be 1.5S. So, WTP/Sec = 0.7. Therefore the CNG speed is : (0.7x60x60) /1500 = 1.68km/hour.

62.5 Hardware Module-2 (Installing Speed Transducer) 1. Collect the speed transducer of Fig-62.4a and connect it with the one-shot circuit of the breadboard as per following specifications:
Transducer Terminals 1 (Red Color) 2 (Green Color) 3 (Black Color)
760

One-shot Terminals A C B
Spindle

Signal Names +5V 0V Signal (Speed Pulse)


Bush Bearing s

+5V-R ED 0V-GR N Sig -BLK


Shield

(1) (2) (3)


(4)

+5V

(1) (3) (2)


(4)

Hall Effect Device

Sig 0V
Shield

760

Figure-62.4a: Pictorial View of Transducer

Figure-62.4b: Equivalent Circuit of Transducer

Apply power to the one-shot circuit. Connect Ch-1 of an oscilloscope at terminal point D and Ch-2 at terminal point E. Turn the spindle of the transducer and check that there appears pulses at D-point. Point-E remains at LH state. 3. Stop turning the spindle. There should not be any pulses at D-point and E-point should assume LL state. The Transducer: It is a low-cost tachometer using hall-effect devices. The shaft of the transducer is mechanically coupled with the shaft of the gearbox of the engine of the vehicle. The constructional structure of the tachometer is shown in Fig-62.4b.

2.

28

62.6 Software Module-1 (p626.asm) Task: Develop program codes, which when executed will produce the following result.
Display Field DP0-DP5 DP6-DP11 DP12-DP15 Name Fare Distance Waiting Value 00.00 0.00 0.00 Comment Initial Fare Initial Distance Initial Waiting

After the execution of p626.asm, let us press the HRD-key. We should see the following readout on the 7Segment display of the trainer.
Display Field DP0-DP5 DP6-DP11 DP12-DP15 Name Fare Distance Waiting Value 12.00 0.00 0.00 Comment Initial Flat Fare Initial Distance Initial Waiting

In the design of any instrument, we need to follow some guidelines, which are: (i) List the all possible input and output variables (ii) List the memory locations, which are used to store all these variables (iii) List the memory locations, which are being used as flags, counters and etc. (iv) And now draw a table of Fig-61.6 what we call Data Structure.

Let us take the help of Figure-A.7 (Apndix-A) and build the following data structure of Fig-62.5.
Tab Loc le 6F

Contents

Rem ark

U19: 8279
BC D SPEED
DP0DP1 1000,100 DP2DP3 1, 10 DP4DP5 1/10,1/100 DP6DP7 1000,100 DP8DP9 1, 10 DPADPB 1/10,1/100 DPCDPD MIN DPEDPF SEC
DP0 DP1 DP2 DP3 DP4 DP5 DP6 DP7 DP8 DP9 DPA DPB DPC DPD DPE DPF

p-a

DP0

DFM

DP5

T4

6D

1 3 8 9
DP6

T3

57 56 55 54 53 52 51 50

STFM (BC D) STDM BC D STW M BC D

DDM

DPB

DFM

2 3 3
DPC

DWM

DPF

DDM

0 3 7
7Segment Display

T2

T5

3F 3E 3D 3C 3B 3A 39 38 37 36 35 34 33 32 31 30 2F
2A

DP0 DP1 DP2 DP3 DP4 DP5 DP6 DP7 DP8 DP9 DPA DPB DDC M IN DDD DPE SEC DPF

1000 100 10 1 1/10 1/100 1000 100 10 1 1/10 1/100

STFM (CC ode)

SUR10

DWM

STDM (CC ode)

SUR11
Fare (Tk)
Wait(Min)

STW M (CC ode)


SPEED CCcode

DP0

LCD Panel
Speed(Km /h)

Distance (Km )

T1

19 18

MIN SEC

SCW M
(BCD)

527a : GM : 10-05

SCWM : Software Current Waiting Tim e Meter STWM : Software Total Waiting Tim e M eter STDM : Software Total Distance Meter STFM : Software Total Fare M eter DFM : Digital Fare Meter DDM : Digital Dstance Meter DWM : Digital Waiting Tim e M eter

29

Instruction Codes for P626.asm.


L1: L2: Initialize display unit for 16-digits and clear by calling SUR8 Write 000000 to STFM of T3 of Fig-62.5 Write 000000 to STDM of Fig-62.5 Write 0000 to STDM of Fig-62.5 Convert BCD code of T3 into CC-code and save them in T2 by calling SUR10 Purge T2 to erase the unnecessary leading Os by calling SUR : DELLZS Insert decimal points at the appropriate places of T3 by calling SUR : PLPOINTS Transfer CC-code of T2 into DP0-DP15 via 8279 by calling SUR11

L3: L4: L5: L6: L7: L8:

NOP keep polling the keyboard of the trainer If (pressed down key = HRD key) Goto L9 Else Goto L8 L9: Show: 12.00 at the Fare Field of the 7Segment display 0.00 at the distance filed 0.00 at the Waiting Field L10: wait here

62.7 Software Module-2 (p627.asm) [Measuring Distances from the Speed Pulse] Add the following codes at the appropriate places of program p626.asm to bring the following affect in the functioning of the program P627.asm. 1. Let us press 17 pulses pressing the breadboard switch K1, the Distance Field of the 7Segment display would show: 0.01. 2. Apply another set of 17 pulses, the distance meter would show: 0.02 and so on. 3. Apply very speedy pulses from using a high frequency oscillator. 4. Keep counting until the display shows: 9999.99. This would verify that the distanceupdating algorithm is working fine! . . L1: the input pulses are entering to Counter-0 of the MCU. Now let us configure the Counter-0 as follows: a. It will keep counting the speed pulses and at the end of counting 17 (11H) pulses, it will produce a flag named TF0 in the TCON-register of the MCU. b. Keep polling the TF0-bit and when found set, update the distance by 10m. We have learnt previously that a CNG auto produces about 1700 pulses for 1km distance. There fore. There will be 17 pulses for 10m of distance. c. Keep measuring the distance, update it and display it. d. The above method of counting the speed pulses is known as Polling Method. P627b.asm (Measuring Speed Pulse on Interrupt Method) L1: Configure Couter-0 for counting 17 pulses to rollovers from all 1s to 0s. L2: Enable Timer-0/Counter-0 interrupts logic L3: Write codes for ISURTFO (Timer-0/Counter-0 overflow Interrupt) to update the distance. L4: Continue .

30

62.8 Software Module-3 (P628.asm) [Computing Distance Fare and Update] Add codes with program p627.asm so that we observe that: 1. Distance would keep updating by 10m. 2. There will be no change in fare for distance <2.00 km. 3. When the distance just arrives at 2.00 Km, the fare would be change to Tk 13.00. 4. After that for each distance of 200m, the fare would be updated by Tk 1.00. 5. The above program behavior is represented by the following flow chart of Fig-62.6.

Inerrupt Service Routine: ISURTF0


1SL1:

address of fb0 = 00H

Increase Mileage by 0.01km

1SL2:
fb0=0

M ileage >=2km N 1SL6:


Increase Fare

1SL3: 1SL7: Y
1 ---> fb0

Mileage=2km ? N 1SL4:

Increase Fare

Display: Mileage, Fare, Total W ait Tim e

1SL5:
Return to MLP

526a : GM ; 10-05

Figure-62.6: Simplified Flow Chart for Updating Fare

Let us convert the flow chart of Fig-62.6 into program instructions and then execute.
ISL2: if (fbo = 0) Goto ISL3 Else Goto ISL6 if ((53H) = 02) Goto ISL7 Else Goto ISL4 Take action as indicated in flow chart Return to MLP See program Codes in the CD See program codes in the CD.

ISL3:

ISL4: ISL5: ISL6: Isl7

31

62.9 Software Module-4 (P629.asm) [Computing Waiting Time, Waiting Time Fare and Update] Add codes with program p628.asm so that we observe that: 1. Distance would keep updating by 10m. 2. There will be no change for distance <2.00 km. 3. When the distance arrives at about 1.70 Km, disconnect the speed pulse source. 4. The taximeter should immediately enter into Waiting State. The Waiting Time Field would start counting the Waiting Time by 1-sec. 5. Keep waiting until the Waiting Time is 2-Min (Waiting Time Field shows: 2.00). Let us observe that at the elapse of 2-Min waiting time, the fare is update4d by Tk 1.00. The additional Tk 1.00 comes from the fare of 120-sec (2-Min) waiting time @ Ps 50/1-Min. 6. Wait for another 1Min and observe that the fare is updated by Tk 1.00. 7. The readers may notice that Ps 50 is updating the fare for a waiting time of 2-Min. The 2-Min waiting time is not a random or convenient choice rather it is a design criterion, which must be respected to see that the fare for 2-Min waiting time is exactly equal to the fare for 200m. In Software Module-5, we shall see the combined affect of Distance Drive and Waiting Time Drive to update the fare by Tk 1.00. Instruction Codes:
L1: add codes to initialize Timer-1 of the MCU to set the TF1-flag bit of TCON register at the end of every approximately 8.9mS. Why 8.9mS? [
18 XT2

OSC
19 XT1

1/12

f1=921.6KHz
SW2
8BH 8DH

Y1 11.0592 MHz

C1-T1/=0 SW1

TL1 (5-bit)

TH1 (8-bit)

TF1

534c

13-Bit Mode-0

Figure-62.7: Mode-0 Operation of Timer-1 to Generate 8.9mS Time Quanta f1 = 921.6 x 1000 = 921600 Hz. Time duration for each pulse = 1/921600 Sec. Timer-1 will count 213 = 8192 pulses to rollover from all 1s to 0s. Each time, there is a rollover, the TF1-flag bit set. Therefore, time difference between two Tf1-flag bits = 8192x(1/921600) Sec = 0.0088Sec = 8.9mS. ] L2: if (p1.1-bit = LL) Goto Waiting State at L3 Else Goto L2 Start Timer-1 (if time counter = 70H) ; 70H = 112 x 8.9 = 996.8mS 1Sec Goto L5 Else Goto L4 Update Waiting Time by 1Sec ; Reset Time Counter Goto L4

L3: L4:

L5:

32

62.10 1. 2.

Software Module-5 (p6210.asm) [Computing Fare for Combined Affect of Distance and Waiting Time]

Bring necessary changes in the mainline program so that the meter behaves as follows: a. Advance the distance by 1.87 Km and then disconnect the speed pulses. b. The meter has entered into waiting state. Can you say after how long of waiting time, the fare would be updated by Tk 1.00. This is to say that the Fare Field would show: Tk 13.00? Ans: 1Min 18Sec. How? Current Distance covered : 1.870 Km Remaining distance to cover 2km : 0.130 Km = 130m = 13x10m 200m distance charges : Ps 100 10m distance would charge : Ps 5 130m distance would charge : Ps 65 = 13x Ps 5 60 (6x10)-Sec waiting time charges 6-Sec waiting time would charge : Ps 50 : Ps 5

c.

Therefore, the equivalent waiting time for the uncovered 130m is: 13x6 = 78-Sec = 1Min 18Sec. Keep waiting for 1Min 18Sec and we would observe that Tk 1.00 augments the fare filed. This is one of the design criterions that must be implemented while designing a digital taximeter. Nm Software Module-6 (p6211.asm) [Computing Fare for Combined Affect of Waiting Time and Distance]

62.11 1. 2.

Bring necessary changes in the mainline program so that the meter behaves as follows: c. Advance the distance by 1.230 Km and then disconnect the speed pulses. d. The meter has entered into waiting state. Wait for 54Sec and then connect the speed pulse source. Can you say after how much of distance coverage, the fare would be updated by Tk 1.00. Tk 13.00? Ans: 680m. How? Current Distance covered : 1.230 Km Remaining distance to cover 2km : 770m Elapsed waiting time : 54Sec = 9x6 Sec Elapsed waiting time would charge : Ps 45 Ps 5 is charged for : 10m Ps 45 would be charged for : 90m Therefore, the additional distance that has to be covered to make the fare field showing Tk 13.00 is : 770m 90m = 680m!

62.12 1. 2.

Now bring necessary change in the mainline program so that it behaves as follows: a. The DP12-DP15 devices of the display unit are configured to work as Speed Meter with readout as: xxx.x Km/Hr.

Software Module-7 (p6212.asm) [Speed (Km/hr) Computation and Display]

33

a.

Apply speed pulses by pressing the switch K1, which is located on the breadboard. We would observe that the DP12-DP15 of the display unit shows some value of the speed in Km/Hr. Keep pressing K1 at a higher rate; we will see that the value of the speed is also changing. b. Apply speed pulses from J10-12 connector, we see that the speed is about: 202.5 Km/Hr. c. Apply speed pulses from J10-13. The speed is about: 405.0 Km/Hr. Instruction Codes: L1: Timer-1 should have been initialized in mainline program to generate 8.9mS time quanta. This time could be used to divide the 10m distances to compute the speed. L2: if (TF0 is set meaning the taxi has covered 10m distance) Compute Speed and display at DP12-DP15 as: xxx.x Km/hr L3: Continue computing distance and display it Speed Measurement Principles: Let us assume that Timer-1 is configured to generate 8.9mS time quanta. To measure speed (Km/Hr), we need to know about time that has elapsed while the taxi traveled 10m distances. Let us also assume that the Timer-1 has generated n number of Time Ticks (TT) during 10m distances. One TT corresponds to 8.9mS time. Now, we may write as:
Speed = 10m/(nxTT) [ 1 TT = (1/f1) x 8192 Sec Refer Fig-61.8 f1 = Y1/12 = 11.0592/12 ] = [[(10/1000) ]x3600 ] / (n xTT) Km/hr = (1/n) x (11059200 x10x3600)/(1000 x 12 x 8192) Km/hr = (10/n) x 405 Km/Hr = 405/(n/10) Km/hr = (405x10)/(n/10) xxx.x.x Km/hr ; Multiply by 10 would allow displaying the speed as having one digit after the decimal point. = 4050/(n/10) = 0FD2H/(n/0AH) ; xxx.x Km/hr

Speed

Implementation: 1. Make arrangement in the program codes to count n 2. Compute n/0AH by calling division SUR13 at 1A00H and SUR14 at 1AA0H.. 3. Compute 0FD2H/(n/0A) by calling SUR13and SUR14. 4. Convert the Binary Speed into BCD by calling SUR15 at: 1B9BH. 5. Display the BCD speed on DP12-DP15 as: xxx.x Km/hr. Now bring necessary change in the program P6212.asm so that DP12-DP15 shows 0.0 Km/hr when the speed pulses are not injected. 62.13 1. 2. Software Module-8 (p6213.asm) [Combined Computation and Display of Speed and Waiting Time]

Now bring necessary change in the mainline so that the meter behaves as follows: a. The DP12-DP15 devices of the display unit are configured to work as Speed Meter with readout as: xxx.x Km/Hr.

34

d. Apply speed pulses by pressing the switch K1, located on the breadboard, we would observe that the DP12-DP15 of the display unit shows some value of the speed in Km/Hr. Keep pressing K1 at a higher rate, we see that the value of the speed is changing. e. Apply speed pulses from J10-12 connector, we see that the speed is about: 202.5 Km/Hr. f. Apply speed pulses from J10-13. The speed is about: 405.0 Km/Hr. g. Disconnect the speed pulse source. Now, the meter should enter into waiting state and counts seconds. The waiting time would appear on DP12-DP15 in the form of: xx.xx. h. Reconnect the speed pulse source. Now the meter should show speed (Km/hr) on DP12DP15 positions. Instruction Codes: L1: if (speed pulse missing) Goto L3 L2: Update distance Compute speed and display at DP12-DP15 L3: Update waiting time and display at DP12-DP15 L4: Goto L1 62.14 Software Module-9 (p6214.asm) [Complete Taximeter based on 89S51 and 8279] Combine together all the software modules/routines so far developed in order to transform the CKIT-06A into a Digital taximeter. The taximeter must comply with the specifications of the following table.
Drive Only Distance Drive. Waiting OFF Result Fare: 13.00 at 2.00 Km Fare: 14.00 at 2.20 Km Fare: 15.00 at 2.40 Km . Fare: 13.00 at 0.00 Km. Waiting :20.00 Fare: 14.00 at 0.00 Km. Waiting: 22.00 Fare: 15.00 at 0.00 Km. Waiting: 23.00 Fare: 13.00 Fare: 14.00 Fare: 15.00 Fare: 13.00 Fare: 14.00 Remarks DP12-DP15 Shows speed (Km/hr)

Only Waiting Drive. Distance Off

DP12-DP15 Shows waiting Time Calculation: 55Sec/6=9 9x10 = 90m 02.00 00.09 = 01.91m Calculation; 2.00- 1.75=0.25 km 250/10=25=25x6=150Sec 150Sec 2.30 sec Calculation: 200-50 =150/10=1590Sec 150m Calculation: 18sec/63x10=30m 200m-70m=130m 130m-30m = 100m 270m+100m = 370m

Distance and Waiting Combined - Get waiting: 0.55, distance: 1.91 Km - Get waiting 0.55, distance: 2.11 Km - Get waiting: 0.55, distance: 2.31 Km Waiting and Distance Combined -Get distance: 1.75 Km. Waiting: 2.30 -get distance:1.75, waiting: 4.30 Distance and Waiting Combined -Get distance 2.25 Km, waiting 0.00 -Get distance 2.25 Km, waiting: 1.30 -get distance 2.25Km, waiting:n3.30 Waiting and Distance Combined -get dist: 2.27 - get wait: 0.18 - get dist: 2.37 -Get distance: 2.57 -get dist: 2.57, wait: 2.18

Fare: 14.00 Fare: 15.00 Fare: 16.00

Fare: 14.00 Fare: 14.00 Fare: 15.00 Fare: 16.00 Fare: 17.00

35

62.15 Single Chip Digital Taximeter


Given below a conceptual block diagram for a single chip taximeter. This meter would offer the following advantages over the taximeter of Fig-62.2.
1. 2. 3. 4. Lower IC counts. Good visibility of the display unit during daylight. Almost no cross talk with the electrical firing system of the engine. The meter immediately enters into waiting state after pressing the Hired switch.
M9
Power Conditioner

1008: GM:02=2005

M1

Voltage Regulator
+12

M5

M6
Microcontroller : 89S51

+9V

Fare

Distance/ Waiting

B+

12V

+5V
+9V

Vcc
P0

0V

M2

Signal Conditioner

Pulse Shaper

+10V COM SPulse

SP 0V

P11 Q2 Q1/ Vcc INT0/ T0/

M7 Power Driver

Transducer

M3
+5V

M4
Switch

2804

0V

0V

GND

User Data

p,...,a

M8
P30

2003

2003

+5

P1 P2

M10
11.0592 MHz

P35

SW1 HIRED / PAY

0V

Figure-62.8: Single Chip Version of the Digital Taximeter

Functional Descriptions: 1. M1 provides immunity to logic power supply during the electric firing of the engine. 2. 3. 4. 5. 6. 7. 8. M3 minimizes the cross talks between the signal lines and the engine firings. M4 allows the MCU to decide if the car is moving or not. M10 allows the meter to enter into waiting state at the activation of the Hired switch. M5 is a voltage regulator to provide +5V for the logic and +9V for power buffers. M7, M8 are the power buffers and provide good visibility for the 7-segment display devices in the daylight. M9 is the 7-segment type display unit. M2 is an electronic transducer that picks up the speed pulses while the car moves.

36

6.3 Development of Digital Weighing Machine using CKIT-06A


6.3.1 Hypothetical Pictorial View of the 8951-Based Digital Weighing Machine
231

Pan

Weight
Display
C ost 1 9 9 8. 8 0 Tk 1 9. 9 9 0 Kg 9 9. 9 9 Tk

Keyboard
7 4 1 0 8 5 2
RTE BKS

9 6 3
RST

W eight R ate/Kg
Heartbeat

Power Sw

Figure-63.1: Hypothetical Pictorial View of 8951 Based Digital Weighing Machine (DWM) using CKIT-06A

The goods are placed on the pan. The weight of the goods is displayed on the Weight Filed of the display unit. The display unit is made using segment display devices. The rate (Tk/Kg) of the goods is entered from an interactive keyboard, which is attached with the front panel of the DWM. The rate is displayed on the Rate Field of the display unit. The cost of the goods is displayed on the Cost Field of the display unit. The DWM continuously
i. ii. iii. iv. v. Reads the weight Reads the rate Computes the cost Displays the Weight, Rate and Cost. Blinks the Heartbeat LED ON/OFF to indicate that the DWM is active.

The rate is acquired on interrupt basis. The DWM remains in rate acquisition mode until the 4digit entry for the rate is complete. During rate acquisition period the weight and cost are not updated. At the end of rate entry, the DWM updates the weight, the rate and the cost.

6.3.2 Conceptual Hardware Block Diagram of DWM Based on CKIT-06A


901/2005

M4 M5
Weight
8051 MCU
We i ght Kg Tk

Dig ital Dis play


Total Cost Tk

Hard + S oft Ware s

Rate /Kg

Load Cell

AM P ADC

M1

M2

Rate fro m K e ybo ard

M3

Figure 63.2: Conceptual Hardware Block Diagram of DWM

37

6.3.3 Design Level Hardware Block Diagram of DWM Based on CKIT-06A


901/2005

Keyboard
7 8 9 4 5 6 1 2 3 0
RTE BKS RS

KDIC
Scan Codes Scan 8279 Codes

MCU
Data Data

CCCodes

DDIC
Display Data

Total Cost in Tk
DP0 DP5
CCCodes

Data

Rate Data

IRQ

Weight in Kg
DP6 DP10

U19
Weight
Analog

U17
BCD

8051
Data Data Data

RAM
6264 2764 U10 U8

Data
8279

Rate/Kg in Tk
DP12 DP15

4433

Loadcell

LCIC

U2

EPROM

U19

Digital Display

Figure- 63.3: Design Level Hardware Block Diagram of DWM Based on CKIT-06A

6.3.4 Load Cell Details

Weight
+ Sense (Blue) + Excitation (Green)
+ Output (Red) + Output (White)

- Excitation (Black) - Sense (Yello)

+5V + Output 20mV / 20Kg. Wt. -5V


GM: loadcellcircuit323: 15/12/01

Load Cell
Figure-63.4: Load Cell

There are three single point load cells primarily intended for use in weighing scales although they may be used in many other applications. The force applied to the load face of the cell causes a deflection of the body, which is measured by the bridge of four strain gauges. A screened lead, 6-wire system is used or best accuracy. When used for weighing scales the load cell can be filleted with a platform up to the maximum size. The output of the cell is independent of the point through which the load acts. [Courtesy: RS Catalog]

38

Sl. No. 1 2 3

Capacity

RS Stock No. 632-736 632-742 645-805

Technical Specifications

Instrument Amplifier RS Stock No 308-815 302-463

2 Kg 20 kg 100 kg

a. Total Error : 0.0025% of the rated load b. Recommended Excitation : 5V (10V) c. Output at Rated Load : 2 mV/V 10% d. Zero Return : 0.025% of the Rated Load e. Zero Balance : 5% of Rated Load f. Safe Overload : 150% of the Rated Load g. Ultimate Overload (for failure) : 300% of the Rated Load h. Insulation : >106 ohm i. Output Impedance : 350 3 ohm

Figure-63.5: Technical Specifications of Load Cells [Courtesy: RS Catalog]

6.3.5

Instrumentation Amplifier
+12V
+V2

R7 10k

3 2

1/2 U1 1 + -

R6 10k 2 8

R3 5k 6
- V1

+ 1/1 U1 LM358

R1 10k R2 10k R4 10k 7 R5 10k

Gain = 100 (V2 - V1) / ( (R1+R2+R3) ) /R3) (R7/R6)

1/1 U2 LM358

0V

-12V

323b

Figure-63.6: Discrete Instrumentation Amplifier

R1: 20k
8
+ V2
12 11 +

N/C
6 OF1

+12V

A10

7 OF2 +V

G SS2

20k
4 G SS1 -

INA1 01
-V
G ST2 10
5 G ST1 A20 9

1 (OU T)
CO M

14

13

- V1

R2: 20k

N/C

-12V

0V

323

Figure-63.7: IC Instrumentation Amplifier

39

6.3.6

Connection Diagram of ADC MC14433 with 89S51 MCU of CKIT-06A


+5V R8 5k

U17
2 10 Vref CLK1

0V

24 Vcc

C17 0.1uF
CO1 C02 7 8

0V
C32 0.1uF (Offset)

U2:8051 U19:8279

DP6

DP7

DP8

DP9

+5V

Rx

R12 External 300k 5k Pot on the Breadboard C31 0.1uF H J8-9 Input 0-2V J8-10 L R 11

11
C34 47uF 3 +

CLK2

Vx

4433

EOC DU OR/
Q3 Q2 Q1 Q0
DS1 DS2 DS3 DS4

14 9 15
23 22 21 20
19 18 17 16

DS1 when Vx > Vref

DS3 DS2 DS4

J8

J21 2 3 5 1 2 3 4

1 470k 4 5 6

Vag

WQ3 WQ2 WQ1 WQ0 DS1 DS2 DS3 DS4

P17 P16 P15 P14 P13 P12 P11 P10

0V

R1 R1/C 1 C1

LCD Panel

C33 0.1uF (Mylar)

GND Vee 12 13

C37 0.1uF
GM:648a: 06-04:10-05

-5V

0V

Figure-63.8: Connection Diagram of ADC MC14433 with 8951 Microcontroller

6.3.7

Single Chip Design of DWM using 89S51 Microcontroller


Keyboard
P27 - P24

GM:648a: 06-04:10-05

PWR BUF Display DP0-DP7


P07 - P00

Weight

P32 - P30

RAM

ROM

Display DP8 - DP15 PWR BUF

P17-P10

P23-P20

Load Cell

Amplifier

ADC

Microcontroller

4 to16 MUX PWR BUF

Figure-63.9: Single Chip Design of Digital Weighing Machine

40

6.3.8 Computation Flow Chart for the 89S51 Based Digital weighing Machine

Hardware Module KeyPad


Walking 0's Keyboard 8279Based
4-Bytes Scan Codes (stream) for Rate Data 00.00-99.99 Tk/Kg. Example: 99.99 Tk/Kg. 13H,13H, 13H, 13H

Software Module Subroutine


BCD-toCCcode Converter

Software Module Subroutine


CCcode Transferred to Display

Rate in Tk/Kg.

7 8 9 4 5 6 1 2 3 0 REN RES BKS


A

Software Module Instruction Codes


ScanCode-toBCD Converter
2-Bytes Packed-BCD 99 99

Software Module Subroutine


BCD-to-Binary Converter

4-Bytes CommonCathode Codes 6F, 6F, 6F, 6F

Hardware Module DP12 - DP15

Software Module Subroutine


270FH

D
Each 16-Bits Binary

Software Module Subroutine Software Module Software Module Subroutine Subroutine Cost in Tk
Binary-toBCD Converter BCD-toCCcode Converter
CC xfer to Display

Goods

2-Bytes Packed-BCD 19 99 Load Cell


20mV/20Kg

16-bit x 16-bit Binary Multiplication

D C
BCD-to-Binary Converter
07CFH 19988001 0130FE21H

Unpacked BCD to BCD Converter

Hardware Module DP0 - DP5 Cost:

Amplifier, ADC and Interface Controller 101A, MC14433 Port-1

Software Module Instruction Codes

Software Module SUR: 7

Cost:
32-Bits Binary 4-Bytes Common Cathode Codes 06, 6F, 6F, 6F

Cost:
4-Bytes Packed-BCD

Rounded to 6-Bytes Common Cathode Codes

4-Bytes Unpacked BCD for Weight Data : 00.00-19.99 Kg. Example: 19.99 Kg. 1000, 1001, 1001, 1001

Weight in Kg.
BCD-toCCcode Converter

CCcode Transferred to Display

Hardware Module

Software Module Subroutine

Software Module Subroutine


GM:dwmflow:1201 : 902 , 01/2005

Hardware Module DP6 - DP10

Figure-63.10: Computation Flow Chart for Digital weighing Machine

41

6.3.9

Acquisition/Computation Flow Chart of Digital Weighing Machine


Interrupt Subroutine to Acquire Rate (Tk/Kg)
ISURINT0:

Main Line Program


L1: C100H

Initialization: Stack, Bank, Port-1 as Input, Vector Link INT0


L 2:

L25A:

Make Arificial RETI and Makes the ISURINT0 as an Artificial Main Line Program L24:

Initialization: Initial Rate 00.00, Initial Weight 00.000


L3 :

Enable Interrupt

fb1= LH ? N L25:
N

8279 Init., Flag Bit Init, Interrupt Init


L4:
Wt >20Kg ?
L5: Y
Blank Wt Field

REN Cmnd ? Y

Acquire UpBCD Wt: DS1, DS2, DS3, DS4 and save at: 58H, 59H, 5AH, 5BH

L14:

1. Show: _ _ . _ _ at the Rate Field with a Blinking Cursor 2. Set fb1 to LH 3. Init Cursor Position, Digits to Print 4. Enable Interrupt
L23A; Cursor ON/OFF

Obtain Packed BCD Wt from UpBCD Weight and Save at: T5C of Data Structure
L15: SUR

Convert BCDRATE and BCDWT into BINRATE and BINWT


BCD2BIN L17:
SUR
Y

Compute BINCOST = BINRATE x BINWT


BMULT

REN Key ?
N L26A:

L18:

Compute BCDCOST and saving at T5A of Data Structure


L20:

SUR BIN2BCD

Adjust Print Position

Print Rate Digits Save Scan Code

Print Done ?
L28: Y

Convert BCDRATE, BCDWT and BCDCOST into CCcoded Data and save at T3 of Data Structure. Place Decimal Points at T3
L22:

SUR BCD2CC

Remove Leading Zeros of Cost. Transfer CCdata of T3 into Display RAM of 8279
L23:
HearBeat LED ON/OFF via P3.4 Port Pin

SUR CCX8279

1. Obtain BCDRATE from SCANRATE 2. Save at T5C

SUR TDELAY

1. Adjust Cursor Pos 2. Adjust Digits Print 3. Enable Interrupt

The Product rate (Tk/Kg.) is acquired from the keyboard on interrupt basis in is shown here to the right of Main Line Program. The interrupt ocurs at INT0 pin of the MCU. The vector direction is: KeyPress ---> INT0 -----> 0013H ---> C0F0H ----> ISURINT0. The mail line program is located at C1000H. The MPU reads the rate, the weight and then computes the total cost using EPROM resident subroutins. 294

Figure-63.11 : Data Acquisition/Computation Flow Chart for the Digital Weighing Machine

42

Remote Controlled Speed Regulation System


Microcontroller Based Remote Controlled Multichannel Speed Regulation System
Remote Command and Control Signals
ZCD

Chapter - 6.4

Microcontroller xx51
RxDP30

MCU AT89C0251

100Hz ZCD
PC5 PC4 PC3

AC

220V AC
TR1

POS1
POS2 POS3
D7-D0 WR/ A CS0/

25mS
25mS

TR2 TR3
L
L

25mS

Remote Monitoring Signals


TxDP31

P17-P10 P32 P34-P33

PIT 8253
POS4
POS5 POS6
25mS

PC2 PC1 PC0

TR4
25mS
25mS

TR5 TR6
L
L

2K EEPROM
64 Byte RAM 64 Byte SFR

D7-D0 WR/ A CS1/


PB5 PB4 PB3

PIT 8253
POS7
POS8 POS9
25mS

TR7
25mS
25mS

TR8 TR9
L
L

D7-D0 WR/ A CS2/


P37 P36 P35

PIT 8253
25mS
25mS
25mS

PB2 PB1 PB0

POS10
POS11 POS12
D7-D0 WR/ A CS3/

TR10 TR11 TR12


L
L

PDEC 74138

CS/

CS7/-CS0/

PIT 8253
25mS
25mS
25mS

PA5

POS13
POS14 POS15
D7-D0 WR/ A CS4/

TR13 TR14 TR15


L
L

PIO 8255
D7-D0 WR/ A CS6/

PA4 PA3

PIT 8253
250mS
25mS
50mS

PA2

POS16
POS17 POS18
D7-D0 WR/ A CS5/

TR16 TR17 TR18


L
L

PC5-PC0 PB5-PB0 PA5-PA0

PA1 PA0

PIT 8253

MBSD\REMOTE1: GM:01-03

Figure-64.1: Remote Controlled Speed Regulation System

43

Appendix-A Architecture of ISP-Mode CISC Microcontroller


What is a Microcontroller? The answer is that it is a Single Chip Based Controller and hence the name Microcontrolling Unit (MCU) or simply a Microcontroller. The 89S51 chip of the Atmel Company presents itself as an example of a single chip Microcontroller This chip internally contains in partial amount the functions of the following hardware resources.
a. b. c. d. e. f. g. h. An 8-bit CPU with an 8-bit Accumulator (A-register) A 1-bit CPU called Boolean Processor with a 1-bit Accumulator, the Carry. 4 Kbytes EEPROM with Security Bit, which when Fused prevents a user from reading the memory content 128 Bytes RAM 2-Channel Timing/Counting Functions 2-Channel External Hardware Interrupts with Built-in Interrupt Priority Resolver. Full Duplex Serial IO Controller 28 (max: 32) IO Lines, which can be individually programmed as input or output. ISP (In System Programming) Programming Capability using LPT port of IBMPC.

The conceptual view of the 89S51 microcontroller is shown in Fig-A.1.


697
PIO
P3

8-Bit CPU

P37-P30

4K EEPROM
128 Byes RAM
T-C1/ T-C0/
INT1/ INT0/
RxD TxD
P2

P27-P20

Tim in/ Counting


Interrupt Resolver
Serial IO

P1

P17-P10

P0

P07-P00

Figure-A.1: Conceptual View of the 89S51 Microcontroller

The Atmel Microcontrollers The Atmel Company of the USA has launched a series of microcontroller chips, which offer very cost effective solutions to many industrial control applications. These chips have borrowed the Instruction Set and the CPU from the 8051 of the Intel Company. It is also fully compatible with the Intel 8-Bit peripheral controllers. The following are the commonly used MCUs of the Atmel Company:
a. b. c. d. 892051 89S51 89S52 89S8252 : A 20-pin version with 1 Kbytes EEPROM for program codes. : 4K Code Memory with In-System Programming (ISP) capability. : 8K Code Memory but ISP capability. : 8K Code Memory, 2K Data Memory, ISP capability and SPI Port.

44

89S51 Architecture
89S51
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 P10 Vcc P11 P00-AD0 P12 P01-AD1 P02-AD2 P13 P03-AD3 P14 P15/MOSI P04-AD4 P16/MISO P05-AD5 P17/SC K P06-AD6 RST P07-AD7 P30-RxD EA/-Vpp P31-TxD ALE-PG/ P32-INT0/ PSEN/ P33-IN1/ P27-A15 P34-TC 0/ P26-A14 P35-TC 1/ P25-A13 P36-WR / P24-A12 P37-RD/ P23-A11 XTAL2 P22-A10 XTAL1 P21-A9 GND P20-A8
40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21

698

Y = 6MHz
18 XTAL2

698

19 XTAL1 P37-P30

NC

30 29

ALE PSEN/

17,16,15,14,13,12,11,10

P27-P20 9 RST

28,27,26,25,24,23,22,21

P17-P10

8,7,6,5,4,3,2,1

Exernal Port Lines Operated IO Devices

31

EA/-(Vpp)

40 20

Vcc GND

P07-P00

32,3334,35,36,37,38,39

Figure-A.2: Physical Pin Diagram

Figure-A.3: Port Lines Operated 8951 Based System


Data/ Control

TxD R xD

10 11

RxD TxD

P1

P17-P10

8,7,6,5,4,3,2,1

External Modem

RST

21 SFRs 128 Byte RAM


RD/ W R/
PSEN/
A15-A8

External Port

13 12 15 14 19
Y = 6MHz
18 31 40 20

4k ROM INT1/ INT0/


TC1/ TC0/ XTAL1

17 16
29
28,27,26,25,24,23,22,21

RD/ WR/
PSEN/ A15-A8

+5V

ALE XTAL2 EA/ Vcc AD7-AD0 GND

30
32,3334,35,36,37,38,39

ALE
AD7-AD0

External Bus Operated ROM, RAM and Port

699

Figure-A.4: Bus Lines Operated 89C51 Based System Accessing External ROM, RAM and IO Devices

Fig-A.3 is an application of the 89S51, in which all the internal four ports consisting of 32 (4x8) IO lines have been used as simple IO lines to accomplish data transfer operations with the peripheral devices. Fig-A.4 depicts a system in which the MCU is accessing external Program Memory, Data Memory, Memory-mapped Port and also supports the functions of Interrupt, Counting, Serial IO and Parallel IO.

45

Internal Architecture of 89S8252 CISC Microcontroller

M1

M2
divide by 12
8-BIt CPU

M3
1-BIt CPU

M4
In Sys. Prog. Interface

11.0592 MHz

SCK DataOut, DataIn

M6

M7
SPI Interface

M5 8-BIT
Accum ulator (A)

1-BIT Accum ulator (C)

SS/, SCK MOSI, MISO

M8
Rx, Tx
TC0-2
INT0-1

M12
M13
M13

Serial Com m unication Tim er/Counter

M9
Code EEPROM (FLASH) 0000 - 1FFF
Security Bit

M10
Data EEPROM 0000 - 7FFF
Security Bit

M11
SFR (80-FF) Upp RAM (80-FF) for 89X52 only Lower Block of RAM (00-7F)

Exter. Interrupt

M14

M15
Addree Bus Interface

P00-P07

Port-0

A00-A15

M16

M17

P10-P17

Port-1

Data Buffer

D0-D7

M18

Control Matrix (Sequence Generator)

M19
Write Control Logic

P20-P27

Port-2

WR/

M20

M21
Read Control Logic
RD/ PSEN/

P30-P37

Port-3

783 : GM : 1-11-05

Figure-A.5: Internal Architecture of 89S8252 CISC Microcontroller

46

Internal Details of 89S8252 Microcontroller


cngm et\ch8\8-6: 784
Port-3 Latches
17
P37 R D/

Processing Module-1

Internal R AM FF

R egister Set
B*

Processing Module-2

F0 E0

xx52
80 7F

AC C * -

Port-1 Latches P17 P17 P15 P14 P13 P12 P11 P10
Port-2 Latches P27 P26 P25 P24 P23 P22 P21 P20 A15 A14 A13 A12 A11 A10 A9 A8
Port-0 Latches

ISP and SPI Interface


(8)

16

P36 WR/

D0 CD T2 Tim er-2 C 8 B8 IP*


PSW*
P3*

15

P35 C 1/

B0

2F Bit Space 20 1F 18 17 10 0F 08 07 00 BK3

IE* P2* SBUF

A8

14

P34 C 0/

A0

(8)

BK2 BK1 BK0

91

SC ON* 98 P1* TH1

13

P33 INT1/

Internal 2K EEPR OM 07FF

90

8D 8C 8B 8A

12

P32

TH0

0000
INT0/

TL1 TL0

P07 P06 P05 P04 P03 P02 P01 P00 A7 A6 A5 A4 A3 A2 A1 A0 D7 D6 D5 D4 D3 D2 D1 D0

11

Internal 8K Flash 1FFF

TM OD 89 TC ON

(8)

P31 TxD

88

PC ON* 87

DP1H DP1L
DP0H DP0L

85 84
83

10

P30 R xD

82
81
80

SP
0000

P0*

29 30

PSEN/

PC = 16-Bit

A15-A00

ALE
MOVX @DPTR , A: DPTR = 16-Bit

A15-A00

R egisters m arked by * are Bit Addressable

MOVX @R 1 (R 0), A: R 1 or R 0 = 8-Bit

A15-A08 by P2 A7-A0

Figure-A.6: Internal Details of 89S8252 CISC Microcontroller

47

Recommended Data Structure for Atmel CISC Microcontrollers


Internal RAM
FF
80 7F Accessible by indirect addrees as: MOV A, @R 0

Internal SFRs of the MCU


FF
NOT AC C ESSIBLE

SP

70 6F 6E 6D 6C 6B 58 57

Key Sccan C ode C TP (C ursor Type) NPD (Digits Printd left of C urs C R P (C urs Pos)/ PR P (Print Pos)
Scratch pad Mem ory Space

F1 F0 EF

F7

F0

NOT AC C ESSIBLE

Packed Hex of form at: XX

DP0DP1

E1 E0 DF

E7

E0

AC C

NOT AC C ESSIBLE

50 4F

Packed Hex of form at: XX Unpacked Hex of form at: 0X

DPEDPF DP0

D1 D0 D7 CF
NOT AC C ESSIBLE

D0

PSW

CD CC CB CA C9 C8

TH2 TL2 R C AP2H R C AP2L T2M OD T2C ON

40 3F

Unpacked Hex of form at: 0X C C C ode for Digit of DPF

DPF DP0
B9 B8 BF B7 B8

IP

B1 B0 B7 AF

NOT AC C ESSIBLE
B0

P3

30 2F

27

20 1F 18 17 10 0F 08 07 00

CC CC CC CC 7F 7E 77 6F 67 5F 57 4F 47 3F 37 2F 27 1F 17 1F 07 06

C ode for C ode for C ode for C ode for 7D 7C

Digit of Digit of Digit of Digit of 7B 7A

05

04

03

Bank-3

Bank-2 Bank-1

Bank-0

DP3 DP2 DP1 DP0 79 78 70 68 60 58 50 48 40 38 30 28 20 18 10 08 02 01 00 R7 R0 R7 R0 R7 R0 R7 R0

A9 A8 AF A7

NOT AC C ESSIBLE
A8

IE

DPF

A1 A0 A7 9F

NOT AC C ESSIBLE
A0

P2

9A 99 98

NOT AC C ESSIBLE
98

9F

SBUF SC ON

91 - 97

NOT AC C ESSIBLE
97

Flag Table

90 8E - 8F 8D 8C 8B 8A 89 88 87 86 85 84 83 82 81 80

NOT AC C ESSIBLE

90

P1

87
NOT AC C ESSIBLE

88

TH1 TH0 TL1 TL0 TM OD TC ON PC ON


DP1H DP1L DP0H DP0L SP P0

87

80

Figure-A.7: Recommended Data Structure for Atmel CISC Microcontrollers

48

8952 only
761

49

You might also like