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

📄 thermlcd.c

📁 AVR单片机的C语言源程序,包括按键扫描EEPROM通讯LCD显示数码管显示等等的源程序DEMO代码
💻 C
字号:
/* Thermometer with LCD display
   using the National Semiconductor LM75 I2C bus
   temperature sensor

   CodeVisionAVR C Compiler
   (C) 2000-2003 HP InfoTech S.R.L.
   www.hpinfotech.ro

   Chip: AT90S8515
   Memory Model: SMALL
   Data Stack Size: 128 bytes
*/

// 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

#include <lm75.h>  // LM75 driver routines
#include <stdio.h> // sprintf
#include <delay.h> // delay_ms

/*
  Use an 2x16 alphanumeric LCD connected
  to the STK500 PORTC header as follows:

  [LCD]   [STK500 PORTC HEADER]
   1 GND- 9  GND
   2 +5V- 10 VCC  
   3 VLC- LCD contrast control voltage 0..1V
   4 RS - 1  PC0
   5 RD - 2  PC1
   6 EN - 3  PC2
  11 D4 - 5  PC4
  12 D5 - 6  PC5
  13 D6 - 7  PC6
  14 D7 - 8  PC7
*/

#asm
    .equ __lcd_port=0x15
#endasm

#include <lcd.h> // LCD driver routines

// LCD display buffer
char lcd_buffer[33];

void main(void)
{
char sign;
int temp;
// initialize the LCD
lcd_init(16);
// 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 display loop
while (1)
      {
      // read LM75 temperature *10癈
      // from chip with address 0
      temp=lm75_temperature_10(0);
      sign='+';
      if (temp<0)
         {
         sign='-';
         temp=-temp;
         };
      sprintf(lcd_buffer,"t=%c%i.%u\xdfC",sign,temp/10,temp%10);
      // display the temperature
      lcd_clear();
      lcd_puts(lcd_buffer);
      delay_ms(200);
      }
}

⌨️ 快捷键说明

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