Actions

Difference between revisions of "Fake Cricket"

From Just in Time

m
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
A fake cricket is not a really useful application, but it is very simple to create and can be fun to drive people crazy. Or to hide and seek with children.
 
A fake cricket is not a really useful application, but it is very simple to create and can be fun to drive people crazy. Or to hide and seek with children.
  
If you use a high-impedance speaker, it can be driven directly from the output pins of your microcontroller. A piezo element should also work, but might not give much output power with low voltages.
+
If you use a high-impedance speaker, it can be driven directly from the output pins of your microcontroller. A piezo element should also work, but might not give much output power with low voltages / low frequencies.
  
 
For a low-impedance speaker a simple 'amplifier' (transistor) should work.
 
For a low-impedance speaker a simple 'amplifier' (transistor) should work.
  
Tip: Instead of connecting your output speaker with one pin to VDD/VSS, more output can be generated by connecting with two output pins and swapping them. This trick seems to work, and I think it works because a speaker is current-driven. For a piezo, it doesn't matter, since a piezo is voltage-driven.
+
Here is the Fake Cricket built in a cheap scan radio.
  
Cricket sample code:
+
[[Image:cricket.jpg]]
  
----
+
Tip: Instead of connecting your output speaker with one pin to VDD/VSS, more output can be generated by connecting with two output pins and alternating them. This trick seems to work, and I think it works because a speaker is current-driven. For a piezo, it doesn't matter, since a piezo is voltage-driven.
  
; File cricket.asm
+
; File cricket.asm
; Assembly code for a 4MHz PIC12F509 microcontroller
+
; Assembly code for a 4MHz PIC12F509 microcontroller
;
+
;
; Description: Fake cricket sound for a 12F509  
+
; Description: Fake cricket sound for a 12F509  
; Author: Vincent
+
; Author: Vincent
; Last Modified: 17 / 8 / 06
+
; Last Modified: 17 / 8 / 06
 +
 
 +
;
 +
; CPU configuration
 +
        processor 12f509
 +
          __config  _IntRC_OSC & _WDT_OFF & _MCLRE_OFF 
 
   
 
   
;
+
  ;=======================================
; CPU configuration
+
;  Configuration (FUSE) BIT Definitions  
        processor 12f509
+
;=======================================
        __config _IntRC_OSC & _WDT_OFF & _MCLRE_OFF
+
_MCLRE_ON            EQU        0FFFh       
 
+
_MCLRE_OFF          EQU        0FEFh       
;=======================================
+
_CP_ON              EQU        0FF7h       
;  Configuration (FUSE) BIT Definitions  
+
_CP_OFF              EQU        0FFFh       
;=======================================
+
_WDT_ON              EQU        0FFFh       
_MCLRE_ON            EQU        0FFFh       
+
_WDT_OFF            EQU        0FFBh       
_MCLRE_OFF          EQU        0FEFh       
+
_LP_OSC              EQU        0FFCh       
_CP_ON              EQU        0FF7h       
+
_XT_OSC              EQU        0FFDh       
_CP_OFF              EQU        0FFFh       
+
_IntRC_OSC          EQU        0FFEh       
_WDT_ON              EQU        0FFFh       
+
_ExtRC_OSC          EQU        0FFFh        
_WDT_OFF            EQU        0FFBh       
+
_LP_OSC              EQU        0FFCh       
+
_XT_OSC              EQU        0FFDh       
+
; 509 defs  
_IntRC_OSC          EQU        0FFEh       
+
_ExtRC_OSC          EQU        0FFFh      
+
PCL equ H'02'
 
+
STATUS equ H'03'
 
+
OSCCAL equ H'05'
; 509 defs
+
GPIO equ H'06'
 
+
Z equ H'02'  
PCL equ H'02'
+
STATUS equ H'03'
+
; variables
OSCCAL equ H'05'
+
       
GPIO equ H'06'
+
CounterA equ H'1F' ; delay counter
Z equ H'02'
+
CounterB equ H'1E' ; delay counter
 
+
CounterC equ H'1D' ; delay counter
; variables
+
CounterD equ H'1C' ; delay counter  
       
+
CounterA equ H'1F' ; delay counter
+
; statics
CounterB equ H'1E' ; delay counter
+
CounterC equ H'1D' ; delay counter
+
aupin equ H'00'
CounterD equ H'1C' ; delay counter
+
aupin2  equ H'01'  
 
+
; statics
+
; Program
 
+
 
