Rainbow Electronics MAX1402 User Manual

Page 33

Advertising
background image

MAX1402

+5V, 18-Bit, Low-Power, Multichannel,

Oversampling (Sigma-Delta) ADC

______________________________________________________________________________________

33

/* Low-level function to write 8 bits
** The example shown here is for a bit-banging system with (CPOL=1, CPHA=1)
*/
void WriteByte (BYTE x)
{
drive SCK pin high
count = 0;
while (cout <= 7)
{
if (bit 7 of x is 1)
drive DIN pin high
else
drive DIN pin low
drive SCK pin low
x = x * 2;
drive SCK pin high
count = count + 1;
}
}

/* Low-level function to read 8 bits
** The example shown here is for a bit-banging system with (CPOL=1, CPHA=1)
*/
BYTE ReadByte (void)
{
x = 0;
drive SCK pin high
count = 0;
while (cout <= 7)
{
x = x * 2;
drive SCK pin low
if (DOUT pin is high)
x = x + 1;
drive SCK pin high
count = count + 1;
}
}
return x;

Figure 15. Bit-Banging SPI Replacement

V

DD

P3.0

P3.1

RESET

DOUT

DIN

SCLK

CS

8051

MAX1402

Figure 14. MAX1402 to 8051 Interface

Advertising