^59 - The Dipswitch Port

This read only port contains the state of all the dipswitches on a device in banks of 8. The value is a bitfield with each contact represented by a single bit.

As this port contains the state of more than one input you may need to use the AND command to isolate a single input or the SHR command to check them one at a time.

Syntax

LDA ^59,x
Where x is the bank of dipswitches you want the status of.
LDA ^59,0 will give the state of dipswitches 1-8.
LDA ^59,1 will give the state of dipswitches 9-16.

Examples

Example 1

Example showing using SHR to interrogate one dipswitch at a time.

Task1()
{
    Name="Occupancy Trigger"    //Checks the state of dipswitch 3.
    LDA ^59,0           //Get the dipswitch port
    SHR                 //Move dipswitch 1 into the carry flag
    SHR                 //Move dipswitch 2 into the carry flag
    SHR                 //Move dipswitch 3 into the carry flag
    BRC Occupancy       //If carry flag is set sensor saw motion
    ...
}

Example 2

{
LDA ^59,0           //Load the first 8 dipswitchs
AND #0x04           //AND it with 0x04 and mask out all but dipswitch 3
BRZ ThreeOff        //If off branch, if not assume on
...
}

Example 3

This task sets the area of the device to match the combined dipswitch value.

{
LDA ^59,0     //Load the dipswitchs
STA ^50,0     //Store into the default area port to change the area of all the buttons.
Null
}

Example 4

{
LDA ^59,1       //Load the second set of 8 dipswitchs
AND #0x02       //AND it with 0x02 and mask out all but second bit (ID2 Dipswitch 2)
BNE TwoOn       //If On branch, if not assume off
...
}