Syntax

' =========================================================================
'
'   File...... COUNT.SXB
'   Purpose... Demonstrates SX/B COUNT instruction
'   Author.... (c) Parallax, Inc. -- All Rights Reserved
'   E-mail.... support@parallax.com
'   Started...
'   Updated... 05 JUL 2006
'
' =========================================================================

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' This program will count the transitions on the FreqIn (RA.0) pin for
' one second.  Run the program in Debug mode, then select Poll from the
' Debug control panel.

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

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

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

FreqIn          VAR     RA.0                    ' frequency input

' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

Duration        CON     1000                    ' measure for one second

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

hertz		VAR	Word			' measured cycles

WATCH hertz					' for Debug display 

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

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

Start:
  DO
    COUNT FreqIn, Duration, hertz               ' measure frequency
    BREAK                                       ' display in Watch window
  LOOP