Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] LED Display - One Works, One Doesn't

Status
Not open for further replies.

Frank01

Newbie
Joined
Mar 23, 2014
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,335
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 a moderator:

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.
 

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top