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

📄 ds1820.c

📁 AVR单片机的C语言源程序,包括按键扫描EEPROM通讯LCD显示数码管显示等等的源程序DEMO代码
💻 C
字号:
/* Multipoint thermometer with LCD display
   using the Dallas Semiconductor DS1820/18S20
   1 Wire bus temperature sensors

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

   Chip: AT90S8515
   Memory Model: SMALL
   Data Stack Size: 128 bytes
   
   THE AT90S8515 CLOCK FREQUENCY MUST BE 3.6864 MHz

   The DS1820/18S20 sensors are connected to
   bit 6 of PORTA of the AT90S8515 as follows:

   [DS1820/18S20] [STK500 PORTA HEADER]
    1 GND         -   9  GND
    2 DQ          -   7  PA6
    3 VDD         -  10 +5V

   All the temperature sensors must be connected
   in parallel
   
   AN 4.7k PULLUP RESISTOR MUST BE CONNECTED
   BETWEEN DQ (PA6) AND +5V !
*/
#asm
    .equ __w1_port=0x1b
    .equ __w1_bit=6
#endasm

/* Use an 2x16 alphanumeric LCD connected
   to PORTC 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
#include <ds1820.h>
#include <delay.h>
#include <stdio.h>

char lcd_buffer[33];

/* maximum number of DS1820/DS18S20 connected to the 1 Wire bus */
#define MAX_DEVICES 8

/* DS1820/DS18S20 devices ROM code storage area */
unsigned char rom_code[MAX_DEVICES][9];

main()
{
unsigned char i,j,devices;
int temp;

lcd_init(16);
lcd_putsf("CodeVisionAVR\n1 Wire Bus Demo");
delay_ms(2000);
lcd_clear();

/* detect how many DS1820/DS18S20 devices
   are connected to the 1 Wire bus */
devices=w1_search(0xf0,rom_code);
sprintf(lcd_buffer,"%u DS1820\nDevice detected",devices);
lcd_puts(lcd_buffer);
delay_ms(2000);

/* display the ROM codes for each device */
if (devices)
   {
   for (i=0;i<devices;i++)
       {
       sprintf(lcd_buffer,"Device #%u ROM\nCode is:",i+1);
       lcd_clear();
       lcd_puts(lcd_buffer);
       delay_ms(2000);
       lcd_clear();
       for (j=0;j<8;j++)
           {
           sprintf(lcd_buffer,"%02X ",rom_code[i][j]);
           lcd_puts(lcd_buffer);
           if (j==3) lcd_gotoxy(0,1);
           };
       delay_ms(5000);
       };
   }
else
while (1); /* stop here if no devices were found */

/* measure and display the temperature(s) */       
while (1)
      {
      for (i=0;i<devices;)
          {
          temp=ds1820_temperature_10(&rom_code[i][0]);
          j='+';
          if (temp<0)
             {
             j='-';
             temp=-temp;
             };
          sprintf(lcd_buffer,"t%u=%c%i.%u\xdfC",++i,j,temp/10,temp%10);
          lcd_clear();
          lcd_puts(lcd_buffer);
          delay_ms(800);
          };
      };
}

⌨️ 快捷键说明

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