// Programowanie mikrokontrolerow 2015/2016, Wydzial Fizyki UW // Program sterujacy rzutnikiem w sali cwiczeniowej. // // Autorzy: Pawel Klimczewski, Bartlomiej Zglinicki // Wymagane polaczenia w ukladzie ZL15AVR: // // PB0 - SW0 (przycisk sterujacy) // PB3 - dioda IRED #include #include //--------------------------------------------------------------------------- void configure_pins() { DDRB = 1 << PB3; // Wyjscie OC0. } //--------------------------------------------------------------------------- void configure_timer() { // 16 000 000 / 200 / 2 = 40 000. OCR0 = 210; // Zliczamy F_CPU, zakres do OCR0. TCCR0 = 1 << CS00 | 1 << WGM01; // CTC, top = OCRA } //--------------------------------------------------------------------------- inline bool btn() { return ( PINB & 1 << PB0 ) == 0; } //--------------------------------------------------------------------------- inline void modulation( bool b ) { TCCR0 &= ~( 1 << COM01 | 1 << COM00 ); if ( b ) { // Toggle OC0 on Compare Match TCCR0 |= 1 << COM00; } else { // Clear OC0 on Compare Match TCCR0 |= 1 << COM01; } } //--------------------------------------------------------------------------- int main() { configure_pins(); configure_timer(); while ( true ) { if ( btn() ) { modulation( true ); _delay_ms(9); modulation( false ); _delay_ms(4.5); uint32_t x = 0b00000000000011000111001010001101; // off for ( uint8_t i = 32; i; --i ) { modulation( true ); _delay_ms(0.56); modulation( false ); if (x & 1ul<<31) { _delay_ms(1.69); } else { _delay_ms(0.56); } x <<= 1; } modulation(true); _delay_ms(0.56); modulation( false ); break; } } } //---------------------------------------------------------------------------