Tuesday, August 25, 2009

END SUB

The sub does all it's normal stuff, but also sets the port to 0 if a 0 was passed to it. This is a very easy to clear up a port if you create strange bit patterns by trying to turn a bit on twice. You may want to keep track of the state you expect the port to be and compare it to the actual state by using the INP function. If the two do not match, clear the port and reset all the the bits using your other variable.

Now that we know a few useful functions with respect to output, we should look at a very useful input function. When using the port in software, you will very likely need to know the status of a single bit at one time or another. There are various ways of doing this, but I find the function below to be the most useful:


FUNCTION BitStatus(PortAddress%, BitYouWant%) AS INTEGER

IF PortAddress% = 888 THEN

NumOfBits% = 8

ELSE IF PortAddress% = 889 THEN

NumOfBits% = 5

ELSE

NumOfBits% = 4

REDIM PortBits(NumOfBits%) AS INTEGER
PortNum% = INP(PortAddress%)
FOR i = 1 To NumOfBits%

PortBits%(i) = PortNum% MOD 2
PortNum% = FIX(PortNum% / 2)

NEXT I
BitStatus% = PortBits%(BitYouWant%)

0 Comments:

Post a Comment