作者: Action 时间: 2016-5-23 23:39
加我q201792056 发给我 我看一下作者: Action 时间: 2016-5-23 23:42
加我q 201792056 发给我 我看一下吧作者: chinomango 时间: 2016-5-24 06:30
/*************************************************
Digital voltmeter using an
Maxim MAX1241 ADC
connected to an AT90S8515
using the SPI bus
The measured voltage is transmitted
through the STK200 RS232 interface
Communication parameters: 9600 8N1
CodeVisionAVR C Compiler
(C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
Chip type : AT90S8515
Clock frequency : 4.000000 MHz
Memory model : Small
Internal RAM size: 512
External RAM size: 0
Data Stack size : 128
*************************************************
union adcu
{
unsigned char byte[2];
unsigned int word;
};
// Make one AD conversion and return the value
unsigned int max1241_read(void)
{
union adcu adc_data;
// exit MAX1241 from shutdown
NSHDN=1;
// wait 5us for the MAX1241 to wake up
delay_us(5);
// now select the chip to start the conversion
NCS=0;
// wait the conversion to complete
// DOUT will be 0 during conversion
while (DOUT==0);
// DOUT=1 -> conversion completed
// read MSB
adc_data.byte[1]=spi(0);
// read LSB
adc_data.byte[0]=spi(0);
// deselect the chip
NCS=1;
// enter shutdown
NSHDN=0;
// now format the result and return it
return (adc_data.word>>3)&0xfff;
}
void main(void)
{
// store the conversion result here
unsigned n;
// Input/Output Ports initialization
// Port A
DDRA=0x00;
PORTA=0x00;
// Port B
// the /SS pin is set as an output
// with level 1, it's required by
// the SPI to work in master mode
DDRB=0xA3;
PORTB=0x12;
// Port C
DDRC=0x00;
PORTC=0x00;
// Port D
DDRD=0x00;
PORTD=0x00;
// UART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// UART Receiver: Off
// UART Transmitter: On
UCR=0x08;
// UART Baud rate: 9600
UBRR=0x19;
putsf("MAX1241 Demo using the CodeVisionAVR C Compiler");
putsf("***********************************************\n");
// Make AD conversions and send the results to RS232
while (1)
{
n=max1241_read();
printf("MAX1241-> N=%4u U=%4umV\n",n,(unsigned) ((long) n*VREF/4096));
// 0.3 sec. delay
delay_ms(300);
};
}作者: 传浩 时间: 2016-5-24 11:46
chinomango 发表于 2016-5-24 06:30
/*************************************************
Digital voltmeter using an
Maxim MAX1241 ADC