|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 08, 2004 10:39 pm |
|
|
You're having so much trouble making this work.
Peter Anderson has some code for the DS1820 on his website.
He uses the CCS compiler:
http://www.phanderson.com/PIC/PICC/CCS_PCM/ds1820.html
Here's the main page:
http://www.phanderson.com/PIC/PICC/index.html
The only problem with his code is that he doesn't always
use CCS functions. For example, he writes his own
delay functions, in order to make his code be more
"universal". But by doing so, he makes it more
difficult for CCS users who run their PIC at a different
crystal frequency than he uses. So I suggest that
when you see his code like this
then you should change it to use the CCS function, like this:
Code: | delay_us(500); // 10 us x 50 = 500 us |
Also, delete his delay_ms() function, since CCS has its own
delay_ms() function.
At the end of his DS1820 code, he has some LCD code which
you don't need. Just delete it. |
|
|
Guest
|
|
Posted: Fri Jul 09, 2004 6:29 am |
|
|
Hi PCM:
thank you for you answer.
I did make 1820 working using Peter Anderson's program after make a little modification on parasite power situation, when I change the connection to non-parasite power situation, the reading is consistantly 85 degree c. could you tell me why. and where should I changed. I tried to remove _1w_strong_pull_up(sensor); in the program, but there is no change.
Code: |
#if defined(__PCM__)
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#include <lcd420_1.c>
#include <math.h>
#byte PORTA =0x05
#byte TRISA =0x85
#define MAX_SENSORS 4
// 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
void main(void)
{
int sensor, n;
float buff;
sensor=5;
while(1)
// for (sensor=0; sensor<MAX_SENSORS; sensor++)
{
_1w_init(sensor);
_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
buff=(float)(_1w_in_byte(sensor))/(2.0);
lcd_init();
printf(lcd_putc," ");
printf(lcd_putc," ");
lcd_gotoxy(1,1);
printf(lcd_putc,"* Temperature *");
lcd_gotoxy(1,2);
printf(lcd_putc,"Tem=%4.2f%1cC",buff,0xdf);
}
}
// The following are standard 1-Wire routines.
void _1w_init(int sensor)
{
_1w_pin_hi(sensor);
_1w_pin_low(sensor);
delay_us(50);
_1w_pin_hi(sensor);
delay_us(50);
}
int _1w_in_byte(int sensor)
{
int n, i_byte, temp, mask;
mask = 0xff & (~(0x01<<sensor));
for (n=0; n<8; n++)
{
PORTA=0x00;
TRISA=mask;
TRISA=0xff;
#asm
CLRWDT
NOP
NOP
#endasm
temp=PORTA;
if (temp & ~mask)
{
i_byte=(i_byte>>1) | 0x80; // least sig bit first
}
else
{
i_byte=i_byte >> 1;
}
delay_us(6);
}
return(i_byte);
}
void _1w_out_byte(int d, int sensor)
{
int n, mask;
mask = 0xff & (~(0x01<<sensor));
for(n=0; n<8; n++)
{
if (d&0x01)
{
PORTA=0;
TRISA=mask; // momentary low
TRISA=0xff;
delay_us(6);
}
else
{
PORTA=0;
TRISA=mask;
delay_us(6);
TRISA=0xff;
}
d=d>>1;
}
}
void _1w_pin_hi(int sensor)
{
TRISA = 0xff;
}
void _1w_pin_low(int sensor)
{
PORTA = 0x00;
TRISA = 0xff & (~(0x01 << sensor));
}
void _1w_strong_pull_up(int sensor) // bring DQ to strong +5VDC
{
PORTA = 0x01 << sensor;
TRISA = 0xff & (~(0x01 << sensor));
delay_ms(120);
TRISA = 0xff;
}
|
|
|
|
Jerry I
Joined: 14 Sep 2003 Posts: 96 Location: Toronto, Ontario, Canada
|
|
Posted: Fri Jul 09, 2004 4:14 pm |
|
|
Do you have more than one sensor.
This happened to me also, and I found out that sensor was dead.
Try that first.
Jerry
I did make 1820 working using Peter Anderson's program after make a little modification on parasite power situation, when I change the connection to non-parasite power situation, the reading is consistantly 85 degree c. could you tell me why. and where should I changed. I tried to remove _1w_strong_pull_up(sensor); in the program, but there is no change. |
|
|
Guest
|
|
Posted: Mon Jul 12, 2004 12:27 pm |
|
|
Hi Jerrt:
No I just have one 1820 sensor. I believe my sensor is working. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|