Syntax


40 Ω Speaker or
peizo element

' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' This program generates a constant tone 25 followed by an ascending tones.
' Both the tones are played for about 100 milliseconds.

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

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

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

Spkr            VAR     RA.0                    ' piezo or 40-ohm speaker

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

tone            VAR     Byte                    ' tone to play
temp1           VAR     Byte                    ' for subroutine
temp2           VAR     Byte

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

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

PLAY            SUB     2                       ' pass note and timing

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

Start: 
  FOR tone = 1 TO 127
    PLAY 25, 10                                 ' play tone 25
    PLAY tone, 10                               ' play ascending tone
  NEXT
  END

' -------------------------------------------------------------------------
' Subroutines Code
' -------------------------------------------------------------------------

' Use: PLAY note, duration
' -- play 'note' for 'duration' units

PLAY:
  temp1 = __PARAM1                              ' save note
  temp2 = __PARAM2                              ' save duration
  IF temp1 > 0 THEN
    IF temp2 > 0 THEN
      SOUND Spkr, temp1, temp2
    ENDIF
  ENDIF
  RETURN