@@ -44,8 +44,7 @@ void timer0_ISR(void) interrupt 1
4444 /* NOTE: How long does a system tick take?
4545 *
4646 * The calculation goes like:
47- * tick frequenycy =
48- * system frequency / 12 / (65536 - [RL_TH0, RL_TL0])
47+ * tick frequenycy = system frequency / 12 / (65536 - [RL_TH0, RL_TL0])
4948 *
5049 * The '12' is because we set the AUXR register to increment the
5150 * timer register only every 12th clock cycle.
@@ -62,7 +61,6 @@ void timer2_ISR(void) interrupt 12 using 1
6261{
6362 // TODO: Way too long for an ISR...
6463
65-
6664 static float avg_button = 10 ;
6765 static float avg_avr_online = 10 ;
6866
@@ -128,25 +126,25 @@ void setup()
128126 CLR_BIT (AUXR , 7 ); // Timer 0 in 12T Mode
129127 TH0 = (65536 - 1000 ) / 256 ; // Reload values after overflow, High value
130128 TL0 = (65536 - 1000 ) % 256 ; // Low value
131-
129+
132130 // Timer 2
133- AUXR |= 0x04 ; //Timer clock is 1T mode
134- T2L = 0xA0 ; //Initial timer value
135- T2H = 0x15 ; //Initial timer value
131+ AUXR |= 0x04 ; //Timer clock is 1T mode
132+ T2L = 0xA0 ; //Initial timer value
133+ T2H = 0x15 ; //Initial timer value
136134
137135
138- /* NOTE on Reload Values for STC15 uC:
136+ /* NOTE: Reload Values for STC15 uC:
139137 * Any value written into TH0/TL0 are passed to the reload registers
140138 * RL_TH0/TL0 as long as TR0=0.
141139 * If TR0=1, then the values are written into the hidden reload registers only.
142140 */
143141
144- ET0 = 1 ; // Enable Timer 0 interrupts
145- SET_BIT (IE2 , 2 ); // IE2, ET2: Enable Timer 2 interrupts
142+ ET0 = 1 ; // Enable Timer 0 interrupts
143+ SET_BIT (IE2 , 2 ); // Enable Timer 2 interrupts (IE2, ET2)
144+
145+ TR0 = 1 ; // Start Timer 0
146+ AUXR |= 0x10 ; // Start Timer 2
146147
147- TR0 = 1 ; // Start Timer 0
148- AUXR |= 0x10 ; // Start Timer 2
149-
150148}
151149
152150unsigned long int ticks_since (unsigned long since )
@@ -177,7 +175,6 @@ void main()
177175 PCON = 0x02 ; // Stop/PowerDown Mode
178176 _nop_ (); // We need at least one NOP after waking up
179177 transition_to_state (IDLE );
180-
181178 break ;
182179
183180 case IDLE :
@@ -186,7 +183,6 @@ void main()
186183 O_AVR_BUTTON = LOW ; // notify avr about the pressed button
187184 transition_to_state (BOOT );
188185 }
189-
190186 break ;
191187
192188 case BOOT :
@@ -207,6 +203,7 @@ void main()
207203
208204 if (avr_online_state == LOW ) {
209205 O_BOOST = LOW ;
206+ O_AVR_BUTTON = LOW ;
210207 transition_to_state (SLEEP );
211208 }
212209
0 commit comments