PIC kIT 2 starter help!

Thread Starter

chrischristian

Joined Feb 22, 2008
43
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!
 

hgmjr

Joined Jan 28, 2005
9,027
Rich (BB code):
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
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
 

Thread Starter

chrischristian

Joined Feb 22, 2008
43
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:

randyjones

Joined May 12, 2008
2
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.
 

Thread Starter

chrischristian

Joined Feb 22, 2008
43
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.
 
Top