ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - SITXT.pbp

PICBASIC PRO sample Telemarketing stopper. Reads caller id and plays Special Information Tones (SIT) when CID information has been blocked.
' Name        : SITXT.pbp
' Compiler    : PICBASIC PRO Compiler 2.6
' Assembler   : PM or MPASM
' Target PIC  : PIC16F877-20, PIC18F452 or similar type
' Hardware    : LAB-XT Experimenter Board
' Oscillator  : 20MHz external
' Keywords    : FREQOUT, SERIN2, WAIT
' Description : PICBASIC PRO sample Telemarketing stopper. Reads caller id 
' and plays Special Information Tones (SIT) when CID information has been blocked.
'

Define LOADER_USED 1  ' Only required for melabs Loader
Define OSC 20         ' Match the crystal on the board

led4            Var PORTC.1     ' LED4 output pin
sieze           Var PORTD.1     ' Relay control pin (sieze line)
loop_current    Var PORTA.3     ' Loop current present (active low)
ring_detect     Var PORTA.2     ' Ring detect pin (active low, square wave)
dtmf_out        Var PORTE.2     ' DTMF signal output pin
cid_serial_data Var PORTA.0     ' Caller ID data from FSK chip

   ADCON1 = 7           ' Set PORTA and PORTE to digital
   TRISD = 0            ' Set PORTD to output
   PORTD = 0            ' Initialize PORTD, all low

' Define program variables
j         Var Byte      ' Loop counter, misc
ring_freq Var Word      ' Frequency of ring signal (speaker PWM)
cid_code  Var Byte      ' Stores reason code from CID string

initialize:
   sieze = 0            ' Deactivate the line-sieze relay (Hang Up)
   Pause 250            ' Wait 250mS for things to settle 

mainloop:
   ' If Off Hook and the loop_current drops, the caller has hung up. Drop the line
   IF (sieze = 1) AND (loop_current = 1) Then initialize        
   IF (ring_detect = 0) Then    ' Check for ring-detect (incoming call, active low)
      j = 0                     ' Clear j variable (time elapsed since last ring-detect)
ring_cycle:
      High led4                 ' Light LED to indicate incoming call
      Pause 1                   ' Pause 1mS so we can time this loop
      j = j + 1                 ' Each count of j represents 1mS of time 
      IF (j > 60) Then stop_ringing ' If no ring_detect for 60mS, ring has ended
      IF ring_detect = 1 Then ring_cycle' Stay in this loop until ring_detect
      Pause 30                  ' Pause 30mS.  (Low period of ring-detect)              
      j = 30                    ' Set j to 30 (30mS)
      GoTo ring_cycle           ' Loop to keep monitoring the ring-detect
stop_ringing:                   ' Jump here at end of ring or to answer call
     Low led4                   ' Shut off the LED
     Pause 250                  ' Wait 250mS for line to settle
     
     ' Look for CID data, abort if no data for 500mS
     SerIn2 cid_serial_data, 813, 500, mainloop, [wait($80),wait($04,$01), cid_code]
     IF cid_code = "P" Then block_call  ' Check for "Private" code
   EndIF        
   GoTo mainloop                ' Repeat main loop

block_call:                     ' Jumps here if turned on and the caller id is blocked
   sieze = 1                    ' Sieze line (Off Hook)
   Pause 500                    ' Wait 500mS to establish loop current 
   FreqOut dtmf_out,330,950     ' Send 950Hz tone for 330mS
   Pause 25                     ' 25mS of silence
   FreqOut dtmf_out,330,1400    ' Send 1400Hz tone for 330mS
   Pause 25                     ' 25mS of silence
   FreqOut dtmf_out,330,1800    ' Send 1800Hz tone for 330mS
   Pause 1000                   ' 1 second of silence
   GoTo mainloop                ' Back to main loop

   End

           

Download the program file.