Ds1820.zip

Oprogramowanie ds1820 w C

Program CodeVisionAVR (nawet w wersji testowej) zawiera w przykładach coś takiego, czyli termometr. Poniżej przykład i potrzebne biblioteki biblioteki - w katalogu Inc .

  • Ds1820.zip
    • ds1820.vec
    • Ds1820.c
    • Ds1820.txt
    • Array
    • ds1820.sym
    • ds1820.err
    • ds1820.inc
    • ds1820.lst
    • Ds1820.prj
    • ds1820.eep
    • ds1820.map
    • ds1820.asm


Pobierz plik - link do postu

Ds1820.zip > Ds1820.c

/* Multipoint thermometer with LCD display
using the Dallas Semiconductor DS1820/18S20
1 Wire bus temperature sensors

CodeVisionAVR C Compiler
(C) 2000-2003 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 & lt; lcd.h & gt; // LCD driver routines
#include & lt; ds1820.h & gt;
#include & lt; delay.h & gt;
#include & lt; stdio.h & gt;

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 & lt; 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 & lt; 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 & lt; devices;)
{
temp=ds1820_temperature_10( & rom_code[i,0]);
j='+';
if (temp & lt; 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);
};
};
}


Ds1820.zip > Delay.h

// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.

#ifndef _DELAY_INCLUDED_
#define _DELAY_INCLUDED_

#pragma used+

void delay_us(unsigned int n);
void delay_ms(unsigned int n);

#pragma used-

#endif


Ds1820.zip > Stdio.h

// CodeVisionAVR C Compiler
// (C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.

// Prototypes for standard I/O functions

#ifndef _STDIO_INCLUDED_
#define _STDIO_INCLUDED_

#include & lt; stdarg.h & gt;

#ifndef NULL
#define NULL 0
#endif

#ifndef EOF
#define EOF -1
#endif

#pragma used+

char getchar(void);
void putchar(char c);
void puts(char *str);
void putsf(char flash *str);

#ifdef _MODEL_TINY_
char *gets(char *str,unsigned char len);
#endif

#ifdef _MODEL_SMALL_
char *gets(char *str,unsigned int len);
#endif

void printf(char flash *fmtstr,...);
void sprintf(char *str, char flash *fmtstr,...);
void vprintf (char flash * fmtstr, va_list argptr);
void vsprintf (char *str, char flash * fmtstr, va_list argptr);
signed char scanf(char flash *fmtstr,...);
signed char sscanf(char *str, char flash *fmtstr,...);

#ifdef _DEBUG_TERMINAL_IO_
// Used for AVR Studio Terminal I/O
// DON'T CHANGE!

#ifndef _DEBUG_TERMINAL_IO_FN_DEFINED_
#define _DEBUG_TERMINAL_IO_FN_DEFINED_

#pragma warn-
void _c_getchar(void) {}

char getchar(void)
{
#asm
push r16
push r17
getchar0:
#endasm
_c_getchar();
#asm
cpi r17,0xff
breq getchar0
mov r30,r16
pop r17
pop r16
#endasm
}

void _c_putchar(void) {}

void putchar(char c)
{
#asm
mov r30,r16
ld r16,y
#endasm
_c_putchar();
#asm
mov r16,r30
#endasm
}

#ifdef _WARNINGS_ON_
#pragma warn+
#endif

#endif

#endif
#pragma used-

#pragma library stdio.lib

#endif


Ds1820.zip > Ds1820.h

/*
CodeVisionAVR C Compiler
(C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.

Prototypes for Dallas Semiconductor
DS1820 1 Wire bus temperature sensor
functions

BEFORE #include -ING THIS FILE YOU
MUST DECLARE THE I/O ADDRESS OF THE
DATA REGISTER OF THE PORT AT WHICH
THE 1 WIRE BUS IS CONNECTED AND
THE DATA BIT USED

EXAMPLE FOR PORTB:

#asm
.equ __w1_port=0x18
.equ __w1_bit=3
#endasm
#include & lt; ds1820.h & gt;
*/

#ifndef _DS1820_INCLUDED_
#define _DS1820_INCLUDED_

#include & lt; 1wire.h & gt;

#define DS1820_FAMILY_CODE 0x10

#pragma used+
struct __ds1820_scratch_pad_struct
{
unsigned char temp_lsb,temp_msb,
temp_high,temp_low,
res1,res2,
cnt_rem,cnt_c,
crc;
} __ds1820_scratch_pad;

unsigned char ds1820_select(unsigned char *addr);
unsigned char ds1820_read_spd(unsigned char *addr);
int ds1820_temperature_10(unsigned char *addr);
unsigned char ds1820_set_alarm(unsigned char *addr,signed char temp_low,signed char temp_high);
#pragma used-
#pragma library ds1820.lib

#endif