RD_      EQU P0.4          ; !RD line for the DTMF transceiver (active low)
WR_      EQU P0.5          ; !WR line for the DTMF transceiver (active low)
CS_DTMF  EQU P0.6          ; !CS line for the DTMF transceiver (active low)
RS_0     EQU P3.7          ; Register Select line of the DTMF transceiver


_WRITE_CREG:
  MOV    A,R7              ; Get the data to be written
  ORL    A,#0F0h           ; Mask the high nibble so that the control line are not affected
  MOV    P0,A              ; 
  SETB   RS_0              ; Set the Register Select line to select the Control Register
  CLR    CS_DTMF           ; Select the transceiver
  CLR    WR_               ; Pulse the WR line low
  SETB   WR_
  SETB   CS_DTMF           ; Set the Chip Select high
  RET
  
  
_WRITE_TREG:
  MOV    A,R7              ; Get the data to be written
  ORL    A,#0F0h           ; Mask the high nibble so that the control line are not affected 
  MOV    P0,A              ; 
  CLR    RS_0              ; Clear the Register Select line to select the Transmit Register
  CLR    CS_DTMF           ; Select the transceiver
  CLR    WR_               ; Pulse the WR line low
  SETB   WR_
  SETB   CS_DTMF           ; Set the Chip Select high
  RET
  
READ_CREG:
  MOV    P0,#0FFh          ; Setup P0 for input
  SETB   RS_0              ; Set the Register Select line to select the Control Register
  CLR    CS_DTMF           ; Select the transceiver
  CLR    RD_               ; Clear the RD line
  MOV    A,P0              ; Get the data
  SETB   RD_               ; Deactivate the RD
  SETB   CS_DTMF           ; Deselect the transceiver
  ANL    A,#0Fh            ; Mask off the high nibble
  MOV    R7,A              ; Copy the data to R7 for C compatibility
  RET
  
READ_RREG:
  MOV    P0,#0FFh          ; Setup P0 for input
  CLR    RS_0              ; Clear the Register Select line to select the Receive Register
  CLR    CS_DTMF           ; Select the transceiver
  CLR    RD_               ; Clear the RD line
  MOV    A,P0              ; Get the data
  SETB   RD_               ; Deactivate the RD
  SETB   CS_DTMF           ; Deselect the transceiver
  ANL    A,#0Fh            ; Mask off the high nibble
  MOV    R7,A              ; Copy the data to R7 for C compatibility
  RET