16f876 PortA set-up trouble?


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91

    Default 16f876 PortA set-up trouble?

    I am trying to read 2 Microchip TC74 i2c temp sensors (both different addresses, TC74A0 and TC74A5) on portA and send the result to a serial LCD for display. For some reason I am having trouble. Here are a few snippetts from my code. I have made this work on portB in the past. That's why I think I have a problem with portA setup. I get erratic numbers anywhere from 289 to 12500. It's probably something I'm overlooking.
    Let me know if you need more info.

    DEFINE LOADER_USED 1 'Only required if bootloader used to program
    Define OSC 4

    INCLUDE "modedefs.bas"
    INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
    INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

    OPTION_REG.7 = 0
    ADCON1 = 7 ' PORTA digital

    PORTA = %00000000 'Set all INPUTS to 0
    TRISA = %00111011 'Set PORTA RA0-RA5
    PORTB = %00000000 'Set all outputs to 0 (off)
    TRISB = %00000000 'Set PORTB to all output
    PORTC = %00000000 'Set all outputs to 0 (off)
    TRISC = %00000000 'Set PORTC to all output

    '::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
    ' Alias pins
    '::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
    scl VAR PORTA.2 'clock line for temp sensors
    sda VAR PORTA.0 'data line for temp sensors
    led1 var PORTC.0 'heartbeat LED
    display var byte
    temp1 VAR word
    temp2 VAR word
    control VAR BYTE



    '((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
    ' Clear LCD and pause to start
    '((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))

    Pause 5000
    Serout2 PORTC.4,84,[$fe, 1]
    Pause 1000
    Serout2 PORTC.4,84,[$fe, 1]
    Pause 1000
    Serout2 PORTC.4,84,[$fe,1,$fe,128,"START"]
    Pause 1500

    temp1 = 0
    temp2 = 0
    display = 0

    ASM
    INT_LIST macro ; IntSource, Label, Type, ResetFlag?
    INT_Handler TMR1_INT, _ToggleLED1, PBP, yes
    endm
    INT_CREATE ; Creates the interrupt processor
    ENDASM

    T1CON = $31 ; Prescaler = 8, TMR1ON
    @ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

    '((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))
    ' Main program loop - updates the LCD and siteplayer with the time
    'and status of temperatures and pumps
    '((((((((((((((((((((((((((((((((((((((()))))))))) )))))))))))))))))))))))))))))

    mainloop:

    pause 10
    GoSub showonlcd
    pause 10
    goto mainloop

    '---[INT - interrupt handler]---------------------------------------------------
    ToggleLED1:
    TOGGLE LED1
    display = display + 1
    @ INT_RETURN
    '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''
    showonlcd:

    select case display

    case 11

    INTCON.7 = 0
    display = display + 1
    control = %10010000
    i2cwrite sda,scl,control,$1,[$00] ' Place in normal operating mode
    pause 10
    i2cread sda,scl, control,$0,[temp1]'[avgtemp1] ' Read temperature
    temp1 = (temp1*(9/5)) + 32
    i2cwrite sda,scl, control,$1,[$01]
    Serout2 PORTC.4,84, [$fe, 1]
    Serout2 PORTC.4,84, [$fe,128,"MAIN TANK TEMP"]
    Serout2 PORTC.4,84, [$fe, 196,#temp1, " DEGREES"]
    INTCON.7 = 1

    case 21

    INTCON.7 = 0
    display = display + 1
    control = %10011010
    i2cwrite sda,scl, control,$1,[$00] ' Place in normal operating mode
    i2cread sda,scl, control,$0,[temp2]'[avgtemp2] ' Read temperature
    temp2 = (temp2 * 9/5) + 32
    i2cwrite sda,scl, control,$1,[$01] 'Place in stand-by operating mode
    Serout2 PORTC.4,84, [$fe, 1]
    Serout2 PORTC.4,84, [$fe,128,"Q/T TANK TEMP"]
    Serout2 PORTC.4,84, [$fe, 196,#temp2, " DEGREES"]
    INTCON.7 = 1
    display = 0
    end select
    RETURN

    goto mainloop
    end
    Last edited by ronjodu; - 18th February 2006 at 03:32.

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default You may not have to set PORTA

    Hi,

    When you are using an i2cread PBP does it in a open collector fashion. That means for a 1 it sets the pin to an input and for a 0 it sets the pin to an output with 0. This ensures that the i2cread routine can read the acknowledge from the peripheral. As it might hold the line low itself. It is obvious that the port directions are handled by PBP itself. What is really important are the pull-up resistors on the SDA and SCL line. Without them the open collector line is erratic!!!

    Hope this helps

    Regards

    Sougata

  3. #3
    Join Date
    Dec 2003
    Location
    Storrs, Ct.
    Posts
    91


    Did you find this post helpful? Yes | No

    Default No change

    Thanks for your reply. I do have 4.7K resistors on SDA and SCL. I tried deleting my portA data direction and still no good. I do get readings back from each sensor however they are strange readings. I'm off to read the datasheet and Midrange Micro sheets again.
    Any other suggestions are welcome.

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  3. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  4. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

Members who have read this thread : 1

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