PIC kIT 2 starter help!

Discussion in 'Embedded Systems and Microcontrollers' started by chrischristian, May 12, 2008.

  1. chrischristian

    Thread Starter Active Member

    Feb 22, 2008
    43
    0
    Hi there!
    After struglling with JDM and facing failure I bought PIC KIT2 and it works very good, I successfuly programmed LED blinking but now I want to give an input to my PIC 16f690 and here is the codes I tryed:


    list p=16f690
    #include<p16f690.inc>

    #define LED PORTC,0
    #define SWITCH PORTC,4


    __CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    ERRORLEVEL -302

    TEMP_VAR UDATA
    temp RES 1
    delay1 RES 1
    delay2 RES 1

    ;*******************************************************************
    Main
    org 0x05
    Setpins
    bsf STATUS,RP0
    movlw b'11110'
    movwf TRISC
    bcf STATUS,RP0
    Start

    On
    bsf LED
    wait
    btfss SWITCH
    goto wait
    call Loop
    call Loop
    Off
    bcf LED
    call Loop
    call Loop
    goto Start
    Loop
    decfsz delay1,1
    goto Loop
    decfsz delay2,1
    goto Loop
    return
    END


    As per the codes, the LED should come to stand still (continious lightning(ON) ) as soon as HIGH (+5v) is removed from pin 4 of PORT C but, that is not happening insted it continue to blink for a while even after removing HIGH from pin 4 of PORT C and then it comes to stand stiil (ON), I think this should happen immediatly, why it is not so? I considered : http://www.winpicprog.co.uk/pic_tutorial1.htm which is of course for blinkin an LED and for f628 not for f690 but, I think I it has something to do with COMPARATORS and that's why mine programme not working , I know very little about programming so if you have solution try to be simple, please!
     
  2. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Code ( (Unknown Language)):
    1.  
    2. list p=16f690
    3. #include<p16f690.inc>
    4.  
    5. #define LED PORTC,0
    6. #define SWITCH PORTC,4
    7.  
    8.  
    9. __CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
    10. ERRORLEVEL -302
    11.  
    12. TEMP_VAR UDATA
    13. temp RES 1
    14. delay1 RES 1
    15. delay2 RES 1
    16.  
    17. ;************************************************* ******************
    18. Main:
    19.      org 0x05
    20.      Setpins
    21.      bsf STATUS,RP0
    22.      movlw b'11110'
    23.      movwf TRISC
    24.      bcf STATUS,RP0
    25.  
    26. Start:
    27.  
    28.      On
    29.      bsf LED
    30.  
    31. wait:
    32.      btfss SWITCH
    33.      goto wait
    34.  
    35.      call Loop
    36.      call Loop
    37.      Off
    38.      bcf LED
    39.      call Loop
    40.      call Loop
    41.      goto Start
    42.  
    43. Loop:
    44.      decfsz delay1,1
    45.      goto Loop
    46.      decfsz delay2,1
    47.      goto Loop
    48.      return
    49. END
    50.  
    Code cleanup using the CODE tag features of VBulletin.

    Most assembly language labels require a colon following a label. This identifies it as a label. In my reformatted version of your program, I have taken the liberty of adding colons to each of the labels in your code.

    hgmjr
     
  3. chrischristian

    Thread Starter Active Member

    Feb 22, 2008
    43
    0
    Thanks hgmjr but the problem still persists, and that is.........

    As per the codes, the LED should come to stand still (continious lightning(ON) ) as soon as HIGH (+5v) is removed from pin 4 of PORT C but, that is not happening insted it continue to blink for a while even after removing HIGH from pin 4 of PORT C and then it comes to stand stiil (ON), I think this should happen immediatly, why it is not so?


    .......... is this because I'm just touching a wire to pin 4 of port c from +5v and then taking it off ? Because if I not only disconnect pin 4 from +5v but instantly connect it to GND then the programme works well, that is how actual switch works isn't it?. Any way answer me that what do you think about the problem and this solution I found.
     
    Last edited: May 12, 2008
  4. randyjones

    New Member

    May 12, 2008
    2
    0
    The clue that helps determine your difficulty is that it works as expected when you ground the pin. Just removing the +5 volts is not enough - the pin needs to be "helped" to a low state (as you have discovered).

    The standard way to do this is called a "pull down" resistor. It is not a special type of resistor - that is just the name of its function. Connect a 10k ohm (any value from 1k to 50k should be fine) resistor between the pin and ground. That keeps the pin "pulled down" to 0 volts most of the time. When you connect the +5 volts to the pin it overcomes the pull down resistor and the pin goes high.

    You can do the same thing if you want a pin to be normally high... Connect a "pull up" resistor between the pin and +5 volts. It will normally stay high until you apply a low input to the pin.

    Without anything connected to the pin, we say the pin is "floating" - in other words it has no direction and can go high, low, or flutter back and forth. The pin is like a little antenna and can pick up local static charges, electrical noise, or anything. It is considered bad practice to leave input pins floating. When I'm working on a PIC project I make any unused I/O pin an output so it is not a floating input.
     
  5. chrischristian

    Thread Starter Active Member

    Feb 22, 2008
    43
    0
    Thanks ! for those very useful advices, now I feel very releaved as I know there is nothing wrong with the codes. By the way, I would like to know about COMPARATORS what are those ? I found on this link:

    http://www.winpicprog.co.uk/pic_tutorial1.htm

    that making COMPARATOR OFF the PIC behaves like 16f84, why so? and how can I do that with 16f690, I been through some MPLAB tutorials and HELP files but they are still very complicated for me so, if you can explain this in simpler manner I'll be very grateful.
     
Loading...