please dont rip this site

Dave Thomas's  PIC DTMF Encoder

; keypad tone generator with wakeup on keypress



audioport	equ	RA
ROWMASK		equ	00000001b
COLMASK		equ	00000010b
keyport		equ	RB
KEYMASK		equ	00001111b
col0		equ	RB.4
col1		equ	RB.5
col2		equ	RB.6

temp		equ	09h
colcount	equ	0ah
ccount		equ	0bh
rowcount	equ	0ch
rcount		equ	0dh
tonetimehi	equ	0eh
tonetimelo	equ	0fh
row0		equ	10h		; current state of key row 0
row1		equ	11h		; current state of key row 1
row2		equ	12h		; current state of key row 2
keycode		equ	13h

		RESET Start

		clrb	col0
		clrb	col1
		clrb	col2

; KeyMap -- map key ID to DTMF tone code
		jmp	PC+W
; straightforward matrix
;		retw	0000b,0001b,0010b
;		retw	0100b,0101b,0110b
;		retw	1000b,1001b,1010b
;		retw	1100b,1101b,1110b
; PacTec brain damaged membrane keyboard
		retw	1000b,0000b,1100b
		retw	0100b,1001b,0001b
		retw	1101b,0101b,1010b
		retw	0010b,1110b,0110b

;697 Hz		90	123A row
;770 Hz		81	456B row
;852 Hz		73	789C row
;941 Hz		66	*0#D row
;1209 Hz	52	147* col
;1336 Hz	47	2580 col
;1477 Hz	42	369# col
;1633 Hz	38	ABCD col

		jmp	PC+W
		retw	90,81,73,66
		jmp	PC+W
		retw	52,47,42,38

; DTMF_send -- send a DTMF tone pair as encoded in W on entry.
;	encoding is xxxxRRCC where x = dont care, RR = row#, CC = col#

		; get row and col encoding into rowcount,colcount
		mov	colcount,W
		mov	rowcount,W
		and	colcount,#00000011b
		rr	rowcount
		rr	rowcount
		and	rowcount,#00000011b

		; replace with actual counts from lookup tables
		mov	W,colcount
		call	ColTab
		mov	colcount,W
		mov	W,rowcount
		call	RowTab
		mov	rowcount,W

		; preload counters && timers
		mov	rcount,rowcount
		mov	ccount,colcount
		mov	tonetimehi,#TONE_DURATION<
		mov	tonetimelo,#TONE_DURATION>

		; time to stop?
		dec	tonetimelo
		jnz	:keepon
		dec	tonetimehi
		ret	; done! get out.

		; wait for clock tick
		mov	temp,RTCC
		mov	W,RTCC
		xor	W,temp
		jz	:tickwait

		; decrement counters
		djnz	rcount,:checkcol

		; row count reached zero -- toggle audio and reset counter
		mov	W,audioport
		xor	W,#ROWMASK
		mov	audioport,W
		mov	rcount,rowcount
		djnz	ccount,:dtmf_loop

		; col count reached zero -- toggle audio and reset counter
		mov	W,audioport
		xor	W,#COLMASK
		mov	audioport,W
		mov	ccount,colcount
		jmp	:dtmf_loop

		clrb	col0
		mov	row0,keyport
		setb	col0
		xor	row0,#KEYMASK
		and	row0,#KEYMASK

		clrb	col1
		mov	row1,keyport
		setb	col1
		xor	row1,#KEYMASK
		and	row1,#KEYMASK

		clrb	col2
		mov	row2,keyport
		setb	col2
		xor	row2,#KEYMASK
		and	row2,#KEYMASK


		clr	keycode

		test	row0
		jz	:tryrow1

		; definitely a bit on in row0
		mov	keycode,#1
		snb	row0.0
		rr	row0
		inc	keycode
		jmp	:loop0

		test	row1
		jz	:tryrow2

		; definitely a bit on in row1
		mov	keycode,#5
		snb	row1.0
		rr	row1
		inc	keycode
		jmp	:loop1

		test	row2

		; definitely a bit on in row2
		mov	keycode,#9
		snb	row2.0
		rr	row2
		inc	keycode
		jmp	:loop2

		mov	OPTION,#00000100b	; RTCC @ 125 KHz
		mov	!RB,#00001111b
		mov	!RA,#0000b		; all outputs

		setb	col0
		setb	col1
		setb	col2

		call	Scan		; read keyboard
		call	Decode		; decode bit pattern to key ID
		test	keycode
		jz	:release	; if no key, don't send
		dec	keycode
		mov	W,keycode	; get key ID
		call	KeyMap		; map key ID to DTMF code
		call	DTMF_send	; send DTMF tone
		; now wait for key to be released and sleep
		call	Scan
		call	Decode
		test	keycode
		jnz	:release
		jmp	zzzzz

file: /Techref/microchip/dtmf-en-dt.htm, 3KB, , updated: 2009/2/13 15:23, local time: 2024/7/23 05:13,

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF=""> Dave Thomas's PIC DTMF Encoder</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!