Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 3.c
- *
- * Created: 05.11.2019 13:53:30
- * Author : dspproject
- */
- #define F_CPU 14745600UL
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- int x = 0;
- int ev = 0;
- ISR(TIMER1_COMPA_vect) //subrutina daca interupt
- {
- ev = 1;
- }
- void init_timer()
- {
- unsigned value = 18; //asta ii OCR1A , grija la virgula
- OCR1AH = (value >> 8) & 0xFF; //OCRA impartit in 2 registre => adaugi MSB half aici
- OCR1AL = (value & 0xFF); //LS half aici
- TCCR1B = 1 << 3; //mode 4
- TCCR1B |= 1 << 1; // clk pt asta trebuie sa fie 1 (CS11 = 1)
- TIMSK |= 1<<4;
- /*
- if((OCIE1A & (1<<4)) == 1 ) //verifica daca flagul pt interuperi ii 1
- {
- ISR(TIMER1_COMPA_vect);
- }*/ // nu mai trebuie verificat, fiind flagul setat mai sus, la TIMSK, o sa faca singur subrutina de sus
- //OCR1A = value;
- }
- int main(void)
- {
- sei(); //global enable interrupt function for external events
- DDRB |= 1;
- init_timer();
- while (1)
- {
- if (ev == 1)
- {
- if(!x) //blink-ane corect
- {
- PORTB |= 1;
- }
- else
- {
- PORTB = 0;
- }
- x = x ? 0 : 1;
- ev = 0;
- }
- ////
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement