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

📄 1wire.c

📁 Pic Nic 16f877/18f452控制 rtl8019as 原代码
💻 C
字号:
/*
 * 1WIRE.C - 1-wire communication library
 *
 * By F醔io Pereira
 *
 * Adapted by Rafael
 *
 */

#define ONE_WIRE_PIN pin_b5	  // Default 1 Wire Communication Pin

#inline
void seta_saida_1w (void) {
	output_float (ONE_WIRE_PIN);
}

#inline
void limpa_saida_1w (void) {
	output_low (ONE_WIRE_PIN);
}

//Reset devices on the 1Wire Bus
boolean reset_1w(void) {
	boolean presente;
	limpa_saida_1w ();
	delay_us(480);
	seta_saida_1w ();
	delay_us(60);
	presente = input (ONE_WIRE_PIN);
	delay_us (240);
	return (presente);
   //Returns:
	// 0 = a device is present
	// 1 = no detected device
}

//Gives power to the Bus for devices on parasite mode
void alimenta_barramento_1w (void) {
	output_high (ONE_WIRE_PIN);
	delay_ms(1000);
	seta_saida_1w();
}

//Read a bit from the Bus
boolean le_bit_1w (void) {
	limpa_saida_1w ();
	seta_saida_1w ();
	delay_us (25);
	return (input(ONE_WIRE_PIN));
}

//Write a bit to the Bus
void escreve_bit_1w (boolean bit) {
	limpa_saida_1w ();
	if (bit) seta_saida_1w ();
	delay_us (120);
	seta_saida_1w ();
}

//Read a byte from the Bus
byte le_byte_1w (void) {
	byte i, dado = 0;
	// Read 8 bits starting from the lsb
	for (i=0;i<8;i++)	{
		if (le_bit_1w ()) dado|=0x01<<i;
		delay_us(90);
	}
	return (dado);
}

//Write a byte to the Bys
void escreve_byte_1w (char dado) {
	byte i, temp;

	for (i=0; i<8; i++) {
		temp = dado>>i;
		temp &= 0x01;
		escreve_bit_1w (temp);
	}
}

⌨️ 快捷键说明

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