4 ALARM SOUNDS using PIC12F629

4 ALARM SOUNDS

This project is a miniature 1-chip alarm. All you need is a tilt switch, battery and piezo to produce a complete alarm.
If you want a very high output, you can add a Darlington buffer transistor, piezo tweeter and a 10mH choke.
The chip does all the work.
It sits in sleep mode (100 microamps) and waits for the enable line to go high via the tilt switch.
It then produces a SPACE GUN alarm for approx 3 minutes and goes into sleep mode again.
The .asm and .hex for  4 Alarm Sounds chip with Space Gun selected when A0 and A1
HIGH, is in the following files:
4 Alarm Sounds.asm
4 Alarm Sounds.hex

4 ALARM SOUNDS

Below is the program written by the original designer of the project. It is complex and contains an instruction: movlw wabl_dir_mask ;change direction  This instruction is now allowed. Possibly it should be: movfw wabl_dir_mask ;change direction. I don’t know how he was able to compile the program. I could not assemble it.
Read through the program then look at the next program for PIC12F629. It is shorter, easier to read, has better sounds, includes sleep mode (100microamps) and a 3 minute timer. You can always learn from other peoples work.
Here are some of the things to consider.
1. The second program has has fewer instructions for each sub-routine. For instance:
decf      dwell,1 ; test if dwell = 0
btfsc     ZERO
has been replaced with:
decfsz   dwell,1 ; test if dwell = 0
goto       $-2    ;go up the program two instructions
2. The piezo lines toggle via the following instructions:
movlw       b’00100001′
xorwf        GPIO,1         ;toggle bits 0 & 5
This makes GP0 and GP5 change state each time the sub-routine is executed. You do not need to know the previous state of either line. They change state each time the sub-routine is called.
3.  Instruction:  goto $+1   uses 2 cycles and saves writing:    nop    nop  and saves one  line of code.

4 ALARM SOUNDS for PIC12F509

;	alarmt.asm	

__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT 

GPIO	equ	6	
STATUS	equ	3		
PC	equ	2			
#define	CARRY	STATUS,0				
#define	ZERO	STATUS,2				
#define	outa	GPIO,0	;Output to Piezo - toggles with GPIO,5	
#define	modea	GPIO,1	;Input A0 determines 1 of 4 sounds: 00, 01, 10, 11
#define	modeb	GPIO,2	;Input A1 determines 1 of 4 sounds: 00, 01, 10, 11
#define	enbf	GPIO,3	;tied LOW			
#define	enbt	GPIO,4	;HIGH input enables the chip to produce sounds 	
#define	outb	GPIO,5	;Output to Piezo - toggles with GPIO,0

;Files for temporary storage:		
bits	equ	0Ah   	;flags file		
temp	equ	0Bh	;temporary storage	
dwell	equ	0Ch	;cycles
count	equ	0Dh	;delay
steps	equ	0Eh	;dwell
cnth	equ	0Fh	;counter HIGH	
cntl	equ	10h	;counter LOW	
#define	flag		bits,1	;flags file, bit 1 = 0Ah,1		
#define	wabl_dir	bits,2	;flags file, bit 2 = 0Ah,2		
#define	wabl_dir_mask	bits,4  ;flags file, bit 4 = 0Ah,4

;*************************************
;Program starts HERE
;*************************************
			
esetvec	org	0			
 	movlw	0D0h	;1101 0000  	
 	movwf	option_reg	;Weak pull-up and Pin-change disabled	
			;Option is normally 1111 1111 - so 0D0h has no effect	
 	movlw	1Eh	;0001 1110			
 	movwf	GPIO	;Make GP 0 and 5 LOW for piezo 	
 	movwf	trisio	;Make GP4 input			
top1						
 	bcf	wabl_dir     ;clear flags bit 2	
 	bcf	flag	  ;clear bit 1 in flags file			
top						
 	btfss	enbt	;test GPIO,4  - Chips is enabled when HIGH 
 	goto	top1	;micro goes here when enable low - loops 4 instructions above
 	nop		;micro goes here when enable HIGH - then to rrf below!!	
 	btfsc	enbf	;Tied LOW!! - will always be "clear" - LOW
 	goto	top1	;micro can never go HERE.			
			;micro always goes here	

		;The following creates a miniature Table:

 	rrf	GPIO,w	;GPIO will have 0000 0xx0 via A0 and A1		
 	andlw	3	;after rrf the result will be: 0000 00xx		
 	addwf	PC,1	;masks all but the two lowest bits and adds to Program Counter
 	goto	mode0	;jumps here if A0 and A1 LOW		
 	goto	mode1	;jumps here if A0 HIGH and A1 LOW		
 	goto	mode2	;jumps here if A0 LOW and A1 HIGH		
	goto	mode3	;jumps here if A0 and A1 HIGH
		
mode3      ;mode 3   SIREN
								
i1 	movlw	37	;set frequency delay	
 	movwf	count						
 	movlw	6	; set number of frequency steps
 	movwf	steps						
i2								
 	movlw	0x20	; 0010 0000 set frequency dwell delay 64d
 	movwf	dwell					
