Skip to content

Instantly share code, notes, and snippets.

@devedetti
Last active December 27, 2015 22:49
Show Gist options
  • Select an option

  • Save devedetti/7401877 to your computer and use it in GitHub Desktop.

Select an option

Save devedetti/7401877 to your computer and use it in GitHub Desktop.
Puteando con las interrupciones!
#include <16f84a.h>
#fuses NOWDT
#use delay(crystal=4MHz)
#use fast_io(b)
byte previous_b = 0b00000000;
int16 timeout = 1000;
boolean is_interruptable = true;
#INT_RB
void rb_isr()
{
if (is_interruptable) {
is_interruptable = false;
enable_interrupts(INT_TIMER0);
set_timer0(128);
byte changes, port_b;
port_b = input_b();
changes = previous_b ^ port_b;
previous_b = port_b;
if (bit_test(changes, 4) && bit_test(previous_b, 4)) {
timeout = 2000;
}
if (bit_test(changes, 5) && bit_test(previous_b, 5)) {
timeout = 500;
}
}
}
#INT_TIMER0
void timer0_isr()
{
is_interruptable = true;
disable_interrupts(INT_TIMER0);
}
void main()
{
set_tris_a(0b00000);
set_tris_b(0b11110000);
setup_counters(RTCC_INTERNAL,RTCC_DIV_16);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
while(true) {
output_high(PIN_A0);
output_low(PIN_A1);
delay_ms(timeout);
output_low(PIN_A0);
output_high(PIN_A1);
delay_ms(timeout);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment