Port Addressing Issue


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Bingo! That is exactly what I want

  2. #2
    Join Date
    Nov 2004
    Location
    Fribourg, Switzerland
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    Hi Cocacolakid

    Try this:

    PortB.0 [sensor]

    If you need more info, read section 4.11 on the manual.

    Hope this help.

    Hans

  3. #3


    Did you find this post helpful? Yes | No

    Default

    After sleeping on this I figured out an easy way to accomplish this task. I just added a subroutine that gets the port state according to the value of "sensor". I works like a charm.

    Code:
    read_sensors:
        for sensor = 0 to 4
        temp_c = 0
        temp_f = 0
        temp_k = 0
        dummy = 0
        dq = 0
        gosub ds_init
        gosub read_temp
        sign_c_array[sensor] = sign_c
        sign_f_array[sensor] = sign_f
        temp_c_array[sensor] = temp_c
        temp_f_array[sensor] = temp_f
        temp_k_array[sensor] = temp_k
        next sensor
    
    ds_init:
        low sensor                              ' Set the data pin low to initialize
        pauseus 500                             ' Wait for more than 480us
        input sensor                            ' Make data pin port an input
        pauseus 100                             ' Wait for more than 60us
        gosub direction
        if SensorState = 1 then                ' Is there a DS18B20 detected
            debug cmd,line3,"Not Present"       ' If not set flag indicating so
            SensorMissing = 1
            return					
        endif					
        pauseus 400                             ' Wait for end of presence pulse
        debug cmd,line3,"Present    "           ' Set flag indicating there is a 
        SensorMissing = 0                       ' sensor present
        return
    
    direction:
        if sensor = 0 then 
        SensorState = portb.0
        return
        endif
        if sensor = 1 then 
        SensorState = portb.1
        return
        endif
        if sensor = 2 then 
        SensorState = portb.2
        return
        endif
        if sensor = 3 then 
        SensorState = portb.3
        return
        endif
        if sensor = 4 then 
        SensorState = portb.4
        return
        endif
    
    read_temp:
        if SensorMissing = 1 then
                temp_c = 32767
                temp_f = 62181
                temp_k = 60082
                sign_c = "+"
                sign_f = "+"
                return
            endif
            owout sensor,1,[$CC,$44]            ' Send start temperature conversion 
                                                ' command
            low portb.5                         ' Turn on transistor between rail and 
                                                ' data pin
            pause 750                           ' Allow enough time to process Tconv
            high portb.5                        ' Turn off transistor between rail and 
                                                ' data pin
            owout sensor,1,[$CC,$BE]            ' Send read scratch pad command
            owin sensor,0,[STR dq\9]            ' Read all 9 bytes and store them in dq 
                                                ' array
            raw_temp.Byte0 = dq[0]              ' Isolate raw temperature from the rest
            raw_temp.Byte1 = dq[1]
            gosub get_crc                       ' Calculate the CRC of the data
            gosub convert_temp                  ' Convert raw data into real temps
            return

  4. #4
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Smile

    Glad to see you found a solution. I still think there should be a way to do it similar to what I was thinking, and Hans's idea. Any thoughts from the guru's?
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. Change On Interrupt, PIC16F884
    By elec_mech in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 14th November 2008, 17:25
  2. port config.
    By tamertokgoz in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th July 2008, 12:25
  3. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. STATUS re-curtain W
    By zugvogel1 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 13th February 2005, 15:21

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