Discussion in "8051 Discussion Forum" started by    joepotter    Oct 29, 2010.
Fri Oct 29 2010, 08:25 pm
#1
Hello

Im new in C programming with Keil. I would like to implement the interrupt function in . But I dont know how I can calculate the waiting time after Interrupt(for example 100 ms) and after that to output a Value in Port (Port1).

thanks
Fri Oct 29 2010, 10:11 pm
#2
Interrupts and delays are largely separate things.

Check through our 8051 tutorial section.

Practise creating delays, then move onto handling interrupts.

I assume you mean create a delay after getting an interrupt from outside
the 8051.
The simplest way is to create a variable to act as a flag

e.g
volatile char somethingHappened=0; //must be volatile

In your interrupt handler just say
" somethingHappened=1;"

Clear the interrupt bit for whatever caused the interrupt,this depends on the 8051 hardware.
Exit the handler.





In main() keep checking "somethingHappened"
and when it changes to 1 start your delay.

There are many ways to do it, this is just one simple method.
Fri Oct 29 2010, 11:33 pm
#3
hi joepotter
8051 has 6 interrupt every one has its own purpose and use when an interrupt occur a relevant flag high that cpu detect and execute a specific code out side the main function in c.
timers interrupt is used to generate delay
first learn how to handle simple timer then go to interrupts
Sat Oct 30 2010, 01:01 am
#4
thanks for the explication, can I get the timer example with KEIL ?
thanks
Sat Oct 30 2010, 01:35 am
#5
here is the example of timer 0 interrupt in keil
interrupt generate after each 50 ms
#include <reg51.h>


sbit clock = P1^0;

void timer0 (void) interrupt 1              // interrupt function
{
clock=~clock;
TH0=0X4B;
TL0=0xFD;
}

void main (void)
{
TMOD=0X01;            // @ 11.0592MHz
TH0=0X4B;         // 50 ms delay
TL0=0xFD; 
TR0=1;
IE=0X82;   // enable timer0 interrupt along with global interrupt enable
while(1);

}
Sat Oct 30 2010, 04:59 pm
#6
thank you very much ,
I understand now, How I can make an interrupt( and delay). but now how can I verified that the interrupt work fine with 50ms with use of "breakpoint"..

thanks
Sat Oct 30 2010, 06:25 pm
#7
u can use a protus simulation to check it is it working or not
that is an easy way
Sun Oct 31 2010, 05:41 pm
#8
it´s not possible to use the Keil v4 ?
to make the breakpoint and check that we have the right delay .(50ms for example) .

thanks
Sun Oct 31 2010, 06:05 pm
#9
simulator is available with all keil versions. you can use breakpoints anywhere you want.
Sun Oct 31 2010, 06:15 pm
#10
but how ? , can I get an example .. with the code from majoka ?

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am
DonaldKnown
Thu Apr 18 2024, 12:24 am