Syntax

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Transfers a counter value to eight LEDs using a 74HC595 shift register.
'
' A SpeedMult value of 10 is used to bump the SHIFTOUT clock speed to 
' ~830 kBit/sec (well within 74x595 limits and 4 MHz SX clock).

' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID              "SHIFTOUT"

' -------------------------------------------------------------------------
' IO Pins
' -------------------------------------------------------------------------

Dpin            VAR     RA.0                    ' shift data
Cpin            VAR     RA.1                    ' shift clock
Latch           VAR     RA.2                    ' latch outputs

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

counter         VAR     Word                    ' counter to display
tmpB1           VAR     Byte

' =========================================================================
  PROGRAM Start
' =========================================================================

' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

PUT_595         SUB     1, 2                    ' allow byte or word

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  DO
    FOR counter = 0 TO 255                      ' loop through all values
      PUT_595 counter                           ' transfer counter to 595
      PAUSE 100                                 ' wait 1/10 second
    NEXT
  LOOP

' -------------------------------------------------------------------------
' Subroutine Code
' -------------------------------------------------------------------------

' Use: PUT_595 value
' -- moves LSB of 'value' (can be byte or word) to 74HC595

PUT_595:
  tmpB1 = __PARAM1                              ' save LSB of value
  SHIFTOUT Dpin, Cpin, MSBFIRST, tmpB1, 10      ' send the bits
  PULSOUT Latch, 1                              ' transfer to outputs
  RETURN