aupin equ H'00'
+
        org    0        ; start at address 0
aupin2  equ H'01'
+
       
 
+
start: 
; Program
+
movwf OSCCAL ; calibration bits
 +
movlw 0 ; set tris output
 +
tris GPIO
 +
 +
mainloop:
 +
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
call freq4500
 +
call freq4200
 +
 
 +
none:
 +
call secdelay ; which is in fact 8 secs
 +
 +
goto mainloop
 +
 +
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 +
; subs
 +
 
 +
freq4200: ; freq loop should be 238 cycles to get 4200Hz
 +
movlw 0040h ; counter set for 11msec
 +
movwf CounterD
 +
 
 +
loop42:
 +
bcf GPIO,aupin
 +
bsf GPIO,aupin2
 +
call del42
 +
bcf GPIO,aupin2
 +
bsf GPIO,aupin
 +
call del42
 +
 
 +
decfsz CounterD,1
 +
goto loop42
 +
 +
retlw 0
 +
 +
freq4500: ; freq loop should be 222 cycles to get 4500Hz
 +
movlw 002Dh ; counter set for 14msec
 +
movwf CounterD
 +
loop45:
 +
bcf GPIO,aupin
 +
bsf GPIO,aupin2
 +
call del45
 +
bcf GPIO,aupin2
 +
bsf GPIO,aupin
 +
call del45
 +
 
 +
decfsz CounterD,1
 +
goto loop45
 +
 +
retlw 0
 +
 +
;;;;;;;;;;
 +
del42
 +
movlw 0023h
 +
movwf CounterA
 +
 
 +
loop4 decfsz CounterA,1
 +
goto loop4
 +
 
 +
retlw 0
 +
 +
;;;;;;;;;;;
 +
del45
 +
movlw 0026h
 +
movwf CounterA
 +
 
 +
loop5 decfsz CounterA,1
 +
goto loop5
 +
 +
retlw 0
 +
 +
 +
secdelay
 +
; insert picloops code here
 +
;PIC Time Delay = 8,0000040 s with Osc = 4,000000 MHz
 +
movlw D'41'
 +
movwf CounterC
 +
movlw D'190'
 +
movwf CounterB
 +
movlw D'87'
 +
movwf CounterA
 +
sloop decfsz CounterA,1
 +
goto sloop
 +
decfsz CounterB,1
 +
goto sloop
 +
decfsz CounterC,1
 +
goto sloop
 +
retlw 0
 
   
 
   
        org    0        ; start at address 0
 
       
 
start: 
 
movwf OSCCAL ; calibration bits
 
movlw 0 ; set tris read except for aupin
 
tris GPIO
 
 
mainloop:
 
 
   
 
   
call freq4500
+
        end
call freq4200
+
[[Category:PIC]]
call freq4500
+
{{Comments}}
call freq4200
 
call freq4500
 
call freq4200
 
call freq4500
 
call freq4200
 
 
 
none:
 
call secdelay
 
 
 
goto mainloop
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
; subs
 
 
 
freq4200: ; freq loop should be 238 cycles to get 4200Hz
 
movlw 0040h ; counter set for 11msec
 
movwf CounterD
 
 
 
loop42:
 
bcf GPIO,aupin
 
bsf GPIO,aupin2
 
call del42
 
bcf GPIO,aupin2
 
bsf GPIO,aupin
 
call del42
 
 
 
decfsz CounterD,1
 
goto loop42
 
 
 
retlw 0
 
 
 
freq4500: ; freq loop should be 222 cycles to get 4500Hz
 
movlw 002Dh ; counter set for 14msec
 
movwf CounterD
 
loop45:
 
bcf GPIO,aupin
 
bsf GPIO,aupin2
 
call del45
 
bcf GPIO,aupin2
 
bsf GPIO,aupin
 
call del45
 
 
 
decfsz CounterD,1
 
goto loop45
 
 
 
retlw 0
 
 
 
;;;;;;;;;;
 
del42
 
movlw 0023h
 
movwf CounterA
 
 
 
loop4 decfsz CounterA,1
 
goto loop4
 
 
 
retlw 0
 
 
 
;;;;;;;;;;;
 
del45
 
movlw 0026h
 
movwf CounterA
 
 
 
loop5 decfsz CounterA,1
 
goto loop5
 
 
 
retlw 0
 
 
 
 
 
secdelay
 
; insert picloops code here
 
;PIC Time Delay = 8,0000040 s with Osc = 4,000000 MHz
 
movlw D'41'
 
