Syntax:
#option volatile `bit`
This option ensures port settings are glitch-free.
Explanation:
#option volatile bit, where bit is an I/O bit, like PORTB.0, appended.
This will cause the compiler to set the bit without any glitches when copying a value from another variable, but will increase code size slightly.
Example:
'Set chip model
#chip 16f877a
'Example command
#option volatile portb.0 ' <<< marking this pin for glitch-free read-modify-write
dir portb.0 out
do forever
portb.0 = !portb.0
loopKey line: #option volatile portb.0 — without this, portb.0 = !portb.0 compiles to a plain read-modify-write on PORTB that can glitch other bits of the port for an instant; with it, the compiler generates the extra instructions needed to toggle
only bit 0 cleanly.
See Also:
- #Option NoLatch — a related fix for whole-port read-modify-write glitches via LATx
- #Option Shadowregister — a whole-port shadow-latch alternative on chips without LATx

