Subversion Repositories group.electronics

Rev

Rev 12 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 15
Line 16... Line 16...
16
 
16
 
17
volatile uint8_t pcIntCurr = 0;
17
volatile uint8_t pcIntCurr = 0;
18
volatile uint8_t pcIntLast = 0;
18
volatile uint8_t pcIntLast = 0;
19
volatile uint8_t pcIntMask = 0;
19
volatile uint8_t pcIntMask = 0;
20
 
20
 
-
 
21
volatile uint8_t timer0_ovf = 0;
-
 
22
volatile uint8_t time_rot = 0;
-
 
23
 
21
void doInt();
24
void doInt();
22
 
25
 
23
int main() {
26
int main() {
24
	cbi(DDRB, PCINT2);
27
	cbi(DDRB, PCINT2);
25
	cbi(DDRB, PCINT3);
28
	cbi(DDRB, PCINT3);
-
 
29
 
-
 
30
	TIMSK = (1<<TOIE0);                   // Eable timer overflow for Timer0
-
 
31
	TCNT0 = 0x00;                         // Set Timer0 to 0
-
 
32
	TCCR0B = (1<< CS02) | (1<<CS00);      // /1024 prescaler
-
 
33
 
26
	PORTB |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //turn on pullups
34
	PORTB |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //turn on pullups
27
	PCMSK |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //enable encoder pins interrupt sources
35
	PCMSK |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //enable encoder pins interrupt sources
28
	sei();
36
	sei();
29
	GIMSK |= ( 1 << PCIE ); //enable pin change interupts
37
	GIMSK |= ( 1 << PCIE ); //enable pin change interupts
30
 
38
 
Line 36... Line 44...
36
	_delay_ms(1000);
44
	_delay_ms(1000);
37
        cbi(PORTD, PD6);
45
        cbi(PORTD, PD6);
38
 
46
 
39
	for (;;) {
47
	for (;;) {
40
 
48
 
-
 
49
		if (!time_rot) {
-
 
50
			cbi(PORTD, PD4);
-
 
51
			cbi(PORTD, PD5);
-
 
52
		}
-
 
53
 
41
		if (pcIntMask)
54
		if (pcIntMask)
42
			doInt();
55
			doInt();
43
	}
56
	}
44
}
57
}
45
 
58
 
46
void doInt() {
59
void doInt() {
47
  xbi(PORTD, PD6);
60
  xbi(PORTD, PD6);
48
 
61
 
49
  if (rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntMask, PCINT2) ) {
62
  if (rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntMask, PCINT2) ) {
50
	cbi(PORTD, PD5);	// Clear oppposite direction
63
	cbi(PORTD, PD5);
51
 
-
 
52
	sbi(PORTD, PD4);	// Depress current direction for DEPRESS time
-
 
53
	_delay_ms(DEPRESS_TIME);
64
	sbi(PORTD, PD4);
54
	cbi(PORTD, PD4);	
65
	time_rot = 5;
55
  } else if (rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntMask, PCINT3) ) {
66
  } else if (rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntMask, PCINT3) ) {
56
	cbi(PORTD, PD4);
67
	cbi(PORTD, PD4);
57
 
-
 
58
	sbi(PORTD, PD5);
68
	sbi(PORTD, PD5);
59
	_delay_ms(DEPRESS_TIME);
-
 
60
	cbi(PORTD, PD5);
69
	time_rot = 5;
61
  }
70
  }
62
 
71
 
63
  pcIntMask = 0;
72
  pcIntMask = 0;
64
}
73
}
65
 
74
 
-
 
75
ISR(TIMER0_OVF_vect) {
-
 
76
        timer0_ovf++;
-
 
77
 
-
 
78
        if (time_rot) {
-
 
79
                time_rot--;
-
 
80
        }
-
 
81
}
-
 
82
 
66
 
83
 
67
ISR(PCINT_vect)
84
ISR(PCINT_vect)
68
{
85
{
69
  pcIntCurr = PINB;
86
  pcIntCurr = PINB;
70
  pcIntMask = pcIntCurr ^ pcIntLast;
87
  pcIntMask = pcIntCurr ^ pcIntLast;