View previous topic :: View next topic |
Author |
Message |
young
Joined: 24 Jun 2004 Posts: 285
|
DS1820 temperature |
Posted: Fri Jun 25, 2004 2:10 pm |
|
|
I am trying to use the DS1820 temperature sensor to measure temperature provided with the easy2 package. Does anyone has sample programs. I want to read the temperature and show the results on the LCD.
Thanks in advance |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Fri Jun 25, 2004 4:20 pm |
|
|
I used this several years ago. It should give you a starting point at least.
Code: |
Int8 shiftbit,data;
Int16 Temperature,Address;
/*-------------------------------------------------------------------
Pull Reading From Temp Probe
-------------------------------------------------------------------*/
resetDallas(); // Transmit reset
data = 0xCC;
writeDallas(); // Transmit rom command "skip"
data = 0xBE;
writeDallas(); // Transmit memory command "read"
ReadDallas();
resetDallas(); // Transmit reset
data = 0xCC;
writeDallas(); // Transmit rom command "skip"
data = 0x44;
writeDallas(); // Transmit memory command "aquire Temp"
Temperature = Address;
/********************************************************************
* Reset Dallas Temperature Sensor *
********************************************************************/
void resetDallas()
{ output_high(PIN_B2); //Low pulse for 600 uS
delay_us(600); //time as stated
output_low(PIN_B2); //High pulse for 600 uS
delay_us(600); //time as stated
}
/********************************************************************
* Write Int to Dallas Temperature Sensor *
********************************************************************/
void writeDallas() // last for about 66 uS per bit
{ for(shiftbit=1;shiftbit<=8;++shiftbit)
{ output_high(PIN_B2);
delay_us(8);
output_bit(PIN_B2,!(shift_right(&Data,1,0)));
delay_us(57);
output_low(PIN_B2);
delay_us(2);
}
delay_us(200);
}
/********************************************************************
* Read Long Int from Dallas Temperature Sensor *
********************************************************************/
void ReadDallas() // last for about 66 uS per bit
{ Address = 0;
for(shiftbit=1;shiftbit<=16;++shiftbit)
{ output_high(PIN_B2);
delay_us(14);
output_low(PIN_B2);
delay_us(4);
shift_right(&Address,2,input(PIN_B0));
delay_us(55);
}
} |
|
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: DS1820 temperature |
Posted: Mon Jun 28, 2004 8:15 am |
|
|
young wrote: | I am trying to use the DS1820 temperature sensor to measure temperature provided with the easy2 package. Does anyone has sample programs. I want to read the temperature and show the results on the LCD.
Thanks in advance |
the ds1820 and ds1822 work very much the same. thus, check out the code library forum, where i have posted full ccs source code for a ds1822 driver...
http://www.ccsinfo.com/forum/viewtopic.php?t=19520
jds-pic |
|
|
young
Joined: 24 Jun 2004 Posts: 285
|
|
Posted: Mon Jun 28, 2004 12:35 pm |
|
|
Hi neutone and Jds-Pic:
I am totally new on the pic world. and do not know how to handle the problem. regarding to Jds-Pic's prohgram when I compiled it, there is a ONE_WIRE_PIN not fedined error occured, what this ONE_WIRE_PIN refers to, is that the PIN that measure the temperature (middle pin of the DS1820 sensor)? by the way, this is just a .h header file, could you please provide a complete file with main() and LCD display function? I am currently connecting the sensor pin with RE2 (easy2 pic16f877a), and my lcd is connected with portB.
Please help!
Thanks |
|
|
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
|
Posted: Mon Jun 28, 2004 3:25 pm |
|
|
young wrote: | there is a ONE_WIRE_PIN not fedined error occured, what this ONE_WIRE_PIN refers to, is that the PIN that measure the temperature (middle pin of the DS1820 sensor)? |
that pin does not "measure the temperature". it is the onewire I/O pin, by which you communicate with the DS1820 device. hence, you'll need a declaration in your source file as such:
#define PIN_C5 31765
#define ONE_WIRE_PIN PIN_C5
note that you will have to determine the correct pin and correct register for the specific PIC you are using. the example above is for the 18F252, port C5. don't forget that you need a pullup (1K should be OK) on the onewire net.
young wrote: | by the way, this is just a .h header file, could you please provide a complete file with main() and LCD display function? I am currently connecting the sensor pin with RE2 (easy2 pic16f877a), and my lcd is connected with portB.
Please help!
Thanks |
no problem -- i've gone ahead and completed the code as you described above, and ordered a couple of prototype boards as well. the system documentation will be complete as well when the prototype boards arrive in a few days. moreover, i've also scheduled UL and FCC compliance testing. i'll let you know how initial board bringup and software integration comes along.
jds-pic |
|
|
Guest
|
|
Posted: Mon Jun 28, 2004 3:52 pm |
|
|
Jds_pic:
Thank you very much for your great help. The board I am using is PIC easyPIC2 from Mikro, with PIC16f877a chip. the DS1820 comes with the microchip packages, and on the board there is already a DS1820 setup position. DS1820 is easily pluged into the three pins, I guess( I also measure the pin voltage after I plug it in) it should be build up with power on the ground and Vqq pins (not the kinds of PARASITE_POWER). DQ pin could be connected to RA5 or RE2 by jumper.
Thanks agagin, and waiting for your response eagerly! |
|
|
|