Witam.
Ponownie DS
ale jakoś nie mogę znaleźc błedu.
HW i biblioteki 1 wire sprawdzone z inym programem i DS18(nieB)20.
1) Wartośc po 0xBE i reset_1w () przez chwile pokazuje 85 (poprawnie) a potem tylko 127.
Timingi sprawdzalem
2) Jak poprawnie zapisac temperature z dokadnoscia do 0.1 na dwoch bajtach unsigned char? Nie chce uyzwac floatow ani int bo za duzo pamieci mi to zjada.
Ponownie DS
HW i biblioteki 1 wire sprawdzone z inym programem i DS18(nieB)20.
1) Wartośc po 0xBE i reset_1w () przez chwile pokazuje 85 (poprawnie) a potem tylko 127.
Timingi sprawdzalem
2) Jak poprawnie zapisac temperature z dokadnoscia do 0.1 na dwoch bajtach unsigned char? Nie chce uyzwac floatow ani int bo za duzo pamieci mi to zjada.
int main(void)
{
unsigned char T_LSB = 0x00;
unsigned char T_MSB = 0x00;
unsigned char CRC = 0x00;
unsigned char ds_map [9];
unsigned char i;
unsigned char DS_Present = 0x00;
unsigned char Temperature;
TIMSK = 0x82; // TOIE1 - Timer/Counter1 interrupt Enable, TOIE0 - Timer/Counter0 interrupt Enable set to "1"
TCNT0 = TCNT0_INIT; // Initialise TCNT0
TCNT1 = TCNT1_INIT; // Initialise TCNT1
TCCR0 = 2; // Prescaler for TCNT0 CLK/8
TCCR1B = 3; // Prescaler for TCNT1 CLK/64
DDRB = 0xFF; // PORTB Output
DDRD = 0x24; // PD0, PD1 - Inputs (SW1, SW2), PD2 - output (Clock dots)
PORTB = 0x00; // PD3 - 1Wire, PD4 - Buzzer, PD5 - BI/RBI, PD6 - LT
PORTD = 0x27; // 0V on PD6
temp_units = 0;
sei ();
while(1)
{
CRC = 0;
DS_Present=reset_1w();
if (DS_Present != 0)
{
temp_sign = 8;
temp_h = 8;
temp_l = 8;
temp_units = 8;
}
else
{
send_1w(0xCC);
send_1w(0x44);
_delay_ms(750);
DS_Present=reset_1w();
if (DS_Present == 0)
{
send_1w(0xCC);
send_1w(0xBE);
for (i=0; i<9; i++)
{
ds_map [i] = get_1w();
Count_CRC (ds_map [i], &CRC);
}
T_LSB = ds_map [0];
T_MSB = ds_map [1];
reset_1w();
if (CRC==0)
{
T_LSB = T_LSB >> 4;
T_MSB &= 0x07;
T_MSB = T_MSB << 4
Temperature = T_MSB | T_LSB; //obliczanie dla DS18B20
DisplayValue (Temperature);
}
}
else temp_units = 12;
}
...
}i biblioteka (nie moja)
#include <avr/io.h>
#include <util/delay.h>
#include <inttypes.h>
#include "1wire_lib.h"
/*********************************************************************************/
// Reset interfejsu 1-Wire
//1-Wire reset
uint8_t reset_1w(void)
{
unsigned char presence=1;
write_1w;
write_zero;
_delay_us(330);
read_1w;
_delay_us(70);
if(clear_1w) presence=0;
_delay_us(400);
return presence;
}
/*********************************************************************************/
// Zapis bajtu
// Write byte to 1-wire device
void send_1w(unsigned char data)
{
unsigned char u;
unsigned char x;
for(u=0; u<8; u++)
{
x=0x01&data;
if (x==0)
{
write_1w;
write_zero;
_delay_us(60);
read_1w;
_delay_us(5);
}
else
{
write_1w;
write_zero;
_delay_us(5);
read_1w;
_delay_us(60);
}
data>>=1;
}
}
/*********************************************************************************/
// Odczyt bajtu
//Read byte from 1-Wire device
unsigned char get_1w(void)
{
unsigned char x=0x00;
unsigned char u;
for(u=0; u<8; u++)
{
x>>=1;
write_1w;
write_zero;
_delay_us(4);
read_1w;
_delay_us(6);
if(set_1w)
{
x=x+0x80;
}
_delay_us(90);
}
return x;
}
