Subversion Repositories group.electronics

Rev

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

Rev 18 Rev 19
Line 60... Line 60...
60
  ACSR |= (1<<ACD); // Disable analog comparator
60
  ACSR |= (1<<ACD); // Disable analog comparator
61
 
61
 
62
  // DDR : 1 = Output, 0 = Input
62
  // DDR : 1 = Output, 0 = Input
63
  // PORT: 1 = Pullup for Input, otherwise set output
63
  // PORT: 1 = Pullup for Input, otherwise set output
64
  // PIN : Read input pin
64
  // PIN : Read input pin
65
  DDRB		= 0B00010011;
65
  DDRB		= 0B00000001;
66
  PORTB 	= 0B00011111;
66
  PORTB 	= 0B00000110;
67
 
67
 
68
  DDRD		= 0B01110000;
68
  DDRD		= 0B00000000;
69
  PORTD		= 0B00110000;
69
  PORTD		= 0B01100000;
70
 
70
 
71
  PORTB |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //turn on pullups
71
  //PORTB |= (( 1 << PCINT1 ) | ( 1 << PCINT2 )); //turn on pullups
72
  PCMSK |= (( 1 << PCINT2 ) | ( 1 << PCINT3 )); //enable encoder pins interrupt sources
72
  PCMSK0 |= (( 1 << PCINT1 ) | ( 1 << PCINT2 )); //enable encoder pins interrupt sources
73
  GIMSK |= ( 1 << PCIE ); //enable pin change interupts
73
  PCICR |= ( 1 << PCIE0 ); //enable pin change interupts
74
 
74
 
75
  // Setup timer0
75
  // Setup timer0
76
  TIMSK = (1<<TOIE0);			// Eable timer overflow for Timer0
76
  TIMSK0 = (1<<TOIE0);			// Eable timer overflow for Timer0
77
  TCNT0 = 0x00;				// Set Timer0 to 0
77
  TCNT0 = 0x00;				// Set Timer0 to 0
78
  TCCR0B = (1<< CS01) | (1<<CS00);	// /1024 prescaler
78
  TCCR0B = (1<< CS01) | (1<<CS00);	// /1024 prescaler
79
 
79
 
80
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
80
  usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
81
  _delay_ms(500);
81
  _delay_ms(500);
Line 94... Line 94...
94
//		doInt();
94
//		doInt();
95
 
95
 
96
	if (!time_rot) {
96
	if (!time_rot) {
97
		report.rot1 = 0;
97
		report.rot1 = 0;
98
		report.rot2 = 0;
98
		report.rot2 = 0;
99
		cbi(PORTD, PD6);
99
		cbi(PORTB, PB0);
100
	}	
100
	}	
101
 
101
 
102
    if(usbInterruptIsReady()){
102
    if(usbInterruptIsReady()){
103
      //report.data = 0x05; // Center pad, little endian
103
      //report.data = 0x05; // Center pad, little endian
104
 
104
 
Line 109... Line 109...
109
		report.Y--;
109
		report.Y--;
110
	if (bit_is_clear(PINB, PB2))
110
	if (bit_is_clear(PINB, PB2))
111
		report.X--;
111
		report.X--;
112
	if (bit_is_clear(PINB, PB3))
112
	if (bit_is_clear(PINB, PB3))
113
		report.Y++;
113
		report.Y++;
114
 
114
*/
115
	if (bit_is_clear(PIND, PD4))
-
 
116
		report.A = 1; */
-
 
117
	if (bit_is_clear(PIND, PD5))
115
	if (bit_is_clear(PIND, PD5))
-
 
116
		report.A = 1;
-
 
117
 
-
 
118
	if (bit_is_clear(PIND, PD6))
118
		report.B = 1;
119
		report.B = 1;
119
 
120
 
120
      /* called after every poll of the interrupt endpoint */
121
      /* called after every poll of the interrupt endpoint */
121
      usbSetInterrupt(&report, sizeof(report));
122
      usbSetInterrupt(&report, sizeof(report));
122
    }
123
    }
123
  }
124
  }
124
}
125
}
125
 
126
 
126
void doInt() {
127
void doInt() {
127
  if (rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntMask, PCINT2) ) {
128
  if (rbi(pcIntCurr, PCINT1) == 0 && rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntMask, PCINT1) ) {
128
	time_rot = 60;
129
	time_rot = 60;
129
	report.rot1 = 1;
130
	report.rot1 = 1;
130
	report.rot2 = 0;
131
	report.rot2 = 0;
131
	sbi(PORTD, PD6);
132
	sbi(PORTB, PB0);
132
  } else if (rbi(pcIntCurr, PCINT3) == 0 && rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntMask, PCINT3) ) {
133
  } else if (rbi(pcIntCurr, PCINT1) == 0 && rbi(pcIntCurr, PCINT2) == 0 && rbi(pcIntMask, PCINT2) ) {
133
	time_rot = 60;
134
	time_rot = 60;
134
	report.rot1 = 0;
135
	report.rot1 = 0;
135
	report.rot2 = 1;
136
	report.rot2 = 1;
136
	sbi(PORTD, PD6);
137
	sbi(PORTB, PB0);
137
  }
138
  }
138
 
139
 
139
  pcIntMask = 0;
140
  pcIntMask = 0;
140
}
141
}
141
 
142
 
Line 145... Line 146...
145
	if (time_rot) {
146
	if (time_rot) {
146
		time_rot--;
147
		time_rot--;
147
	}
148
	}
148
}
149
}
149
 
150
 
150
ISR(PCINT_vect)
151
ISR(PCINT0_vect)
151
{
152
{
152
  pcIntCurr = PINB;
153
  pcIntCurr = PINB;
153
  pcIntMask = pcIntCurr ^ pcIntLast;
154
  pcIntMask = pcIntCurr ^ pcIntLast;
154
  pcIntLast = pcIntCurr;
155
  pcIntLast = pcIntCurr;
155
  doInt();
156
  doInt();