tempuart.c

来自「8051试验程序 基础教材」· C语言 代码 · 共 47 行

C
47
字号
//====================================================================
//
// Author        : ADI - Apps
//
// Date          : November 2001
//
// File          : TempUart.c
//
// Hardware      : ADuC836
//
// Description   : This Program takes a temperature measurement every
//                 second from the on-chip temp sensor and sends the
//                 temp in degrees Celcius up the UART to the PC where
//                 it can be read using hyperterminal
//====================================================================

#include <stdio.h> 
#include <ioADuC836.h>

void main (void)
{	
	int i, temp;

	//UART config        
	T3CON = 0x82;
        T3FD = 0x12;
        SCON = 0x52;

        ADCMODE = 0x10;	// ENABLE AUX Mode - Power down 
        ADC1CON = 0x20; // USE INTERNAL REFERENCE PTAT(+) --> PTAT(-) BIPOLAR MODE Fixed +/- 2.5V range 

	printf("____________________________________\n"
               "Analog Devices MicroConverter ADuC834\n"
               "Temp Sensor Demo Routine\n");
  
	while(1)
	{	
		ADCSTAT_bit.RDY1 = 0;
		ADCMODE = 0x12;
		while (ADCSTAT_bit.RDY1 == 0);	// wait for result	
		temp = ADC1H-128; 		      
		printf("\n\n");
		printf("%d degrees C\n", temp);
	    for (i = 0; i < (10000); i++) {}
	}
}

⌨️ 快捷键说明

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