From 082a24d76203339e899fe694201544fcead9db52 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Mon, 15 Feb 2016 14:23:02 +0100 Subject: [PATCH] Switched to dev --- MIC-Week1/.vs/MIC-Week1/v14/.atsuo | Bin 10240 -> 13824 bytes MIC-Week1/main.c | 247 ++++++++++++++++++++++++++++- 2 files changed, 242 insertions(+), 5 deletions(-) diff --git a/MIC-Week1/.vs/MIC-Week1/v14/.atsuo b/MIC-Week1/.vs/MIC-Week1/v14/.atsuo index fecfe895528282bcc77b9cb0da7f14bed95115f1..b208fe9aab12a79f807c4a6c24ce9be31dbcf539 100644 GIT binary patch delta 645 zcmYk2yGsK>5XN^e=UsBiB{66cC3+`{Vxhz)Cg39?7J@}A1qDS>1Qm-EVs&Z6!a{Cr ztd#r%l3Xu=RIv~Q5d{TH5j!79K;ujvX9m8T*>7%Vf4fG?*g78LVs5<1O>qw9B;6bR zetLP|xZxhgSkepo(kv9^5gvz6>00F)x|MoBM(j(3(1>vSV6>rr8r^yhqDQ3@vkTQ; zUsqtr8S0|l)cr-ZU`<)Z9Hu%qe`ZsqCO>Q{eiv|>$2{w9wagw#Qv#RX&vZ;5eS!ESg>jbSm0qLIJY)_C3{2p}j^ zYIS_$!RWE9v~tArenU2uh+~HB!Aidd6SCrT&}#~Tm3W0bV1J?r`%rQyJnU|3lD8LNFAfrGo-(14i z!?=luiD@#E-oeSvJhqGU87Jv0Y*r9RV4o~u +#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) { - /* Replace with your application code */ - while (1) - { - } + DDRC = 0b00000000; //input + DDRD = 0b11111111; //output + + // Prescaler + TCCR0 |= (1 << CS01) | (1 << CS00); + //Enable Overflow Interrupt Enable + TIMSK|=(1<= 0x80) + { + direction = 1; + } + else if (PORTD <= 0x1) + { + direction = 0; + } + + if(direction) + PORTD = (PORTD>>1); + 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 + } +}