/* * MIC-Week1.c * * Created: 2-2-2016 11:48:44 * Author : kenny */ #define F_CPU 8000000UL #define NELEMS(x) (sizeof(x) / sizeof(x[0])) #include #include #include int reset = 0; /******************************************************************/ void wait( int ms ) /* short: Busy wait number of millisecs inputs: int ms (Number of millisecs to busy wait) outputs: notes: Busy wait, not very accurate. Make sure (external) clock value is set. This is used by _delay_ms inside util/delay.h Version : DMK, Initial code *******************************************************************/ { for (int i=0; i 4000) { blink = 4000; } } int main(void) { DDRC = 0b00000000; //input DDRD = 0b11111111; //output // Prescaler TCCR0 |= (1 << CS01) | (1 << CS00); //Enable Overflow Interrupt Enable TIMSK|=(1<= 0x80) { PORTD= 0x1; } else { PORTD = (PORTD<<1); } } void opgave5(void) { if(PINC != 0 ) { speed = PINC; } // Write data to PORTD PORTD = pattern[count].data; // wait wait(pattern[count].delay * speed); count++; if(count >= NELEMS(pattern)) { count = 0; } } void opgave6(void) { PORTD = 0b10000000; wait( blink ); PORTD = 0b00000000; wait( blink ); } void charlieplexing(void) { //Button C0 if( (0b00000001 & PINC) != 0) { DDRD = 0b00000011; //PIN 1 & 2 as output. Pin 3 as input (TRI-STATE) PORTD = 0b00000001; //PIN 1 High, PIN 2 Low } //Button C1 else if( (0b00000010 & PINC) != 0) { DDRD = 0b00000011; //PIN 1 & 2 as output. Pin 3 as input (TRI-STATE) PORTD = 0b00000010; //PIN 2 High, PIN 1 Low } //Button C2 else if( (0b00000100 & PINC) != 0) { DDRD = 0b00000110; //PIN 2 & 3 as output. Pin 1 as input (TRI-STATE) PORTD = 0b00000010; //PIN 2 High, PIN 3 Low } //Button C3 else if( (0b00001000 & PINC) != 0) { DDRD = 0b00000110; //PIN 2 & 3 as output. Pin 1 as input (TRI-STATE) PORTD = 0b00000100; //PIN 3 High, PIN 2 Low } //Button C4 else if( (0b00010000 & PINC) != 0) { DDRD = 0b00000101; //PIN 3 & 1 as output. Pin 2 as input (TRI-STATE) PORTD = 0b00000100; //PIN 3 High, PIN 1 Low } //Button C5 else if( (0b00100000 & PINC) != 0) { DDRD = 0b00000101; //PIN 3 & 1 as output. Pin 2 as input (TRI-STATE) PORTD = 0b00000001; //PIN 1 High, PIN 3 Low } }