Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Michał Grzegorczyk sprawozdanie- timer.
- */
- //Zadanie 1. Tryb normal (odczyt flagi TOV0)
- /*
- #include <avr/io.h>
- #define LED1 (1<<PA7) //definicja LED1, podłączonego do pinu PA7
- void timer0()
- {
- TCCR0 |= (1<<CS00); //Ustawienie timera bez preskalera
- TCNT0=0; //ustawienie countera
- }
- void main(void)
- {
- DDRA |= LED1; //Ustawienie pinu sterującego diodą jako wyjście
- timer0(); //Ustawienie timera
- while(1)
- {
- if(TCNT0>=243)
- {
- PORTA ^= LED1;
- TCNT0=0;
- }
- }
- }
- */
- //Zadanie 1b. tryb ctc
- #include <avr/io.h>
- #define LED1 (1<<PA7) //definicja LED1, podłączonego do pinu PA7
- void main(void)
- {
- DDRA |= LED1; //Ustawienie pinu sterującego diodą jako wyjście
- OCR0 = 243; // Ustawienie częstotliwości timera do około 4Hz
- TCCR0 |= (1<<CS02)|(1<<CS00)|(1<<WGM01)|(1<<COM00); //Ustawienie timer0 z preskalerem 64 w trybie CTC
- while(1); //nieskończona pętla
- }
- //Zadanie 2.
- /*
- #include <avr/io.h>
- #include <util/delay.h>
- int main(void) {
- DDRB = (1<<PB3) //Ustawienie PB3 jako wyjście.
- TCCR0A = (1<<COM0A1)|(1<<COM0B1)|(1<<COM0B0)|(1<<WGM01)|(1<<WGM00); //Ustawienie rejestrów porównań
- DDRD = 0xFF; //ustawienie kierunku linii portu D w stronę wyjścia
- DDRC = 0x0F; //ustawienie połowy pinów portu C w stronę wyjścia
- DDRA = 0b11110000; // Ustawienie kierunku połowy linii portu A w strone wejścia
- PORTA |= (1 << PA0); // Aktywowanie rezystora podciągajcego
- OCR0A = 255; //Maksymalna jasność diody
- TCCR0B = (1<<CS00);
- while (1) //nieskończona pętla
- {
- _delay_ms(8); //opóźnienie
- int x = 128;
- for(int j=0;j<4;j++)
- {
- PORTA = ~x;
- x=x/2;
- }
- switch(PINA)
- {
- case 0b01111110: OCR0A=1;_delay_ms(50);break;
- case 0b01111101: OCROA=25;_delay_ms(50);break;
- case 0b01111011: OCROA=81;_delay_ms(50);break;
- case 0b01110111: OCROA=169;_delay_ms(50);break;
- case 0b10111110: OCROA=4;_delay_ms(50);break;
- case 0b10111101: OCROA=36;_delay_ms(50);break;
- case 0b10111011: OCROA=100;_delay_ms(50);break;
- case 0b10110111: OCROA=196;_delay_ms(50);break;
- case 0b11011110: OCROA=9;_delay_ms(50);break;
- case 0b11011101: OCROA=49;_delay_ms(50);break;
- case 0b11011011: OCROA=121;_delay_ms(50);break;
- case 0b11010111: OCROA=225;_delay_ms(50);break;
- case 0b11101110: OCROA=16;_delay_ms(50);break;
- case 0b11101101: OCROA=64;_delay_ms(50);break;
- case 0b11101011: OCROA=144;_delay_ms(50);break;
- case 0b11100111: OCROA=254;_delay_ms(50);break;
- default OCROA = 50;
- }
- }
- */
- //Zadanie 3.
- include <avr/io.h>
- void main(void)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement