PIC18F8720 PORTD problem


Closed Thread
Results 1 to 29 of 29

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    25

    Default PIC18F8720 PORTD problem

    Hi,

    I'm trying to read PORTD on the PIC18F8720 and it just doesn't work. I have set the memcon.7 = 1 to enable it to read, but nothing seems to be working on that PORT. I have also set the TRISD register for inputs. What am I missing?

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Make certain that PSPCON is set to "0".
    Charles Linquist

  3. #3
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks, but that doesn't help either. The problem is still there. However I notice that the PIC only reads the input once at the time of reset and not after that in the loop I have. Also I notice that there is voltage drop on the inputs connected to PORTD. Instead of reading +5V(high) when they are on, the read +2.5V. Why is there a voltage drop? I think I have accounted for the MEMCON.7 = 1 and the PSPCON.4 = 0 and set the TRISD = %11111111.
    Even after this, it still doesn't read on ever occurance of the loop. The PIC has to be reset for it to read the present inputs. Please help!

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    schematic?

    Code?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Oct 2006
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    DEFINE OSC 20
    DEFINE ADC_BITS 10
    DEFINE ADC_SAMPLEUS 25


    INCLUDE "MODEDEFS.BAS"
    INTCON.7 = 1
    MEMCON.7 = 1
    PSPCON.4 = 0

    TRISD = %11111111

    channel var byte
    outputAB VAR BIT
    ch_onoff VAR BIT
    SYSEN VAR BIT

    CHANNEL = 0
    OUTPUTab = 0
    CH_ONOFf = 0
    SYSEN = 0

    loop:

    channel.bit0 = PORTD.0
    channel.bit1 = PORTD.1
    channel.bit2 = PORTD.2
    channel.bit3 = PORTD.3
    channel.bit4 = PORTD.4
    channel.bit5 = 0
    channel.bit6 = 0
    channel.bit7 = 0

    outputAB = PORTD.5
    ch_onoff = PORTD.6
    SYSEN = PORTB.7

    pause 500

    serout PORTB.4,N9600,["Channel = ",#channel,13]
    serout PORTB.4,N9600,["Output AB ",#outputAB,13]
    serout PORTB.4,N9600,["Channel ON/OFF = ",#ch_onoff,13]
    serout PORTB.4,N9600,["SYSEN = ",#SYSEN,13]


    goto loop

    end

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Code:
    DEFINE  OSC	20
    DEFINE ADC_BITS 10
    DEFINE ADC_SAMPLEUS 25
    INCLUDE "MODEDEFS.BAS"
    intcon.7=1:memcom.7=1: pspcon.4:trisd=$ff:channel var byte
    outputab var bit:ch_onoff var bit:sysen var bit:channel=0: outputab=0
    ch_onoff=0:sysen=0
    loop:
    channel=portd:channel=channel & $1F: outputAB=portd.5:ch_onoff=portd.6
    sysen=portd.7:pause 500
    serout portb.4,n9600,["Channel = ",#channel,13,"Output AB ",#outputAB,13,"Channel ON/OFF = ",#ch_onoff,13,"SYSEN = ",#SYSEN,13]
    goto loop
    end
    Which revision of the '8720 do you have?
    The early ones had REAL, documented problems running above 4Mhz. The problems varied and depended mainly on the code running, some things worked fine, others didn't. Try running your program at 4Mhz or less once and see if it works.
    I had issues with the early ones awhile back, couldn't figure it out. Read the errata sheets about the 4Mhz problem. Tried running programs at both 4Mhz and 10Mhz...4Mhz worked, 10Mhz didn't, and this was only blinking LEDs.
    After I got a few of the new revisions, the problems went away.
    And I simplified your program a bit...

Similar Threads

  1. 16F877 HSERIN problem with 3th party software
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 11th March 2009, 17:11
  2. PWM Problem
    By cihhan in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th June 2008, 18:43
  3. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. Interrupt stack overflow problem with Resume {label}
    By Yuantu Huang in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd May 2005, 01:17

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