When trying to answer a question on the site I started a dense search of how to work with interrupts in C.
Interruptions for those who did not understand works as follows:
I'm running my program normally, as soon as something happens, regardless of where I am in my program, I run an X function.
In processor programming, the C language is also used, it works like this:
int duty;//duty 0-100
#int_TIMER0
void TIMER0_isr(void)
{
int led;
set_timer0(128);
if(led==0/*&&duty<contador*/)
{
led=1;
}
else {led=0;}
output_bit (PIN_B5,led);
}
void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
// TODO: USER CODE!!
while(true)
{
//aqui meu programa principal
}
}
How this works:
I am running my main program and as soon as the counter counts 128ms it executes the TIMER0_isr();
function ie this is a time interrupt, every 128ms run the function x.
There are also other interrupt types for processors, such as the keyboard, you can set an X function to run whenever someone presses a key.
What I researched so much and did not find, how to do this compiling to a PC. that is, I want to make my program run perfectly and whenever someone presses a key on the keyboard I execute a function y. Or when it bursts a certain time I execute a function z.
How do I do this?
(something like the onclicklistner method of java would also work)