⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledtest.c

📁 The information in this publication is believed to be accurate as of its publication date. Such info
💻 C
📖 第 1 页 / 共 2 页
字号:
#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_byte();
						  // crcbit=read_bit();
						   setcrc16(0x0000);     //
                           docrc16(0x0f);
                           docrc16(y);
                           docrc16(0x00);
						   docrc16(y);
                             // read and calculate the read crc
                           docrc16(temp1);
                           lastcrc16 = docrc16(temp2);
                           // crc should now be 0xB001
                           if (lastcrc16 != 0xB001)
                               {
							    ow_reset();
				                tx_str("write crc error!");
					           }
                         else{
	                          tx_str("write crc correct!");
			                 }
                            tx_lfbs();                
							 wdelay(10000);
						 }
						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();
						temp1=read_byte();
						temp2=read_byte();
						 setcrc16(0x0000);     //
                           docrc16(0xF0);
                           docrc16(y);
                           docrc16(0x00);
						   docrc16(test);
                             // read and calculate the read crc
                           docrc16(temp1);
                           lastcrc16 = docrc16(temp2);
                           // crc should now be 0xB001
                           if (lastcrc16 != 0xB001)
                               {
							    ow_reset();
				                tx_str("read crc error!");
					           }
                         else{
	                          tx_str("read crc correct!");
			                 }
							   if (test==0xff)
							       {
								     tx_str("read_byte=0xff!");
									 tx_lfbs();
									}
							   else {	
	         				         tx_str("read_byte=");
									 tx_char((test+55));
									  tx_lfbs();
									}
							   wdelay(10000);
                            }
                            break;
          case '5':
                   tx_str("read status  from ds2406!");
                   tx_lfbs();
		          for (y=0x00;y<0x08;y++)
					      {
					       ow_reset();                
					       write_byte(0xCC);   //LSB address
	                       write_byte(0xaa);   //MSB address
					       write_byte(y);   //LSB address
	                       write_byte(0x00);   //MSB address
                           test=read_byte();  //LSB address
                           temp1=read_byte();
						   temp2=read_byte();
						  // crcbit=read_bit();
						   setcrc16(0x0000);     //
                           docrc16(0xaa);
                           docrc16(y);
                           docrc16(0x00);
						   docrc16(test);
                             // read and calculate the read crc
                           docrc16(temp1);
                           lastcrc16 = docrc16(temp2);
                           // crc should now be 0xB001
                           if (lastcrc16 != 0xB001)
                               {
							    ow_reset();
				                tx_str("read status crc error!");
					           }
                         else{
	                          tx_str("read status crc correct!");
			                 }
                            tx_lfbs(); 
               			     if (test==0xff)
							       {
								     tx_str("read_byte=0xff!");
									 tx_lfbs();
									}
							   else {	
	         				         tx_str("read_byte=");
									 tx_char((test+48));
									  tx_lfbs();
									}
							 delay(5000);

						 }
						 break;
		    case '6':
			         tx_str("setup search  conditional");
					 tx_lfbs();
                     tx_str("make PIOA high start!");
                     tx_lfbs();
					       ow_reset();                
					       write_byte(0xCC);   //LSB address
	                       write_byte(0x55);   //MSB address
					       write_byte(0x07);   //LSB address
	                       write_byte(0x00);   //MSB address
                           write_byte(0x56);  //LSB address
                           temp1=read_byte();
						   temp2=read_byte();
						  // crcbit=read_bit();
						   setcrc16(0x0000);     //
                           docrc16(0x55);
                           docrc16(0x07);
                           docrc16(0x00);
						   docrc16(0x56);
                             // read and calculate the read crc
                           docrc16(temp1);
                           lastcrc16 = docrc16(temp2);
                           // crc should now be 0xB001
                           if (lastcrc16 != 0xB001)
                               {
							    ow_reset();
				                tx_str("make PIOB Low crc error!");
					           }
                         else{
	                          tx_str("make PIOB low crc correct!");
			                 }
                            tx_lfbs(); 
							 delay(5000);
			         tx_str("Performing search rom CODE");
					 tx_lfbs();
					 ow_reset();
					 first(TRUE);
                     if (ROM_NO[0]==0x12)
					       {
						       tx_str("conditional search Correct find Ds2406 family ROM code");
							   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 '7':
                   tx_str("make PIOA high start!");
                   tx_lfbs();
					       ow_reset();                
					       write_byte(0xCC);   //LSB address
	                       write_byte(0x55);   //MSB address
					       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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -