REM File: Port13IO.BAS Date: 12/08/1999 REM REM /* (c) Copyright BLUE EARTH RESEARCH, MANKATO, MN 1999. */ REM /* All rights reserved. */ REM REM This program demonstrates how to write values to the CPU I/O Port REM pins. It includes individual example lines of code for writing REM each of the available Port1 and Port3 pins high and low. REM The example lines are written so that only one port pin is affected. REM The other port pins are not changed. 1 REM Port13IO.BAS - Demo Port1 & Port3 I/O program - 12/08/1999 - TMB REM Bit Mask value for writing to Port3 4 M=0C3H : GOTO 9 REM Print current port value, delay for a while 5 PH0. PORT1, : FOR X = 0 TO 500 : NEXT X : RETURN 6 PH0. M.OR.PORT3, : FOR X = 0 TO 500 : NEXT X : RETURN 9 PRINT "Port1 & Port 3 demo." REM Port1 & Port3 I/O examples - turn on (low), then off (high) all channels REM First make sure that they are all off (high) 10 PORT1=255 : PORT3=255 20 PRINT : PRINT "Port1 = ", REM Values to write to Port1 to address individual I/O bits. REM The values are shown in decimal (and Hex). REM REM Port Port on off REM Pin Pin (low) (high) REM P1.0 254 (0FEH) 1 (1H) REM P1.1 253 (0FDH) 2 (2H) REM P1.2 P3.2 251 (0FBH) 4 (4H) REM P1.3 P3.3 247 (0F7H) 8 (8H) REM P1.4 P3.4 239 (0EFH) 16 (10H) REM P1.5 P3.5 223 (0DFH) 32 (20H) REM P1.6 191 (0BFH) 64 (40H) REM P1.7 127 (07FH) 128 (80H) REM For example, to toggle P1.0, 100 PORT1 = PORT1 .AND. 254 : REM P1.0 on (low) 110 GOSUB 5 120 PORT1 = PORT1 .OR. 1 : REM P1.0 off (high) REM P1.1 130 PORT1 = PORT1 .AND. 253 140 GOSUB 5 150 PORT1 = PORT1 .OR. 2 REM P1.2 160 PORT1 = PORT1 .AND. 251 170 GOSUB 5 180 PORT1 = PORT1 .OR. 4 REM P1.3 200 PORT1 = PORT1 .AND. 247 210 GOSUB 5 220 PORT1 = PORT1 .OR. 8 REM P1.4 230 PORT1 = PORT1 .AND. 239 240 GOSUB 5 250 PORT1 = PORT1 .OR. 16 REM P1.5 260 PORT1 = PORT1 .AND. 223 270 GOSUB 5 280 PORT1 = PORT1 .OR. 32 REM P1.6 300 PORT1 = PORT1 .AND. 191 310 GOSUB 5 320 PORT1 = PORT1 .OR. 64 REM P1.7 330 PORT1 = PORT1 .AND. 127 340 GOSUB 5 350 PORT1 = PORT1 .OR. 128 REM Repeat with similar code for Port3 390 PRINT : PRINT "Port3 = ", REM P3.2 400 P3 = PORT3 .AND. 251 : PORT3 = P3 .OR. M 410 GOSUB 6 420 P3 = PORT3 .OR. 4 : PORT3 = P3 .OR. M REM P3.3 430 P3 = PORT3 .AND. 247 : PORT3 = P3 .OR. M 440 GOSUB 6 450 P3 = PORT3 .OR. 8 : PORT3 = P3 .OR. M REM P3.4 460 P3 = PORT3 .AND. 239 : PORT3 = P3 .OR. M 470 GOSUB 6 480 P3 = PORT3 .OR. 16 : PORT3 = P3 .OR. M REM P3.5 500 P3 = PORT3 .AND. 223 : PORT3 = P3 .OR. M 510 GOSUB 6 520 P3 = PORT3 .OR. 32 : PORT3 = P3 .OR. M