E ai galera blz?
Sou novo com os produtos da freescale mas acabei comprando um kit e estou no caminho.
Estou tentando acessar o DS1822 mas nao esta dando certo, estou fazendo o programa em C, vou colocar a biblioteca para voces se alguem puder por favor me ajudar.
Estou usando o mc9s08jm60 da familia hcs08jm quando inicio o chip mostra o bus como 8mhz (interno).
Desde ja agradeco,
Abraco,
Icaro
#define DQ PTADD_PTADD0 // DS1822 enable pin direction
// Display configuration global variable
static char i;
//**************************************************************************
//* Prototypes
//**************************************************************************
unsigned char ow_reset(void);
unsigned char read_bit(void);
void write_bit(char bitval);
unsigned char read_byte(void);
void write_byte(char val);
// DELAY - with an 8MHz internal.
// Calling the routine takes about 33us, and then
// each count takes another 22us.
//
void delay(int useconds)
{
int s;
for (s=0; s<useconds;s++);
}
//////////////////////////////////////////////////////////////////////////////
// OW_RESET - performs a reset on the one-wire bus and
// returns the presence detect. Reset is 480us, Presence checked
// another 70us later
//
unsigned char ow_reset(void)
{
unsigned char presence;
DQ = 1; //pull DQ line low
delay(21); // leave it low for 480us
DQ = 0; // allow line to return high
delay(2); // wait for presence
presence = DQ; // get presence signal
delay(18 ); // wait for presence
return(presence); // presence sign
}
//////////////////////////////////////////////////////////////////////////////
// READ_BIT - reads a bit from the one-wire bus. The delay
// required for a read is 15us, so the DELAY routine won't work.
// We put our own delay function in this routine in the form of a
// for() loop.
//
unsigned char read_bit(void)
{
unsigned char i;
DQ = 1; // pull DQ low to start timeslot
DQ = 0; // then return high
for (i=0; i<2; i++); // delay 15us from start of timeslot
return(DQ); // return value of DQ line
}
//////////////////////////////////////////////////////////////////////////////
// WRITE_BIT - writes a bit to the one-wire bus, passed in bitval.
//
void write_bit(char bitval)
{
DQ = 1; // pull DQ low to start timeslot
if(bitval==1) DQ =0; // return DQ high if write 1
delay(4); // hold value for remainder of timeslot
DQ = 0;
}
//////////////////////////////////////////////////////////////////////////////
// READ_BYTE - reads a byte from the one-wire bus.
//
unsigned char read_byte(void)
{
unsigned char i;
unsigned char value = 0;
for (i=0;i<8;i++)
{
if(read_bit()) value|=0x01<<i; // reads byte in, one byte at a time and then
// shifts it left
delay(4); // wait for rest of timeslot
}
return(value);
}
//////////////////////////////////////////////////////////////////////////////
// WRITE_BYTE - writes a byte to the one-wire bus.
//
void write_byte(char val)
{
unsigned char i;
unsigned char temp;
for (i=0; i<8; i++) // writes byte, one bit at a time
{
temp = val>>i; // shifts val right 'i' spaces
temp &= 0x01; // copy that bit to temp
write_bit(temp); // write bit in temp into
}
delay(4);
}