📄 adctimer.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : May 2002
File : ADCtimer.c
Hardware : ADuC831
Description : Performs ADC conversions at 10KSPS in Timer2 mode.
P3.3 indicates convesion complete. Continuously
flashes LED (independently of ADC routine) at
approximately 10Hz.
All rate calculations assume an 11.0592MHz crystal
********************************************************************/
#include<stdio.h>
#include<aduc831.h>
sbit adcled = 0x0B3 ;
sbit LED = 0x0B4; //P3.4 drives red LED on eval board
void adc_int() interrupt 6{
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 = 0x0D2; //sample period = 2 * T2 reload prd
RCAP2H = 0x0FF;
TL2 = 0x0D2;
TH2 = 0x0FF;
/*LAUNCH Timer2 DRIVEN CONVERSIONS...*/
EA = 1; // enable interrupts
EADC = 1; // enable ADC interrupt
TR2 = 1; // run Timer2
/*CONTINUE WITH OTHER CODE...*/
for (;;)
{
LED ^= 1;
DELAY(3200);
}
/*; 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 + -