Flashing an LED problem...

Status
Not open for further replies.

RobertD

New Member
Hi folks. I'm using Pommie's program to flash an LED, first time it worked, and I have one chip that flashes, but the same programs on the next two chips hangs after a couple or three minutes, and the LED stops flashing. The same program I used is this one modified slightly for time. Does anyone know why it stops flashing after three minutes?

 
Last edited:
Looks fine, nothing looks like it would overflow the stack or stop after 3 minutes.
movlw 0x42 ; is 1MHz (0x72 = 8)

PS use the code "#" button tags instead of quotes as it retains the formatting.
 
The debugger runs through no problem. I just don't know why it stops flashing...?

I tried different delays, same thing happens.
And yes I didn't change the 1mhz time when I adjusted the clock.
 
Last edited:
I found it... I was running the LED directly from the chip, and it was running hot. I put a current limiting resistor and changed the LED now it's running OK...

Baby steps can be frustrating sometimes...

_LVP_OFF, what will this do?

No... it stopped again...

I'll add _LVP_OFF see if that works.
 
Last edited:


Use your Firefly, it has the limiting resistors.

You can blink a Firefly LED easy
change your PORTA,1 to PORTA,6 in the main loop.

OK will do that. I do have to get into the firefly for the AD programming.

Like this you mean:

main
bsf PORTA,6
call delay
bcf PORTA,6
call delay
goto main
 
Last edited:
Fantastic, I have LED 1 and 2 flashing....

I programmed in the ZIF socket and transferred the chip to the tutor position.

Actually 1 flashes red, and 2 flashes green.
 
Last edited:
Now I have to program RB4 (switch 3) to trigger the AD read when pressed. So I can read the output on ADRESH/L, in MPLAB.

The firefly has all the features I need for my program, LED's, A/D inputs, and switches...

First step, make PORTB,4 input.
 
Last edited:
I program the chip while it's running? I thought I had to stop the program before programming it. That'swhy I took it out of tutor and put it in the ZIF

I programmed this to get the flashing LEDs to stop when pressing the switch RB0, but it's not working. I use weak pull-up to turn all PortB switches on, when I press RB0, I ground it, at least that's what I'm thinking, unless the switch RB0 is not connected to ground.


movlw B'11111111' ;make all Bports input
movwf TRISB
BCF OPTION_REG,7
bcf STATUS,RP0 ;select bank 0

main
bsf PORTA,6
call delay
bcf PORTA,6
call delay
btfsc PORTB,0
goto main
goto skip

(delay routine here)

skip nop
end
 
Last edited:
I have not used that hardware, so can't comment on the RB0 to ground (did you try btfss). Just one thing I usually do, instead of letting the program run to end, rather put in something like:
GOTO $-0 which will put it in an infinite loop at that position, and you can put the rest of your delay and other routines under that line.

How long are your delays, are you keeping the switch pressed in long enough?
 
Last edited:
Hi Boomslang, I tried btfss, that didn't work either, I use a one second delay, and I press the switch long enough, I just have to keep pecking at it until it works... I should read the user manuel and get to know how the firefly is built, it really is a handy programmer.
 
Have a look at the circuit diagram to see how the pin is setup.

A way to make your code a bit smaller:

Code:
main
      btg     PORTA,6
      call     delay
      btfsc   PORTB,0
      goto    main
      goto $-0

(delay routine here)
 
Last edited:
I looked at the diagram, and the pins are grounded, so I set up the option_reg and the btfsc and it works, when I press SW4, the led stops flashing, but it doesn't go to the end of the program, as I thought. It goes back on flashing. Now I have to test rb0 and rb1 if the bits are set, as the option_reg says they are.

This is very exciting for me, like a baby making his first baby steps... It's like a whole new world opened up.


(And yes, sw0 and sw1 work as well, so the pull up command works, as well as the pull downs... )
 
Last edited:
Thanks Bill,

I found out how to program it in circuit, very easy, just flip dip #4, it's a lot easier than moving the chip each time I change something in the code. I'm beginning to appreciate the versatility of the firefly. Next step is to get the A/D working. I got the switches working, so I want to trigger the AD with the switch, and go to adresh/L and read the results. I'll write a program by itself just for that.
 
Last edited:
Your program is probably continuing because it is running through memory and restarting. The END instruction doesn't stop the program from running, you need a loop going to itself.
Code:
		movlw	B'11111111'	;make all Bports input
		movwf	TRISB
		bcf	OPTION_REG,7
		bcf	STATUS,RP0	;select bank 0

main
		bsf	PORTA,6
		call	delay
		bcf	PORTA,6
		call	delay
		btfsc	PORTB,0
		goto	main
		goto	skip

(delay		routine	here)

skip		nop
[COLOR="Blue"]Hang		goto	Hang[/COLOR]
		end

Anyway, it sounds like you're having fun.

Mike.
 
Indeed I am enjoying this. So the program restarts and that's why it keeps on flashing after I press the switch. Is there anyway to have the program stop after it's done it's thing? Hanging the program doesn't stop it, some kind of power down interrupt perhaps?

Today, I'll try to get the AD working all by itself. Once I have it running by itself, I'll incorporate it to the routine.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…