We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi is there anyway of knowing if the LPC is receiving pulses on its INT0 pin. I have it already set up like this: IT0 = 1; //Pulses are edge detected EX0 = 1; //interrupt enable bit EA =1; It works fine, but is there anyway to find out if the pulses have stopped coming into this pin? The time the pulses will be present at this pin is unknown. This message is also posted at http://www.8052.com/forum/post.phtml
I'm not sure what you mean by "I see that parameter INT0# is always checked". Do you mean that you're getting external interrupts on the INT0 pin? Interrupt vector 03h? External interrupt 0? Represented by the IE0 flag (TCON.1) and EX0 (IE.0)? What "parameter" are you talking about, and what is doing the checking? Are you running under a simulator, or is this something in your emulator software interface, or what? I don't think you'll get a repeated interrupt to your timer ISR unless you clear TF0. The transition from 0 to 1 is what makes the interrupt occur. The code you posted does clear TF0, though. Does Sec_Counter increase? Is there any extra interrupt hardware in your particular device that needs to be enabled? Check the user's manual and datasheet for the part.
Hi Drew Davis, I do not know what that means INT0#, I do not think is INT0 pin, but is always checked and I do not know why. However, I have noticed that as I single step through the program and timer 0 registers TH0 and TL0 are loaded with their values TF0 gets set right away, but it does not jump to the ISR. Sec_Counter does not increase because it is never getting into the ISR. I am using the emulator. Is there any way you could try it, at least with an emulator. thank you very much
Why don't you post the minimum COMPLETE program that shows the problem. Someone may be able to help you then. Also, what clock frequency are you using? Stefan
Stefan Duncanson, the code is already posted. I am using the internal osc. at 7.373 MHz. The other part of the program are the initialization of ports and the clock source and speed. Nothing else. Thank you
"the code is already posted" You've only posted the bit where YOU think the problem lies. "The other part of the program are the initialization of ports and the clock source and speed. Nothing else." Well, post it then. Stefan
Here is Stefan, this is the whole program I am testing with out success. Thank you #include <Reg932.h> #include <stdio.h> #include <intrins.h> void init(void); void brkrst_init(void); void Time_Base(void); unsigned int Sec_Counter = 0; void Main(void) { P2 = 0x00; P0 = 0x00; init(); // configure ports brkrst_init(); //enable UART break detect Time_Base(); } void init(void) { P0M1 = 0x00; P0M2 = 0xCD; // Quasi-bidirectional P1M1 = 0x00; // Push-pull P1M2 = 0xFF; P2M1 = 0x00; // push pull output P2M2 = 0xFF; P1M1 |= 0x18; // make INT0 and INT1 input pins P1M2 &= 0xE7; ES = 1; // enable UART interrupt EA = 1; } void brkrst_init(void) // This function allows ISP entry through the UART break detect { SCON = 0x50; // select the BRG as UART baud rate source, pg. 60 SSTAT = 0x00; //Timer1 BRGR0 = 0xF0; // 9600 BAUD at @ 7.373MHz internal RC oscillator BRGR1 = 0x02; //timer increments every .0271 microsec. BRGCON = 0x03; // enable BRG, pg. 59 AUXR1 |= 0xC0; // enable reset on break detect, pg. 102 } void UART(void) interrupt 4 //Interrupt number for serial port { RI = 0; // clear receive interrupt flag } void Time_Base(void) { ET0 =1; TR0 = 0; TMOD |= 0x01; TAMOD = 0x00; TH0 = (65536-30720)/256; // 34816 TL0 = (65536-30720)%256; // .2 TF0 = 0; EA = 1; TR0 = 1; } void timer(void) interrupt 1 using 1 { Sec_Counter++; if (Sec_Counter == 20) // if 1 sec have passed { Sec_Counter = 0; P2 = 0xFF; TR0 = 0; } }
This version of the program differs from the earlier one in the timer ISR, which is no longer calling Time_Base(). The ISR needs to clear the overflow flag (TF0) so that the interrupt can re-occur. And since this is a one-shot timer mode, the ISR must also reload the timer registers. I would expect this program to produce one timer interrupt (50 msec after main finishes, assuming the timer values are calcuated correctly). When posting source code, if you put the text between the "pre" and "/pre" tags, it will preserve indentation on the left. Try something like:
void T0_Start (void) { TH0 = (65536-30720)/256; // 34816 TL0 = (65536-30720)%256; // .2 TF0 = 0; } void Time_Base(void) { ET0 =1; TR0 = 0; TMOD |= 0x01; TAMOD = 0x00; T0_Start(); EA = 1; TR0 = 1; } void timer(void) interrupt 1 using 1 { T0_Start(); // start timer again Sec_Counter++; if (Sec_Counter == 20) // if 1 sec have passed { Sec_Counter = 0; P2 = 0xFF; TR0 = 0; } }
Drew Davis I made the changes you posted. It still does not work. I tried it with emulator and it single steps, jumps into the ISR, reloads the timer, but does not clear TF0 flag bit. It increments the sec_counter variable once though. Did you try it yourself. did it work for you. I tried with the actual chip LPC932 revision F and it did not work...I say that because it did not turn on P2 LED's. What would be the next step. #include <Reg932.h> #include <stdio.h> #include <intrins.h> void init(void); void brkrst_init(void); void Time_Base(void); void T0_Start(void); unsigned int Sec_Counter = 0; void Main(void) { P2 = 0x00; P0 = 0x00; init(); // configure ports brkrst_init(); //enable UART break detect Time_Base(); } void init(void) { P0M1 = 0x00; P0M2 = 0xCD; // Quasi-bidirectional P1M1 = 0x00; // Push-pull P1M2 = 0xFF; P2M1 = 0x00; // push pull output P2M2 = 0xFF; P1M1 |= 0x18; // make INT0 and INT1 input pins P1M2 &= 0xE7; ES = 1; // enable UART interrupt EA = 1; } void brkrst_init(void) // This function allows ISP entry through the UART break detect { SCON = 0x50; // select the BRG as UART baud rate source, pg. 60 SSTAT = 0x00; //Timer1 BRGR0 = 0xF0; // 9600 BAUD at @ 7.373MHz internal RC oscillator BRGR1 = 0x02; //timer increments every .0271 microsec. BRGCON = 0x03; // enable BRG, pg. 59 AUXR1 |= 0xC0; // enable reset on break detect, pg. 102 } void UART(void) interrupt 4 //Interrupt number for serial port { RI = 0; // clear receive interrupt flag } void Time_Base(void) { ET0 =1; TR0 = 0; TMOD |= 0x01; TAMOD = 0x00; T0_Start(); EA = 1; TR0 = 1; } void timer(void) interrupt 1 using 1 { T0_Start(); // start timer again Sec_Counter++; if (Sec_Counter == 20) // if 1 sec have passed { Sec_Counter = 0; P2 = 0xFF; TR0 = 0; } } void T0_Start (void) { TH0 = (65536-30720)/256; // 34816 TL0 = (65536-30720)%256; // .2 TF0 = 0; }
The ISR needs to clear the overflow flag (TF0) so that the interrupt can re-occur no need, quoting "the bible" Cleared by hardware as the program vectors to the interrupt routine. Erik
Erik, TF0 could be cleared by software as well...But can any one try it on his simulator or emulator...please. Thank you
void Main(void) { P2 = 0x00; P0 = 0x00; init(); // configure ports brkrst_init(); //enable UART break detect Time_Base(); } What do you think happens after the call to Time_Base()? Stefan