Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * GccApplication7.c
- *
- * Created: 3/26/2019 3:59:00 PM
- * Author : dspuser
- */
- MAINNNN
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include "timer.h"
- int count=0;
- //TIFR=0;
- void led_toggle(){
- if(count%2){
- PORTB |= 1<<1;//aprind LED1;
- }
- else
- PORTB &= ~(1<<1);
- count++;
- }
- void init_led(){
- DDRB|=(1<<1);//setam PB1 as output ca sa se aprinda primul led
- }
- int main(void)
- {
- init_led();
- timer_init();
- while(1)
- {
- if (((TIFR & (1 << 4)) != 0))
- {
- // compare match on channel 1 has occurred
- led_toggle();
- TIFR |= 1 << 4; // reset flag
- }
- }
- // some code
- }
- TIMEEEEEEEEEEEER
- /*
- * timer.c
- *
- * Created: 3/26/2019 4:04:07 PM
- * Author: dspuser
- */
- #include <avr/io.h>
- #include "timer.h"
- void timer_init()
- {
- OCR1AH = (value >> 8) & 0xFF;
- OCR1AL = (value & 0xFF);
- //set interrupt on compare match
- TCCR1B |= (1<<CS12)|(1 << WGM12);//mode 4, Mode of Operation CTC, 0100,prescalar 256,
- //sei(); //enable interrupts
- }
- HEAAAAAAAAAAAADER
- /*
- * timer.h
- *
- * Created: 3/26/2019 4:04:23 PM
- * Author: dspuser
- */
- void timer_init();
- #ifndef F_CPU
- #define F_CPU 14745600
- #endif
- #ifndef value
- #define value 0x7080
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement