owout not working on 16f77 ? (hangs)


Closed Thread
Results 1 to 11 of 11

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    this is driving me nuts lol... still cant figure out why it hangs on the owout command, no matter how it's done, what port, config settings, etc.. Have no problems at all with it on other pics.

    (ugly but working temp recorder/readout to monitor our flaky fridge)
    Code:
    @ device pic12F683, intrc_osc_noclkout
    @ device pic12F683, wdt_on
    @ device pic12F683, mclr_off
    @ device pic12F683, protect_off
    
    DEFINE OSC 8
    
    OSCCON.0=1    'system clock select bit 1=internal 0=config word
    OSCCON.4=1    'set int osc to 8MHZ
    OSCCON.5=1
    OSCCON.6=1
    ANSEL.3=0     'set all digital
    ANSEL.2=0
    ANSEL.1=0
    ANSEL.0=0
    CMCON0=7      'turn comparators off!
    ADCON0=0      'turn ADC off
    GPIO.7 = 0    'enable weak pullups  'NOTE: this didn't work for one wire or i2c coms.
    WPU = %00111000                     '   had to use external pullup anyways (did I set it wrong?)
    '===========================================   
    DEFINE DEBUG_REGG GPIO         'set debug port to porta
    DEFINE DEBUG_BIT 0             'use pin a0 of porta for debug
    DEFINE DEBUG_BAUD 9600         'set baud rate to 2400
    DEFINE DEBUG_MODE 0            'communicate in true mode
                                   '12f683 is 14bit, no scl/sda defines
    
    SCL var GPIO.4 ' Clock pin 
    SDA var GPIO.5 ' Data pin
    readbutton var GPIO.3
    
    maxsensor con 4
    
    trisio.3 = 1                   ' switch logging/readout stored temps (using mclr pin, mclr disabled)
    
    
    Cold_Bit    VAR Raw.Bit11      ' Sign-Bit for +/- Temp. 1 = Below 0 deg C
    id          var byte[8]        
    ADDR        var WORD           ' 24c32a uses 2 bytes for address (24lc256 as well)
    raw         var word
    records     var word
    recordaddr  var word
    readloops   var word
    readaddr    var word
    tempc       var word
    tempf       var word
    Sign        VAR byte            ' +/- sign for temp display
    fsign       var byte
    sensor      var byte
    hexbyte     var byte
    col         var byte
    busy        var bit
    rsign       var bit
    
    CLEAR
    
    recordaddr = 31998 'store records at end (been writing to address 0 too much)
    ADDR = 2      ' normal start address
    'addr = 31960 'temporary testing eeprom full 
    
    goto start
    
    subC_TO_F:
        'DISABLE ' Necessary if On Interrupt used
        'tempF = tempC * 9
        'tempf = DIV32 5
        'ENABLE ' Necessary if On Interrupt used
        tempf = (tempc */ 461)
    
        IF rsign = 1 THEN 'if the sign bit is "1" is minus C
          IF tempF > 3200 THEN
           fsign="-"
            tempF = tempF - 3200
            'SEROUT2 sSEROUT_PIN,cBAUD,[" -",DEC C/100,".",DEC2 C," C  = -",DEC F/100,".",DEC2 F," F",13]
          ELSE
          fsign="+"
            tempF = 3200 - tempF
            'SEROUT2 sSEROUT_PIN,cBAUD,[" -",DEC C/100,".",DEC2 C," C  = ",DEC F/100,".",DEC2 F," F",13]
          ENDIF
        ELSE
          tempF = tempF + 3200
          fsign = "+"
          'SEROUT2 sSEROUT_PIN,cBAUD,["  ",DEC C/100,".",DEC2 C," C  = ",DEC F/100,".",DEC2 F," F",13]
        ENDIF
    RETURN
      
    GetID:
        Select Case sensor
            Case 1 :LOOKUP hexbyte,[$28,$00,$3E,$D8,$05,$00,$00,$10], col 
            Case 2 :LOOKUP hexbyte,[$28,$E1,$E2,$D6,$05,$00,$00,$64], col 
            Case 3 :LOOKUP hexbyte,[$28,$3C,$75,$D6,$05,$00,$00,$0C], col 
            Case 4 :LOOKUP hexbyte,[$28,$4F,$62,$D8,$05,$00,$00,$F5], col 
            'Case 5 :LOOKUP hexbyte,[], col 
            'Case 6 :LOOKUP hexbyte,[], col 
            'Case 7: LOOKUP hexbyte,[], col 
            'Case 8 :LOOKUP hexbyte,[], col 
            'Case 9 :LOOKUP hexbyte,[], col 
        end select
    return
    
    IDLOOP:
        for hexbyte=0 to 7  'each sensor address is 8 bytes
                gosub getid     'go look up each sensors address
                id[hexbyte]=col 'load the ID array with the retrieved address byte
        next hexbyte
    return 
           
    DisplayTemp:                        ' +32.0 to +257 F 
        IF raw.bit15 = 1 THEN   ' If Cold_Bit = 1, it's below "0" deg C
        rsign = 1
        Sign  = "-"
        else
        sign = "+"
        endif
        raw = abs(raw)
        tempc = raw */ 1600
        'tempf = (tempc */ 461) + 3200
         debug $0D,$0A,"reading : ",dec records
         if readbutton = 1 then debug " - Sensor: ",dec1 sensor
         debug "  ",sign, DEC (tempc / 100), ".", DEC2 tempc, " C "
         gosub subc_to_f 
         
         debug " / ",fsign, DEC (tempf / 100), ".", DEC2 tempf, " F "
    return
    
    
    START:
    
    pause 800
    
    IF readbutton = 0 then readstart
    ReadSensor:
        OWOUT GPIO.2, 1, [$cc,$44] 'skip romcheck (only one sensor), initiate[$44] temperature conversion
    Ckbsy:
        OWIN GPIO.2, 4, [busy]      ' Check for still busy converting
        IF busy = 0 THEN ckbsy  ' Still busy?, then loop
        sensor = sensor + 1
        if sensor = maxsensor+1 then sensor = 1
        gosub idloop
        '=============================================
        'owout GPIO.2,1,[$cc,$BE]   'skiprom (one sensor only) send back scratchpad[$BE] 
        owout GPIO.2,1,[$55,str id\8,$BE]   'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE] 
        '=============================================
        OWIN GPIO.2, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]
            if addr > 31997 then
                debug "eeprom full, not stored"
            else
                I2CWRITE SDA,SCL,$A0,ADDR,[raw.lowbyte,raw.highbyte]  
                pause 100
                records = addr / 2
                i2cwrite sda,scl,$A0,recordaddr,[records]
                addr = addr + 2
            endif
       gosub displaytemp
    goto start
    
    readstart:
      readaddr = 0
      i2cread sda,scl,$A0,recordaddr,[records]
      readloops = records*2
    rloop:
        while readaddr < readloops
        pause 50
        I2CREAD SDA,SCL,$A0,readaddr,[raw.lowbyte,raw.highbyte]
        readaddr = readaddr + 2
        records = readaddr / 2
        gosub displaytemp
        IF readbutton = 1 then start 
        wend
    goto start
    
    end
    really frustrating as I really wanted to use one of these 16f77 boxes I have.

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    Nomad, I'm going out on a limb here but, looking at your code are you sure it's hanging on the OWOUT statement and not the OWIN? I see where you are queing the sensor for a busy signal but what happens if you do not receive any?
    Dave Purola,
    N8NTA
    EN82fn

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    that code is on the 12f683 and works fine.

    for the 16f77 ive stripped it all down to
    Code:
    @ __CONFIG  _BODEN_ON & _CP_OFF & _PWRTE_ON & _WDT_ON & _HS_OSC
    
    DEFINE OSC 16
    
    ADCON1 = 7
    
    
    start:
    
        pause 500
        debug "owout (start conversio)"     
        OWOUT portb.2, 1, [$CC,$44] 
        debug "success!"
        pause 500
    
    goto start
    I see the start message, but nothing more.
    what really has me is even if there wasn't a device connected, it shouldn't hang on owout, and I can't even think of a condition it could hang at owout. I've found nothing on this being an issue, so I'm just going to have to use a different device.

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    Your code compiled with PBP3:
    hex.txt
    Just change extension to .hex instead of .txt.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    well, it appears I need to upgrade to pbp3. :/
    that bites lol.

    using the 3 demo it didn't hang at the owout.

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    Look in .mac file which macro is called when compile for 12F, and which for 16F.
    I think that should be same. If it is same, then problem must be in MPASM. So try another version of MPASM...

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: owout not working on 16f77 ? (hangs)

    the 12f683 and 16f77 are both 14bit. ( It works on 16f917, and tried both pm and mpasm prior to posting)
    As I mentioned getting pbp3, my wife gave me that *oh heck no* look, (I just bought some electronic toys).
    So that will have to wait a while.
    I copied the pbp3 pbppic14.lib,.mac,and .ram files to my pbp, and presto, it didn't hang!
    actually had temp readings on the lcd!
    going to compare the ow macros and see what is different from 2.5 to 3 that the 16f77 was choking on when I get time.

    ***Thank You*** for taking the time to compile it, I don't know that I would have went to pbp3 to test on my own.
    problem solved (well, it's working anyways), now to watch other devices wig from the wrong macro file lol

Similar Threads

  1. pic18f4550 hangs.. RX_INT DT_INTS-18.. please help
    By cluster in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 6th November 2011, 16:32
  2. uC Hangs after second serout command
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 17th August 2011, 17:57
  3. AC voltage measurement with 16F77
    By MARWEN in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 22nd May 2011, 20:54
  4. PIC HANGS with SERIN and Timeout?
    By koossa in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 18th January 2008, 17:33

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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