Subversion Repositories group.electronics

Rev

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

Rev 57 Rev 58
Line 1... Line 1...
1
#include <avr/io.h>
1
#include <avr/io.h>
2
#include <avr/pgmspace.h>
2
#include <avr/pgmspace.h>
3
#include <avr/interrupt.h>
3
#include <avr/interrupt.h>
4
#include <avr/wdt.h>
4
#include <avr/wdt.h>
5
 
5
 
6
#include "petelib.h"
6
#include "util.h"
7
#include <util/delay.h>
7
#include <util/delay.h>
8
 
8
 
9
#include <stdlib.h>
9
#include <stdlib.h>
10
 
10
 
11
#include "wire.h"
11
#include "wire.h"
12
#include "lcd.h"
12
#include "lcd.h"
13
 
13
 
14
 
-
 
15
volatile uint8_t pcIntCurr[3] = {0,0,0};
-
 
16
volatile uint8_t pcIntLast[3] = {0,0,0};
-
 
17
volatile uint8_t pcIntMask[3] = {0,0,0};
-
 
18
 
-
 
19
volatile uint8_t tmr0_ovf = 0;
14
volatile uint8_t tmr0_ovf = 0;
20
volatile uint8_t tmr2_ovf = 0;
15
volatile uint8_t tmr2_ovf = 0;
21
volatile uint32_t systime = 0;
16
volatile uint32_t systime = 0;
22
volatile uint8_t lcdupdate = 1;
17
volatile uint8_t lcdupdate = 1;
23
 
18
 
Line 65... Line 60...
65
	PD7	- Input, Pullup		- Keypad 5
60
	PD7	- Input, Pullup		- Keypad 5
66
  */
61
  */
67
  DDRD		= 0B00010001;
62
  DDRD		= 0B00010001;
68
  PORTD		= 0B11100011;
63
  PORTD		= 0B11100011;
69
 
64
 
70
	PCMSK2 |= (( 1 << PCINT16 ) | ( 1 << PCINT17 )); //enable encoder pins interrupt sources
-
 
71
	PCICR |= ( 1 << PCIE2 ); //enable pin change interupts
-
 
72
 
-
 
73
	TIMSK0 = (1<<TOIE0);			// Enable 8bit timer overflow for Timer0
65
	TIMSK0 = (1<<TOIE0);			// Enable 8bit timer overflow for Timer0
74
	TCNT0 = 0x00;				// Set Timer0 to 0
66
	TCNT0 = 0x00;				// Set Timer0 to 0
75
	TCCR0B = (1<< CS00) ;			// /1 prescaler
67
	TCCR0B = (1<< CS00) ;			// /1 prescaler
76
 
68
 
77
	TIMSK2 = (1<<TOIE2);			// Enable 8bit timer overflow for Timer2
69
	TIMSK2 = (1<<TOIE2);			// Enable 8bit timer overflow for Timer2
Line 119... Line 111...
119
	}
111
	}
120
  }
112
  }
121
}
113
}
122
 
114
 
123
 
115
 
124
/*
-
 
125
 *
-
 
126
 * Process the Pin Change Interrupt.
-
 
127
 * pcint provides what bank caused the interrupt
-
 
128
 *
-
 
129
 */
-
 
130
void doInt(uint8_t pcint) {
-
 
131
 
-
 
132
	// Clear the mask so we know we've delth with it
-
 
133
	pcIntMask[pcint] = 0;
-
 
134
}
-
 
135
 
-
 
136
ISR(TIMER0_OVF_vect) {
116
ISR(TIMER0_OVF_vect) {
137
	tmr0_ovf++;
117
	tmr0_ovf++;
138
	if (tmr0_ovf>=62) {
118
	if (tmr0_ovf>=46) {
139
		xbi(PORTD, PD0);
119
		xbi(PORTD, PD0);
140
		systime++;
120
		systime++;
141
		tmr0_ovf = 0;
121
		tmr0_ovf = 0;
142
	}
122
	}
143
}
123
}
144
 
124
 
145
ISR(TIMER2_OVF_vect) {
125
ISR(TIMER2_OVF_vect) {
146
	tmr2_ovf++;
126
	tmr2_ovf++;
147
	if (tmr2_ovf>=78) {
127
	if (tmr2_ovf>=58) {
148
		xbi(PORTD, PD4);
128
		xbi(PORTD, PD4);
149
		lcdupdate=1;
129
		lcdupdate=1;
150
		tmr2_ovf = 0;
130
		tmr2_ovf = 0;
151
	}
131
	}
152
}
132
}
153
		
-
 
154
	
-
 
155
 
-
 
156
ISR(PCINT1_vect)
-
 
157
{
-
 
158
        // Save the state and work out which pin caused
-
 
159
        //  the interrupt to occur
-
 
160
        pcIntCurr[1] = PIND;
-
 
161
        pcIntMask[1] = pcIntCurr[1] ^ pcIntLast[1];
-
 
162
        pcIntLast[1] = pcIntCurr[1];
-
 
163
        doInt(1);
-
 
164
}
-
 
165
 
-
 
166
ISR(PCINT2_vect)
-
 
167
{
-
 
168
	// Save the state and work out which pin caused
-
 
169
	//  the interrupt to occur
-
 
170
	pcIntCurr[2] = PIND;
-
 
171
	pcIntMask[2] = pcIntCurr[2] ^ pcIntLast[2];
-
 
172
	pcIntLast[2] = pcIntCurr[2];
-
 
173
	doInt(2);
-
 
174
}
-
 
175
 
-