PDA

View Full Version : Newbie question about switch + led



mradde
- 23rd January 2009, 02:11
start:
input porta.3
low portc.0
If porta.3 = 1 then led ' when switch is pressed it goes to label "led" right?
goto start

led:
high portc.0 'here should the led light up?
pause 100
goto start
end
It happens NOTHING with this code.
If i change the value to "If porta.3 = 0 then led" the led always lights up except when switch is pressed down.
Any suggestions?

mackrackit
- 23rd January 2009, 02:16
start:
input porta.3
low portc.0
If porta.3 = 1 then led ' when switch is pressed it goes to label "led" right?
goto start

led:
high portc.0 'here should the led light up?
pause 100
goto start
end
It happens NOTHING with this code.
If i change the value to "If porta.3 = 0 then led" the led always lights up except when switch is pressed down.
Any suggestions?
How is everything connected?

mradde
- 23rd January 2009, 02:36
It is the Low Pin Count Demo Board from PICkit2.
You can see schematic diagram in attached file!

mackrackit
- 23rd January 2009, 03:39
Do you have JP5 connected?
Without JP5 connected you will get strange results.
With JP5 connected A3 will always be high, then when the button is pressed A3 will go low.

Bill Legge
- 23rd January 2009, 03:58
I don't know what MCU chip you are using but if it has and A/D capability PORT A starts up in Analog mode. If this is the case you can fix the problem by:

1. Avoiding PORTA or

2. Looking up the A/D info in the MCU spec. This is often in the ADCON1 register and PORTA made digital by putting something like

ADCON1 = %00001111

near the beginning of your code. Good luck

Regards Bill Legge

mackrackit
- 23rd January 2009, 04:14
I don't know what MCU chip you are using but if it has and A/D capability PORT A starts up in Analog mode. If this is the case you can fix the problem by:


The MCU should be a 16F690 ans A3 doubles as MCLR.

BTW.
How are the configs set ?

mradde
- 23rd January 2009, 04:35
Yes correct the MCU is 16F690.
On the JP5 it is nothing there, just two "soldering holes".

I don't have a "config set"? The posted code is completely everything i have wrote.

Maybe i should try to use some other extern components on a breadboard.

mackrackit
- 23rd January 2009, 04:51
This is what I will bet is happening.

If you have not changed the *.inc file (configs) MCLR is on.

When A3 = 0 causes the LED to go high, then when the switch is pressed A3 goes to a hard LOW resetting the PIC. Something like that.

Yup, move over to a bread board to get started.

mradde
- 23rd January 2009, 05:05
Nah i haven't change anything in the *.inc files.
I will try with some resistors, switch and led on a breadboard, will get back here when i have tried.
But so far your eye can see, it isn't anything wrong with the code?
This is my first real program to PBP, but you get my final point what the program should do right?
Led = off and when switch is pressed led = on, when switch released led = off.

mackrackit
- 23rd January 2009, 13:28
Nah i haven't change anything in the *.inc files.
I will try with some resistors, switch and led on a breadboard, will get back here when i have tried.
But so far your eye can see, it isn't anything wrong with the code?
This is my first real program to PBP, but you get my final point what the program should do right?
Led = off and when switch is pressed led = on, when switch released led = off.
Looks "OK" to me.

biggej
- 23rd January 2009, 17:33
The PicKit2 has excellent tutorials. Yes they start with assembler but they will teach you the hardware of the LowPin count board if you read the tutorial. They don't take too long to complete either.

The advice given by MACKRACKIT is right on target. You must change the .inc file to turn mclr off or the pushbutton will reset the PIC. This is explained in the PicBasicPro example code very well.

Keep trying. The PicKit and LPC are good learning tools.

Jim

mradde
- 24th January 2009, 17:40
I did change the MCLR to off in the *.inc file to my MCU so now is everything works like a charm!
Thanks for your fast helps guys!