diff --git a/Makefile b/Makefile index 8214327..c78cfdb 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,27 @@ -CC = msp430-gcc -CFLAGS += -mmcu=msp430g2553 -CFLAGS += -Wall +CC = avr-gcc +CFLAGS += -mmcu=atmega328p +CFLAGS += -DF_CPU=16000000UL CFLAGS += -Os -CFLAGS += -g +CFLAGS += -w -all: main blink +AVDFLAGS += -p m328p +AVDFLAGS += -c arduino +AVDFLAGS += -b 115200 +AVDFLAGS += -P /dev/ttyACM0 + + +upload: .upload + +.upload: blink.hex + avrdude $(AVDFLAGS) -U flash:w:$< + touch $@ + +blink.hex: blink + avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ + +clean: + rm -f blink.hex blink + + + + diff --git a/blink.c b/blink.c index 4f46403..aa63e92 100644 --- a/blink.c +++ b/blink.c @@ -1,28 +1,39 @@ -#include - -unsigned int i = 0; - -unsigned char bits1 = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; -unsigned char bits2 = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5; - -int -main(void) +#include +#include + + +int main (void) { - WDTCTL = WDTPW + WDTHOLD; - P1DIR |= bits1; - P2DIR |= bits2; - - P1OUT |= bits1; - P2OUT &= ~bits2; - - for (;;) { - i = (i + 1) % 40000; - - if (i == 0) { - P1OUT ^= bits1; - P2OUT ^= bits2; - } - } - - return 0; + unsigned char counter; + /* set PORTB for output*/ + DDRB = 0xFF; + + while (1) + { + /* set PORTB.2 high */ + PORTB = 0xFF; + + /* wait (10 * 120000) cycles = wait 1200000 cycles */ + counter = 0; + while (counter != 50) + { + /* wait (30000 x 4) cycles = wait 120000 cycles */ + _delay_loop_2(60000); + counter++; + } + + /* set PORTB.2 low */ + PORTB = 0x00; + + /* wait (10 * 120000) cycles = wait 1200000 cycles */ + counter = 0; + while (counter != 50) + { + /* wait (30000 x 4) cycles = wait 120000 cycles */ + _delay_loop_2(30000); + counter++; + } + } + + return 1; } \ No newline at end of file