beautypg.com

An118 – Cirrus Logic AN118 User Manual

Page 27

background image

AN118

AN118REV2

27

/**************************************************************/
/* Routine - Delay

*/

/* Input - none

*/

/* Output - none

*/

/* Description - This routine is used as a LED delay routine

*/

/**************************************************************/
void Delay(void) {

data int j;
for (j=0; j<10000; j++)

for (j=0; j<10000; j++);

}

;****************************************************************
;* Routine - RECEIVE_BYTE
;* Input - none
;* Output - Byte received is placed in R7
;* Description - This subroutine receives 1 byte from converter
;****************************************************************

; The function prototype is: char RECEIVE_BYTE(void);

$DEBUG
USING 0

; Use register bank 0

TCOD SEGMENT CODE

; Define ROUT as a segment of code

PUBLIC RECEIVE_BYTE

; Make subroutine global

RSEG TCOD

; Make code relocatable

RECEIVE_BYTE:

MOV

R1,#08

; Set count to 8 to receive byte

LOOP:

; Receive the byte

MOV

C,P1.2

; Move bit to carry

RLC

A

; Rotate A in preparation for next bit

SETB

P1.3

; Set SCLK

CLR

P1.3

; Clear SCLK

DJNZ

R1,LOOP ; Decrement byte, repeat loop if not zero

MOV

R7,A

; Byte to be return is placed in R7

RET

; Exit subroutine

END