Connect with us

PIC 16F84A Problems

Discussion in 'Electronic Design' started by Cason, Jul 8, 2004.

Scroll to continue with content
  1. Cason

    Cason Guest

    I have a PIC 16F84A that I am trying to write a simple program for, that
    simply counts up in binary and displays the count on LEDS connected directly
    to PORTB. I have had some trouble because the count will not go past the
    third LED (the number 7). It just starts the program over again or so it
    seems....When I count up by twos instead of by one, 3 different LED's work
    but it wont count past 14 in the case of counting by twos....

    Does anyone have any suggestions? I will post the code below..

    ;Setup constants
    STATUS equ 03h
    TRISA equ 85h
    PORTA equ 05h
    TRISB equ 86h
    PORTB equ 06h
    COUNT equ 09h

    ;Setup Counter #2 and set PortB to 0
    movlw 00h
    movwf PORTB
    movlw 38h
    movwf COUNT

    ;Setup ports
    bsf STATUS,5
    movlw 00h
    movwf TRISB
    movlw 00h
    movwf TRISA
    bcf STATUS,5

    ;Main Program
    movlw 00h
    movwf PORTB
    movlw 38h
    movwf COUNT

    SwitchCheck movlw 01h
    addwf PORTB,1
    call Delay
    goto SwitchCheck


    Delay
    Loop decfsz COUNT,1
    goto Loop
    movlw 38h
    movwf COUNT
    return
    end
     
  2. Activ8

    Activ8 Guest

    You mean you're using an obsolete chip. 628A/648A - cheap.
    7 is 111 so that's 3 leds
    how do you get 14 if only 3 leds work? 14 is 1101.
    ^^^ ^^^
    0x09 is an eeprom control register, but WTF?

    Use the include files
    1st thing to remember is that movwf is a read/modify/write
    instruction so anything external that affects PORT B's pins is read,
    incremented, and rewritten.

    Maybe, despite what the manual says, MPASM doesn't like 38h, etc and
    prefers h'38' or 0x38.

    Can you get all the leds to light with brute force code? Also, if
    you drive your leds the common way, then a 0 output is what should
    activate them, but I assume you're driving the anodes with a 1.
     
  3. Andrew Holme

    Andrew Holme Guest

    I don't know the processor but -

    Do you need current limiting resistors (e.g. 1K) in series with the
    LEDs?

    Even if the outputs are current limited i.e. able to drive an LED
    without a series resistor, the addwf PORTB instruction might not read
    the correct value if the I/O pin is held too low by the LED.
     
  4. Cason

    Cason Guest

    I guess I didnt explain my problem well enough.....I can get whatever I want
    to light up with brute force(ie movlw b'1111111' and movwf PORTB). What I
    meant by the counting to 7 and 14 is, is that it will only incf or addwf
    seven times before resetting the program. All of the LED's work, I just cant
    increment them past 7 or '0000111' if I am counting by ones or 14('0001110')
    is counting by twos or 28('0011100') if counting by 4's. I have stuck a
    little code and used incfsz to see if I can get it to skip my goto
    SwitchCheck statement sometime but it never gets there...It just seems to
    staert the program over....

    I am sorry but I dont understand this statement, could you elaborate? I am
    using ones to drive the LED's I dont get how it should be done the other
    way...

    I am using it because it seems like that is the chip everyone beginner
    starts with. are those two chips you listed the newer non obsolete chips?


    Thanks,
    Cason
     
  5. Cason

    Cason Guest

    Thats a good question....I was wondering that myself. Does anyone know the
    answer to this? I just saw in some other guys schematic that he didnt use
    resistors....Seemed a little strange, but it seems to work, or not in my
    case...=) The LED's dont seem like they get the color they do when you hook
    them staight up to a battery without limiting the current.

    What kind of output do the pins of the 16F84A have as far as Voltage and
    Current when they are high/low? I use 4.5 Volts to run my circuit.

    Another question: is low(logical 0) differentiable from no voltage?
     
  6. Tim Wescott

    Tim Wescott Guest

    Is your power supply unable to drive the microprocessor driving three
    LEDs? This would cause a sag, which would cause a reset.

    Try incrementing by 3, see if it makes it to 15 (no 3-LED combinations),
    increment by 5 & look for 15, etc.
     
  7. Tim Wescott

    Tim Wescott Guest

    _Always_ use current limiting resistors, if not for the $0.10 LEDs then
    for the $2.00 processor.

    Externally a logic low is not reliably differentiable from 0 volts,
    particularly on CMOS. Internally (i.e. reading back the port) depends
    on the processor -- some companies read back what you've commanded, some
    read back the physical port (so if you yank it around with short
    circuits and the like it messes it up). I don't know what Microchip does.
     
  8. Wim

    Wim Guest


    Sounds like you didn't program the fuses to disable the watchdog timer
    which will restart your program.

    (or put a clrwdt instruction in your delay loop)

    Wim
     
  9. I guess I didnt explain my problem well enough.....I can get whatever I want
    - don't ever use read-modify-write instructions on the ports, *only*
    use movwf (google for pic read-modify-write problem)
    - did you by any chance enable the watchdog?


    Wouter van Ooijen

    -- ------------------------------------
    http://www.voti.nl
    PICmicro chips, programmers, consulting
     
  10. Andrew Holme

    Andrew Holme Guest

    See http://ww1.microchip.com/downloads/en/DeviceDoc/35007b.pdf

    The output swing is VOL=0.6V (max) to VOH=3.8V (min) with a 4.5V
    supply. The absolute maximum output current for PORTB is 100mA.
    There is a weak pull-up mode but it can only source a few hundred
    micro-amps and your program is not selecting it. You need series
    resistors.
     
  11. Activ8

    Activ8 Guest

    Good question. I was looking for something that would change the
    program flow, but the only error I see in the code is using the
    EEADDR register for the count, which I don't think is the prob.
     
  12. Activ8

    Activ8 Guest

    Vcc ----/\/\/\/---->|--- logic zero
    Yes, and they also use absolute code (like COUNT equ 0x-- or org
    0x04) because they're not savvy programmers or didn't RTFM and take
    the time to learn the linker.

    When I was a beginner, the 84 wasn't obsolete. I was away from it
    for a while and when I came back, I was basically a beginner again.
    So I took my advice and went to PICList and found everything
    including glitchbusters.com where there should still be an article
    on page 1 about gaffing the 84 and using a 628/48/88 or whatever.
    The instruction set is the same or close to it. It just doesn't make
    sense to use the old chip, in fact, I ran out of program mem real
    quick with the 628 and ordered some 648s (I had a lot of LCD strings
    to store in code.)
     
  13. Activ8

    Activ8 Guest

    what an idiot :)
    I'm speechless.
    There's this thing called a spec sheet. IIRC, PIC has TTL gosintas
    and CMOS gosoutas and the Vhimin Vlomax are all there as well as the
    fact that the pins source/sink 25 ma, IIRC.
    It could be higher than 0 V - read the spec.
    not that much. 330 usually does the trick for me.
    Read-modify-write.
     
  14. Activ8

    Activ8 Guest

    Another good reason to gaff the '84. The '62x ports can handle 200
    mA (or 25 mA per pin) which means you can drive 8 leds at 25 mA
    each.
     
  15. Cason

    Cason Guest

    I didnt enable the watchdog that I know of. Im not sure what a WDT is right
    now, Ill go learn about it and try all the other suggestions.
    As for using the EEADDR register for the COUNT, I did that modeling code
    from someone that has a beginnning PIC programming website. Apparently not
    a good one... I be using 0Ch to 4Fh I suppose...
     
  16. Barbarian

    Barbarian Guest

    Avoid using a RMW instruction on an I/O port by doing your counting by
    incrementing a byte in SRAM (General Purpose Register like 0x10) then
    copying from SRAM to PORTB.

    i.e.:
    INCF NUMBER,F
    MOVF NUMBER,W
    MOVWF PORTB


    I hope this helps,
    Dennis
     
  17. I didnt enable the watchdog that I know of. Im not sure what a WDT is right
    Just make sure that you know for sure that you turned it off (in the
    configuration word).


    Wouter van Ooijen

    -- ------------------------------------
    http://www.voti.nl
    PICmicro chips, programmers, consulting
     
  18. Graham Orme

    Graham Orme Guest

    I guess I didnt explain my problem well enough.....I can get whatever I want
    to light up with brute force(ie movlw b'1111111' and movwf PORTB). What I
    meant by the counting to 7 and 14 is, is that it will only incf or addwf
    seven times before resetting the program. All of the LED's work, I just cant
    increment them past 7 or '0000111' if I am counting by ones or 14('0001110')
    is counting by twos or 28('0011100') if counting by 4's. I have stuck a
    little code and used incfsz to see if I can get it to skip my goto
    SwitchCheck statement sometime but it never gets there...It just seems to
    staert the program over....
    [/QUOTE]

    I think I know what your problem is. I had the same thing happen to me
    using a 16F627, which was also doing a simple binary count displayed on
    LEDs. When you get sufficient LEDs all changing state at the same time
    it puts a glitch onto the supply and resets the processor. The solution
    is to decouple the supply close to the PIC and the LEDs. 100uF worked
    for me.
     
  19. Cason

    Cason Guest

    I fixed the problem, it was the WDT which I had enabled on accident. Thanks
    for all your help and advice.

    Cason
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-