📄 adccont.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : Sept. 2005
File : ADCcont.c
Hardware : Applicable to ADuC702x rev H or I silicon
Currently targetting ADuC7026.
Description : Performs 1024 continuous ADC conversions on ADC0,
store the results in SRAM and send them through UART
at 9600bps when the 1024 conversions are done
*********************************************************************/
#include <ADuC7026.h>
void senddata(short);
void ADCpoweron(int);
char hex2ascii(char);
int main (void) {
unsigned short ADCDATA[1024];
int i;
ADCpoweron(20000); // power on ADC
ADCCP = 0x00; // select ADC channel 0
REFCON = 0x01; // internal 2.5V reference. 2.5V on Vref pin
GP0CON = 0x100000; // Enable ADCbusy on P0.5
// configures GPIO to flash LED P4.2
GP4DAT = 0x04000000; // P4.2 configured as an output. LED is turned on
// Setup tx & rx pins on P1.0 and P1.1
GP1CON = 0x011;
// Start setting up UART at 9600bps
COMCON0 = 0x80; // Setting DLAB
COMDIV0 = 0x88;
COMDIV1 = 0x00;
COMCON0 = 0x07; // Clearing DLAB
ADCCON = 0x4E4; // Config: fADC/2, acq. time = 2 clocks => ADC Speed = 1MSPS
while(1)
{ // start continuous conversion
for (i=0; i <2; i++)
{
while (!ADCSTA){} // wait for end of conversion
ADCDATA[i] = (ADCDAT >> 16);
if (ADCCP == 0) ADCCP = 1; // change channel
else ADCCP = 0;
}
GP4DAT ^= 0x00040000; // Complement P4.2
for (i=0; i <1024; i++) senddata (ADCDATA[i]);
GP4DAT ^= 0x00040000; // Complement P4.2
}
}
void senddata(short to_send)
{
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0A; // output LF
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = 0x0D; // output CR
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 8) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii ((to_send >> 4) & 0x0F);
while(!(0x020==(COMSTA0 & 0x020))){}
COMTX = hex2ascii (to_send & 0x0F);
}
char hex2ascii(char toconv)
{
if (toconv<0x0A)
{
toconv += 0x30;
}
else
{
toconv += 0x37;
}
return (toconv);
}
void ADCpoweron(int time)
{
ADCCON = 0x20; // power-on the ADC
while (time >=0) // wait for ADC to be fully powered on
time--;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -