703
HTTP/1.1 200 OK
Date: Sat, 18 Jun 2005 20:19:18 GMT
Server: Apache/1.3.26 (Unix) Debian GNU/Linux mod_perl/1.26 mod_ssl/2.8.9 OpenSSL/0.9.6g PHP/4.1.2
Last-Modified: Wed, 08 Jan 2003 19:42:05 GMT
ETag: "95c9b9-703-3e1c7f0d"
Accept-Ranges: bytes
Content-Length: 1795
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: text/x-csrc

// **********max1247.c

// Interface between MC68HC812 and Max1247 (four channel 12-bit ADC)

// Uses simple port J I/O

// Last modified 1/15/02 by Jonathan W. Valvano

 

// Copyright 2002 by Jonathan W. Valvano, valvano@uts.cc.utexas.edu 

//    You may use, edit, run or distribute this file 

//    as long as the above copyright notice remains 



#define	ThePort	*(unsigned char volatile *)(0x0028) // PORTJ

#define	TheDDR	*(unsigned char volatile *)(0x0029) // DDRJ

#define CS   0x08 // Out bit 3 Max1247 chip select

#define SCLK 0x04 // Out bit 2 Max1247 serial clock

#define DIN  0x02 // Out bit 1 Max1247 data input

#define DOUT 0x01 // In  bit 0 Max1247 data output

void Max1247_Init(void){   // initialize

  TheDDR  |= CS+SCLK+DIN;  // specifies outputs

  TheDDR  &= ~DOUT;        // specifies inputs

  ThePort |= CS;           // PJ3=CS=1

  ThePort &= ~(SCLK+DIN);  // PJ2=SCLK=0, PJ1=DIN=0

}

//#define CHAN0 0x9F

//#define CHAN1 0xDF

//#define CHAN2 0xAF

//#define CHAN3 0xEF

unsigned int Max1247_in(unsigned int channel){ // channel =9F,DF,AF,EF

// result 0 to 4095 for Vin 0 to +5.0 V

unsigned int i,data,command;

  ThePort &= ~CS;    // CS=0

  command = channel;

  for(i=0;i<8;i++){ // send 8 bit command

    if(command&0x80){ 

      ThePort |= DIN;  // DIN=1 if bit 7 is high

    }

    else{

      ThePort &=~DIN;  // DIN=0 if bit 7 is low

    }

    ThePort |= SCLK;   // SCLK=1

    ThePor
0

t &=~SCLK;   // SCLK=0

    command = command<<1;

  }

	  

  ThePort &=~DIN;  // DIN=0

  data = 0;

  for(i=0;i<16;i++){ // receive 16-bit data

    ThePort |= SCLK;   // SCLK=1

    ThePort &=~SCLK;   // SCLK=0

    data = data << 1;

    if(ThePort & DOUT){

      data |= 0x01;

    }

  }

  return data>>3;

}

// example 

// data=Max1247_in(CHAN1);