Сообщение от dimonbest
|
Сообщение от woroba
|
Как я понял(из хелпа) функции DS18B20 в CVAVR используют аппаратную часть UARTa.
|
не правильно поняли... в cvavr протокол 1-wire реализован програмно, а не аппаратно.. а датчик можно прицепить к любому пину...
|
Example:
Зачем тогда в примерах инициализируется UART???
#include ‹90s8515.h›
/* specify the port and bit used for the 1 Wire bus */
#asm
.equ __w1_port=0x18 ;PORTB
.equ __w1_bit=2
#endasm
/* include the DS18B20 functions prototypes */
#include ‹ds18b20.h›
/* include the printf function prototype */
#include ‹stdio.h›
/* quartz crystal frequency [Hz] */
#define xtal 4000000L
/* Baud rate */
#define baud 9600
/* maximum number of DS18B20 connected to the bus */
#define MAX_DEVICES 8
/* DS18B20 devices ROM code storage area,
9 bytes are used for each device
(see the w1_search function description),
but only the first 8 bytes contain the ROM code
and CRC */
unsigned char rom_codes[MAX_DEVICES][9];
/* allocate space for ROM codes of the devices
which generate an alarm */
unsigned char alarm_rom_codes[MAX_DEVICES][9];
main()
{
unsigned char i,devices;
/* initialize the UART's baud rate */
UBRR=xtal/16/baud-1;
/* initialize the UART control register
TX enabled, no interrupts, 8 data bits */
UCR=8;
/* detect how many DS18B20 devices
are connected to the bus and
store their ROM codes in the rom_codes array */
devices=w1_search(0xf0,rom_codes);
/* display the number */
printf("%-u DEVICE(S) DETECTED\n\r",devices);
/* if no devices were detected then halt */
if (devices==0) while (1); /* loop forever */
/* set the temperature alarms & temperature
measurement resolutions for all the devices
temp_low=25°C temp_high=35°C resolution 12bits */
for (i=0;i‹devices;i++)
{
printf("INITIALIZING DEVICE #%-u ",i+1);
if (ds18b20_init(&rom_codes[i][0],25,35,DS18B20_12BIT_RES))
putsf("OK"); else putsf("ERROR");
};
while (1)
{
/* measure and display the temperature(s) */
for (i=0;i‹devices
printf("t%u=%+.3f\xf8C\n\r",i+1,
ds18b20_temperature(&rom_codes[i++][0]));
/* display the number of devices which
generated an alarm */
printf("ALARM GENERATED BY %-u DEVICE(S)\n\r",
w1_search(0xec,alarm_rom_codes));
};
}
Refer to the DS18B20 data sheet for more information.