movwf CounterC
 
movlw D'190'
 
movwf CounterB
 
movlw D'87'
 
movwf CounterA
 
sloop decfsz CounterA,1
 
goto sloop
 
decfsz CounterB,1
 
goto sloop
 
decfsz CounterC,1
 
goto sloop
 
retlw 0
 
 
 
 
 
        end
 

Latest revision as of 00:20, 26 January 2011

A fake cricket is not a really useful application, but it is very simple to create and can be fun to drive people crazy. Or to hide and seek with children.

If you use a high-impedance speaker, it can be driven directly from the output pins of your microcontroller. A piezo element should also work, but might not give much output power with low voltages / low frequencies.

For a low-impedance speaker a simple 'amplifier' (transistor) should work.

Here is the Fake Cricket built in a cheap scan radio.

Cricket.jpg

Tip: Instead of connecting your output speaker with one pin to VDD/VSS, more output can be generated by connecting with two output pins and alternating them. This trick seems to work, and I think it works because a speaker is current-driven. For a piezo, it doesn't matter, since a piezo is voltage-driven.

; File cricket.asm
; Assembly code for a 4MHz PIC12F509 microcontroller
;
; Description: Fake cricket sound for a 12F509 
; Author: Vincent
; Last Modified: 17 / 8 / 06
 
; 
; CPU configuration
        processor 12f509
         __config  _IntRC_OSC & _WDT_OFF & _MCLRE_OFF   

;=======================================
;  Configuration (FUSE) BIT Definitions 
;=======================================
_MCLRE_ON            EQU        0FFFh       
_MCLRE_OFF           EQU        0FEFh       
_CP_ON               EQU        0FF7h       
_CP_OFF              EQU        0FFFh       
_WDT_ON              EQU        0FFFh       
_WDT_OFF             EQU        0FFBh       
_LP_OSC              EQU        0FFCh       
_XT_OSC              EQU        0FFDh       
_IntRC_OSC           EQU        0FFEh       
_ExtRC_OSC           EQU        0FFFh         


; 509 defs 

PCL		equ	H'02'
STATUS		equ	H'03'
OSCCAL		equ	H'05'
GPIO		equ	H'06'
Z		equ	H'02' 

; variables
        
CounterA	equ	H'1F'		; delay counter
CounterB	equ	H'1E'		; delay counter
CounterC	equ	H'1D'		; delay counter
CounterD	equ	H'1C'		; delay counter 

; statics

aupin	equ	H'00'
aupin2  equ H'01' 

; Program
 
        org     0         	; start at address 0
        
start:   
	movwf	OSCCAL		; calibration bits
	movlw	0		; set tris output
	tris	GPIO		

mainloop:

	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
	call freq4500
	call freq4200
 
none:	
	call secdelay 	 	; which is in fact 8 secs

	goto mainloop

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; subs
 
freq4200:			; freq loop should be 238 cycles to get 4200Hz 
	movlw	0040h		; counter set for 11msec
	movwf	CounterD
 
loop42:
	bcf		GPIO,aupin
	bsf		GPIO,aupin2
	call del42
	bcf		GPIO,aupin2
	bsf		GPIO,aupin
	call del42
 
	decfsz	CounterD,1
	goto loop42

	retlw 0

freq4500:			; freq loop should be 222 cycles to get 4500Hz
	movlw	002Dh		; counter set for 14msec
	movwf	CounterD	
loop45:
	bcf		GPIO,aupin
	bsf		GPIO,aupin2
	call del45
	bcf		GPIO,aupin2
	bsf		GPIO,aupin
	call del45
 
	decfsz	CounterD,1
	goto loop45

	retlw 0

;;;;;;;;;;
del42
		movlw	0023h
		movwf	CounterA
 
loop4	decfsz	CounterA,1
		goto loop4
 
		retlw 0

;;;;;;;;;;;
del45
		movlw	0026h
		movwf	CounterA
 
loop5	decfsz	CounterA,1
		goto loop5

		retlw 0


secdelay
; insert picloops code here	
;PIC Time Delay = 8,0000040 s with Osc = 4,000000 MHz
		movlw	D'41'
		movwf	CounterC
		movlw	D'190'
		movwf	CounterB
		movlw	D'87'
		movwf	CounterA
sloop	decfsz	CounterA,1
		goto	sloop
		decfsz	CounterB,1
		goto	sloop
		decfsz	CounterC,1
		goto	sloop
		retlw 0


        end

Template:Comments