Hello! I'm a beginner with with pics, and need your help: I searched over the web for a 1wire mcc18 lib, but I've found nothing complete... I'd like to build a simple thermometer with 18f4520, ds1820 with 2 7 segmens display, On a breadboard I've built it, the 7 segment display works well (connected on portD, and PortC) but the ds1820 gives zero... Thank you for your help! here is the source: (the mcu is running @20MHz) the main function isn't important, it must have to work, this is the new source which I've added to it... I call from the main program with: i = gettemp(); d1 = i/10; //digit1 d2 = i%10; //digit2 What do you think? Where I made mistakes? ----------------------------------------------------------------------------------------------------------------- #include #define MAX_SENSORS 1 // 1-wire prototypes void _1w_init(int sensor); int _1w_in_byte(int sensor); void _1w_out_byte(int d, int sensor); void _1w_pin_hi(int sensor); void _1w_pin_low(int sensor); void _1w_strong_pull_up(int sensor); // not used in this routine int gettemp(void) { int buff[9], sensor, n; int temperature; sensor = 0; _1w_out_byte(0xcc, sensor); // skip ROM _1w_out_byte(0x44, sensor); // perform temperature conversion _1w_strong_pull_up(sensor); _1w_init(sensor); _1w_out_byte(0xcc, sensor); // skip ROM _1w_out_byte(0xbe, sensor); // read the result for (n=0; n<9; n++) { buff[n]=_1w_in_byte(sensor); } temperature = buff[0]>>1; // temperature without LSB (0.5C) return temperature; } // The following are standard 1-Wire routines. void _1w_init(int sensor) { _1w_pin_hi(sensor); _1w_pin_low(sensor); Delay10TCYx(250); _1w_pin_hi(sensor); Delay10TCYx(250); } int _1w_in_byte(int sensor) { int n, i_byte, temp, mask; mask = 0xff & (~(0x01<>1) | 0x80; // least sig bit first } else { i_byte=i_byte >> 1; } Delay10TCYx(30); } return(i_byte); } void _1w_out_byte(int d, int sensor) { int n, mask; mask = 0xff & (~(0x01<>1; } } void _1w_pin_hi(int sensor) { TRISB = 0xff; } void _1w_pin_low(int sensor) { PORTB = 0x00; TRISB = 0xff & (~(0x01 << sensor)); } void _1w_strong_pull_up(int sensor) // bring DQ to strong +5VDC { PORTB = 0x01 << sensor; TRISB = 0xff & (~(0x01 << sensor)); Delay1KTCYx(1250); TRISB = 0xff; } -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist