Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Hausübung.c
- *
- * Created: 15.01.2018 17:13:44
- * Author : Mario
- */
- #include <avr/io.h>
- #define F_CPU 16000000UL
- #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
- #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT))
- #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
- #define READ(x,y) ((0u == (x & (1<<y)))?0u:1u)
- #include <util/delay.h>
- int main(void)
- {
- DDRC = 0b1111110; // Pin0 auf Eingang schalten, die anderen sind Ausgänge
- PINC = 0b000001;
- int i = 0; // Variable i deklarieren
- while (1)
- {
- if ((PINC & (1<<PINC0))) //abfrage ob pin o gedrückt - wenn nicht - gleich weiter zu nächsten Pin
- {
- _delay_ms(200); //wenn gedrückt 100 ms warten
- if (PINC & (1 << PINC0))
- {
- if (i == 0)
- {
- CLEARBIT(PORTC, PORTC3);
- SETBIT(PORTC, PORTC1);
- _delay_us(500);
- i++;
- }
- else if (i == 1)
- {
- CLEARBIT(PORTC, PORTC1);
- SETBIT(PORTC, PORTC2);
- i++;
- }
- else if (i == 2)
- {
- CLEARBIT(PORTC, PORTC2);
- SETBIT(PORTC, PORTC3);
- i = 0;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement