es512.asm

来自「isd voice record and playback code」· 汇编 代码 · 共 1,955 行 · 第 1/3 页

ASM
1,955
字号
;  Primary controls
$MOD51
$TITLE(ES512 control software)
$PAGEWIDTH(132)
$DEBUG
$OBJECT
$NOPAGING
;
;  Variable declarations
;

evm	equ	0
m224	equ	0		;1->224 messages, 0->96 messages
nrows equ	4		;number of rows per cluster (not yet checked for other values)

;5116 memory usage: depends on number of messages and number of rows per sector
;  each message requires 15 bytes for additional info plus 1 byte for sampling rate
;  the basic message map requires approximately 2048/nrows = 512 bytes = 2 rows of 2048 digital bits, minus the space required for the maps and information
;  to allow changes, a copy of each set is kept
; 
; for 96 messages:
;  msginfo = 16*96 = 1536 bytes = 6 rows of 2048 digital bits
;  2 rows for message map
;  2*8 rows = 16 rows of 2048 for data, first 2032 available for analog data (520 seconds)
;  base of information area, first copy, is top of array - 16. base of first copy of message map is top - 10. 2nd copies are at top-8 and top-2
; for 224 messages:
;  msginfo = 16*224 = 3584 bytes = 14 rows of 2048 digital bits
;  2 rows for message map
;  2*16 rows = 32 rows of 2048 for data, first 2016 available for analog data (516 seconds)
;  base of information area, first copy, is top of array - 32. base of first copy of message map is top - 18. 2nd copies are at top-16 and top-2
; top is 0x7ff row, 0xffe0 is first 8 byte scan of top row
; 

;Register usage, bank 0:
;R0 - pointer to databuf (8 byte chunk of message map)
;R1 - pointer to bitmap	(64 byte representation of active clusters, one bit per cluster)
;R2 - 508 code; keys
;R3	-	general loop counter
;R4	-	I2C byte loop counter
;R5 - 508 code; keys
;R6 - cluster count low byte
;R7 - cluster count high byte

if (evm)
SCL	BIT	P1.6
SDA	BIT	P1.5
;SCLIN	BIT	P1.6
;SDAIN	BIT	P1.5
SCLIN	BIT	P2.0
SDAIN	BIT	P2.1
else
SCL	BIT	P2.0
SDA	BIT	P2.1
SCLIN	BIT	P2.0
SDAIN	BIT	P2.1
endif
INT_	BIT	P2.2	;input
RAC	BIT	P3.3	;input
MIC	BIT	P2.4

SHDN_	BIT	P1.4
DIN	BIT	P1.5
DOUT	BIT	P1.6
LOBAT	BIT	P1.7	;input

ED	BIT	P3.0
RW	BIT	P3.1
DCLK	BIT	P3.2	;input (INT0)
RS	BIT	P2.3

EDbit	EQU	1
RWbit	EQU	2
DCLKbit	EQU	4
RACbit	EQU	8

KEYIN	EQU	00FH	;key input mask- port 1

NULL	EQU	0
WAIT	EQU	1
SETPLAY	EQU	0a9h	;requires addrh, addrl, sendlong
CPLAY		EQU	0a8h	;use sendshort
SETREC	EQU	091h	;requires addrh, addrl, sendlong
CREC		EQU	090h	;use sendshort
LDADDR	EQU	081h	;requires addrh, addrl, sendlong
DIGRD		EQU	0e1h	;requires addrh, addrl, readdigital
DIGWR		EQU	0c9h	;requires addrh, addrl, writedigital
DIGER		EQU	0d1h	;requires addrh, addrl, sendlong
SETCFG0	EQU	082h	;default is power on (bit 080h)
SETCFG1	EQU	083h	;default is power on (bit 080h)
STOP		EQU	080h	;leaves power on, use sendshort
STOPDIG	EQU	0C0h	;leaves power on, use sendshort, sets DAB
STOPPDN	EQU	000h	;turns power off, use sendshort
TPUD	EQU	100
PROMPT	EQU	0
QREC		EQU	12
MREC		EQU	2
IDLE	EQU	11
OFF		EQU	10
SCROLLUP	EQU 3
YES	EQU	15
SCROLLDN	EQU	9
POFF	EQU	14
PON	EQU	15
VOLSET	EQU	12
AUTOPD	EQU	02fh	;approx four minutes auto power down
TMRHI20	EQU	0b8h	;20ms @ 11.059MHz
TMRLO20	EQU	000h
;TMRHI20	EQU	0b1h	;20ms @ 12MHz
;TMRLO20	EQU	0e0h

if (m224)		;need last sixteen rows * 2. Base address is top-32, msgmap base is top-18
DATAMAPL	EQU 000h
DATAMAPH	EQU	0fch	;16 rows of array covers everything
MSGMAPL	EQU 0c0h		;last two rows of map block
MSGMAPH	EQU	0fdh
else				;need last eight rows * 2. Base address is top-16, msgmap base is top-10
DATAMAPL	EQU 000h
DATAMAPH	EQU	0feh	;8 rows of array covers everything
MSGMAPL	EQU 0c0h		;last two rows of map block
MSGMAPH	EQU	0feh
endif

TWEAKL	EQU	0e0h
TWEAKH	EQU	0fbh

KHZ8	EQU	000h
KHZ6	EQU	004h
KHZ5	EQU	008h
KHZ4	EQU	00Ch
blank	equ	0010h

TOP	equ	07fh

; should put this stuff within the first 40 locations allowing for special regs, R0-R7
	DSEG at 0008h
tptr1:		DS	1	;(R0 in second bank)		&&&
tptr2:		DS	1	;(R1 in second bank)		&&&
scans:		DS	1
temp1:		DS	1
temp2:		DS	1
dig3:			DS	0
status:		DS	1	;	&&&
cdl:			DS	1	;(R6 in second bank)
cdh:			DS	1	;(R7 in second bank)
timeout0:	DS	1
timeout1:	DS	1
command:	DS	1
priorkey:	DS	1
keycount:	DS	1
lastkey:	DS	1
keycode:	DS	1
keybuf:		DS	1
cfg:			DS	1
volume:		DS	1
samprate:	DS	1
dispctr:	DS	1
bits:			DS	1
dig1:			DS	0
datal:		DS	1
dig2:			DS	0
datah:		DS	1
msg:			DS	1
rmsg:			DS	1

	DSEG at 0021h	
altmapl:	DS	1
altmaph:	DS	1
addrh:		DS	1
addrl:		DS	1
flag1:		DS	1
flag2:		DS	1
flag3:		DS	1
databuf:	DS	8
bitmap:		DS	63
racs:			DS	1
stack:		DS	16

writeback	BIT	flag1.0
killit	BIT	flag1.1
taskactive	BIT	flag1.2
newkey	BIT	flag1.3
keyup		BIT	flag1.4
power		BIT	flag1.5
first		BIT	flag1.6
occupied	BIT	flag1.7

valid		BIT	flag2.0
empty		BIT flag2.1
recflag	BIT	flag2.2
stopflag	BIT	flag2.3
lastone	BIT	flag2.4
testx		BIT	flag2.5
noack		BIT	flag2.6
done		BIT	flag2.7

doit		BIT	flag3.0
freeform	BIT flag3.1
emptyrow	BIT	flag3.2
digit			BIT	flag3.3
ackerror	BIT	flag3.4
;	BIT	flag3.5
;	BIT	flag3.6
;	BIT	flag3.7

if (m224)
mapbit	BIT	altmaph.6
bumpadd	BIT	altmaph.7
else
mapbit	BIT	altmapl.6
bumpadd	BIT	altmapl.7
endif

trailer	equ	(bitmap + 15)


	CSEG
;
	ORG	0000H
	LJMP initialize

	ORG 0003H
ext0svc:
	push	PSW
	push	ACC
	ljmp	ext0svc1

	ORG 000BH
tmr0svc:
	push	PSW
	push	ACC
	ljmp	tmr0svc1

	ORG 0013H
ext1svc:
	push	PSW
	push	ACC
	ljmp	ext1svc1

	ORG 001BH
tmr1svc:
	push	PSW
	push	ACC
	ljmp	tmr1svc1

;	ORG 0030H
main:
	call poweroff
	call	enabledisplay
	call	readstatus
	call poweron
	call	readstatus
	mov	DPTR,#startstring
	call	prints
	call wait2s

	call	setaltmap

	mov	msg,#1
	mov	rmsg,#1

setidle:
	mov	cfg,#IDLE
	call	setcfg
	clr	testx
	call	showmsg
cleartask:
	mov	timeout0,#0
	mov	timeout1,#AUTOPD
	clr	taskactive
	clr	newkey
	mov	TL1,#TMRLO20
	mov	TH1,#TMRHI20
	setb	ET1
	setb	TR1
	setb	EA
