12bit_adc_interrupt.c

来自「范例程序 SONiX」· C语言 代码 · 共 44 行

C
44
字号
#include <sn8p2758.h>
#include "adc_12bit.h"
unsigned int adc_buf_hi,adc_buf_low;

void main (void)
{
	
		FADENB=1;						// Enable ADC circuit
		delay(200);						// Delay 200us
		P4UR=0xfe;						// Disable P4.0 pull-up resistor
		P4M=0x00;						// Set P40 as input pin
		P4CON=0x01;						// Set P40 as pure analog input
		ADR=0x60;						// To set 12-bit and  Fcpu/1.		
		ADM=0x90;						// Enable ADC and set AIN0 input
		FADCIEN=1;						// Enable ADC interrupt service
		FADCIRQ=0;						// Clear ADC interrupt request flag
		FGIE=1;							// Enable GIE
		FADS=1;							// To start conversion
		
//===============================================
// 
//		User code  		
//	
//===============================================

}

void delay (unsigned int i)
{
		unsigned int  j;
		for (j=i;j>0;j--)
		NOP(1);
}

__interrupt isr (void)
{
		if((FADCIEN==1)&&(FADCIRQ==1))
    {
			FADCIRQ=0;
			adc_buf_hi=(ADB&0xF0)>>4;			// To get ADC transform data
			adc_buf_low=((ADB&0x0F)<<4)|(ADR&0x0F);
 	}
}

⌨️ 快捷键说明

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