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

📄 adc.c

📁 s3c44box 的远程序~!很有价值的啊!!!包括地层硬件编程!
💻 C
字号:
#include <string.h>
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\adc.h"

void __irq BDMA1_Done(void);

void Test_Adc(void)
{
    Uart_Printf("The ADC_IN are adjusted to the following values.\n");	      
    Uart_Printf("Push any key to exit!!!\n");	 

    rCLKCON=0x7ff8;	
    
    while(Uart_GetKey()==0)
    {
	rADCPSR=0x0;		// MCLK/2

	rADCCON=0x1|(0x0<<2);	// AIN0
	while(!(rADCCON & 0x40));
	Uart_Printf("A0=%03xh ",rADCDAT);

	rADCCON=0x1|(0x1<<2);	// AIN1
	while(!(rADCCON & 0x40));
	Uart_Printf("A1=%03xh ",rADCDAT);

	rADCCON=0x1|(0x2<<2);	// AIN2
	while(!(rADCCON & 0x40));
	Uart_Printf("A2=%03xh ",rADCDAT);

	rADCCON=0x1|(0x3<<2);	// AIN3
	while(!(rADCCON & 0x40));
	Uart_Printf("A3=%03xh\n",rADCDAT);

	rADCCON=0x1|(0x4<<2);	// AIN4
        while(!(rADCCON & 0x40));
	Uart_Printf("A0=%03xh ",rADCDAT);

	rADCCON=0x1|(0x5<<2);	// AIN5
	while(!(rADCCON & 0x40));
	Uart_Printf("A1=%03xh ",rADCDAT);

	rADCCON=0x1|(0x6<<2);	// AIN6
	while(!(rADCCON & 0x40));
	Uart_Printf("A2=%03xh ",rADCDAT);

	rADCCON=0x1|(0x7<<2);	// AIN7
	while(!(rADCCON & 0x40));
	Uart_Printf("A3=%03xh\n",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)+(1<<20)+10*4;//timer,unit,end->interrupt,enable,count=10(word) 

    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 + -