Ok, I wrote one. My first c program. I did it first in programmers notepad, compiled with winAVR, then played a little in Studio REgardless, it does what I expected, and I have a few questions.
First the code:
//Tiny2313 i/o...my first c program #includemain(void) {//set port b as outputs port d as inputs DDRB= 0xff; DDRD = 0x00; while(1) { PORTB = PIND; } }
No biggie, portb reflects portd. It works.
My first question is the compiler in WinAVR kicked up a fuss and said something about ddrb, ddrd, portb, portd, pind as undefined. I made everything capitals as you see above and that went away.
Why can't you use lower case?
Second thing I saw in the WinAVR compiler was a warning that "return type defaults to 'int'"
I noticed that if I put 'int' before main that warning goes away.
Since this was not a numerical function I assumed that int was not needed...Am I wrong?
When I created a gcc project in studio I pointed to a new folder that had my .c and makefile in it, and there was everything I did in programmers notepad. OK, I went and hit COMPILE in Studio and got this back in the BUILD window:
mmcu=attiny2313 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT 2313_first.o -MF dep/2313_first.o.d -c ../2313_first.c
/usr/bin/sh: -Wall: command not found
make: [2313_first.o] Error 127 (ignored)
Build succeeded with 0 Warnings...
The program loaded into the Tiny and runs fine. What is that error 127(ignored) about?
also, in assembler there is usually a command at the end of the code that says jump back to the beginning...something like RJMP BEGIN to tell the AVR to start over, or in the case of branches etc, to jump back to the beginning. Where is that in C? To me this program looks like it runs off the end of the flas then starts over which kind of is silly.
Am I missing something?
Enlighten me away!! :)