This program is for: PIC12C508A
For full details of the project, go to
the pages in the side-bar on the left:
Introduction
Construction
Using Probe
Using Pulser
Going Further

There are 8 files:
(The capital letters indicate the .asm files)
LoPIC08 - this is .asm - no tones
Lopic08- this is .hex - no tones
LoPIC08T- this is .asm - with tones
Lopic08t- this is .hex - with tones
LoPIC84- this is .asm - no tones
Lopic84- this is .hex - no tones
LoPIC84T- this is .asm - with tones
Lopic84t- this is .hex - with tones

Start










 Alarm

 Alarm1

 Alarm2











 Delay

 Delay1

 Delay2










 Input



 Input1








 Input2
 Input3








 Input4





 Input5
 Input6










 TstA








 TstA1









 Hi




 Lo 


 Tone 






 Main





 Main1

 Main2
















ORG 0x00 
MOVLW 08h       ;Put 08 into W 
TRIS 06               ;Make GP3 input, others output
OPTION 0DFh  ;Make GP2 an output & disable weak pullups
CLRF 06             ;Clear port 6
BSF 06,4            ;Make probe-line HIGH
CLRF 11h           ;Clear 1 minute alarm file 
BTFSC 06,3       ;Is input RB3 HIGH or LOW?
GOTO Main        ;It is HIGH 
GOTO Siren       ;It is LOW

MOVLW 20h      ;Length of the alarm
MOVWF 12h
MOVLW 40h       ;The HIGH/LOW time
MOVWF 13h
DECFSZ 13h,1    ;Time for ON and OFF periods
GOTO Alarm2 
MOVLW 20h       ;Toggle the Piezo line
XORWF 06,1
DECFSZ 14,1      ;256 loops of ON/OFF
GOTO Alarm1
DECFSZ 12h,1
GOTO Alarm1
CLRF 11h              ;Clear the alarm 1-minute timer file
BCF 06,5               ;Turn off piezo bit
RETURN

MOVLW 05         ;5 loops of routine below
MOVWF 0E ;
MOVLW 0B0h     ;Create the 1/4sec ON period
MOVWF 0Dh
CALL Input
CALL TstA
DECFSZ 0Dh,1    ;Loop for 0B loops to create 1/4 sec
GOTO Delay2
DECFSZ 0Eh,1    ;Loop 5 lots of 0B loops
GOTO Delay1
RETURN

;The "Input" sub-routine will put a 
;value in files 1E and 1F

CLRF 1E             ;Clear the HIGH count file
CLRF 1F             ;Clear the LOW count file
MOVLW 08h      ;8 loops
MOVWF 0Ch      ; file 0C is 8 for 8 loops
BSF 06,4            ;Make probe Tip HIGH
NOP
NOP
NOP                   ;Allow time for 47p to charge
NOP
BTFSS 06,3       ;Test the input line RB3
GOTO Input2     ;Input is LOW
INCF 1E,1          ;Increment the HIGH file
GOTO Input3
INCF 1F,1          ;Increment the LOW file
BCF 06,4           ;Make probe tip LOW
NOP
NOP
NOP
NOP
NOP                   ;Allow time for 47p to discharge
NOP
MOVLW 05
MOVWF 13h
BTFSC 06,3       ;Test the input line RB3
GOTO Input5
DECFSZ 13h,1
GOTO Input4
INCF 1F,1           ;Increment the LOW file
GOTO Input6
INCF 1E,1           ;Increment the HIGH file 
DECFSZ 0Ch,1
GOTO Input1
BCF 06,0            ;Turn off LOW LED
BCF 06,1            ;Turn off HIGH LED
RETURN

;This routine checks to see if file 1E is zero 
; if not, it does a subtraction with W to 
; see if it is 1, 2 or 3. This indicates a pulse!
;The routine then checks for a constant HIGH or LOW

MOVLW 00h      ;Eliminate file 1E if it is zero
XORWF 1E,0      ;XOR file 1E with W
BTFSC 03,2        ;Test the zero flag to see if file 1E is zero
GOTO TstA1      ;File 1E is zero
MOVLW 04        ;Put 04 into W for subtract operation
SUBWF 1E,0      ;Carry will be set if 1E is = or more than 4
BTFSS 03,0        ;Test the carry flag 
GOTO Hi             ;Will go to Hi if 1E is 1, 2, or 3

MOVLW 00h     ;This tests if the waveform is never LOW
XORWF 1F,0     ; - it must be HIGH
BTFSC 03,2       ;Test zero bit in Option file
GOTO Hi
MOVLW 00h      ;This tests if the waveform is never LOW
XORWF 1E,0 ;
BTFSC 03,2       ;Zero flag in Option file will be set
GOTO Lo           ; if 1E is equal to zero
RETURN ;

MOVLW 40h      ;Length of Hi tone
MOVWF 1A
BSF 06,1            ;Turn on HIGH LED
GOTO Tone

BSF 06,0            ;Turn on LOW LED
GOTO Tone

DECFSZ 1A,1
GOTO Tone 
MOVLW 20h 
XORWF 06,1      ;Toggle the piezo bit 
CLRF 11h           ;Clear the 1 minute alarm file
RETURN

BSF 06,2            ;Set the Pulser output HIGH
CALL Delay
BCF 06,2             ;Set the pulser output LOW
CALL Delay
MOVLW 05         ;5 loops for file 0E
MOVWF 0E
MOVLW 0B0h     ;B0 loops for file 0D
MOVWF 0D
MOVLW 04h       ;toggle the Logic Pulser output RB2
XORWF 06,1
CALL Input
CALL TstA
DECFSZ 0Dh,1    ;B0 loops
GOTO Main2
DECFSZ 0Eh,1     ;5 lots of B0 loops
GOTO Main1
BCF 06,2              ;Set the Pulser output LOW
CALL Delay
INCF 11h,1            ;increment the 1 minute alarm file
MOVLW 40h         ;40h = 64 loops of 1 second = 1 minute
XORWF 11h,0      ;Is alarm file =zero
BTFSC 03,2          ;Test the zero flag
CALL Alarm          ;"turn off Logic Probe" beep
BCF 06,5              ;Turn off piezo bit
GOTO Main
. ;Below are the tone routines in the alternate area. 
;Access is via probe-tip to earth before switch-on.
;Table1 has been placed before the routines  to keep it
;       in Page0 (for 508A)

Table1











































 Siren
 Siren1 






 Repeat

 On




 Off















 Siren2





 Ack2
 Ack3



 Again

 LineOn



 LineOff











 Ack4


 

ADDWF 02,1       ;Add W to Program Counter (register)
RETLW 0F5h       ;500 Hz
RETLW 1h
RETLW 0A2h      ;750 Hz
RETLW 2h
RETLW 79h         ;1,000 Hz
RETLW 2h
RETLW 5Fh         ;1,250 Hz
RETLW 3h
RETLW 4Fh         ;1,500 Hz
RETLW 2h
RETLW 3Bh         ;2,000 Hz
RETLW 1h
RETLW 2Eh         ;2,500 Hz
RETLW 2h
RETLW 26h         ;3,000 Hz
RETLW 1h
RETLW 20h         ;3,500 Hz
RETLW 1h
RETLW 1Bh         ;4,000 Hz
RETLW 2h
RETLW 18h         ;4,500 Hz
RETLW 1h
RETLW 14h          ;5,000 Hz
RETLW 3h
RETLW 0Eh          ;6,000 Hz
RETLW 5h
RETLW 0Ch          ;7,000 Hz
RETLW 4h
RETLW 0Ch          ;8,000 Hz
RETLW 1h
RETLW 8h            ;9,000 Hz
RETLW 4h
RETLW 8h             ;10,000 Hz
RETLW 2h
RETLW 0FFh         ;End of table marker


;Siren is a Siren-Up sound with repeat.
;Can be used for determining the resonant frequency of a 
; piezo-choke combination.

;SIREN

BSF 1F,0               ;Set "flag"
MOVLW 80h         ;Number of cycles for each tone
MOVWF 0Eh 
MOVWF 10h
MOVLW 50h          ;Number of steps (was 30h)
MOVWF 0Fh          ;1F holds the number of steps
MOVLW 50h          ;Determines frequency
MOVWF 0Ch
MOVF 0C,0            ;File 0C is moved to W
MOVWF 0D            ;W is moved to file 0D
BSF 06,5                ;Length of HIGH time to Piezo 
BSF 06,2                ;Turn on Pulser line
DECFSZ 0D,1          ;      "            "
GOTO On                ;       "           "
MOVWF 0Dh            ;W is moved to file 0D again
BCF 06,5                 ;Length of LOW time to Piezo
BCF 06,2                 ;Turn off pulser line
DECFSZ 0D,1          ;       "        "
GOTO Off               ;        "        "
DECFSZ 10h,1        ;Number of cycles for each tone
GOTO Repeat
DECF 0C,1               ;HIGH and LOW is shortened -tone rises 
INCF 0E,1                 ;Increase the number of cycles
MOVF 0E,0              ;File 0E to W
MOVWF 10h            ;W to file 10h
DECFSZ 0F,1           ;Number of steps
GOTO Repeat 
BTFSS 06,3              ;Is probe touching earth?
GOTO Siren2            ;Yes
BCF 1F,0                   ;No. Clear Probe touching earth "flag"
GOTO Siren1
BTFSS 1F,0              ;(Has probe been lifted and replaced)
GOTO Ack2              ;Yes. Probe is touching earth AGAIN 
GOTO Siren1

;AckAck    An alarm sound similar to anti-aircraft gun

BSF 1F,0
MOVLW 40h         ;Number of steps
MOVWF 14h
MOVLW 0C0h       ;Frequency of tone
MOVWF 15h
MOVF 15h,0          ;Move file 15h to W
MOVWF 16h          ;Move W to file 16h
BSF 06,5                ;Turn on Piezo
BSF 06,2                ;Turn on Pulser line
DECFSZ 16h,1
GOTO LineOn        ;Create the HIGH time
BCF 06,5                ;Turn off piezo
BCF 06,2                ;Turn off pulser line
DECFSZ 16h,1
GOTO LineOff        ;Create the LOW time
DECF 15h,1            ;Make the tone higher frequency
DECF 15h,1
DECFSZ 14h,1
GOTO Again 
BTFSS 06,3            ;Is probe touching earth?
GOTO Ack4            ;Yes
BCF 1F,0                 ;No. Clear Probe touching earth "flag"
GOTO Ack3
BTFSS 1F,0             ;(Has probe been lifted and replaced)
GOTO Hee               ;Yes. Probe is touching earth AGAIN 
GOTO Ack3
This is 20 bytes before Page0. Page0 is half the memory of a PIC12c508A. All Tables and routines that you want to call (such as CALL Hee) must be placed in Page0. Routines containing a CALL (such as Tones) can be placed in Page1. 



 Hee
 Hee1

 Hee2


 Hee3






 Hee4





 Haw

 Haw1



 Haw2






 Haw3








 Haw4






Tones 


Tones1 









Tones2



Loop1


Loop2
















Tones3

;Standard Hee Haw siren sound

BSF 1F,0 
MOVLW 0FFh          ;Number of loops
MOVWF 14h            ;The loop fine
MOVLW 0C0h          ;Duration of HIGH
BSF 06,5                  ;Turn on piezo
BSF 06,2                  ;Turn on pulser line
NOP
DECFSZ 15h,1         ;Create the HIGH time
GOTO Hee3
MOVLW 0C0h          ;Duration of the LOW
MOVWF 15h             ;The LOW file
BCF 06,5                   ;Turn off piezo
BCF 06,2                   ;Turn off pulser line
NOP
DECFSZ 15h,1          ;Create the LOW time
GOTO Hee4
DECFSZ 14,1            ;Decrement the loop file
GOTO Hee2              ;Do more cycles

MOVLW 0C0h           ;Number of loops
MOVWF 14h              ;The loop file
MOVLW 0FFh
MOVWF 15h
BSF 06,5                   ;Turn on piezo
BSF 06,2                   ;Turn on pulser line
NOP
DECFSZ 15h,1           ;Create the HIGH time
GOTO Haw2
MOVLW 0FFh            ;Duration of the LOW
MOVWF 15h              ;The LOW fine
BCF 06,5                    ;Turn off piezo
BCF 06,2                    ;Turn off pulser line
NOP
DECFSZ 15h,1            ;Create the LOW time
GOTO Haw3
DECFSZ 14,1              ;Decrement the loop file
GOTO Haw1               ;Do more cycles 
BTFSS 06,3                 ;Is probe touching earth?
GOTO Haw4               ;Yes
BCF 1F,0                     ;No. Clear Probe touching earth "flag"
GOTO Hee1
BTFSS 1F,0                ;Has probe been lifted and replaced?
GOTO Tones              ;Yes. Probe is touching earth AGAIN 
GOTO Hee1

;Tones - the table for "Tones" is above to be within 
;                      Page0 (00 to FF) boundary

CLRF 0C           ;Clear the Table-jump1 file
MOVLW 01
MOVWF 0F       ;Put 01 into Table-jump2 file
BSF 1F,0           ;Set the debounce flag
MOVF 0C,0       ;Move jump1 value into W for table CALL
CALL Table1
MOVWF 0D       ;File 0D is holding file1
XORLW 0FFh    ;Ex-OR W with FF for end of table
BTFSC 03,2       ;Look at zero flag in Status file
GOTO Siren       ;End of table found
MOVF 0F,0        ;Move jump2 value into W for Table CALL
CALL Table1 
MOVWF 10h      ;File 10h is holding file2
MOVF 0D,0        ;Move file 0D into W
MOVWF 0E        ;File 0E is decrementing file1
MOVF 10h,0      ;Move file 10h into W
MOVWF 11h      ;11h is decrementing file 2
NOP
DECFSZ 0E,1     ;Create HIGH and LOW values 
GOTO Loop1
DECFSZ 11h,1
GOTO Loop2
MOVLW 20h 
XORWF 06,1      ;Toggle piezo line
MOVLW 04
XORWF 06,1      ;Toggle Pulser line
BTFSC 06,3        ;Is Probe touching earth?
GOTO Tones3    ;No
BTFSC 1F,0        ;Yes. See if Probe has been lifted
GOTO Tones2    ;No
DECFSZ 1A,1     ;Yes. 256 loop debounce
GOTO Tones2
INCF 0C,1           ;Increment the table-jump value1 
INCF 0C,1           ;Increment the table-jump value1 
INCF 0F,1           ;Increment the table-jump value2 
INCF 0F,1           ;Increment the table-jump value2 
GOTO Tones1   ;Go to next tone
BCF 1F,0            ;Clear the debounce flag
GOTO Tones2 

END    

You cannot use this file as a .asm file because it is divided
into different columns. In addition, the assembler does
not like some files that have been copied from other sources and it puts up "error" messages. The only way to get rid of this error message is to re-hand-type the code!