Syntax

           

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Reads value from an ADC0831 and places that value on LEDs connected to
' port RB.
'
' Note that the SpeedMult feature is used with SHIFTIN to bump the clock
' speed up to ~332 kBits/sec (ADC0831 max is 400).

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

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

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

Dpin            VAR     RA.0                    ' shift data
Cpin            VAR     RA.1                    ' shift clock
CS              VAR     RA.2                    ' chip select

LEDs            VAR     RB
TRIS_LEDs       VAR     TRIS_B

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

tmpB1           VAR     Byte                    ' parameter

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

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

GET_ADC         SUB     0                       ' get value from ADC

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

Start:
  TRIS_LEDs = %00000000                         ' make LED ports outputs
  HIGH CS                                       ' make CS output, no ADC
  LOW Cpin                                      ' make clock 0-1-0

Main:
  LEDs = GET_ADC                                ' move ADC value to LEDs
  PAUSE 100                                     ' wait 0.1 second
  GOTO Main

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

' Use: aVar = GET_ADC
' -- reads ADC0831 and places value into 'aVar'

GET_ADC:
  CS = 0                                        ' activate ADC0831
  SHIFTIN Dpin, Cpin, MSBPOST, tmpB1\1, 4       ' start conversion
  SHIFTIN Dpin, Cpin, MSBPOST, tmpB1, 4         ' shift in the data
  CS = 1                                        ' deactivate ADC0831
  RETURN tmpB1