Close

Reading 80C52 Port 3 Bits

mit41301mit41301 wrote 03/26/2024 at 16:16 • 1 min read • Like

Introduction: 

While BASIC-52 allows you to access Port 1 bits directly through BASIC, it does not allow direct access of the Port 3 bits available on many of the boards and modules

Background: Port 3 is an 8 bit bi-directional I/O port with internal pullups.

Program Listing:

Example 1: Waiting for a bit to be set or cleared

BASIC-52 program . . . CALL xxxxh

Assembly routine

xxxxh Label1: JB P3.x, Label1 ;Loop until bit is set RET ;Return to BASIC program

or

xxxxh Label1: JNB P3.x,Label1 ;Loop until bit is cleared RET ;Return to BASIC program

Example 2: Return the state of a bit to BASIC-52

BASIC-52 program . . . CALL xxxxh

Assembly routine

Xxxxh Label1: JB P3.x, B_SET ;Test the bit, jump if set B_CLR: MOV 20h, #0 ;Store 0 if cleared RET

B_SET: MOV 20h, #1 ;Store 1 if set RET

Once you are back in the BASIC program use the following line to read what was stored:

IF DBY(20h)=0 THEN PRINT "P3.x = Low" ELSE PRINT "P3.x = High"

This page is based on Micromint inc's AN101 Dated: 7/28/99

Like

Discussions