4 ALARM SOUNDS


Home


See more projects using micros:
Elektor,EPE,Silicon Chip

4 ALARM SOUNDS chip $2.50

To order send an email to us and we will reply with the details.
 

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

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

4 ALARM SOUNDS for PIC12F629

;	alarm_4Sounds.asm	for PIC12F629   29-1-2010
;
;This program has goto mode 2,3 changed to produce 
;SPACE GUN with A0 and A1 HIGH 
;quiescent current = 100microamps
;
;
;
;       --+------------ +5v     
;	  |                  |  |
;    +--- | -----------------|[]|----+
;    |    |Vdd ---v---       |  |    |
;    |    +---|1   Gnd|      piezo   |
;    |        |       |              |
;    +--------|GP5 GP0|--------------+
;             |       |                    
;  Enable-----|GP4 GP1|----A0
;             |       |     
;        +----|GP3 GP2|----A1
;        |     -------     
;        |    PIC12F629        
;        |
;        |
;    ----+---------- 0v
;


	radix	dec
	include	"p12f629.inc"
	
	errorlevel	-302	; Don't complain about BANK 1 Registers 

	__CONFIG	_MCLRE_OFF & _CP_OFF & 
			_WDT_OFF & _INTRC_OSC_NOCLKOUT  ;Internal osc.



STATUS	equ	3		
PC	equ	2			
#define	CARRY	STATUS,0				
#define	ZERO	STATUS,2				
#define	outa	GPIO,0	;			
#define	modea	GPIO,1	;			
#define	modeb	GPIO,2	;			
#define	enbf	GPIO,3	;			
#define	enbt	GPIO,4	;		
#define	outb	GPIO,5	;		
flags	equ	20h	;flags file	
temp	equ	21h		
delA         equ           22h
delB         equ           23h

dwell        equ           25h          ;cycles
count       equ           26h          ;delay
steps       equ           27h          ;dwell
cnth         equ           28h 
cntl          equ           29h 		
		
		
	org 0 
	goto setup
	nop
	nop
	nop
	nop
	goto Enable
	

SetUp	movlw 	b'00001111' ;0001 1111 
	movwf 	GPIO        ;Make GP 0 HIGH and GP5 LOW for piezo & GP4 low
	bsf 	status,rp0 	;Bank 1 
	movlw 	b'00011110'
	movwf	 trisio 	;Make GP1,2,3,4 input GP0,5 output
	movlw 	b'10000110'   ;Turn off T0CKI, prescaler for TMR0 = 1:128
	movwf 	option_reg 
	bsf 	intcon,3 	;enable GPIO state change int
	bsf 	intcon,7 	;enable global interrupt GIE
	bsf 	IOC,4 	;enables interrupt on GPIO 4 
	bcf 	status,rp0 ;bank 0 
	movlw 	07h 	;Set up W to turn off Comparator ports
	movwf 	CMCON 	;must be placed in bank 0 
	clrf 	delA
	movlw 	.140 	;for 3 minutes
	movwf 	delB
				
		
		;look for enable HIGH
	
	goto $+1
	goto $+1
	decfsz 	temp,1
	goto 	$-3
	movf 	GPIO,w 	;clears the Int-on-change flag
	bsf 	status,rp0 ;Bank 1 
	bcf 	intcon,gpif
	bcf 	status,rp0 ;bank 0 
	nop
	sleep 
	nop 		;micro goes to ISR at address 04!!!!!!!!!
Enable 	call 	_3min
	btfsc 	GPIO,1 	;Test A0
	goto 	$+4 	;A0=High
	btfsc 	GPIO,2 	;A0=Low Test A1
	goto 	mode3 	;A0=Low A1=high
	goto 	mode0 	;A0=Low A1=low
	btfsc 	GPIO,2 	;A0=High Test A1
	goto 	mode2     ;A0=High A1=high This program produces SPACE GUN
	goto 	mode1 	;A0=High A1=low           with A0 and A1 HIGH
	
		
	;mode	0	CONSTANT 2.2kHz tone   A0=Low  A1=low
	
mode0	movlw	.20	; set frequency 
	movwf	count
	call	toggle		
	btfsc	GPIO,4 	;test GPIO,4 - High Input enables chip to produce tone
	goto	$-4
	goto	Enable
		
		
	;mode 1   CHIRP	  A0=High  A1=low
							
mode1		
	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	toggle					
	decfsz	cntl,1	;decrement and test counters	
	goto	mode1a						
	decfsz	cnth,1						
	goto	mode1a						
	movlw	2	;set pause delay to counters
	movwf	cnth		
	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	
	call	toggle	
	decfsz	cntl,1	;decrement and test counters
	goto	mode1c					
	decfsz	cnth,1					
	goto	mode1c
	btfsc	GPIO,4 	;test GPIO,4 - High Input enables chip to produce tone
	goto	mode1
	goto	Enable					
						
		
			
	;SPACE GUN	A0=Low  A1=high
					
mode2						
	movlw	7	;number of steps
	movwf	steps			
mode2a								
	movlw	5	;dwell		
	movwf	dwell					
	call	toggle
	decfsz	dwell,1	; test if dwell = 0
	goto	$-2						
	movlw	5				
	subwf	count,1	 ;increment frequency			
	btfss	GPIO,4 	;test GPIO,4 - High Input enables chip to produce tone
	goto	Enable	;see if Enable is still HIGH and loop again
	decfsz	steps,1	 ;test if more steps	
	goto	mode2a						
	goto	mode2
		
			
		
mode3      ;mode 3 SIREN   A0=High  A1=high

 	movlw	37	;set frequency 	
	movwf	count					
	movlw	6	; set number of steps
	movwf	steps						
mode3a	movlw	0x20	; 0010 0000 set dwell 
	movwf	dwell					
mode3b	call	toggle						
	decfsz	dwell,1	; test if any more cycles	
	goto	mode3b					
	movlw	5	; step frequency delay		
	subwf	count,1					
	decfsz	steps,1	; test if last step in progress
	goto	mode3a	;
	btfsc	GPIO,4 	;test GPIO,4 - High Input enables chip to produce tone
	goto	mode3
	goto	Enable
				
							
toggle	movf	count,0
	movwf	temp
	goto	$+1
	goto	$+1
	decfsz	temp,1
	goto	$-3
	movlw	b'00100001'
	xorwf	GPIO,1		;toggle bits 0 & 5	
	retlw	00
_3min 	decfsz 	delA
	retlw 	00
	decfsz 	delB
	retlw 	00
	goto 	SetUp

	end	


The PIC12F629 chip is available for $2.50 with
4 Alarm Sounds.hex burnt into it.
You will just need a small PC board, mercury switch, battery, switch, and piezo to complete the alarm.
If you are going to burn the program yourself, you will need a PICkit-2 programmer,
a 6 pin to 5 pin adapter to connect between the PICkit-2 programmer and the Project ($1.50) and the above components. 
You should read about programming PIC chips by clicking this link:
Start here with PIC12F629
If you have any other questions, contact Colin Mitchell via email.


  2/1/10