alarm1	; send 1 cycle					
 	call	alarm1_set				
 	movlw	1Fh	;0001 1111		
 	movwf	GPIO	;Makes GP0 HIGH GP5 LOW			
 	call	alarm1_clr				
out1							
 	decfsz	dwell,1	; test if any more cycles	
 	goto	alarm1					
 	movlw	5	; step frequency delay		
 	subwf	count,1					
 	decfsz	steps,1	; test if last step in progress
 	goto	i2	;				
 	goto	top	;see if Enable is still HIGH and loop again
			;Enable must go LOW to stop alarm
		
mode0	;init mode  0  CONSTANT	
 	movlw	35	; set	frequency delay		
 	movwf	count					
 	call	alarm1_set	; send 1 cycle	
 	movlw	1Fh	; 0001 1111		
 	movwf	GPIO	;Makes GP0 HIGH  - GP5 LOW			
 	call	alarm1_clr					
 	nop						
 	goto	top	;see if Enable is still HIGH and loop again
			;Enable must go LOW to stop alarm

;							
mode1	;init mode	1  CHIRP		
 	bcf	flag	;clear bit1 in bits file - flags file		
 	movlw	35	; set frequency delay	
 	movwf	count	;put 35 into Count file				
 	movlw	1	; 		
 	movwf	cnth	;put 1 in counter HIGH file			
 	clrf	cntl	;clear counter LOW file			
mode1a								
 	call	alarm1_set	; set	1st pulse		
 	movlw	1Fh	; 0001 1111			
 	movwf	GPIO	;Makes GP0 HIGH - GP5 LOW			
 	call	alarm1_clr					
 	decfsz	cntl,1	; decrement and test counters	
 	goto	mode1a						
 	decfsz	cnth,1						
 	goto	mode1a						
 	movlw	2	; set	pause	delay	to counters
	movwf	cnth	; pause = ~6*cnth*~255us	
	clrf	cntl					
mode1b							
 	nop							
 	nop							
 	nop					
 	decfsz	cntl,1	; decrement and test counters	
 	goto	mode1b						
 	decfsz	cnth,1						
 	goto	mode1b						
 	movlw	1	;init second pulsed delay to counters
 	movwf	cnth					
 	clrf	cntl						
mode1c	; send 1 cycle					
 	call	alarm1_set					
 	movlw	1Fh	; 0001 1111				
 	movwf	GPIO	;Makes GP0 HIGH - GP5 LOW			
 	call	alarm1_clr					
 	decfsz	cntl,1	; decrement and test counters
 	goto	mode1c					
 	decfsz	cnth,1					
 	goto	mode1c					
 	goto	top	;see if Enable is still HIGH and loop again
			;Enable must go LOW to stop alarm
mode2	;init mode 2   WARBLE			
 	btfsc	flag	; test control flag	
 	goto	mode2fa					
 	movlw	0x19 	; init frequency delay
 	movwf	count					
mode2e							
 	movlw	8	; init number of frequency steps
 	movwf	steps						
mode2b								
 	movlw	5	; init frequency dwell		
 	movwf	dwell						
mode2a								
 	decf	dwell,1	; test if dwell = 0
 	btfsc	ZERO						
 	goto	mode2d						
 	call	alarm1_set	;set 1 cycle		
 	movlw	1Fh						
 	movwf	GPIO						
 	call	alarm1_clr				
 	goto	mode2a						
mode2d								
 	decf	steps,1	; test if more steps	
 	btfsc	ZERO				
 	goto	mode2f				
 	btfss	wabl_dir ; test warble direction
 	goto	mode2g				
 	movlw	5				
 	subwf	count,1	; increment frequency	
 	goto	mode2b				
mode2g						
 	movlw	5	; decrement frequency	
 	addwf	count,1				
 	goto	mode2b				
mode2f						
 	bsf	flag	; set	control flag		
 	goto	top	;see if Enable is still HIGH and loop again
			;Enable must go LOW to stop alarm
mode2fa							
 	movlw	wabl_dir_mask	; change direction
 	xorwf	bits,1					
 	movlw	7	; reload number of frequency steps
 	movwf	steps					
 	goto	mode2b	

alarm1_set	; set 1 cycle sub-service		
 	movlw	3Eh	; 0011 1110  Make GP0 LOW -  GP5 HIGH		
 	movwf	GPIO	;toggles GP0 and 5 
alarm1_clr	; copy and decrement frequency delay	
 	movfw	count	;set for *4 to define pulse frequency
 	movwf	temp					
Dec2	; 14+2*(4*temp*~1us)= frequency	
 	nop					
 	decfsz	temp,1		
 	goto	Dec2			
 	clrf	GPIO	; leave all output lines LOW
 	retlw	0				

	end

The .asm and .hex for  4 Alarm Sounds chip with Space Gun selected when A0 and A1
HIGH, is in the following files:
4 Alarm Sounds.asm
4 Alarm Sounds.hex

Read more: 4 ALARM SOUNDS using PIC12F629

Leave a Comment

Your email address will not be published. Required fields are marked *