Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/io.h>
- #include <util/delay.h>
- #include <avr/interrupt.h>
- #define S_ALL (_BV(PE2) | _BV(PE3) |_BV(PE4)| _BV(PE5))
- volatile uint8_t buttonpressed = 0;
- //interrupt service routine for ext. int. on PORT 6
- ISR(INT6_vect)
- {
- //invert LED1
- PORTG ^= _BV(PORT1);
- }
- //interrupt service routine for timer1
- ISR(TIMER1_COMPA_vect)
- {
- static uint8_t old_state = S_ALL;
- uint8_t new_state = PINE & S_ALL;
- if (new_state < old_state) {
- buttonpressed = 1;
- }
- }
- int main(void)
- {
- // insert code here
- //set LED1,2 as output, set S1,...,5 as input with internal pullup
- DDRG |= _BV(DD0) | _BV(DD1);
- PORTE |= _BV(PORT2) | _BV(PORT3) | _BV(PORT4) | _BV(PORT5) | _BV(PORT6);
- DDRE &= ~(_BV(DD2) | _BV(DD3) | _BV(DD4) | _BV(DD5) | _BV(DD6));
- //se int6 on falling edge
- EICRB |= _BV(ISC61);
- EICRB &= ~(_BV(ISC60));
- //enable INT6
- EIMSK |= _BV(INT6);
- //set timer compare reg. for interrupt every 40ms~25Hz, 7.3728M, 64x prsc, OCR1A = 7.3728/64/25 = 4608
- OCR1A = 4608;
- //set timer1 CTC
- TCCR1A &= ~(_BV(WGM10) | _BV(WGM11));
- TCCR1B &= ~(_BV(WGM13));
- TCCR1B |= _BV(WGM12);
- //set timer1 prsc to 64
- TCCR1B &= ~(_BV(CS12));
- TCCR1B |= _BV(CS10) | _BV(CS11);
- //enble tim comp1a interrupt
- TIMSK |= _BV(OCIE1A);
- //enable global interrupts
- sei();
- while(1)
- {
- if (buttonpressed)
- {
- buttonpressed=0;
- PORTG ^= _BV(PORT0);
- }
- }
- return 0;
- }
- /*
- #include <avr/io.h>
- #include <util/delay.h>
- #include "blik.h"
- #include <avr/pgmspace.h>
- #include <avr/interrupt.h>
- ISR(INT6_vect)
- {
- // PORTG = PORTG ^ _BV(PG1); //XOR - preklopeni, 11 je 0, 01 je 1
- }
- ISR(TIMER1_COMPA_vect)
- {
- PORTG = PORTG ^ _BV(PG1); //XOR - preklopeni, 11 je 0, 01 je 1
- #define S_ALL (_BV(PE2
- static uint8_t old_state = PINE & S_ALL;
- uint8_t
- }
- int main(void)
- {
- // uint8_t morse[] = {1,0,1,0,1,0,0,1,1,1,0,1,1,1,0,1,1,1,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0};
- DDRG |= _BV(PG1);
- DDRG |= _BV(PG2);
- PORTE |= _BV(PE2) | _BV(PE3) | _BV(PE4) | _BV(PE5) | _BV(PE6) ; //interrupty: 17.1.1
- EICRB |= _BV(ISC61) ; //int 6 aktivace na falling edge
- EICRB &= ~(_BV(ISC60)); //vynulujeme 60
- EIMSK |= _BV(6);
- sei();
- // timer setup
- TCCR1A&= ~(_BV(WGM10) | _BV(WGM11)); //vynuluju tyhle bity. TOP je OCR1A (mode4 )
- TCCR1B&= ~(_BV(WGM13));
- TCCR1B&= _BV(WGM12);
- OCR1A=4608; // 40ms...25Hz je kmitocet preklapeni , 7.37M, 64x prescaler OCR1A = 7.3728M/64/25
- TCCR1B&= ~_BV(CS12);
- TCCR1B&= _BV(CS11) | _BV(CS10);
- TIMSK=_BV(OCIE1A);
- //str. 189, Bit 4 – OCIE1A: Timer/Counter1, Output Compare A Match Interrupt Enable pouzijeme tento, Bit 2 – TOIE1: Timer/Counter1, Overflow Interrupt Enable bychom pouzili jen pri pouhem preteceni, kdybt pocital do konce
- while (1) {
- PORTG |= _BV(pin);
- _delay_ms(1000);
- PORTG &= ~_BV(pin); //led 1 is turned off. PORTG = PORTG & 0b11111101 - this is called mask.
- _delay_ms(1000);
- for (int i=0;i<32;i++) {
- blik(1,morse[i]);
- }
- //PORTG = PORTG & 0b11111101
- for (uint8_t i = 0; i < 4; i++) {
- uint8_t pomocna = 0;
- pomocna = pgm_read_byte(&pole[i]);
- for (uint8_t j = 0; j < 8; j++) {
- uint8_t pomocna2 = 0;
- pomocna2 = pomocna & 1; //vezmu bit
- blik(1, pomocna2);
- pomocna = pomocna >> 1;
- }
- }
- }
- return 0;
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement