; interrupt service routine for A/D sampler t0isr: jb int1,t0isr ; wait for conversion movx a,@r0 ; read setb tr0 movx @r0,a ; start another sample movx @dptr,a ; store inc dptr mov a,dph cjne a,#high rawdat+1,more setb ready ; yup, tell human clr ex0 ; stop more: reti ; timer 0 used for sweep data sampler init_sampler: mov r1,ie ; save enable flags clr ea mov dptr,#0bh ; timer 0 interrupt vector address mov a,#2 ; ljmp movx @dptr,a inc dptr mov a,#high t0isr movx @dptr,a inc dptr mov a,#low t0isr movx @dptr,a mov ie,r1 ; reset enable ret ; sample a/d data sampler: clr ready ; nothing yet mov r1,ie clr ea anl tcon,#0cfh ; timer 0 off anl tmod,#0f0h ; clear timer 0 orl tmod,#02h ; mode 2 - auto-reload mov th0,#srate ; 8000hz sample rate mov dptr,#rawdat ; where to put data mov p2,#high AD0 ; where to get data mov r0,#0 ; a/d low address mov a,r1 orl a,#82h orl ie,a ; enable interupts movx @r0,a ; start sampling setb tr0 ; run wfr: jnb ready,wfr ; twiddle thumbs clr tr0 ret ; return to caller