Driving me NUTS!


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216

    Default Driving me NUTS!

    Hi once again all.
    I have a medium length program, with everything working....except for a couple of lines .....

    What I have is a BINARY coded switch feeding 4 bits into portD lower 4 bits. The inputs have pull-down resistors and the switch switches 5v into the inputs.

    The code is like this...


    BLAH
    BLAH
    BLAH chip setup and first part working fine.
    included in the above:
    TRISD = %00001111 'low 4 bits inputs, high 4 bits unused

    LOOP:
    PORTB = PORTD
    goto loop

    after I read the inputs, go on to more code, which works OK
    BLAH
    BLAH
    BLAH



    Now, there are LEDs on PORTB to repeat the settings on the input port.
    To my way of thinking, the inputs will be repeated on the LEDs and going to the loop will continually update the LEDs to match the inputs. IE, changing the switch position should be immediately repeated on the LEDs. (I have checked the PORTD input lines and they do change with the switch changes)
    BUT.....the only way I can get the LEDs to update is to reset the PIC and then the current switch setting comes up on the LEDs correctly. I am using a 16F877 and have in fact swapped chips 3 times with the same results each time.

    I have also added TOGGLE PORTC.0 , as a debug indicator, to just before the GOTO LOOP line and this output does in fact toggle, showing that the loop is looping correctly.

    The 3 line of code were originally to read the input switch settings, calculate a delay and a few other things. The 3 lines shown above are a result of simplifying the final code back to absolute basics because the original code wasn't working either and was taken simpler to try and see what the trouble was, but that didn't show anything. It seems to me that the 3 lines above can't get much simpler and should work OK.
    Last edited by muddy0409; - 13th October 2005 at 06:23.

  2. #2
    PaulJC's Avatar
    PaulJC Guest


    Did you find this post helpful? Yes | No

    Default

    Im no expert (far from it lol) but i don't think that "PORTB = PORTD" would work.

    I would try something like:

    Loop:
    IF PortD.0 = 1 Then PortB.0 = 1
    IF PortD.1 = 1 Then PortB.1 = 1
    IF PortD.2 = 1 Then PortB.2 = 1
    IF PortD.3 = 1 Then PortB.3 = 1
    Goto Loop


    Cheers Paul

  3. #3
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    Thanks for the suggestion Paul.
    Just tried that but still no go.
    It appears that the loop is looping, just that the portD input data is not being read into wherever it is supposed to go, unless I reset the chip.

    Bloody frustrating, ain't it???

  4. #4
    PaulJC's Avatar
    PaulJC Guest


    Did you find this post helpful? Yes | No

    Default

    Bloody frustrating, ain't it???
    Yep lol.

    Do you have the datasheet for your switch?

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Hi Muddy. I am not at all familiar with the PIC you are using except I read a post by someone who had PORTD problems and fixed them with setting the ADCON1 and ADCON2 registers.

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default

    Hi Muddy,
    First make a short loop blinking the LED's on PORTB to make sure they work and that the port is set up correct. (Which they seem to be since it reflects changes on reset).

    Code:
    For i = 1 to 5
      PortB = %00001111
      Pause 200
      PortB = %00000000
    Next
    Then try to read PortD to a variable first and then write that variable to PortD.

    Code:
    Switch VAR Byte
    Loop:
      Switch = PortD                 'Read PortD, store in Switch
      PortB = Switch                 'Write switch to PortB
      Pause 10                         'Wait 10mS
    Goto Loop                          'Do it again.
    How about that, does that work?

    /Henrik Olsson. (At work, no board to test with here.)

  7. #7
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    Gooday Henrik.
    Tried that along the way back from final code back to the simplified code described above. No, it doesn't work.

    Peter

  8. #8
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216


    Did you find this post helpful? Yes | No

    Default I found it!!

    Thanks to everyone who made suggestions. But I RTFM and came up with the answer, which just may help someone else.....
    PORTD is also the PARALLEL SLAVE PORT. To make it a general purpose I/O port, Bit4 of TRISE must be set to 0 IE TRISE.4 = 0

    Did that and now seems to be OK. Will spend the next few hours reverting to the final code and see what happens.


    Peter Moritz.

Similar Threads

  1. Experience of driving TFT screens?
    By isaac in forum General
    Replies: 1
    Last Post: - 26th September 2008, 00:15
  2. Replies: 1
    Last Post: - 1st May 2008, 05:07
  3. Buttons are driving me nuts
    By Doormatt in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st May 2007, 23:09
  4. driving APR6008
    By mech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th December 2006, 18:37
  5. Driving a logic-level HEXFET
    By thelightbrain in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th November 2004, 23:34

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