Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

Project Request

Return
Bahman Mohammadhoseini
bobx

posted on 2011/10/15 03:48:07 AM CEST

Timers (Real time clock)

Reapeated 5 seconds interrupt

Hello.I want to write an interrupt so that at every 5 seconds goes to one of the 3 different
labels in my Main program and runs all instructions followed by each labels
and after run the label3 back again to the label1 and repeat all those
labels endlessly,that is;

.........
........... //*** My circuit specifications; PIC18F8722,XTAL=20MHZ.
..........

void interrupt(){ // 5 seconds interrupt.

????? //At each 5 seconds just goes and runs
//one of labels and do the other one then
//reapeat those again and again,endlessly.
}//~

void main(){
.............

Label1:
instruction1;
instruction2;
instruction3;
.......

Label2:
instructionx1;
instructionx2;
instructionx3;
.......

Label3:
instructiony1;
instructiony2;
instructiony3;
.......

}//~!

Would you please help me to write that interrupt?

Thanks,

USER Comments

Robinson Velasquez
Cagiva125

posted on 2013/03/13 08:37:18 PM CET

You can download this tool used for easier calculation of timer interrupts:
http://www.libstock.com/projects/view/398/timer-calculator

Puede configurar interrupciones de 100mS y un contador hasta 50 para que cambie de
etiqueta cada vez que llegue a 30 el contador.

(0,1 Seconds) *50 = 5 Seconds.

Example:

//Timer1 PIC18F
//Prescaler 1:8;
//TMR1 Preload = 3033;
// Actual Interrupt Time : 100 ms
// XTAL HS 20MHz

//Place/Copy this part in declaration section

int Contador=0;
int Etiqueta=1;

void InitTimer1()
{
T1CON = 0x31;
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xD9;
TMR1IE_bit = 1;
INTCON = 0xC0;
}

void Interrupt()
{
if (TMR1IF_bit)
{
TMR1IF_bit = 0;
TMR1H = 0x0B;
TMR1L = 0xD9;
//Enter your code here
Contador++;

if (Contador<50) Etiqueta=1;
if (Contador>=50 && Contador <100) Etiqueta=2;
if (Contador>=100 && Contador <150) Etiqueta=3;
if (Contador=150) Contador=0; // Si Tiempo =15 Segundos reiniciar el Contador.
}
}

void main ()
{
do
{


if(Etiqueta==1)
{
instructiony1;
instructiony2;
instructiony3;
.......
}

if(Etiqueta==2)
{
instructiony1;
instructiony2;
instructiony3;
.......
}

if(Etiqueta==3)
{
instructiony1;
instructiony2;
instructiony3;
.......
}

}while(1);

}



Espero que Funcione.

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 637 in "Reapeated 5 seconds interrupt" request.

Ronald Arthur
esarearthur

posted on 2011/11/01 05:08:23 AM CET

What micro controller are you using, take advantage of the timer within the MCU.

  • Rating:
0
No Abuse Reported

Do you want to report abuse comment ID: 139 in "Reapeated 5 seconds interrupt" request.