8bit_adc_interrupt.c

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

C
44
字号
#include <sn8p2758.h>
#include "adc_8bit.h"

unsigned int adc_buf;

void main (void)
{
	FADENB=1;						// Enable ADC circuit
	delay(100);						// Delay 100us
	P4UR=0xfe;						// Disable P4.0 pull-up resistor
	P4M=0x00;						// Set P40 as input pin
	P4CON=0x01;						// Set P40 as pure analog input
	ADR=0x40;						// To set 8-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=ADB;					// To get AIN0 input data adc_isr=1;
	}	
}	 

⌨️ 快捷键说明

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