
{"id":43,"date":"2012-05-04T10:34:53","date_gmt":"2012-05-04T09:34:53","guid":{"rendered":"http:\/\/www.kanda.com\/blog\/?p=43"},"modified":"2012-05-04T11:09:48","modified_gmt":"2012-05-04T10:09:48","slug":"avr-microcontroller-code","status":"publish","type":"post","link":"https:\/\/www.kanda.com\/blog\/microcontrollers\/avr-microcontrollers\/avr-microcontroller-code\/","title":{"rendered":"AVR Microcontroller C Code"},"content":{"rendered":"<p>The AVR microcontroller is excellent with C code because it was designed with C in mind. Atmel have also made it easy to use C in AVR Studio, as WinAVR compiler can run from within AVRStudio just like the assembler.<\/p>\n<p>Only a few years ago, using C compilers involved complicated commandline instructions and make files but WinAVR more or less takes care of this for you. WinAVR is based on the free GNU-GCC compiler but is much friendlier, especially for beginners.<\/p>\n<p><!--more--><\/p>\n<p>When you create a project in AVRStudio, you just choose C project and write your code in the editor. Then you just click Make and WinAVR does the rest. There are a few settings to be aware of in the compiler that you should set.<\/p>\n<p>Go to <strong>Project &#8211; Configuration Options<\/strong> menu, and on first screen check these points:<\/p>\n<ul>\n<li>Check Device matches your device. This is a different device setting from \u00a0the AVRStudio project device setting<\/li>\n<li>Set Optimization to -0s at first otherwise lots of example code won&#8217;t run properly<\/li>\n<li>The default output file is [project-name].elf. This is the debug file format, used by simulator and emulators like JTAG ICE and AVR Dragon. For output for programmers as well, check <strong>Create Hex File<\/strong> as this is the file for programmers.<\/li>\n<li>Output files including the Hex file are created in a sub-folder called Default<\/li>\n<\/ul>\n<p>That&#8217;s it. \u00a0Now you can paste in C code (or write it) and compile it. Emulators can step through C code in AVR Studio just like assembler code, which makes debugging much easier.<\/p>\n<p>We have some C code example projects on our support pages.<\/p>\n<ol>\n<li><a href=\"\/AVR-C-Code-UART.php\">AVR C UART Code<\/a><\/li>\n<li><a href=\"\/AVR-C-Code-keypad.php\">AVR C LCD Code<\/a><\/li>\n<li><a href=\"\/AVR-C-Code-LCD.php\">AVR C Keypad Code<\/a><\/li>\n<\/ol>\n<p>Apart from WinAVR C compiler, there are professional compilers that produce \u00a0smaller and faster code but they tend to be expensive. IAR do a free version of their compiler called Kick Start, which is limited to 4KB of output code. This is enough for most simple projects. Kanda Starter Kits include a book on getting going with embedded C programming.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The AVR microcontroller is excellent with C code because it was designed with C in mind. Atmel have also made it easy to use C in AVR Studio, as WinAVR compiler can run from within AVRStudio just like the assembler. Only a few years ago, using C compilers involved complicated commandline instructions and make files &hellip; <a href=\"https:\/\/www.kanda.com\/blog\/microcontrollers\/avr-microcontrollers\/avr-microcontroller-code\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">AVR Microcontroller C Code<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[18],"class_list":["post-43","post","type-post","status-publish","format-standard","placeholder-for-hentry","category-avr-microcontrollers","tag-avrtrainer"],"_links":{"self":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/43","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":6,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kanda.com\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}