12f509 and DS18B20


+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2005
    Posts
    35

    Default 12f509 and DS18B20

    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

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    the problem will be in the code not posted

    this works fine

    Name:  rg.jpg
Views: 199
Size:  180.8 KB
    Warning I'm not a teacher

  3. #3
    Join Date
    Nov 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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
    Warning I'm not a teacher

  5. #5
    Join Date
    Nov 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,451


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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]
    Warning I'm not a teacher

  7. #7
    Join Date
    Nov 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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.

  8. #8
    Join Date
    Aug 2011
    Posts
    431


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    ...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

  9. #9
    Join Date
    Nov 2005
    Posts
    35


    Did you find this post helpful? Yes | No

    Default Re: 12f509 and DS18B20

    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.

Similar Threads

  1. 12F509 doesn't do anything
    By madphys in forum General
    Replies: 2
    Last Post: - 31st January 2010, 09:00
  2. Timer and 12F509
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 3rd November 2008, 14:51
  3. 12f509 and OSCCAL
    By mwhatley in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 20th October 2007, 01:35
  4. how to use 12F509
    By marad73 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 30th April 2006, 21:49
  5. 12F509 programmer
    By Michael in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 3rd February 2006, 19:20

Members who have read this thread : 12

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts