📄 adc_8bits.c
字号:
/**
* @file $RCSfile: Adc_8bits.c,v $
*
* Copyright (c) 2004 Atmel.
*
* Please read file license.txt for copyright notice.
*
* @brief This file is an example to use Adc.
*
* This file can be parsed by Doxygen for automatic documentation
* generation.
* Put here the functional description of this file within the software
* architecture of your program.
*
* @version $Revision: 1.0 $ $Name: $
*/
/* @section I N C L U D E S */
#include "t89c51cc01.h"
unsigned char value_converted=0x00; /* converted value */
unsigned char value_AN6=0x00; /* converted AN6 value */
unsigned char value_AN7=0x00; /* converted AN7 value */
bit end_of_convertion=0; /* software flag */
/**
* FUNCTION_PURPOSE:this function setup Adc with channel 6 and 7 and start
* 8bits convertion.
* FUNCTION_INPUTS:void
* FUNCTION_OUTPUTS:void
*/
void main(void)
{
/* configure channel P1.6(AN6) and P1.7(AN7) for ADC */
ADCF = 0xC0;
/* init prescaler for adc clock */
/* Fadc = Fperiph/(2*(32-PRS)), PRS -> ADCLK[4:0] */
ADCLK = 0x06; /* Fosc = 16 MHz, Fadsc = 153.8khz */
ADCON = 0x20; /* Enable the ADC */
EA = 1; /* enable interrupts */
EADC = 1; /* enable ADC interrupt */
while(1)
{
ADCON &= ~0x07; /* Clear the channel field ADCON[2:0] */
ADCON |= 0x06; /* Select channel 6 */
ADCON &= ~0x40; /* standard mode */
ADCON |= 0x08; /* Start conversion */
while(!end_of_convertion); /* wait end of convertion */
end_of_convertion=0; /* clear software flag */
value_AN6=value_converted; /* save converted value */
ADCON &= ~0x07; /* Clear the channel field ADCON[2:0] */
ADCON |= 0x07; /* Select channel 7 */
ADCON &= ~0x40; /* standard mode */
ADCON |= 0x08; /* Start conversion */
while(!end_of_convertion); /* wait end of convertion */
end_of_convertion=0; /* clear software flag */
value_AN7=value_converted; /* save converted value */
}
}
/**
* FUNCTION_PURPOSE:Adc interrupt, save ADDH into an unsigned char
* FUNCTION_INPUTS:void
* FUNCTION_OUTPUTS:void
*/
void it_Adc(void) interrupt 8
{
ADCON &= ~0x10; /* Clear the End of conversion flag */
value_converted = ADDH; /* save value */
end_of_convertion=1; /* set flag */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -