Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 3rd April 2007, 03:13 PM   (permalink)
Question How to stop interrupt inthe the timer0 interrupt 1

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++);
}
prevravanth is offline  
Old 3rd April 2007, 05:31 PM   (permalink)
Default

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.
Papabravo is offline  
Old 4th April 2007, 02:21 AM   (permalink)
Default

From any bank
BCF INTCON, T0IF ; STOP TIMER0 INTERRUPT.
BSF INTCON, T0IF ; START TIMER0 INTERRUPT.
donniedj is offline  
Old 4th April 2007, 02:26 AM   (permalink)
Default

Quote:
Originally Posted by donniedj
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.
__________________
L.Chung
eblc1388 is offline  
Old 4th April 2007, 02:56 AM   (permalink)
Default

They don't unless you believe that a C compiler makes 8051 specific code platform independent. Posters should read carefully before they opine.
Papabravo is offline  
Old 4th April 2007, 04:37 AM   (permalink)
Default

Just as which device was not stated, neither did i state a device. And as for carefull, that completes the circle of assumption.
donniedj is offline  
Old 4th April 2007, 09:10 AM   (permalink)
Default

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.
__________________
L.Chung
eblc1388 is offline  
Old 4th April 2007, 09:17 AM   (permalink)
Default

Quote:
Originally Posted by eblc1388
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!.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline  
Old 4th April 2007, 12:56 PM   (permalink)
Default

Quote:
Originally Posted by donniedj
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.
Papabravo is offline  
Old 5th April 2007, 06:58 AM   (permalink)
Default

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
mcs51mc is offline  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
Timer0 Prescale lord loh. Micro Controllers 10 8th October 2008 06:14 PM
Question about Interrupt tinhnho Micro Controllers 3 11th February 2007 08:08 PM
how to give 120degree phase shift i've written a code esconele Micro Controllers 18 16th February 2006 01:49 PM
HANDLING THE INTERRUPT. alamy Micro Controllers 6 26th March 2005 04:37 PM
Cant get timer0 to interrupt 2camjohn Micro Controllers 5 16th June 2004 01:06 PM



All times are GMT. The time now is 07:52 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker