Set

Syntax:

    Set variable.bit {On | Off}

Command Availability:

Available on all microcontrollers.

Explanation:

The purpose of the Set command is to turn individuals bits on and off.

The Set command is most useful for controlling output ports, but can also be used to set variables.

Often when controlling output ports, Set is used in conjunction with constants. This makes it easier to adapt the program for a new circuit later.

Example:

    'Blink LED sample program for GCBASIC
    'Controls an LED on PORTB bit 0.

    'Set chip model and config options
    #chip 16F84A, 20

    'Set a constant to represent the output port
    #define LED PORTB.0

    'Set pin direction
    Dir LED Out

    'Main routine
    Do
        Set LED On          ' <<< the Set instruction
        Wait 1 sec
        Set LED OFF
        Wait 1 sec
    Loop

Key line: Set LED On — drives the LED bit (aliased to PORTB.0) high; using the LED constant instead of writing PORTB.0 directly means only the #define line needs to change if the circuit moves to a different pin.

See Also: