[an error occurred while processing this directive]
|
These functions are intended for easy interfacing between C programs and the DS1621 I2C bus thermometer/thermostat.
The prototypes for these functions are placed in the file ds1621.h, located in the ..\INC subdirectory. This file must be #include -ed before using the functions.
The I2C bus functions prototypes are automatically #include -ed with the ds1621.h.
Prior to #include -ing the ds1621.h file, you must declare which microcontroller port and port bits are used for communication with the DS1621 through the I2C bus.
Example:
/* the I2C bus is connected to PORTB */
/* the SDA signal is bit 3 */
/* the SCL signal is bit 4 */
#asm
.equ __i2c_port=0x18
.equ __sda_bit=3
.equ __scl_bit=4
#endasm
/* now you can include the DS1621 Functions */ The DS1621 Functions are: void ds1621_init(unsigned char chip,signed char tlow,signed char thigh, unsigned char pol) Besides measuring temperature, the DS1621 functions also like a thermostat. Refer to the DS1621 data sheet for more information. unsigned char ds1621_get_status(unsigned char chip) this function reads the contents of the configuration/status register of the DS1621 with address chip. void ds1621_set_status(unsigned char chip, unsigned char data) this function sets the contents of the configuration/status register of the DS1621 with address chip. Refer to the DS1621 data sheet for more information about this register. void ds1621_start(unsigned char chip) void ds1621_stop(unsigned char chip) int ds1621_temperature_10(unsigned char chip) this function returns the temperature of the DS1621 sensor with the address chip. The temperature is in °C and is multiplied by 10. Example how to display the temperature of two DS1621 sensors with addresses 0 and 1: /* the SDA signal is bit 3 */ /* the SCL signal is bit 4 */ #asm .equ __i2c_port=0x18 .equ __sda_bit=3 .equ __scl_bit=4 #endasm /* include the DS1621 Functions */ #include /* the LCD module is connected to PORTC */ #asm .equ __lcd_port=0x15 #endasm /* include the LCD Functions */ #include /* include the prototype for sprintf */ #include /* include the prototype for abs */ #include char display_buffer[33]; void main(void) { int t0,t1; /* initialize the LCD, 2 rows by 16 columns */ lcd_init(16); /* initialize the I2C bus */ i2c_init(); /* initialize the DS1621 sensor with address 0 */ /* tlow=20°C thigh=25°C */ ds1621_init(0,20,25,0); /* initialize the DS1621 sensor with address 1 */ /* tlow=30°C thigh=35°C */ ds1621_init(1,30,35,0); /* temperature display loop */ while (1) /* read the temperature of DS1621 #1 *10°C */ /* prepare the displayed temperatures */ /* display the temperatures */
E-mail:
info@telesys.ru
#include
this function initializes the DS1621 chip.
Before calling this function the I2C bus must be initialized by calling the i2c_init function.
This is the first function that must be called prior to using the other DS1621 Functions.
If more then one chip is connected to the I2C bus, then the function must be called for each one, specifying accordingly the function parameter chip.
Maximum 8 DS1621 chips can be connected to the I2C bus, their chip address can be from 0 to 7.
The Tout output becomes active when the temperature exceeds the thigh limit, and leaves the active state when the temperature drops below the tlow limit.
Both tlow and thigh are expressed in °C.
pol represents the polarity of the DS1621 Tout output in active state.
If pol is 0, the output is active low and if pol is 1, the output is active high.
Refer to the DS1621 data sheet for more information about this register.
this functions exits the DS1621, with address chip, from the power-down mode and starts the temperature measurements and the thermostat.
this functions enters the DS1621, with address chip, in power-down mode and stops the temperature measurements and the thermostat.
/* the DS1621 I2C bus is connected to PORTB */
{
/* read the temperature of DS1621 #0 *10°C */
t0=ds1621_temperature_10(0);
t1=ds1621_temperature_10(1);
/* in the display_buffer */
sprintf(display_buffer,
"t0=%-i.%-u%cC\nt1=%-i.%-u%cC",
t0/10,abs(t0%10),0xdf,t1/10,abs(t1%10),0xdf);
lcd_clear();
lcd_puts(display_buffer);
};
}
Ответы
Перейти к списку ответов
|||
Конференция
|||
Архив
|||
Главная страница
|||
Содержание