src/switch.c
changeset 8 61eba9d55764
equal deleted inserted replaced
7:5c37ed521807 8:61eba9d55764
       
     1 #include "stdlib.h"
       
     2 //#include "switch.h"
       
     3 
       
     4 #include <avr/io.h>
       
     5 #include <avr/interrupt.h>
       
     6 
       
     7 byte switch_mask;
       
     8 byte switch_status;
       
     9 byte switch_state;
       
    10 
       
    11 ISR(PCINT0_vect)
       
    12 {
       
    13     switch_status = 1;
       
    14     switch_state = PINB;
       
    15 }
       
    16 
       
    17 ISR(PCINT1_vect)
       
    18 {
       
    19     switch_status = 1;
       
    20     switch_state = PINC;
       
    21 }
       
    22 
       
    23 ISR(PCINT2_vect)
       
    24 {
       
    25     switch_status = 1;
       
    26     switch_state = PIND;
       
    27 }
       
    28 
       
    29 byte switch_read (byte *sp)
       
    30 {
       
    31     if (!switch_status)
       
    32         return 0;
       
    33 
       
    34     switch_status = 0;
       
    35 
       
    36     *sp = ~switch_state & switch_mask;
       
    37 
       
    38     return 1;
       
    39 }