📄 temperature.c
字号:
/*********************************************************************
Author : ADI - Apps www.analog.com/MicroConverter
Date : Sept. 2005
File : Temperature.c
Hardware : Applicable to ADuC702x rev H or I silicon
Currently targetting ADuC7026.
Description : Measures and outputs internal temperature via UART at
9600bps.
*********************************************************************/
#include <ADuC7026.h>
#include <stdio.h>
#include <math.h>
void ADCpoweron(int);
int main(void)
{
float a = 0;
short b;
GP0CON = 0x010100000; // enable ECLK output on P0.7, and ADCbusy on P0.5
GP4DAT = 0x04000000; // P4.2 configured as an output. LED is turned on
GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1
// Setting up UART at 9600 bps for CD = 0
COMCON0 = 0x80; // Setting DLAB
COMDIV0 = 0x88; //
COMDIV1 = 0x00;
COMCON0 = 0x07; // Clearing DLAB
ADCpoweron(2000); // power on ADC
ADCCP = 0x10; // Select Temperature Sensor as an input to the ADC
REFCON = 0x01; // connect internal 2.5V reference to Vref pin
ADCCON = 0xE4; // continuous conversion
while(1)
{
GP4DAT ^= 0x00040000; // Complement P4.2
while (!ADCSTA){}; // wait for end of conversion
b = (ADCDAT >> 16); // To calculate temperature in 癈, use the formula:
a = 0x525 - b; // ((Temperature = 0x525 - Sensor Voltage) / 1.3)
a /= 1.3;
b = floor(a);
printf("Temperature: %d oC\n",b);
}
return 0;
}
void ADCpoweron(int time)
{
ADCCON = 0x20; // power-on the ADC
while (time >=0) // wait for ADC to be fully powered on
time--;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -