?? init_adc.c
字號:
/**********************************************************************
* ?2006 Microchip Technology Inc.
*
* FileName: init_ADC.c
* Dependencies: p33FJ256GP710.h
* Processor: dsPIC33F
* Compiler: MPLAB?C30 v2.01 or higher
*
* SOFTWARE LICENSE AGREEMENT:
* Microchip Technology Inc. (揗icrochip? licenses this software to you
* solely for use with Microchip dsPIC?digital signal controller
* products. The software is owned by Microchip and is protected under
* applicable copyright laws. All rights reserved.
*
* SOFTWARE IS PROVIDED 揂S IS.? MICROCHIP EXPRESSLY DISCLAIMS ANY
* WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL MICROCHIP
* BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL
* DAMAGES, LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF
* PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
* BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF),
* ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER SIMILAR COSTS.
*
* REVISION HISTORY:
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Author Date Comments on this revision
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Richard Fischer 07/14/05 ADC module initialization
* Priyabrata Sinha 01/27/06 Ported to non-prototype devices
*
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
* ADDITIONAL NOTES:
*
*
**********************************************************************/
#include "p33FJ256GP710.h"
/*---------------------------------------------------------------------
Function Name: Init_ADC
Description: Initialize ADC module
Inputs: None
Returns: None
-----------------------------------------------------------------------*/
void Init_ADC( void )
{
/* set port configuration here */
AD1PCFGL = 0x0000;
AD1PCFGLbits.PCFG4 = 0; // ensure AN4/RB4 is analog (Temp Sensor)
AD1PCFGLbits.PCFG5 = 0; // ensure AN5/RB5 is analog (Analog Pot)
/* set channel scanning here, auto sampling and convert,
with default read-format mode */
AD1CON1 = 0x0000;
AD1CON1bits.FORM = 0;
AD1CON1bits.SSRC = 2;
AD1CON1bits.ASAM = 1;
/* select 12-bit, 1 channel ADC operation */
AD1CON1bits.AD12B = 1;
AD1CON1bits.ADDMABM = 1;
/* enable DMA mode (ADC module sends all results
to ADBUF0 and interrupts on each result */
// ADCON1bits.ADDMAEN = 1;
/* No channel scan for CH0+, Use MUX A,
SMPI = 1 per interrupt, Vref = AVdd/AVss */
AD1CON2 = 0x0000;
AD1CON2bits.CSCNA = 1;
AD1CON2bits.SMPI = 1;
/* Set Samples and bit conversion time */
AD1CON3 = 0x0000;
AD1CON3bits.ADCS = 63;
AD1CON4bits.DMABL = 0;
/* set channel scanning here for AN4 and AN5 */
AD1CSSL = 0x0000;
AD1CSSLbits.CSS5 = 1;
AD1CSSLbits.CSS4 = 1;
/* channel select AN5 */
// AD2CHS0 = 0x0005;
/* reset ADC interrupt flag */
IFS0bits.AD1IF = 0;
/* enable ADC interrupts, disable this interrupt if the DMA is enabled */
IEC0bits.AD1IE = 0;
/* turn on ADC module */
AD1CON1bits.ADON = 1;
}
void Init_Timer5(void)
{
T3CONbits.TCS = 0;
T3CONbits.TGATE = 0;
TMR3 = 0;
PR3 = 5000;
IFS0bits.T3IF = 0;
IEC0bits.T3IE = 0;
T3CONbits.TON = 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -