From 1375f65d6d332f228e3e62831d42895bdff67423 Mon Sep 17 00:00:00 2001 From: Harvie Date: Sat, 14 Jan 2012 04:09:20 +0100 Subject: [PATCH] First experiments with AVR (AtTiny2313) --- avr/arduino-isp.txt | 9 +++++++++ avr/blink/Makefile | 27 +++++++++++++++++++++++++++ avr/blink/helloworld.c | 40 ++++++++++++++++++++++++++++++++++++++++ avr/blink/helloworld2.c | 33 +++++++++++++++++++++++++++++++++ c/dreammachine/strobe.c | 14 ++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 avr/arduino-isp.txt create mode 100644 avr/blink/Makefile create mode 100644 avr/blink/helloworld.c create mode 100644 avr/blink/helloworld2.c diff --git a/avr/arduino-isp.txt b/avr/arduino-isp.txt new file mode 100644 index 0000000..07daab9 --- /dev/null +++ b/avr/arduino-isp.txt @@ -0,0 +1,9 @@ +arduino MCU port tiny45 tiny2313 +GND GND 4 10 +5V VCC 8 20 +10 RESET 1 1 +11 MOSI/SDA 5 17 +12 MISO/DO 6 18 +13 SCK/USCK/SCL 7 19 + +avrdude -cstk500v1 -P/dev/ttyUSB0 -b19200 -p attiny2313 diff --git a/avr/blink/Makefile b/avr/blink/Makefile new file mode 100644 index 0000000..9d4a517 --- /dev/null +++ b/avr/blink/Makefile @@ -0,0 +1,27 @@ +#MCU=at90s2313 +MCU=attiny2313 +CC=avr-gcc +OBJCOPY=avr-objcopy +PROJECT=helloworld +# optimize for size: +CFLAGS=-g -mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues +#------------------- +all: $(PROJECT).hex +#------------------- +$(PROJECT).hex : $(PROJECT).out + $(OBJCOPY) -R .eeprom -O ihex $(PROJECT).out $(PROJECT).hex +$(PROJECT).out : $(PROJECT).o + $(CC) $(CFLAGS) -o $(PROJECT).out -Wl,-Map,$(PROJECT).map $(PROJECT).o +$(PROJECT).o : $(PROJECT).c + $(CC) $(CFLAGS) -Os -c $(PROJECT).c +asm : $(PROJECT).c + $(CC) $(CFLAGS) -O -S $(PROJECT).c +# you need to erase first before loading the program. +# load (program) the software into the eeprom: +load: $(PROJECT).hex + avrdude -cstk500v1 -P/dev/ttyUSB0 -b19200 -p $(MCU) -Uflash:w:$(PROJECT).hex:i + # uisp -dlpt=/dev/parport0 --erase --upload --verify if=$(PROJECT).hex -dprog=dapa -v=3 --hash=12 +#------------------- +clean: + rm -f *.o *.map *.out *.hex +#------------------- diff --git a/avr/blink/helloworld.c b/avr/blink/helloworld.c new file mode 100644 index 0000000..f0ffecb --- /dev/null +++ b/avr/blink/helloworld.c @@ -0,0 +1,40 @@ +#define F_CPU 100000UL // Sets up the default speed for delay.h +// this is the header file that tells the compiler what pins and ports, etc. +// are available on this chip. +#include + +// define what pins the LEDs are connected to. +// in reality, PD6 is really just '6' +#define LED PD5 + +// Some macros that make the code more readable +#define output_low(port,pin) port &= ~(1< +#include + +//#include +/* +variable = PINx; // Read a byte from a port, replace x with the port number +PORTx = variable; //Write a byte to a port +PORTx |= 1< #include #include #include +#ifndef __WIN32__ + #include +#else + #include +#endif void signal_handler(int signo) { if(signo == SIGTERM || signo == SIGINT || signo == SIGQUIT) { @@ -48,6 +54,14 @@ int main(int argc, char *argv[]) { fputs(state_a, stdout); fflush(stdout); usleep(half_interval); + #ifndef __WIN32__ + int fflags = fcntl(fileno(stdin), F_GETFL, 0); + fcntl(fileno(stdin), F_SETFL, fflags | O_NONBLOCK); + while(getchar()) puts("."); + fcntl(fileno(stdin), F_SETFL, fflags); + #else + //WARNING! Somehow implement FILE_FLAG_OVERLAPPED & FILE_FLAG_NO_BUFFERING support on windows + #endif if(argc > 2) getchar(); //interactive strobe fputs(state_b, stdout); fflush(stdout); -- 2.30.2