📄 adc_test.c
字号:
/*********************************************************************************************
* File: adc_test.c
* Author: embest
* Desc: S3C2410 ADC Test
* History:
* W.W.Zhang, Programming modify, April,11, 2005
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
/*------------------------------------------------------------------------------------------*/
/* constants define */
/*------------------------------------------------------------------------------------------*/
#define REQCNT 100
#define ADC_FREQ 2500000
#define LOOP 10000
/*------------------------------------------------------------------------------------------*/
/* variables declare */
/*------------------------------------------------------------------------------------------*/
volatile UINT8T unPreScaler;
volatile char nEndTest;
/*********************************************************************************************
* name: adc_test
* func: ADC convert test
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void adc_test(void)
{
int i,j;
UINT16T usConData;
float usEndData;
UINT8T f_szDigital[10] ={0xFC,0x60,0xDA,0xF2,0x66,0xB6,0xBE,0xE0,0xFE,0xF6}; // 0 ~ 9
uart_printf("\n Adc Conversion Test Example (Please look at 8-seg LED)\n");
iic_init_8led(); // initialize iic and leds
for(i=0;i<8;i++)
iic_write_8led(0x70,0x10+i,0);
uart_printf(" ADC_IN Test,channel 2\n");
uart_printf(" ADC conv. freq. = %dHz\n",ADC_FREQ);
unPreScaler = PCLK/ADC_FREQ -1;
rADCCON=(1<<14)|(unPreScaler<<6)|(2<<3)|(0<<2)|(1<<1);//enable prescaler,ain2,normal,start by read
uart_printf(" Please adjust AIN2 value!\n");
uart_printf(" The results of ADC are:\n");
usConData=rADCDAT0&0x3FF;
for(j=0;j<20;j++) // sample and show data both by UART and leds
{
while(!(rADCCON & 0x8000));
usConData=rADCDAT0&0x3FF;
usEndData=usConData*3.3000/0x3FF;
uart_printf(" %0.4f ",usEndData);
iic_write_8led(0x70,0x10+4,f_szDigital[(int)usEndData]+1);
usEndData=usEndData-(int)usEndData;
for(i=0;i<4;i++)
{
usEndData=usEndData*10;
iic_write_8led(0x70,0x10+3-i,f_szDigital[(int)usEndData]);
usEndData=usEndData-(int)usEndData;
}
delay(10000);
}
uart_printf(" end.\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -