⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc.c

📁 这是三星公司的arm7 s3c44b0x芯片的所有外设中断程序
💻 C
字号:
//44BTEST : adc.c
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\adc.h"
void __irq BDMA1_Done(void);
int ReadAdc(int ch);
void Test_Adc(void)
{
	int a0=0,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0;
	int adcpsr;
	Uart_Printf("The ADC_IN are adjusted to the following values.\n");
	Uart_Printf("Push any key to exit!!!\n");
	rCLKCON=0x7ff8;
	rADCCON=0x1|(0<<2); //Enable ADC
	Delay(100); //delay for 10ms for ADC reference voltage stabilization.
	Uart_Printf("Input ADCPSR value:");
	adcpsr=Uart_GetIntNum();
	rADCPSR=adcpsr;
	Uart_Printf("ADC conv. freq.=%d(Hz)\n",(int)(MCLK/(2.*(adcpsr+1.))/16.) );
	while(Uart_GetKey()==0)
	{
		a0=ReadAdc(0);
		a1=ReadAdc(1);
		a2=ReadAdc(2);
		a3=ReadAdc(3);
		a4=ReadAdc(4);
		a5=ReadAdc(5);
		a6=ReadAdc(6);
		a7=ReadAdc(7);
		Uart_Printf("0:%04d 1:%04d 2:%04d 3:%04d 4:%04d 5:%04d 6:%04d 7:%04d\n",a0,a1,a2,a3,a4,a5,a6,a7);
	}
}


int ReadAdc(int ch)
{
	int i;
	static int prevCh=-1;
	if(prevCh!=ch)
	{
		rADCCON=0x0|(ch<<2); //setup channel.
		for(i=0;i<150;i++); //min. 15us
	}
	rADCCON=0x1|(ch<<2); //Start A/D conversion
	while(rADCCON &0x1); //To avoid The first FLAG error case.
	//(The START bit is cleared in one ADC clock.)
	while(!(rADCCON & 0x40));
	for(i=0;i<rADCPSR;i++); //To avoid The second FLAG error case
	prevCh=ch;
	return rADCDAT;
}
volatile char end_test;
void Test_DMA_Adc(void)
{
	unsigned int *dst, *temp,i;
	end_test=0;
	pISR_BDMA1=(unsigned)BDMA1_Done;
	rINTMSK=~(BIT_GLOBAL|BIT_BDMA1);
	Uart_Printf("Test of the 'Start by read' in ADC block.\n");
	Uart_Printf("Change the value of AIN0\n");
	// rCLKCON=0x7ff8;
	dst=(unsigned int *)malloc(0x100);
	rNCACHBE0= ((int)dst>>12) + ( (((int)dst>>12) +1)<<16 );
	temp=dst;
	/***ADC init***/
	rADCCON=0x2; //normal,AIN0,enable start by read
	rADCPSR=0x4; // MCLK/2
	/*
	while(1)
	{
	if( rADCCON & 0x40 )
	{
	i=rADCDAT;
	Uart_Printf("!!!0x%03x, ",i);
	for(i=0;i<0x10;i++);
	}
	}
	*/
	/***BDMA1 init***/
	rBDISRC1=(2<<30)+(3<<28)+0x1d40008; //word,peri.(ADC)
	rBDIDES1=(2<<30)+(1<<28)+(unsigned)dst; //IO2M,++
	rBDICNT1=(1<<30)+(1<<26)+(3<<22)+(0<<20)+10*4;
	//timer,unit,end->interrupt,disable,count=10(word)
	rBDICNT1 |= (1<<20);//enable
	rBDCON1 = 0x0;
	/***Timer0 init***/
	rTCFG0=255; //prescaler0=255
	rTCFG1=(1<<24)+4; //Timer0 DMA, div=32
	rTCNTB0=4902; //(1/(40MHz/255/32))*4902=1.xx s
	rTCON=0xa; //auto, update
	rTCON=0x9; //Start
	while(!end_test);
	Uart_Printf("dst=0x%x,temp=0x%x\n",dst,temp);
	for(i=0;i<10;i++)
		Uart_Printf("%d=0x%03x\n",i,*temp++);
	Uart_Printf("dst=0x%x,temp=0x%x\n",dst,temp);
	free(dst);
	rINTMSK=BIT_GLOBAL;
}
void __irq BDMA1_Done(void)
{
	rI_ISPC=BIT_BDMA1; //clear pending bit
	rTCON=0x0; //Stop
	end_test=1; //set end flag
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -