#include <ledtest.h>
static int LastDiscrepancy;
static int LastFamilyDiscrepancy;
static int LastDeviceFlag;
static int USpeed = 0; // current 1-Wire Net communication speed
static int ULevel = 0; // current 1-Wire Net level
uchar ROM_NO[8];
//uchar FamilySN[MAXDEVICES][8];
uchar crc8;
ushort utilcrc16;
bit c16;
static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
void main(void)
{
int y=0;
int flag=0;
//uchar test;
//uchar receive;
uchar temp1,temp2;
// uchar temp3,temp4;
// bit crcbit;
ushort lastcrc16;
delay(100);
led_blink();
Init_Rs232();
delay(500);
//init conditional search status
while(1)
{
ow_reset();
write_byte(0xcc); //LSB address
write_byte(0x55); //LSB address
write_byte(0x07); //MSB address
write_byte(0x00); //LSB address
if (flag==0)
{
write_byte(0x76); //MSB address
}
else{
write_byte(0x56); //MSB address
}
temp1=read_byte();
temp2=read_byte();
// crcbit=read_bit();
setcrc16(0x0000); //
docrc16(0x55);
docrc16(0x07);
docrc16(0x00);
if (flag==1)
{
docrc16(0x16);
}
else{
docrc16(0x36);
}
// read and calculate the read crc
docrc16(temp1);
lastcrc16 = docrc16(temp2);
// crc should now be 0xB001
if (lastcrc16 != 0xB001)
{
ow_reset();
}
else{
}
if (first(TRUE))
{
if(flag==0)
{
flag=1;
}
else{
flag=0;
}
if(Send_MatchRom())
{
write_byte(0x55); //write status
write_byte(0x07); //LSB address
write_byte(0x00); //MSB address
if (flag==1)
{
write_byte(0x0e); //LSB address
}
else{
write_byte(0x6d); //LSB address
}
temp1=read_byte();
temp2=read_byte();
// crcbit=read_bit();
setcrc16(0x0000); //
docrc16(0x55);
docrc16(0x07);
docrc16(0x00);
if (flag==1)
{
docrc16(0x0e);
}
else{
docrc16(0x6d);
}
// read and calculate the read crc
docrc16(temp1);
lastcrc16 = docrc16(temp2);
// crc should now be 0xB001
if (lastcrc16 != 0xB001)
{
ow_reset();
//tx_str("make PIOA high crc error!");
}
else{
//tx_str("make PIOA high crc correct!");
}
//tx_lfbs();
}
}
}
/*delay(255);
tx_str("Pelease input 1 or 2 or 3 or 4 or 5");
tx_lfbs();
tx_str("case '1':Send 1_wire reset");
tx_lfbs();
tx_str("case '2':Performing search rom CODE");
tx_lfbs();
tx_str("case '3':Performing SKIP READ ROM COMMAND");
tx_lfbs();
tx_str("case '4':Performing SKIP WRITE ROM COMMAND");
tx_lfbs();
tx_str("case '5':read status from ds2406!");
tx_lfbs();
tx_str("case '6':write one low bit!");
tx_lfbs();
tx_str("case '7':make PIOA high crc correct!");
tx_lfbs();
while(1)
{
receive=rx_char();
switch (receive)
{
case '1':
tx_str("Send 1_wire reset");
tx_lfbs();
if (ow_reset())
{
tx_str("reset failure!");
tx_lfbs();
}
else {
tx_str("reset success!");
tx_lfbs();
}
break;
case '2':
tx_str("Performing search rom CODE");
tx_lfbs();
ow_reset();
first(FALSE);
if (ROM_NO[0]==0x12)
{
tx_str("Correct find Ds2406 family ROM code");
tx_lfbs();
}
/* tx_str("ROM_NO[0]=18");
tx_lfbs();
for (y=1;y<8;y++)
{
tx_str("ROM_NO[");
tx_char(y+48);
tx_str("]=");
if (ROM_NO[y]>=128)
{tx_char((ROM_NO[y]-80));
tx_str(" (ROM_NO>128)");
}
else if (ROM_NO[y]<48)
{ tx_char((ROM_NO[y]+48));
tx_str(" (ROM_NO<48)");
}
else{
tx_char(ROM_NO[y]);
}
tx_lfbs();
}*/
/* tx_str("Performing send Match Rom");
tx_lfbs();
if(Send_MatchRom())
{
write_byte(0x55); //write status
write_byte(0x07); //LSB address
write_byte(0x00); //MSB address
write_byte(0x0e); //LSB address
temp1=read_byte();
temp2=read_byte();
// crcbit=read_bit();
setcrc16(0x0000); //
docrc16(0x55);
docrc16(0x07);
docrc16(0x00);
docrc16(0x0e);
// read and calculate the read crc
docrc16(temp1);
lastcrc16 = docrc16(temp2);
// crc should now be 0xB001
if (lastcrc16 != 0xB001)
{
ow_reset();
tx_str("make PIOA high crc error!");
}
else{
tx_str("make PIOA high crc correct!");
}
tx_lfbs();
}
break;
case '3':
tx_str("3:Performing SKIP Read Rom Command");
tx_lfbs();
for (y=0x0a;y<=0x0f;y++)
{
ow_reset();
write_byte(0xCC); //LSB address
write_byte(0xF0); //MSB address
write_byte(y); //LSB address
write_byte(0x00); //MSB address
test=read_byte();
if (test==0xff)
{
tx_str("read_byte=0xff!");
tx_lfbs();
}
else {
tx_str("read_byte=");
tx_char((test+48));
tx_lfbs();
}
}
break;
case '4':
tx_str("4:Performing SKIP Write Rom Command");
tx_lfbs();
for (y=0x0a;y<=0x0f;y++)
{
ow_reset();
write_byte(0xCC); //LSB address
write_byte(0x0F); //MSB address
write_byte(y); //LSB address
write_byte(0x00); //MSB address
write_byte(y); //LSB address
temp1=read_byte();
temp2=read_by
评论0