Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* function to read out switches */
- uint8_t PollSwitch(void)
- {
- unsigned int i;
- _Bool ec_bak = autoencode;
- autoencode = FALSE;
- DDRD |= SWITCHES; // Switches as Output
- SWITCH_ON; // Output HIGH for measurement
- ADMUX = (1 << REFS0) | SWITCH; // AVCC reference with external capacitor
- Sleep(10);
- ADCSRA |= (1 << ADSC); // Start conversion
- while (!(ADCSRA & (1 << ADIF)));// wait for conversion complete
- ADCSRA |= (1 << ADIF); // clear ADCIF
- i = ADCL + (ADCH << 8);
- SWITCH_OFF;
- Sleep(5);
- autoencode = ec_bak;
- return ((10240000/i - 10000) * 63 + 5000)/10000;
- }
- /*!
- * binds switch press to external Interrupt 1
- * catch it with ISR(INT1_vect)
- * see avr-libc documentation for details
- */
- void StartSwitch(void)
- {
- SWITCH_OFF;
- DDRD &= ~SWITCHES; // disable Switches as Input
- Sleep(100); // cool down from pollswitch
- MCUCR &= ~((1 << ISC11) | (1 << ISC10));// Low level generates interrupt
- GICR |= (1 << INT1); // Enable external Interrupt 1
- }
- void StopSwitch(void)
- {
- GICR &= ~(1 << INT1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement