1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

_mclre_off?

Discussion in 'Microcontrollers' started by Roger_NO, Jan 13, 2011.

  1. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    Hi,

    When I write _MCLRE_OFF in the config FUSES to make RA5 as a normal input, RA1 goes high! And when i turn it on again RA1 goes low! This is a problem since i've got a switch connetcted to ra5 and when i press it, RA1 should go high. But it goes high even when RA5 input reads "0".

    I use a PIC16F628A btw.

    Thanks.

    Here is the code. Couldent find anything wrong. Maby you can:p
    Code (text):

      list      p=16F628A           ; list directive to define processor
        #include <p16F628A.inc>       ; processor specific variable definitions

        errorlevel  -302              ; suppress message 302 from list file

        __CONFIG   _CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

     cblock     0x20
        d1
        d2
        d3
        endc

     org        0x0000

     movlw      0x07        ;Turn Off comp
     movwf      CMCON


     clrf       PORTA
     clrf       PORTB

     banksel    TRISA       ;Port definitions
     movlw      b'11110001'
     movwf      TRISA
     movlw      0x00
     movwf      TRISB
     Banksel    PORTA
    ;main----------------------------
    start                   ;Switch interactions
     movlw      b'00001111'
     movwf      PORTB
     movlw      b'00000000'
     movwf      PORTA
     btfsc      PORTA,7
     call       Enable
     btfsc      PORTA,6
     call       ENRW
     btfsc      PORTA,5
     call       RSEN
     btfsc      PORTA,4
     call       clrRW
     btfsc      PORTA,0
     call       clrRS
     goto       start


    ;sub-----------------------------

    Enable
     bsf        PORTA,3
     call       Delay
     bcf        PORTA,3
     retlw      0x00

    ENRW           
     bsf        PORTA,2
     call       Delay
     retlw      0x00

    RSEN       
     bsf        PORTA,1
     call       Delay
     retlw      0x00

    clrRW
     bcf        PORTA,2
     call       Delay
     retlw      0x00

    clrRS
     bcf        PORTA,1
     call       Delay
     retlw      0x00





    Delay
                            ;0.2sec delay
     movlw      0x3F
     movwf      d1
     movlw      0x9D
     movwf      d2
    Delay_0
     decfsz     d1, f
     goto       $+2
     decfsz     d2, f
     goto       Delay_0
     
     goto       $+1
     retlw      0x00
           
     end      
     
     
  2. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    Forget about this part of the code! Something i just tried with no luck!

    Code (text):

     movlw      b'00000000'
     movwf      PORTA
     
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    This is your PIC as powered up, no buttons pressed,,, RA1 is high.
     

    Attached Files:

  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo

    Ok, but how can i get it low?
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Roger,
    How is the switch on RA5 connected.?
     
  7. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    I am using the QL200 Dev board, and the switch is connected like this:
     

    Attached Files:

  8. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Roger,

    When you set AN1 on with the switch thats OK, but then you switch all of PORTA off at the start subr.
    So when the RA5 switch is pressed the AN1 is toggling on/off, so depending when you take your finger off the switch it will always switch AN1 off,


    Code (text):

    start                    ;Switch interactions
     movlw        b'00001111'
     movwf        PORTB

     movlw        b'00000000' ' but [B]here you are turning AN1 off[/B]
     movwf        PORTA
     btfsc        PORTA,7
     call        Enable
     btfsc        PORTA,6
     call        ENRW

     btfsc        PORTA,5; [B]switch pressed so call AN1 on[/B]
     call        RSEN

     btfsc        PORTA,4
     call        clrRW
     btfsc        PORTA,0
     call        clrRS
     goto        start


     
     
  9. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    yep, i posted the wrong code. the part where i force all of port A to "0" was just somthing i wanted to try. And it didn't turn out well. But i have loaded the code without that part and stil RA1 is high, before i press any buttons! Every other button interacts as it should.

    This is the code i am using!

    Code (text):

      list      p=16F628A           ; list directive to define processor
        #include <p16F628A.inc>       ; processor specific variable definitions

        errorlevel  -302              ; suppress message 302 from list file

        __CONFIG   _CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT

     cblock     0x20
        d1
        d2
        d3
        endc

     org        0x0000

     movlw      0x07        ;Turn Off comp
     movwf      CMCON


     clrf       PORTA
     clrf       PORTB

     banksel    TRISA       ;Port definitions
     movlw      b'11110001'
     movwf      TRISA
     movlw      0x00
     movwf      TRISB
     Banksel    PORTA
    ;main----------------------------
    start                   ;Switch interactions
     movlw      b'00001111'
     movwf      PORTB
     btfsc      PORTA,7
     call       Enable
     btfsc      PORTA,6
     call       ENRW
     btfsc      PORTA,5
     call       RSEN
     btfsc      PORTA,4
     call       clrRW
     btfsc      PORTA,0
     call       clrRS
     goto       start


    ;sub-----------------------------

    Enable
     bsf        PORTA,3
     call       Delay
     bcf        PORTA,3
     retlw      0x00

    ENRW           
     bsf        PORTA,2
     call       Delay
     retlw      0x00

    RSEN       
     bsf        PORTA,1
     call       Delay
     retlw      0x00

    clrRW
     bcf        PORTA,2
     call       Delay
     retlw      0x00

    clrRS
     bcf        PORTA,1
     call       Delay
     retlw      0x00





    Delay
                            ;0.2sec delay
     movlw      0x3F
     movwf      d1
     movlw      0x9D
     movwf      d2
    Delay_0
     decfsz     d1, f
     goto       $+2
     decfsz     d2, f
     goto       Delay_0
     
     goto       $+1
     retlw      0x00
           
     end      
     
     
  10. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    It runs OK in simulation see these two images.
    The first one is when RA5 is low at power on and the second when RA5 is high at power on.

    Disconnect the switch from RA5 and ground the pin, power up, check if RA1 is on.???

    EDIT:
    How long are the wires to the switch.?
     

    Attached Files:

    Last edited: Jan 13, 2011
  11. tom_pay

    tom_pay New Member

    Joined:
    May 17, 2009
    Messages:
    199
    Likes:
    1
    Hi

    On an unrelated note, what program are you using to get the MCU pin outs? It looks very good.

    Tom
     
  12. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Tom,
    If you mean me, its the Oshonsoft IDE Simulator.
     
  13. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    hi,
    Good ide! I'll try that tomorrow as I left the project at my workspace at work:) I did run the program in Proteus where it ran without any problem. i also ran a simple "led on off" code on all PORTA and PORTB outputs without any complications. Good to know that the code is right, maybe a hardware error!

    Thanks:)
     
    Last edited: Jan 13, 2011
  14. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    oh,

    And if you mean me Tom, I use Proteus Professional to create and simulate circuits.

    Cheers
     
  15. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    They are about 30cm long.
     
  16. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi Roger,
    For a test, shorten the wires down to say 5cms and twist them together, the problem may be caused by the long 30cm wires, lets know.
     
  17. Roger_NO

    Roger_NO Member

    Joined:
    Oct 11, 2008
    Messages:
    35
    Likes:
    1
    Location:
    Norway, oslo
    Hi Eric,

    I discoverd the error! I feel stupid for not cheking this erlier... The RA5 pin is as you know the VPP pin.. On my dev board the vpp signal is high even when its not receiving any program. The developers of this dev board did not emplement a link witch they should have so I could deactivate the vpp input while onboard testing! I'll just use a bigger Chip with more PORTS..

    Thanks for all the good help!

    Cheers!
     
  18. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi,
    Thanks for letting me know, your post will make other users of dev pcbs aware of the problem.
     

Share This Page