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.

How to stop interrupt inthe the timer0 interrupt 1

Status
Not open for further replies.

prevravanth

New Member
Hi,

How to stop interrupt inthe the timer0 interrupt 1

my logic is
connect port 1.0
start delay for 2.5 sec
start Beep gen at 2.5 sec
stop port 1.0 at 3 sec

check my code is correct and give me some corrected code for this logic

The problem is i cannot stop the timer(i.e port 1.0 not disconnect at 3 sec)
Please help me

___________code_______________
#include<stdio.h>
#include<reg51.h>
#include<stdlib.h>


#include<absacc.h>
#include<intrins.h>

#include "ports.h"

void count(void);
void timdelay(unsigned int);



void main()
{
int i,t;
P0_1=1;

timdelay(500);

for(t=0;t<18;t++)
{
timdelay(1000); time delay for 3 minutes
}



while(1)
{
count();

}

}
void count()
{
TMOD=0x01;
TL0=0xFF; // TL0 Reload value
TH0=0xFE; // TH0 Reload value 1 Khz
ET0=1;
TR0=1; // Start Timer0
EA=1;
while(TF0==0); // Timer0 Over Flow flag=0

TR0=0; // Stop Timer1
TF0=0; // Reset Timer1 Over Flow Flag

}

void timer0() interrupt 1 /* interrupt address is 0x000b */
{

TF0 = 0; // reset interrupt flag
// P0_0 = ~P0_0; /* P1.0 toggle when interrupt. */

}


void timdelay(unsigned int itime)
{
unsigned int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
 
You can either stop Timer0 entirely by setting bit TR0 = 0, or you can disable Timer0 interrupts by setting bit ET0 = 0. You decide which method suits your requirements.
 
From any bank
BCF INTCON, T0IF ; STOP TIMER0 INTERRUPT.
BSF INTCON, T0IF ; START TIMER0 INTERRUPT.
 
donniedj said:
From any bank
BCF INTCON, T0IF ; STOP TIMER0 INTERRUPT.
BSF INTCON, T0IF ; START TIMER0 INTERRUPT.

I didn't know PIC instructions also works on 8051. :)
 
They don't unless you believe that a C compiler makes 8051 specific code platform independent. Posters should read carefully before they opine.
 
Just as which device was not stated, neither did i state a device. And as for carefull, that completes the circle of assumption.
 
I thought #include <reg51.h> and C source code are pretty good indication.

Anyway, my hat off to user posting PIC assembly code as a possible solution.
 
eblc1388 said:
I thought #include <reg51.h> and C source code are pretty good indication.

But it's only an indication, not 100%, there's nothing to stop you having a *.h file called that for a PIC compiler. But really it's a very sloppy question not to mention what processor you're asking about, expecting people to be detectives and work it out!.
 
donniedj said:
Just as which device was not stated, neither did i state a device. And as for carefull, that completes the circle of assumption.
The names of the Special Function Registers(SFR) and the bits that go with them pretty much indicates the target of this particular C program. We didn't start doing this stuff yesterday, and we might be expected to recognize at least the family if not the specific variant that was being used from register names alone.
 
Back to prevravanth's problem :)

First review your code for some typo's.
Description stated port 1.0
In code I see P0_1, P0_0 and again P1.0 in comment. So what will it be?

Timer 0 in mode 1 is a 16 bit timer. Each time the count rolls over from all 1s to all 0s it sets the interrupt flag. Tell me how you get a 1Khz timer (your comment) with a value of FEFF! With a 12MHz osc I got 12MHz/12 * (FFFF - FEFF) = 275µs = 3.6kHz

Your code: while(TF0==0); // Timer0 Over Flow flag=0 without parenthesis, is that normal? I'm not a C guy :( Always assembler :)
And: why using TF0 anyway? It's set by hardware on timer overflow and cleared by hardware when the ISR is serviced. Since you use the ISR, why using TF0?

You need to reload the timer at each ISR. These are the first asm lines I use in my ISR
Code:
;------------------------------------------------------------------------------
RSEG TMR0_Code
			
Timer_0:
mov  th0,#High Time_0		;Restart timer
mov  tl0,#Low  Time_0
push acc				;Save registers used in ISR
push b
push dph
push dpl
push psw
I never set , reset or checked TF0 in any code :(
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top