mainloop:
	jb	taskactive,mainloop
	jnb	newkey,mainloop
	clr	newkey
	clr	EA
	mov	timeout0,#0
	mov	timeout1,#AUTOPD
	setb	taskactive
	mov	A,keycode
	rl	A						;keycode is <80h, so rl is just sl
	mov	DPTR,#functiontable
	jmp @A+DPTR
functiontable:
	ajmp	key0
	ajmp	key1
	ajmp	key2
	ajmp	key3
	ajmp	key4
	ajmp	key5
	ajmp	key6
	ajmp	key7
	ajmp	key8
	ajmp	key9
	ajmp	setsrkey	;"star" key
	ajmp	cancelkey		;"pound" key
	ajmp	recordkey
	ajmp	cleartask	;not used in this array
	ajmp	erasekey
	ajmp	playkey

cancelkey:
key1:
key4:
key7:
	mov	cdh,#0
	jmp	cleartask

key2:
	jmp	playkey
key5:
	jmp	recordkey
key8:
	jmp	erasekey
key0:
	jmp	doinitmap

key6:
	call	getmsginfo
	call	printinfo
	call	wait2s
; display secondary info for 1 sec- if new key on exit, (ph number??)
; display tertiary info	(time and sample rate)
	mov	cdh,#0
	jmp	setidle

key9:	;prev msg in idle, vol up during play
	djnz	msg,msginrange
	mov	msg,#1
	inc	cdh
	mov	A,cdh
	add	A,#0fdh
	jnc	exitscroll
	jmp	doinitmap ; inc bumpctr- if ==3, goto initmap
msginrange:
	mov	rmsg,msg
	call	getmsginfo
	mov	cdh,#0
exitscroll:
	jmp	setidle
key3:	;next msg in idle, vol down during play
	inc msg
if (m224)
	mov	A,#225		;	for 224 msgs
else
	mov	A,#97			;	for 96 msgs
endif
	cjne A,msg,msginrange
if (m224)
	mov	msg,#224	;	for 224 msgs
else
	mov	msg,#96		;	for 96 msgs
endif
	jmp	msginrange

erasekey:
	call	clrscr
	mov	DPTR,#sure
	call	prints
	call	getkey
	clr	newkey
	cjne	A,#yes,exitpk
	mov	A,msg
	jnz	doerase
	jmp	cleartask
doerase:
	call	clrscr
	mov	DPTR,#inerase
	call	prints
	call	erase
exitpk:
	mov	cdh,#0
	jmp	setidle
	
;change to set sample rate- then use up/down plus enter
setsrkey:
	mov	cdh,#0
dosrset:
	call	clrscr
	mov	DPTR,#setsrate
	call	prints
	mov	A,cdh
	jnz	not8
	mov DPTR,#sr8
	jmp finsrset
not8:
	cjne	A,#1,not6
	mov DPTR,#sr6
	jmp finsrset
not6:	
	cjne	A,#2,not5
	mov DPTR,#sr5
	jmp finsrset
not5:	
	mov DPTR,#sr4
finsrset:
	call	prints
keepwaiting:
	call	getkey
	clr	newkey
	cjne	A,#3,notless
	mov	A,cdh
	jz	keepwaiting
	dec	cdh
	jmp	dosrset
notless:
	cjne	A,#9,notmore
	mov	A,cdh
	cjne	A,#3,bumpit
	jmp	keepwaiting
bumpit:
	inc	cdh
	jmp	dosrset
notmore:
	cjne	A,#YES,keepwaiting
	mov	A,cdh
	mov	DPTR,#srdecode
	movc	A,@A+DPTR
	mov	samprate,A
	mov	cdh,#0
	jmp	setidle

doinitmap:
	call	clrscr
	mov	DPTR,#eraseall
	call	prints
	call	getkey
	cjne	A,#0,chkyes1
	jmp	do2
chkyes1:
	cjne	A,#YES,stopthis
do2:
	call	clrscr
	mov	DPTR,#init
	call	prints
	call	initmap
	mov	cdh,#0
	jmp	setidle

recordkey:
	jnb	valid,freespot	
	call	clrscr
	mov	DPTR,#occupado
	call	prints
lookagain:
	call	getkey
	cjne	A,#YES,stopthis
	jmp	doerase
freespot:
	mov	A,rmsg
	jnz dorecord
	jmp	cleartask
