![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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++); } | |
| |
| | (permalink) |
| 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. | |
| |
| | (permalink) |
| From any bank BCF INTCON, T0IF ; STOP TIMER0 INTERRUPT. BSF INTCON, T0IF ; START TIMER0 INTERRUPT. | |
| |
| | (permalink) | |
| Quote:
__________________ L.Chung | ||
| |
| | (permalink) |
| They don't unless you believe that a C compiler makes 8051 specific code platform independent. Posters should read carefully before they opine. | |
| |
| | (permalink) |
| Just as which device was not stated, neither did i state a device. And as for carefull, that completes the circle of assumption. | |
| |
| | (permalink) |
| 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 | |
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) | |
| Quote:
| ||
| |
| | (permalink) |
| 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 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 | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| 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 |