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

📄 adctimer.c

📁 8051试验程序 基础教材
💻 C
字号:
/*********************************************************************

 Author        : ADI - Apps            www.analog.com/MicroConverter

 Date          : October 2003

 File          : ADCtimer.c

 Hardware      : ADuC842

 Description   : Performs ADC conversions at 10KSPS in Timer2 mode.
                 P3.3 indicates convesion complete. Continuously
                 flashes LED (independently of ADC routine) at
                 approximately 4.7Hz.
                 All rate calculations assume an 2.097152MHz Mclk.
		
********************************************************************/

#include<stdio.h>
#include<ioaduc842.h>

#define adcled P3_bit.P33
#define LED P3_bit.P34		//P3.4 drives red LED on eval board

#pragma vector = ADCI_int
__interrupt void adc_int(){
  	        adcled ^= 1;
		return;
			  }
void DELAY(int);
void main(void)
{

int CHAN=0;
/*PRECONFIGURE...*/
ADCCON1 = 0x09E;		// power up ADC & enable Timer2 mode
ADCCON2 = CHAN ; 		// select channel to convert
RCAP2L  = 0x0F6; 		//sample period = 2 * T2 reload prd
RCAP2H  = 0x0FF; 		//  = 2*(10000h-FFF6h)*5.722us
TL2	= 0x0F6; 		//  = 2*9*5.722us
TH2	= 0x0FF;		//   = 102.99us

/*LAUNCH Timer2 DRIVEN CONVERSIONS...*/
IE_bit.EA	= 1;		        // enable interrupts
IE_bit.EADC	= 1;			// enable ADC interrupt
T2CON_bit.TR2	= 1;			// run Timer2

/*CONTINUE WITH OTHER CODE...*/
for (;;)
{
LED ^= 1;
DELAY(1500);
}

/*; the micro is free to continue with other tasks (flashing the LED in
 this case) while the ADC operation is being controlled by Timer2
 and the ADC interrupt service routine.*/

}

void DELAY(int length)
{
while (length >=0)
    {length--;}
}

⌨️ 快捷键说明

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