adc10.c
来自「dc servo using dspic30f」· C语言 代码 · 共 40 行
C
40 行
//---------------------------------------------------------------------
// File: adc10.c
//
// Written By: Lawrence Glaister VE7IT
//
// Purpose: routines to setup and use 10 bit A/D ports
// //
//---------------------------------------------------------------------
//
// Revision History
//
// 18 Mar 2006 -- first version
//----------------------------------------------------------------------
#include "dspicservo.h"
#include <adc10.h>
extern volatile unsigned short int timer_a2d;
/************************************************************************
* Function Name : ADC10_read
* Description : This function reads from ch0 AN0
* Parameters :
* Return Value : unsigned int
*************************************************************************/
unsigned int ADC10_read(void)
{
// printf("adc10-read starting\r\n");
timer_a2d = 5; // 2 ticks of 100us clock
while ( timer_a2d ); // delay for sample time
// printf("adc10-read after sample delay\r\n");
ADCON1bits.SAMP = 0; // start converting
while (!ADCON1bits.DONE); // wait for conversion to complete (12fcy)
// printf("adc10-read after conversion complete\r\n");
return ADCBUF0;
}
/*********************************************************************
* Function Name : setup_ADC10
* Description : Configures the ADC. This includes :
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?