How come my DS18S20 code still works?


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Location
    Australia
    Posts
    15


    Did you find this post helpful? Yes | No

    Default

    Hello Jerry.

    Excellent explanation. Now I understand it a lot better.

    You are right, I really do not need that much accuracy but it was good to find out how it can be done.

    Thanks very much.

    Wilson

  2. #2
    Join Date
    Aug 2007
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: How come my DS18S20 code still works?

    my code just gives me the same output, I'm trying to use 4 7 segment displays can you all help me I am useing a 18f452
    clear
    define osc 20
    include "modedefs.bas"

    trisa=%11111111 ' a as input
    trisb=0 'port b as output
    trisd=%00001111 'portd as output 7-4 & 0-3 as input
    digit var byte
    pattern var byte
    digit1 var portd.7
    digit2 var portd.6
    digit3 var portd.5
    digit4 var portd.4
    'DS18S20_9bit con %00011111;93.75ms,0.5c
    'DS18S20_10bit con %00111111;187.5ms,0.25c
    'DS18S20_11bit con %01011111;375ms,0.125c
    DS18S20_12bit con %01111111;750ms,0.0625c default

    i var word
    DQ var PORTA.4 ' one wire data pin

    Temp_C var word
    SignC var word
    Busy var byte
    Negative var word
    Positive var word

    Temper var word
    count_remain var byte
    count_per_c var word


    digit4=0
    digit3=0
    digit2=0
    digit1=0



    Start:
    temper.lowbyte=0
    temper.highbyte=0
    count_remain=0

    owout DQ,1,[$CC,$B4] 'test for parasite power or external supplies
    pause 10 'wait for power test

    owout DQ,1,[$CC,$4E,0,0,DS18S20_12bit]


    owout DQ,1,[$CC,$44] 'start conversion

    Waitloop: ' check for still busy converting
    owin DQ,4,[count_remain]
    if Count_remain=0 then goto Waitloop

    owout DQ,1,[$CC,$BE] 'read scratchpad

    owin DQ,0,[temper.lowbyte,temper.highbyte,skip 4,count_remain,count_per_c]

    'calculate temperature in c to 2 decimal
    temp_C=((( Temper>>1)*100)-25)+(((count_per_c - count_remain)*100)/count_per_c)
    ' 7 segment 4 led display


    digit=Temp_C dig 3 'get 1000s
    gosub convert
    portb=pattern
    digit4=0
    digit3=0
    digit2=0
    digit1=1

    pause 5

    digit=Temp_C dig 2 'get 100s
    gosub convert
    portb=pattern
    digit4=0
    digit3=0
    digit2=1
    digit1=0
    portb.7=1

    pause 5

    digit=Temp_C dig 1 'get 10s
    gosub convert
    portb=pattern
    digit4=0
    digit3=1
    digit2=0
    digit1=0
    portb.7=0
    pause 5

    digit=Temp_C dig 0 'get 1s
    gosub convert
    portb=pattern
    digit4=1
    digit3=0
    digit2=0
    digit1=0

    pause 5
    digit4=0


    goto Start

    end


    convert:
    lookup digit,[$3f,$06,$5b,$4f,$66,$6d,$7d,$07,$7f,$6f],pattern
    portb=pattern
    return

Similar Threads

  1. Manchester coding/decoding Code help
    By financecatalyst in forum Code Examples
    Replies: 0
    Last Post: - 25th August 2009, 19:05
  2. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  3. Why doesn't my code for 18f452 work on 18f252?
    By senojlr in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2005, 02:42
  4. Timer PIC16F57
    By leonel in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 1st July 2005, 08:14
  5. Port control code Yelp!!
    By andyf in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th May 2005, 22:36

Members who have read this thread : 0

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