1234567891011121314151617181920212223242526272829303132 |
- #include <p33FJ64MC204.h>
- #include <stdlib.h>
- #include <math.h>
- #include "ADC.h"
- /*******************************************************************************
- * 函数名称:InitADC
- * 功能描述:配置ADC控制寄存器
- *******************************************************************************/
- void InitADC(void)
- {
- AD1CON1bits.AD12B=1;
- AD1CON2=0;
- AD1CON2bits.VCFG=0;
- AD1CON3bits.ADRC=0;
- AD1CON3bits.SAMC=20;
- AD1CON3bits.ADCS=5;
- AD1CHS0=0;
- AD1CSSL=0;
- AD1CON1bits.FORM=0;
- AD1CON1bits.SSRC=7;
- AD1CON1bits.ASAM=0;
- }
- unsigned int AD_Get(unsigned int num)
- {
- AD1CHS0bits.CH0SA = num;
- AD1CON1bits.ADON = 1;
- AD1CON1bits.SAMP = 1;
- while (!AD1CON1bits.DONE);
- return (ADC1BUF0);
- }
|