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.

question on PIC16F84 CODE ???

Status
Not open for further replies.

yak103

New Member
Hi everyone ...

actually I am stuck now with my assembly code for PIC16F84 ... basically I am writing a code for controlling 6 LEDs and they work as the following sequence :

00001100 for 10 seconds and 00100001 for 10 seconds as well and repeat this process and my circuit has been designed to be interrupted by a switch connected say on A0 Pin ... what I want now is how can I write just the interrupt Service Routine code to make these LEDs after pressing the switch to jump to the next sequence .. for example if my sequence (1) is 00001100 and after 5 seconds from this sequence, the interruption occured so the PIC must jump straight away to seq(2) which is 00100001 and stay on this sequence for 20 seconds and then return the normal process which is sequence(1) for 10s and seq(2) for 10s. However I have to write my code with just the assembly not in any other language !!!! :D
 
look my friends, what I want is just how can the sequence jump to the other sequence for X seconds when the switch is pressed and then the normal process carry over !!!

this is my question and I have read alot of books and could not find anything relates to this problem !!! plz help me :confused:
 
yak103 said:
.. for example if my sequence (1) is 00001100 and after 5 seconds from this sequence, the interruption occured so the PIC must jump straight away to seq(2) which is 00100001 and stay on this sequence for 20 seconds

Not making much sense. :confused:

Why 20 seconds, not 10 or 15 seconds?

Is it always 20 seconds?
 
this is just an example of the timming system in my code ... in my code it will be maybe 5 or 6 or ...... it is just an example of what i want !!
 
As you want to use interrupts rather than just poll an input, you can use an input on portB as a means to trigger it, see application note AN566:
https://www.electro-tech-online.com/custompdfs/2007/02/00566b.pdf

Within the interrupt, you then would have to determine which sequence is currently enabled, either by directly reading the port register or a flag bit that you set to indicate the state of the sequences.
Then toggle to the other sequence, set the time delay counter for 20 seconds and exit the interrupt.
It sounds easy - but you are guaranteed to have problems unless you are already experienced in using interrupts, you will need to study the interrupt section in the manual.
You must also incorporate code to de-bounce the pushbutton so that it can not repeatedly trigger the interupt and therefore toggle the sequence more than once per operation.
 
With running counters is the answer.

seq 1
seq 2 ----->Forced interrupt - advance to 3 --> return to 2
seq 3
seq 4 ----->Forced interrupt - advance to 5 --> return to 4
seq 5

At any time button pressed:
* Set FORCED flag
* Set seq time shorter
* Advance seq #

In all seq routines:
* Import seq time
* Check for Forced flag, if it is set then reset seq # just before seq is complete and clear the Forced flag.
OR
* Check for Forced flag in a global seq # monitor/advancer.


What is your definition of "normal process carry over"? Does this mean after returning from a forced sequence the seq # automatically resets to #1 or more so to return back to the prior seq # before the interruption? All you need to do is keep track of the running seq # with a variable. So whenever an interruption occurs, do it and aftwards, return back to the running seq #.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top