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

📄 adc_hawkzone.c

📁 自动完成寄存器配置的44b0定时中断和ADC程序
💻 C
字号:

#include "myinc.h"


int ReadAdc(int ch);

void __irq ADC_Int(void);

void Test_Adc(void)
{
	int a0=0,a1=0,a2=0,a3=0,a4=0,a5=0,a6=0,a7=0;	

	while(1)
	{
		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);
		Delay(50000); //5s
	}
}
/************************************************
* Start and read one channel ADC  *
************************************************/
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;
}
/************************************************
* Start and read one channel ADC code end *
************************************************/
/************************************************
* ADC initiation  *
************************************************/
void ADC_Init(U32 con_rate,U8 start)
{
	//rINTCON=0x5;
	//rINTMOD=0x0;    //All=IRQ mode
	pISR_ADC=(unsigned)ADC_Int;
	rINTMSK = rINTMSK & (~(BIT_GLOBAL|BIT_ADC));	//start INT
	
		
	if( start ==1)
	{		
		Uart_Printf("The ADC_IN are adjusted to the following values.\n");
		rADCPSR = MCLK/(2*con_rate*16)-1;
		Uart_Printf("ADC conv. freq.=%d(Hz)\n",(int)(MCLK/(2.*(rADCPSR+1.))/16.) );
		rADCCON=0x00; //Enable ADC
		Delay(100); //delay for 10ms for ADC reference voltage stabilization.
	}	
	else
		rADCCON=0x20; //Disable ADC
}
/************************************************
* ADC initiation code end *
************************************************/
/************************************************
* ADC conversion interrupt  *
************************************************/
void __irq ADC_Int(void)
{
	rI_ISPC=BIT_ADC; //clear pending bit
	Uart_Printf("\n44B0X ADC interrupt test OK !");
}
/************************************************
* ADC conversion interrupt code end *
************************************************/

void Main(void)
{
    rSYSCFG=CACHECFG;   // Using 8KB Cache//

    Port_Init();
    Uart_Init(0,57600);
    Delay(10);
    Uart_Select(0); //Select UART0
    Led_Display(0x01);

    
    Uart_Printf("\nFS44B0X");
//    Uart_Printf("\n");
//    Uart_Printf("\nFS44B0X ADC interrupt test!");
    
    ADC_Init(10000,START);
    Test_Adc();
    
}

⌨️ 快捷键说明

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