?? init_adc.c.bak
字號:
/**********************************************************************
* ?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 */
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 = 0x00E4;
/* select 12-bit, 1 channel ADC operation */
AD1CON1bits.AD12B = 1;
/* enable DMA mode (ADC module sends all results
to ADBUF0 and interrupts on each result */
//ADCON1bits.ADDMAEN = 1;//azg
/* No channel scan for CH0+, Use MUX A,
SMPI = 1 per interrupt, Vref = AVdd/AVss*/
AD1CON2 = 0x0000;
/* Set Samples and bit conversion time */
AD1CON3 = 0x032F;
/* set channel scanning here for AN4 and AN5 */
AD1CSSL = 0x0000;
/* channel select AN5 */
AD1CHS0 = 0x0005;
/* reset ADC interrupt flag */
IFS0bits.AD1IF = 0;
/* enable ADC interrupts, disable this interrupt if the DMA is enabled */
IEC0bits.AD1IE = 1;
/* turn on ADC module */
AD1CON1bits.ADON = 1;
/*******************************************************************/
// ADxCON1 = 0x000000
// Bit15 ADON: ADC Operating Mode bit;"1" ADC module is operating
// Bit14 undefine
// Bit13 ADSIDL: Stop in Idle Mode bit "0" Continue module operation in Idle mode
// Bit12 ADDMABM: DMA Buffer Build Mode bit
// Bit11 undefine
// Bit10 AD12B: 10-bit or 12-bit Operation Mode bit;"1"12-bit,1-channel ADC operation
// Bit09
// Bit08 FORM<1:0>: Data Output Format bits;For 12-bit operation: 1 1.
// Bit07
// Bit06
// Bit05 SSRC<2:0>: Sample Clock Source Select bits
//
// Bit04 undefine
// Bit03 SIMSAM: 12BitMode "0"Samples multiple channels individually in sequence
// Bit02 ASAM: ADC Sample Auto-Start bit
// Bit01 SAMP: ADC Sample Enable bit
// Bit00 DONE: ADC Conversion Status bit;"1"ADC conversion cycle is completed
/******************************************************************/
// ADxCON2 = 0x000000
// Bit15
// Bit14
// Bit13 VCFG<2:0>: Converter Voltage Reference Configuration bits
// Bit12 undefine
// Bit11 undefine
// Bit10 CSCNA: Input Scan Select bit
// Bit09
// Bit08 CHPS<1:0>: Channel Select bits;12Bit is 0 0
// Bit07 BUFS: Buffer Fill Status bit (only valid when BUFM = 1)
// Bit06 undefine
// Bit05
// Bit04
// Bit03
// Bit02 SMPI<3:0>: Increment Rate for DMA Addresses bits
// Bit01 BUFM: Buffer Fill Mode Select bit
// Bit00 ALTS: Alternate Input Sample Mode Select bit
/******************************************************************/
// ADxCON3 = 0x000000
// Bit15 ADRC: ADC Conversion Clock Source bit
// Bit14 undefine
// Bit13 undefine
// Bit12
// Bit11
// Bit10
// Bit09
// Bit08 SAMC<4:0>: Auto Sample Time bits
// Bit07
// Bit06
// Bit05
// Bit04
// Bit03
// Bit02
// Bit01
// Bit00 ADCS<7:0>: ADC Conversion Clock Select bits
/******************************************************************/
// ADxCON4 = 0x000000
// Bit15
// Bit14
// Bit03 undefine
// Bit02
// Bit01
// Bit00 DMABL<2:0>: Selects Number of DMA Buffer Locations per Analog Input bits
/******************************************************************/
// ADxCHS123 = 0x000000
// Bit15
// Bit11 undefine
// Bit10
// Bit09 CH123NB<1:0>: Channel 1, 2, 3 Negative Input Select for Sample B bits
// Bit12Mode 0 0
// Bit08 CH123SB: Channel 1, 2, 3 Positive Input Select for Sample B bit
// Bit07
// Bit03 undefine
// Bit02
// Bit01
// Bit00
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -