⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 temperature.c

📁 DSPic33FJ64GP206单片机的应用
💻 C
字号:
#include "p33FJ64GP206.h"


volatile unsigned int temp1;
volatile unsigned int temp2=0;
volatile unsigned char Temp_flag=0;
volatile unsigned char filtercount=0;
volatile unsigned char hunds;
volatile unsigned char tens;
volatile unsigned char ones;

/*---------------------------------------------------------------------
  Function Name: ADCInterrupt
  Description:   ADC Interrupt Handler
  Inputs:        None
  Returns:       None
-----------------------------------------------------------------------*/
void __attribute__((__interrupt__,no_auto_psv)) _ADC1Interrupt( void )
{

	temp2+=ADC1BUF0;
	/* Simple I am here indicator */
	if ( filtercount++ >= 15) 
	{
		temp1=temp2>>4;
		filtercount = 0;
		temp2=0;
		Temp_flag=1;
	}
	/* reset ADC interrupt flag */
	IFS0bits.AD1IF = 0;           
}


/*---------------------------------------------------------------------
  Function Name: Init_ADC
  Description:   Initialize ADC module
  Inputs:        None
  Returns:       None
-----------------------------------------------------------------------*/
void Init_ADC( void )
{

	TRISBbits.TRISB5=1;
	/* set port configuration here */ 		
 	AD1PCFGLbits.PCFG5 = 0;		// ensure AN5/RB5 is analog (Temp Sensor)
 
 	/* set channel scanning here, auto sampling and convert, 
 	   with default read-format mode */
	AD1CON1 = 0x04E4;
	/* 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;
	
	/* No channel scan for CH0+, Use MUX A,  
	   SMPI = 1 per interrupt, Vref = AVdd/AVss */
	AD1CON2 = 0x0000;
	
	/* Set Samples and bit conversion time */
	AD1CON3 = 0x1f1f;		//

        	
	/* 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 = 0;       

	/* turn on ADC module */
	AD1CON1bits.ADON = 1;          	
}



void hexdec( unsigned char count )
{
 hunds = 0;						//initialize hundred
 tens  = 0;						//initialize tens
 ones = 0;						//initialzise ones
 
	while ( count >= 10 )
	{
	
		if (count >= 100)		//check hundreds
		{
		  count -= 100;		    //subract 100
		  hunds++;				//increment hundred register
		}
	
		if (count >= 10 )		//check tens
		{
		  count -= 10;		    //subtract 10
		  tens++;				//increment tens
		}
	}

	ones = count;				//remaining count equals ones
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -