How to Make (almost) Anything

07 Embedded Programming

Programming using Arduino is straightforward: http://highlowtech.org/?p=1695

I also tried doing it on the terminal: http://highlowtech.org/wiki/pmwiki.php?n=Main.AVRProgrammingAdvanced

Raw c code below.


#define F_CPU 20000000

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRA = _BV(PA3);

  for(;;){
    PORTA = _BV(PA3);
    _delay_ms(1000);
    PORTA = 0;
    _delay_ms(1000);
  }
  return 0;
}

* {#define F_CPU 20000000} this part is required as the default setting is not 20Mhz.


##avrdude -p attiny44 -c avrisp2 -P usb


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9207

avrdude: safemode: Fuses OK (H:FF, E:DF, L:FE)

avrdude done. Thank you.


#avr-gcc -mmcu=attiny44 -o led.out led.c


In file included from led.c:4:0:
/usr/local/CrossPack-AVR-20131216/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
# warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
^


#avr-objcopy -O ihex led.out led.hex
#avrdude -p attiny44 -c avrisp2 -P usb -U flash:w:led.hex


avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9207
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "led.hex"
avrdude: input file led.hex auto detected as Intel Hex
avrdude: writing flash (1090 bytes):

Writing | ################################################## | 100% 0.38s

avrdude: 1090 bytes of flash written
avrdude: verifying flash memory against led.hex:
avrdude: load data flash data from input file led.hex:
avrdude: input file led.hex auto detected as Intel Hex
avrdude: input file led.hex contains 1090 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.35s

avrdude: verifying ...
avrdude: 1090 bytes of flash verified

avrdude: safemode: Fuses OK (H:FF, E:DF, L:FE)

avrdude done. Thank you.

Copyright © 2014 Sang-won Leigh