dorecord:
	call	clrscr
	mov	msg,rmsg
	call showmsgspc
	call	showpos
	call	record
	call	clrscr
	mov	DPTR,#enterdata
	call	prints
	call	wait2s
	call	setmsginfo
stopthis:
	mov	cdh,#0
	jmp	setidle

playkey:
	mov	A,msg
	jnz	doplay
	jmp	cleartask
doplay:
	call	clrscr
	call showmsgspc
	call	showpos
	call	play
	jb	valid,finplay
	call	shownotvalid
finplay:
	mov	cdh,#0
	jmp	setidle

showspace:
	call clrscr
	mov	DPTR,#clsavail
	call	prints
	mov	DPTR,#cls
	call prints
showspace1:
	mov	msg,#0
	call	createbitmap
	call	convertcc
	ret

showmsg:
	call	createbitmap
	call clrscr
	mov	DPTR,#msgno
	call	prints
	mov	A,msg
	call	convertm
	jnb	valid,emptymsg
	mov	DPTR,#length
	call prints
	call	convertcc
	ret
emptymsg:
	mov	DPTR,#emptyphr
	call	prints
	ret

showmsgspc:
	mov	DPTR,#msgno
	call	prints
	mov	A,msg
	call	convertm
	mov	DPTR,#space
	call prints
	ret

showcls:
	mov	DPTR,#cls
	call	prints
	ret

showpos:
	mov	DPTR,#position
	call	prints
	ret

setcfg:
	mov	A,cfg
	add	A,cfg
	mov	DPTR,#cfgtab0
	movc	A,@A+DPTR
	mov	datah,A
	mov	A,cfg
	add	A,cfg
	inc	DPTR
	movc	A,@A+DPTR
	mov	datal,A
	mov	command,#SETCFG0
	call	sendlong
	mov	A,cfg
	add	A,cfg
	mov	DPTR,#cfgtab1
	movc	A,@A+DPTR
	anl	A,#0c7h
	mov	temp2,A
	mov	A,#7
	subb	A,volume
notpdn:
	swap A
	rr	A			;volume is <8, so after swap, rr volume is just sr
orit:
	orl	A,temp2
	mov	datah,A
	mov	A,cfg
	add	A,cfg
	inc	DPTR
	movc	A,@A+DPTR
	anl	A,#0f3h		;mask off frequency bits
	orl	A,samprate
	mov	datal,A
	mov	command,#SETCFG1
	call	sendlong
	mov	A,#(TPUD+10)
	call waitms
	ret

poweron:
	setb	MIC
	setb	power
	mov	command,#STOP
	call	sendshort
	mov	A,#TPUD
	call	waitms
	mov	cfg,#IDLE
	call	setcfg
	ret

poweroff:
	mov	cfg,#IDLE
	call	setcfg
	clr	power
	mov	command,#STOPPDN
	call	sendshort
	mov	A,#TPUD
	call	waitms
	clr	MIC
	ret

sendlonga:
	mov datah,addrh
	mov	datal,addrl
sendlong:
	clr	SDA					;start condition
	mov	A,#080h			;address=040h, write, or
	call	writebyte	;wait for acknowledge
	mov	A,command
	call	writebyte	;wait for acknowledge
	mov	A,datah
	call	writebyte	;wait for acknowledge
	mov	A,datal
	call	writebyte	;wait for acknowledge
	call	dostop
	ret

dostop:
	clr	SDA					;to establish level for subsequent stop condition
	nop
	nop
	nop
	setb	SCL
	jnb	SCLIN,$		;wait until SCL is released to ensure operation is completed
	mov	A,#15
	call waitus
;	nop
	setb	SDA				;stop condition
	ret	

writedigital:
	mov	command,#STOPDIG
	call	sendshort
;	mov	A,#100
;	call	waitus	;******change; added
	call	adjaddr
	setb	SCL	;******change; added
	jnb	SCLIN,$
	jb	freeform,nosetwd
	mov	R0,#databuf
nosetwd:
	clr	SDA					;start condition
	mov	A,#080h			;address=040h, write, or
	call	writebyte	;wait for acknowledge
	mov	A,#DIGWR		;write digital
	call	writebyte	;wait for acknowledge
	mov	A,datah
	call	writebyte	;wait for acknowledge
	mov	A,datal
	call	writebyte	;wait for acknowledge
;	mov	A,#100
;	call	waitus
; get eight byte chunk, set pointer, send eight times
	mov	R3,#8
write8:
	mov	A,@R0
	inc	R0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?