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
CFLAGS += -mmcu=msp430g2553
CFLAGS += -Wall
CC = avr-gcc
CFLAGS += -mmcu=atmega328p
CFLAGS += -DF_CPU=16000000UL
CFLAGS += -Os
CFLAGS += -g
CFLAGS += -w
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
all: main blink

51
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;
unsigned char bits2 = BIT0 + BIT1 + BIT2 + BIT3 + BIT4 + BIT5;
int
main(void)
int main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= bits1;
P2DIR |= bits2;
unsigned char counter;
/* set PORTB for output*/
DDRB = 0xFF;
P1OUT |= bits1;
P2OUT &= ~bits2;
while (1)
{
/* set PORTB.2 high */
PORTB = 0xFF;
for (;;) {
i = (i + 1) % 40000;
if (i == 0) {
P1OUT ^= bits1;
P2OUT ^= bits2;
}
/* 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++;
}
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;
}