HA8ie

Using AVR in Windows console and with C::B
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* 0. Extract gnuavr toolchain, add path.

   1. Compile
  avr-gcc -mmcu=atmega328p -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -std=gnu99 hello.c -o hello.elf

   2. Convert to HEX if needed (SimuTron uses elf)
  avr-objcopy -O ihex -R .eeprom hello.elf hello.hex  */

hello.c

  // have to be *BEFORE* includes
  #define F_CPU 1000000UL

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

  void init(void) {
    DDRB=0xFF;
  }

  int main(void) {
    init();

    while(1) {
      PORTB = 0;    // SimuTron Bug: PORTB = 1; PORTB = 1;
      PORTB = 3;    // Workaround: momentary transition from ~x to x
      _delay_ms(5); // meaningful on SimuTron
      PORTB = 0;
      PORTB = 6;
      _delay_ms(5);
    }
    return 0;
  }

Using Code::Blocks
~~~~~~~~~~~~~~~~~~

0. Extract gnuavr toolchain, add path. Add srecord binaries (http://srecord.sourceforge.net/download.html \"MS Windows downloads -> The 1.64 release folder", copy into a bin folder (where avr-gcc.exe is located))

1. Install Code::Blocks

2. New Project -> AVR Project
                  atmega328p

3. main.c: copy/paste example above starting from line #include <avr/io.h>

4. Open project file (.cbp) with text editor, add line (debug section)

      <Compiler>
        <Add option="-g" />
        <Add option="-Os" />   <=== Add this line
      </Compiler>

5. Build project, test elf (bin/Debug or bin/Release, switch with C::B Build->Select Target) file using Simutron.

More: See \"Comics" section \"C::B and AVR".

Links
~~~~~

  1. Simutron 1.0.1

       https://sourceforge.net/projects/simutron/

  2. AVR-GCC 7.2.0 for Windows 32 and 64 bit (23 May 2017) with
     AVR Toolchain GCC 6.3.0, binutils 2.28, avr-libc 2.0.0 in comments

       http://blog.zakkemble.co.uk/avr-gcc-builds/

  3. Code::Blocks

       http://www.codeblocks.org/downloads/binaries#windows
       codeblocks-16.01mingw-setup.exe
