Continue to Site

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.

  • 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.

PIC16F628 Difficulty Question

Status
Not open for further replies.

micro571

New Member
Hi,

I'm very new to the PIC microcontroller and I'm just learning the asm coding and I've gotten the LED flasher programs to work. That's where I'm at.

How difficult is it to say, make the LED flash for a specific length of time, say 30s and then stop? Using DIP switches, I'd like to change the 30s to say 45s, so if SW1 is on, loop it for 45s. The flash rate would be ~1s, but it would only flash for 45s in total and then stop.

Is this possible? I haven't seen larger timing loops like this is any of the tutorials.

Any advice / links for me to figure this out? Example code would be extremely helpful as well.

Thanks.

MICRO571
 
I would suggest the way to do it is with a one second delay routine, and call that in a loop the required number of times - if you check my tutorials most of the later ones provide a variable delay routine, which delays the number of milliseconds of the value held in the W register. If you change the millisecond routine for a one second delay you would then have a variable seconds delay. You can easily get a one second delay using the delay code generator on the PICList.

Then simply read your switches, and place the result in W, then call the routine which delays W seconds.
 
This would be the perfact chance to get use to timers in the PIC. Set up a timer..1, 2 etc. to trigger an interrupt. in that interrupt routine increase a count. when a count reaches a certain number then turn on your LED. I've done delays as long as 24 hours. It should be pretty easy. It will get you use to using the interrupts also, very usful.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top