| ??? 12/27/02 16:33 Read: times |
#35104 - RE: serial adc |
I wrote this code for the Microchip MPC3204 , and I imagine it will be similar to the Max186
========================================= sbit ADC_CLK = P3^4; sbit ADC_DOUT = P3^5; sbit ADC_DIN = P3^6; sbit ADC_CS = P3^7; ------------------------------------------ void adc_delay(void) {unsigned char delay; for(delay=0;delay<5;delay++); } void adc_init(void){ ADC_CS=1;//disable chip select ADC_CLK=0; } void write_adc_byte(unsigned char output_data) { unsigned char index; for(index = 0; index < 6; index++) // Send 6 bits to the adc { ADC_DIN = ((output_data & 0x01) ? 1 : 0); output_data=output_data >> 1; // Shift the byte by one bit ADC_CLK = HIGH; // Clock the data into the adc adc_delay(); ADC_CLK = LOW; } adc_delay(); } unsigned int read_adc_byte(unsigned char channel ) { unsigned char i; unsigned int adcValue; ADC_CS=0; //enable adc adc_delay(); switch (channel) { case 0 : channel=0x03;break;// single channel0 case 1 : channel=0x13;break;// single channel1 case 2 : channel=0x0b;break;// single channel2 case 3 : channel=0x1b;break;// single channel3 case 4 : channel=0x07;break;// single channel4 case 5 : channel=0x17;break;// single channel5 case 6 : channel=0x0f;break;// single channel6 case 7 : channel=0x1f;break;// single channel7 case 10 : channel=0x01;break;// diff channel0 case 11 : channel=0x0b;break;// diff channel1 case 12 : channel=0x05;break;// diff channel2 case 13 : channel=0x0d;break;// diff channel3 } write_adc_byte( channel); adcValue=0; for(i=0; i<13; ++i) { ADC_CLK=1; adc_delay(); adcValue= adcValue << 1; adcValue |= ADC_DOUT; ADC_CLK=0; } ADC_CS=1; //disables adc return(adcValue); } |
| Topic | Author | Date |
| serial adc | 01/01/70 00:00 | |
| RE: serial adc | 01/01/70 00:00 | |
| RE: serial adc | 01/01/70 00:00 | |
| To:Rob | 01/01/70 00:00 | |
| RE: To:Rob | 01/01/70 00:00 | |
| RE: To:Rob | 01/01/70 00:00 | |
| RE: To:Rob | 01/01/70 00:00 | |
| RE: To:Rob | 01/01/70 00:00 | |
| RE: To:Rob | 01/01/70 00:00 | |
| hi rob | 01/01/70 00:00 | |
| RE: hi rob | 01/01/70 00:00 | |
| RE: hi rob | 01/01/70 00:00 | |
RE: hi rob | 01/01/70 00:00 |



