Eco digitale con scheda 8051

;Etichette
CS      = P1.0
CLK     = P1.1
DATA    = P1.2
STROBE  = P1.3
DOUT    = P1.4
CLKOUT  = P1.5
LEDRec  = P1.6
LEDPlay = P1.7

soglia   = 90h
bufstart = 09000h
bufend   = 0A000h
rplay    = 20
racq     = 20
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
org 8200h
init:
  setb CS
  clr CLK  
  setb DATA
  setb DOUT
  clr CLKOUT
  setb STROBE
  setb LEDPlay
  setb LEDRec
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


loop:
  call lettadc ; primo valore da buttare

main: 
lsoglia:
  call lettadc
  subb a,#soglia
  jc lsoglia
  call Rec
  call PlayEco
  jmp main


   

;+++++++++++++++++++++++++++++Acquisizione++++++++++++++++++++++++++++++++++++++  
Rec:
  clr LEDRec
  mov dptr,#bufstart    
loopacq:
  call lettadc
  movx @dptr,a
  call ritacq  
  inc dptr
  mov a,dph
  cjne a,#high(bufend),loopacq
  mov a,dpl
  cjne a,#low(bufend),loopacq  
  setb LEDRec
  ret

;+++++++++++++++++++++++++++++Riproduzione++++++++++++++++++++++++++++++++++++++  
Play:
  clr LEDPlay
  mov dptr,#bufstart    
loopplay:
  movx a,@dptr
  call OutAna
  call ritplay
  inc dptr
  mov a,dph
  cjne a,#high(bufend),loopplay
  mov a,dpl
  cjne a,#low(bufend),loopplay  
  setb LEDPlay
  ret

;+++++++++++++++++++++++++++++Riproduzione Eco++++++++++++++++++++++++++++++++++++++  
PlayEco:  
  mov r2,#high(bufstart)    
lplayeco:
  mov dph,r2
  mov dpl,#low(bufstart)    
  clr LEDPlay
  call loopplay
  
  inc r2
  cjne r2,#high(bufend),lplayeco
  ret



;+++++++++++++++++++ Subroutine ritardo acquisizione +++++++++++++++++++++++++++
ritacq:
  mov r0,#racq
  djnz r0,$   
  ret
;++++++++++++++++++++ Subroutine ritardo riproduzione ++++++++++++++++++++++++++
ritplay:
  mov r0,#rplay
  djnz r0,$   
  ret

;++++++++++++++ Subroutine lettura ADC seriale TLC548 ++++++++++++++++++++++++
;Il valore letto ritorna sul registro A
lettadc:
  mov r0,#8
  clr CS
loopcv: 
  mov c,DATA
  rlc a
  setb CLK
  clr CLK
  djnz r0,loopcv
  setb CS
  ret

;++++++++++++++ Subroutine Scrittura DAC seriale        ++++++++++++++++++++++++
;Mettere in uscita del Dac il valore analogico corrispondente contenuto di A
OutAna:
	mov r0,#8
LOutAna:
	rrc a
	mov DOUT,c
	setb CLKOUT
	clr CLKOUT	
	djnz r0,LOutAna
	setb STROBE
	clr STROBE
	setb DOUT
	ret
end