+ Post New Thread
Results 1 to 3 of 3
  1. #1
    Newbie level 1
    Points: 699, Level: 5

    Join Date
    Mar 2014
    Posts
    3
    Helped
    0 / 0
    Points
    699
    Level
    5

    LED Display - One Works, One Doesn't

    This should be easy for someone, but I'm befuddled. I like to test LEDs connected to a port at the start of a program being tested to ensure the LEDs are working. I generally light the LEDs in sequence. I wrote two routines, both are supposed to light pin 0 of port d. The first one works fine, the second doesn't.

    I'm programming using the OSHON software and use the Pickit3 for programming the chip. Oddly, when I run the program on the OSHON simulator, both programs light portd, pin0. It is only with the breadboard circuit that the difference shows up.
    Code:
    =================================================
    WORKS ON THE BREADBOARD & SIMULATOR
    =================================================
    ;microchip 16f877a in use
    ;4 mhz resonator, 18 pf capacitors 
    ;
        list p=16f877a
        #include <p16f877a.inc>
        __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF &     _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
    ;
        banksel    trisd        ; bank 1
        clrf        trisd        ; portd pins made outputs
    ;
        banksel    portd        ; bank 0
        movlw    0x01        ; move the value 0x01 t0 the accumulator
        movwf    portd        ; move the value in the accumulator to portd
        goto        $
    end
    Code:
    =========================================================================
    DOESN'T WORK ON THE BREADBOARD, DISPLAYS 0XC7, OXE7 - WORKS ON SIMULATOR
    ==========================================================================
    ;microchip 16f877a in use
    ;4 mhz resonator, 18 pf capacitors 
    ;
        list p=16f877a
        #include <p16f877a.inc>
        __CONFIG _CP_OFF & _DEBUG_OFF & _WRT_ENABLE_OFF & _CPD_OFF & _LVP_OFF &     _BODEN_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC
    ;
        banksel    trisd        ; bank 1
        clrf        trisd        ; portd pins made outputs
    ;
        banksel    portd        ; bank 0
        bsf        portd,0    ; set portd, bit0
        goto        $
    end
    Thanks for any input.
    Last edited by andre_teprom; 14th November 2017 at 22:25. Reason: split code

    •   Alt14th November 2017, 15:20

      advertising

        
       

  2. #2
    Super Moderator
    Points: 68,102, Level: 63
    Achievements:
    7 years registered
    Awards:
    2nd Helpful Member
    betwixt's Avatar
    Join Date
    Jul 2009
    Location
    Aberdyfi, West Wales, UK
    Posts
    11,140
    Helped
    3675 / 3675
    Points
    68,102
    Level
    63

    Re: LED Display - One Works, One Doesn't

    Assuming you are connecting the LED (with suitable series resistor) between PORTD bit 0 and VSS they should both work. There is a subtle difference in them though, in the first code all the other bits of PORTD are set to zero, on the second they are not. If something else on PORTD is overloading it, the PIC may crash.

    Incidentally, if you format the code it makes it easier to read. Add "[ C O D E ]" without the spaces at the beginning of the text you pasted and "[ / C O D E ]" without the spaces after it. Note the '/' to turn the formatting mode off again.

    Brian.
    PLEASE - no friends requests or private emails, I simply don't have time to reply to them all.
    It's better to share your questions and answers on Edaboard so we can all benefit from each others experiences.



    •   Alt14th November 2017, 15:52

      advertising

        
       

  3. #3
    Advanced Member level 3
    Points: 5,666, Level: 17

    Join Date
    Jan 2015
    Posts
    819
    Helped
    264 / 264
    Points
    5,666
    Level
    17

    Re: LED Display - One Works, One Doesn't

    This *could* be a read-modify-write issue but that would also depend on the components connected to the pin. I suggest that you take this as a warning about this style of programming with devices that do not have LAT registers.
    Also *NEVER* try to set the DEBUG config option - that should also be set by the IDE (depending on whether you are compiling for debug or release) as there are other things (behind the scenes) that the IDE does (beyond setting or clearing this config bit).
    Susan



--[[ ]]--