用于单片机使用18B20器件的MAC地址搜索

源代码在线查看: 18b20mac.txt

软件大小: 2 K
上传用户: wuliaowenti
关键词: 18B20 MAC 单片机 器件
下载地址: 免注册下载 普通下载 VIP

相关代码

				//-----------------------------------------------------------------------------
				// Read and return the page data and SHA-1 message authentication code (MAC)
				// from a DS2432.
				//
				int ReadPageMAC(int page, unsigned char *page_data, unsigned char *mac)
				{
					int i;
					unsigned short data_crc16, mac_crc16;
				
					// set the speed to 'standard'
					SetSpeed(1);
				
					// select the device
					if (OWTouchReset()) // Reset the 1-Wire bus
						return 0; // Return if no devices found
				
					OWWriteByte(0xCC); // Send Skip ROM command to select single device
				
					// read the page
					OWWriteByte(0xA5); // Read Authentication command
					OWWriteByte((page 					OWWriteByte(0); // TA2 (always zero for DS2432)
				
					// read the page data
					for (i = 0; i < 32; i++)
						page_data[i] = OWReadByte();
					OWWriteByte(0xFF);
				
					// read the CRC16 of command, address, and data
					data_crc16 = OWReadByte();
					data_crc16 |= (OWReadByte() 				
					// delay 2ms for the device MAC computation
					// read the MAC
					for (i = 0; i < 20; i++)
						mac[i] = OWReadByte();
				
					// read CRC16 of the MAC
					mac_crc16 = OWReadByte();
					mac_crc16 |= (OWReadByte() 				
					// check CRC16...
					return 1;
				}			

相关资源