Smiley's Quick Start Guide for butterfly

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Guys!

I just purchased Smily's "C Programming for
Microcontrollers" and so far it has been a fun read. I have a question about the quick start guide. I would email him directly but he chooses to have questions posted here

Quote:

I think it benefits the community to keep all technical questions public. I have chosen www.AVRFeaks.net to respond to questions so that if someone else has the same question they might find it by searching that forum, using Google, by entering your search terms and following it with site:www.avrfreaks.net.

So, I went through the quick start and made made a new "Blinky" folder and the "Blinky" program

//Blinky.c

#include 
#include 

int main (void)
{
	//set PORTD for output
	DDRD = 0xFF;
	
		while(1)  {
		
				for(int i =1; i < 128; i = i*2)
				
				{
					PORTD = i;
					_delay_loop_2(30000);
				}
				
				for(int i =128; i > 1; i -= i/2)
				
				{
					PORTD = i;
					_delay_loop_2(30000);
				}
			}
			return 1;
		}

and copied the makefile to the Blinky folder and changed

these lines

Quote:

MCU = atmega169
FORMAT = ihex
TARGET = Blinky

And went to tools>Make All

and got this in the log

Quote:

> "make.exe" all

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/usr/bin/sh: test: Blinky: binary operator expected
avr-gcc -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./Blinky.lst -std=gnu99 -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-exceptions -Wall -Wundef -Wa,-adhlns=Blinky.c -Wl,-Map=Blinky .map,--cref -lm Blinky.c -o Blinky
In file included from Blinky.c:3:
c:/winavr-20100110/lib/gcc/../../avr/include/avr/io.h:404:6: warning: #warning "device type not defined"
In file included from Blinky.c:4:
c:/winavr-20100110/lib/gcc/../../avr/include/avr/delay.h:36:2: warning: #warning "This file has been moved to ."
Blinky.c: In function 'main':
Blinky.c:9: error: 'DDRD' undeclared (first use in this function)
Blinky.c:9: error: (Each undeclared identifier is reported only once
Blinky.c:9: error: for each function it appears in.)
Blinky.c:16: error: 'PORTD' undeclared (first use in this function)
avr-gcc: .map,--cref: No such file or directory
make.exe: *** [Blinky] Error 1

> Process Exit Code: 2
> Time Taken: 00:00

I took a look at io.h and found that it points to the other ioxxx.h files based on what micro you have. I double checked the makefile to make sure I have a atmega169 and I did. Not knowing what to do, I thought I would just try iom169.h since that's what it should be pointing to. I also changed the director for delay.h

Now I have this

//Blinky.c

#include 
#include 

int main (void)
{
	//set PORTD for output
	DDRD = 0xFF;
	
		while(1)  {
		
				for(int i =1; i < 128; i = i*2)
				
				{
					PORTD = i;
					_delay_loop_2(30000);
				}
				
				for(int i =128; i > 1; i -= i/2)
				
				{
					PORTD = i;
					_delay_loop_2(30000);
				}
			}
			return 1;
		}

but I still get errors

Quote:

> "make.exe" all

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/usr/bin/sh: test: Blinky: binary operator expected
avr-gcc -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./Blinky.lst -std=gnu99 -gdwarf-2 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -fno-exceptions -Wall -Wundef -Wa,-adhlns=Blinky.c -Wl,-Map=Blinky .map,--cref -lm Blinky.c -o Blinky
In file included from Blinky.c:3:
c:/winavr-20100110/lib/gcc/../../avr/include/avr/iom169.h:45:4: error: #error "Include instead of this file."
Blinky.c: In function 'main':
Blinky.c:9: warning: implicit declaration of function '_SFR_IO8'
Blinky.c:9: error: lvalue required as left operand of assignment
Blinky.c:16: error: lvalue required as left operand of assignment
Blinky.c:23: error: lvalue required as left operand of assignment
avr-gcc: .map,--cref: No such file or directory
make.exe: *** [Blinky] Error 1

> Process Exit Code: 2
> Time Taken: 00:01

I don't know what these errors mean. Do they all need to be resolved before it will make the Blinky.hex? Sorry for the noob questions but I bought this book for a reason and this is the authors choice to have questions posted.

I'm wondering if my OS (Win7 64) or WinAVR ver (WinAVR-20100110) may not be compatible with this quick start guide.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your problem is that there is no -mcu= option on the command line.

Quote:
and copied the makefile to the Blinky folder and changed
Where does the Makefile come from?

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Compilation errors
This is usually a symptom of two things, one is using a more recent version of WinAVR with the original code, by folks who didn't read this from page 18 of the book:

Quote:
...by the time you install all this software, the WinAVR and the AVRStudio will have new and improved versions available on their web sites. DON’T USE THEM! This text is based on the versions on the CD or on the SmileyMicros.com web site and using the new and improved software may only confuse things. Of course, by the time you finish this text, you will be encouraged to get the latest and greatest, by then you’ll know all you need to use it wisely.

I later relented and added this to the book webpage:

Quote:

If you want to use Windows Vista or the newer versions of WinAVR PLEASE READ THIS
That links to this:
Quote:
Using the Newer WinAVR or Windows Vista
If you want to use Windows Vista or the newer versions of WinAVR PLEASE READ THIS:

You don’t need to upgrade anything to use the book or learn C programming, but some people want to use the newer WinAVR and it may be necessary on some Vista installations, so I’ve written a ‘New Quick Start Guide’ and upgraded the source code ‘Source Code the Next Generation’ both available on the downloads menu to your left.

The upgraded project source code will not exactly match the original source code in the book. The differences are mainly in header files and register name changes that are of no import to learning C.

The original Quick Start Guide was a barely modified reprint of the first three chapter of the book C Programming for Microcontrollers by Joe Pardue. It was intended to allow the reader to get a feel for the book before purchasing. It also provided, in Chapter 2, a guide to getting the Butterfly set up for use with the older version of the free WinAVR C compiler toolset and AVRStudio (and a few other things – all on the CD and on www.smileymicros.com). In the ‘New Quick Start Guide’ Chapters 1 and 3 are the same as in the book, but Chapter 2 is totally rewritten to show how to use the new stuff.

I personally recommend using the Classic Stuff and the old WinAVR and Programmer's Notepad, but if you want to use the newer WinAVR you will need to download the 'New Quick Start Guide' from the downloads menu.

Reading this will probably relieve your symptoms.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the reply!

sternst wrote:
Where does the Makefile come from?

I copied the makefile from

C:\WinAVR-20100110\sample

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Smiley,

I figured it was something that simple but couldn't figure it out. I had already installed WinAVR so glossed over that paragraph. Also, I bought the ebook so didn't have a CD. I'm sure this will fix the problem Thanks for the great customer service!

Last Edited: Fri. Feb 3, 2012 - 09:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HyrumF wrote:
I copied the makefile from

C:\WinAVR-20100110\sample

Then you changed more than this (perhaps by accident)

MCU = atmega169
FORMAT = ihex
TARGET = Blinky 

Copy it again. If it still don't work, post the Makefile here.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HyrumF wrote:
Smiley,

That's I figured it was something that simple but couldn't figure it out. I had already installed WinAVR so glossed over that paragraph. Also, I bought the ebook so didn't have a CD. I'm sure this will fix the problem Thanks for the great customer service!

the CD stuff is all on my website under downloads. I'd suggest you get the 'Next Generation' stuff so you can use the newer WinAVR etc.

Smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Where is your "make.exe" from?
If you have WinAVR installed, you can use

which make.exe

in the directory where you originally run the "make.exe" command.

JW