?? therm75.c
字號:
/* Thermometer with RS232 serial data transmision
using the National Semiconductor LM75 I2C bus
temperature sensor
Chip: AT90S8515
Memory Model: SMALL
Data Stack Size: 128 bytes
Clock frequency: 3.6864 MHz
Communication parameters: 9600 8N1
CodeVisionAVR C Compiler
(C) 2000-2003 HP InfoTech S.R.L.
www.hpinfotech.ro
In order to use the RS232 SPARE connector
on the STK500, the following connections must
be made:
[RS232 SPARE header] [PORTD header]
RXD - 1 PD0
TXD - 2 PD1
I2C bus port bits allocations for PORTA
NOTE: 3.3k..4.7k PULL-UP RESITORS TO +5V MUST
BE USED FOR THE SDA & SCL I2C BUS SIGNALS
*/
#asm
.equ __i2c_port=0x1b ;PORTA
.equ __scl_bit=0 ;SCL=STK500 PORTA HEADER pin 1
.equ __sda_bit=1 ;SDA=STK500 PORTA HEADER pin 2
#endasm
// LM75 driver routines
#include <lm75.h>
// printf
#include <stdio.h>
// AT90S8515 I/O register definitions
#include <90s8515.h>
#include <delay.h>
void main(void)
{
char sign;
int temp;
// enable the transmitter
UCR=8;
// Baud=9600 @ 3.6864 MHz
UBRR=23;
// initialize the I2C bus
i2c_init();
// initialize the LM75 chip with address 0
// hysterezis temperature 20癈
// O.S. temperature 25癈
// O.S. output is active high
lm75_init(0,20,25,1);
// temperature transmission loop
while (1)
{
// read LM75 temperature *10癈
// from chip with address 0
temp=lm75_temperature_10(0);
sign='+';
if (temp<0)
{
sign='-';
temp=-temp;
};
// send the measured temperature via the
// RS232 serial communication
printf("t=%c%i.%u\xf8C\r\n",sign,temp/10,temp%10);
delay_ms(200);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -