View Full Version : 12f509 and DS18B20
robertg
- 8th August 2024, 09:24
Hi,
Looking for advice here with the 12F509 and temperature sensor. Using hte DS18B20 since it's one wire.
My first issue, is the 12F509 won't accept the word as variable and any variable is seen as a byte. Spinning wheels a bit on this issue and lookig for some simple code to read the sensor.
Using cut down of the sample code:
temperature VAR WORD ' Temperature storage
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
pause 2000
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
Not seeing data come in from the sensor so suspect it's got something to do with the inability to setup a word variable??
I've got the DS18 operating previously on 18 series micros hence don't think it's a hardware issue at this point.
Did read somewhere I need to run PBPW to support word variables, which I can't seem to find but I'm using PBPX 3.1.6.4
richard
- 8th August 2024, 10:00
the problem will be in the code not posted
this works fine
9704
robertg
- 9th August 2024, 00:36
Okay than Richard,
That is what I'm effectively doing but no joy!
Interestingly I'm now testing the code on a PIC18F45K20 and sensor works fine on PORTC or PORTD but can't seem to get any readings when configured using ports eithe port A, B or E.
Little stumped as to why the don't work on these ports. Think if I can resolve it working on the 18F45K20 i'll get it working on the 12F509
Have played with setting TRISX in various settings with no luck. Have yet to find the difference between the ports or any specific register that need to be set.
Here's the code...
DEFINE OSC 4 ' ensure 4Mhz is set for comms
Include "modedefs.bas"
#CONFIG
CONFIG FOSC = INTIO67 ; Internal Oscillator, no clock out
CONFIG MCLRE = OFF
#ENDCONFIG
OSCCON=%01010000
temperature VAR WORD ' Temperature storage
x var word
'TRISB = %11111111
'TRISA = %00000000
'led1 var portA.2
'low led1
DQ VAR portD.0 ' One-wire data pin c.0 worked on 45K20
tx VAR portC.3
x=1
mainloop:
OWOUT DQ, 1, [$CC, $44] ' Start temperature conversion
pause 500
OWOUT DQ, 1, [$CC, $BE] ' Read the temperature
OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
temperature = temperature */ 1600
SEROUT2 tx,84,[dec x,"temperature",DEC (temperature / 100), ".", DEC2 temperature,10,13]
x=x+1
GoTo mainloop
richard
- 9th August 2024, 01:00
DQ VAR portD.0 ' One-wire data pin c.0 worked on 45K20
tx VAR portC.3
a 12F509 has no portc or portd it has a gpio
if you look in the manual you will find
SEROUT2 is not supported on 12-bit core PIC MCUs due to RAM and stack constraints.
use debug or serout instead
robertg
- 9th August 2024, 01:51
Hi Richard,
The code shown is for the 18F and yep the 12F doesn't support serout2.
But the point I was making below, believe the issue I'm having is PORTA on the 18F is probably the same as the GPIO.X on the 12F
Bottom line is I can't get the code you supplied on the 12F and trying to establish a baseline using the 18F
Rob.
richard
- 9th August 2024, 02:55
what i supplied does not actually do much other than prove that pbp can compile 12f509 code for a onewire device when a word var is declared as per
My first issue, is the 12F509 won't accept the word as variable
Bottom line is I can't get the code you supplied on the 12F and trying to establish a baseline using the 18F
i cannot quite understand that statement. there is no point posting code for a 18f when you are trying to employ a 12f509
post the actual code you are using [preferably in code tags]
robertg
- 9th August 2024, 08:16
Yep correct.
And sorry for wasting your time, I've got everthing I need working on a 18F45K20 now.
Putting aside the extra legs to solder, for the extra $3 for this micro. makes sense to work with the 18f as I now have heaps of program space and no restriction on I/O pins etc.... plus it works!
ciao and thanks anyway!
Rob.
tumbleweed
- 9th August 2024, 14:18
...testing the code on a PIC18F45K20 and sensor works fine on PORTC or PORTD but can't seem to get any readings when configured using ports eithe port A, B or E
That's probably because many pins on ports A, B, and E are also analog pins so the digital input buffer is disabled by default.
See the ANSEL/ANSELH registers
robertg
- 13th August 2024, 00:35
Thanks Tubleweed!
After your comment on the ANSEL/h after searching the datasheet on those registered, yep found that information buried in the doc.
Haven't touched a PIC micro in years, I'm going through the relearning experience. You do forget how powerful and complex these devices are.
Rob.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.