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

📄 therm75.c

📁 AVR单片机的C语言源程序,包括按键扫描EEPROM通讯LCD显示数码管显示等等的源程序DEMO代码
💻 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 + -