AN511

Product: Domino 1 & 2

 

Reading and Writing to T0, T1, INT0, and INT1

 

Date: 4/12/01

Introduction: While BASIC-52 allows you to access Port 1 bits, on the 80C52 processor directly through BASIC, it does not allow direct access of the Port 3 bits available on the Domino 1 and 2 modules. *INT0, *INT1, T0, AND T1 is part of Port 3 on the 80C52 processor.

 

Background: Background: Port 3 is an 8 bit bi-directional I/O port with internal pullups. The only I/O on port 3 for the Domino 1 & 2, that is available to the user is *INT0, *INT1, T0, and T1. Please keep in mind that T0 is also connected to the Serial Port driver and if it is pulled low or programmed low then all serial transmissions will not occur until T0 is set.

Port Pin 

P3.0

P3.1

P3.2

P3.3

P3.4

P3.5

P3.6

P3.7

Alternaye Function

RXD (serial input port)

TXD (serial output port)

*INT0 (external interrupt 0)

*INT1 (external interrupt 1)

T0 (timer 0 external input)

T1 (timer 1 external input)

*WR (external Data Memory write strobe)

RD (external Data Memory read strobe)

Address

N/A

N/A

B2H

B3H

B4H

B5H

N/A

N/A

 

 

How it works: Using Port 3 bits as outputs is as simple as setting or clearing the bits. Using them as inputs is a little trickier. In order for BASIC52 to tell if a bit is set or clear the assembly language routine must set a location in memory to a value for BASIC to read. The 80C52 processor has two bytes reserved for the user(20H and 21H).

Example 2 of the program listing demonstrates how to write a value to location 20H. When the program runs, it calls an assembly language routine that looks at *INT1 to see if it is set or clear. If it is set then a 1 is written into address location 20H. If it is clear a 0 is written into address location 20H. When the program returns back to BASIC it uses the DBY command to look at the processors internal address of 20H and stores the value into the variable X. Then the program prints the value of X out the serial port.

 

Program Listing:

Example 1: Using *INT1 as an output

Assembly Language Program:

Org 6000H

CL_R: CLR P3.3 ; Clear *INT1

RET ; Return Back to BASIC

ORG 6003H

SE_T: SETB P3.3 ; Set *INT1

RET

END

BASIC-52 program:


10 MTOP = 5FFFH

20 XBY(6000H)=0C2H : REM 0C2H is the Hex value for the assembly command CLR

30 XBY(6001H)=0B3H : REM 0B3H is the Hex address where *INT1 is located

40 XBY(6002H)=022H : REM 022H is the Hex value for the assembly command RET

50 XBY(6003H)=0D2H : REM 0D2H is the Hex value for the assembly command SETB

60 XBY(6004H)=0B3H

70 XBY(6005H)=022H

80 Call 6000H : REM Call the assembly routine to clear *INT1

90 Call 6003H : REM Call the assembly language to se *INT1

Example 2: Using *INT1 as an Input

Assembly Language Program:

Org 6000H

BEGIN: JB P3.3,B_SET ; Jump to B_SET if *INT1 is set

B_ CLR MOV 20H,#0 ; Move the value of 0 into internal address 20H

RET ; Return Back to BASIC

B_SET: MOV 20H,#1 ; Move the value of 1 into internal address 20H

RET

END

 

BASIC-52 program:

10 MTOP = 5FFFH

20 XBY(6000H)=020H : REM JB assembly command

30 XBY(6001H)=0B3H : REM Address of INT1

40 XBY(6002H)=004H : REM Jump ahead 4 if INT1 is set

60 XBY(6003H)=075H : REM MOV assembly command

70 XBY(6004H)=020H : REM Address to store the data in

80 XBY(6005H)=000H : REM Data that is going to be stored

90 XBY(6006H)=022H : REM RET Assembly command

100 XBY(6007H)=075H : REM MOV assembly command

110 XBY(6008H)=020H : REM Address to store the data in

120 XBY(6009H)=001H : REM Data that is going to be stored

130 XBY(600AH)=022H : REM RET Assembly command

140 CALL 6000H

150 X = DBY(20H)

160 PRINT "The Value of *INT1 is ",X