adctrig.c

来自「8051试验程序 基础教材」· C语言 代码 · 共 58 行

C
58
字号
//======================================================================
//
// Author        : ADI - Apps
//
// Date          : Feb 2003
//
// File          : adctrig.c
//
// Description   : Flash led an initial rate of 100ms
//		  Pressing INTO triggers single conversion
//		  The ADC result is written to external memory
//		  The delay rate is increased
//		  The program waits for the next INTO to repeat the 
//		  above sequence
//
//======================================================================

#include <stdio.h>
#include <ioADuC836.h>

int loop;

unsigned __xdata test[2];

#pragma vector=extern0
__interrupt void interrupt_0 ()
{	
	ADCMODE=0x22;
	while ( ADCSTAT_bit.RDY0==0 )
	{
	}	
	ADCSTAT_bit.RDY0 = 0;
	test[0] = ADC0M;
	test[1] = ADC0H;
	loop++;
}

void main (void)
{	
	int i,j;
	
	ADCMODE = 0x20;
	ADC0CON = 0x47;
	TCON_bit.IT0 = 1;
	IE_bit.EA = 1;
	IE_bit.EX0 = 1;
	loop = 0x00;
	
	while(1)
	{
		P3 ^= 0x10;
		for (i = 0; i < 1000 ; i++)
		{
			for (j = 0x00; j <= loop ; j++);
		}
	}
}

⌨️ 快捷键说明

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