?? 1wire.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 + -