Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * tset.c
- *
- * Created: 2019-04-09 10:12:18
- * Author : oem1
- */
- /*
- //zadanie 1
- #include <avr/io.h>
- #define F_CPU 16000000UL
- #include <util/delay.h>
- #include <avr/interrupt.h>
- uint8_t seg7[]={0b11000000,
- 0b11111001,
- 0b10100100,
- 0b10110000,
- 0b10011001,
- 0b10010010,
- 0b10000010,
- 0b11111000,
- 0b10000000,
- 0b10010000};
- volatile uint8_t LED[4];
- int main(void)
- {
- TCCR0 |= (1 << WGM01 ) | (0 << WGM00 );
- TCCR0 |= (1 << CS02) | (0 << CS01) | (1 << CS00);
- OCR0=50;
- TIMSK |=(1 << OCIE0);
- sei();
- uint16_t sec = 1955;
- uint16_t tmp = sec;
- LED[3]=seg7[tmp/1000];
- tmp %= 1000;
- LED[2]=seg7[tmp/100];
- tmp %= 100;
- LED[1]=seg7[tmp/10];
- tmp %= 10;
- LED[0]=seg7[tmp];
- DDRB = 0x0F;
- DDRA = 0xFF;
- // Replace with your application code
- while (1)
- {
- }
- }
- ISR(TIMER0_COMP_vect)
- {
- static uint8_t licznik = 0;
- PORTB |= 0x0F;
- PORTA = LED[licznik];
- PORTB &= ~(1 << licznik);
- if (++licznik>3){
- licznik = 0;
- }
- }*/
- //zadanie 2
- #include <avr/io.h>
- #define F_CPU 16000000UL
- #include <util/delay.h>
- #include <avr/interrupt.h>
- uint8_t seg7[]={0b11000000,
- 0b11111001,
- 0b10100100,
- 0b10110000,
- 0b10011001,
- 0b10010010,
- 0b10000010,
- 0b11111000,
- 0b10000000,
- 0b10010000};
- volatile uint8_t LED[4];
- volatile uint8_t key_state1 = 0;
- volatile uint8_t key_state2 = 0;
- int main(void)
- {
- TCCR0 |= (1 << WGM01 ) | (0 << WGM00 );
- TCCR0 |= (1 << CS02) | (0 << CS01) | (1 << CS00);
- OCR0=50;
- TIMSK |=(1 << OCIE0);
- sei();
- uint16_t sec = 1234;
- DDRB = 0x0F;
- DDRA = 0xFF;
- DDRC = 0x00;
- PORTC = 0x03;
- // Replace with your application code
- while (1)
- {
- uint16_t tmp = sec;
- LED[3]=seg7[tmp/1000];
- tmp %= 1000;
- LED[2]=seg7[tmp/100];
- tmp %= 100;
- LED[1]=seg7[tmp/10];
- tmp %= 10;
- LED[0]=seg7[tmp];
- if (key_state1 == 2){
- sec = 1234;
- key_state1 = 3;
- }
- else if(key_state2 == 2){
- sec = 4567;
- key_state2 = 3;
- }
- }
- }
- ISR(TIMER0_COMP_vect)
- {
- static uint8_t licznik = 0;
- PORTB |= 0x0F;
- PORTA = LED[licznik];
- PORTB &= ~(1 << licznik);
- if (++licznik>3){
- licznik = 0;
- }
- switch(key_state1){
- case 0: if ((PINC & 0x01) == 0) key_state1 = 1;
- break;
- case 1: if ((PINC & 0x01) == 0) key_state1 = 2;
- else key_state1 = 0;
- break;
- case 2: break;
- case 3: if ((PINC & 0x01) != 0) key_state1 = 4;
- break;
- case 4: if ((PINC & 0x01) != 0) key_state1 = 0;
- else key_state1 = 3;
- break;
- default:key_state1 = 0;
- }
- switch(key_state2){
- case 0: if ((PINC & 0x02) == 0) key_state2 = 1;
- break;
- case 1: if ((PINC & 0x02) == 0) key_state2 = 2;
- else key_state2 = 0;
- break;
- case 2: break;
- case 3: if ((PINC & 0x02) != 0) key_state2 = 4;
- break;
- case 4: if ((PINC & 0x02) != 0) key_state2 = 0;
- else key_state2 = 3;
- break;
- default:key_state2 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement