Basic Arduino skeleton

This commit is contained in:
Neale Pickett 2013-03-27 21:50:31 -06:00
parent b0eab39a46
commit b58818bb08
2 changed files with 62 additions and 31 deletions

View File

@ -1,7 +1,27 @@
CC = msp430-gcc CC = avr-gcc
CFLAGS += -mmcu=msp430g2553 CFLAGS += -mmcu=atmega328p
CFLAGS += -Wall CFLAGS += -DF_CPU=16000000UL
CFLAGS += -Os 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

63
blink.c
View File

@ -1,28 +1,39 @@
#include <msp430.h> #include <avr/io.h>
#include <util/delay.h>
unsigned int i = 0;
unsigned char bits1 = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5 + BIT6 + BIT7; int main (void)
unsigned char bits2 = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5;
int
main(void)
{ {
WDTCTL = WDTPW + WDTHOLD; unsigned char counter;
P1DIR |= bits1; /* set PORTB for output*/
P2DIR |= bits2; DDRB = 0xFF;
P1OUT |= bits1; while (1)
P2OUT &= ~bits2; {
/* set PORTB.2 high */
for (;;) { PORTB = 0xFF;
i = (i + 1) % 40000;
/* wait (10 * 120000) cycles = wait 1200000 cycles */
if (i == 0) { counter = 0;
P1OUT ^= bits1; while (counter != 50)
P2OUT ^= bits2; {
} /* wait (30000 x 4) cycles = wait 120000 cycles */
} _delay_loop_2(60000);
counter++;
return 0; }
/* 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;
} }