Sign in

username:

password:



Not a member?

Search avrclub



Search tips

Subscribe to avrclub



avrclub by Keywords

AT90S2313 | AT90S8515 | ATMega | ATmega128 | ECL | FETS | IAR | Keyboard | LCD | STK50 | TMOS | UART

Ads

Discussion Groups

Discussion Groups | AVRclub | Re: [AVR club] writing the code in C

Atmel AVR Microcontroller discussion group.

writing the code in C - Eric - Jun 8 9:53:00 2004

Hi
Does anybody write their code in C?
A few years ago I did C and C++, quite a few years ago I was right up to
speed in writing code for 6802 micro in Hexadecimal, but I seem to need
a bit of help with writing a bit of basic code in C for these micro's.
Are there any tutorials around.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07-Jun-04




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )


Re: [AVR club] writing the code in C - John Johnson - Jun 8 17:20:00 2004

Yes, I C :-)

If you're using Windows, look for WinAVR, it's a really nice package.
There is a learning curve with gcc-avr, as there is with any language.
It is nice when you get used to it though.

Check out www.avrfreaks.net, it's a great resource. You can get WinAVR
there as well.

Regards,
JJ

On Tuesday, June 8, 2004, at 09:53 AM, Eric wrote:

> Hi
> Does anybody write their code in C?
> A few years ago I did C and C++, quite a few years ago I was right up
> to
> speed in writing code for 6802 micro in Hexadecimal, but I seem to need
> a bit of help with writing a bit of basic code in C for these micro's.
> Are there any tutorials around. >
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.701 / Virus Database: 458 - Release Date: 07-Jun-04 > Yahoo! Groups Links





(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - David Jones - Jun 8 19:19:00 2004

>>> erichards@eric... 08/06/2004 11:53:09 pm >>>
>Hi
>Does anybody write their code in C?
>A few years ago I did C and C++, quite a few years ago I was right up
to
>speed in writing code for 6802 micro in Hexadecimal, but I seem to
need
>a bit of help with writing a bit of basic code in C for these
micro's.
>Are there any tutorials around.

Personally I don't know why anyone would program in pure assembler any
more except unless absolutely necessary. The higher level languages like
C allow for quicker development time and much more maintainable code. I
would hazard a guess that the majority of micro programmers out there
today are using C.

90% of your C code will be the same regardless of what C compiler you
use, so any C tutorial or book will help you in that respect, a Google
search should brign up plenty. The other 10% of code will be different
for every package out there because they will each have a different way
to handle access to the peripherals (ADC, UART, PWM etc) and I/O ports
etc.

I have just started using CodeVision for the AVR and it's really easy
to use with it's "code wizard", which generates and entire working base
program for you, with all your peripherals and interrupt routines set up
for you automatically.

As a beginner I would avoid gcc-avr as it is very difficult and
daunting to setup and use initially.

Regards
Dave :)





(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - Mark Jordan - Jun 8 23:13:00 2004


Hi,

AVR assembler is my third language. :-))
I do things in assembler that can't be made in C.
Not in the time available.
And the AVR assembler is so easy to write!

Mark Jordan

On 9 Jun 2004 at 9:19, David Jones wrote:

> Personally I don't know why anyone would program in pure assembler any
> more except unless absolutely necessary.




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - Zack Widup - Jun 9 0:39:00 2004

I tried programming a PIC with C a few times and then wrote the same
programs in MPASM. Due to the little tricks I'd learned in programming
with the assembler language and due to unneeded repetition in the C
generated code, my MPASM program was about 4/5 the size of the C
generated code. I write programs in assembler mainly because I'm trying
to conserve space in the program memory.

I haven't tried this with an AVR yet but I'm assuming the same thing will
happen. When you learn to "think like" the microcontroller with its
native assembler, there are lots of little tricks and shortcuts you can
take that the higher level program won't do.

Zack On Wed, 9 Jun 2004, Mark Jordan wrote: > Hi,
>
> AVR assembler is my third language. :-))
> I do things in assembler that can't be made in C.
> Not in the time available.
> And the AVR assembler is so easy to write!
>
> Mark Jordan
>
> On 9 Jun 2004 at 9:19, David Jones wrote:
>
> > Personally I don't know why anyone would program in pure assembler any
> > more except unless absolutely necessary.




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - David Jones - Jun 9 2:05:00 2004

Of course.
But a high level language like C without question allows greater speed
and ease in program development, debugging, formal testing and
maintenance.
Try writing, debugging, testing and coming back in 12 months time (with
a different person) to modify a 10,000 line assembly language program -
it's suicide. Professional microcontroller programming is done using C
for all these reasons.

Yes, assembly is good for speed - if you know what you are doing. But
in many cases there are only a few small routines in your code that are
actually time critical, and in these cases a mixture of C and assembly
works great. You get the benefits of high level language with the
benefits of assembler for the tight spots.

Also, try doing complex stuff like floating point processing using
assembler and you'll quickly throw your hands up in disgust. I've done
it and it's ugly!. It's so much easier to simply go var1=var2+3.141 etc.
Not to mention string formatting with printf etc.

As for file size, yes, a tightly coded assembly program can be smaller,
by up to the margins you suggest. But a 10-20% saving in code space is
not that important if you choose a sensibly speced micro to begin with.
I almost always choose a micro with extra program capacity so that I can
add more features later if need be.

Most micro programmers I know (myself included) don't bother with
assembly above about the 1K mark. As it's then that it starts to get
very unwieldy. I certainly wouldn't touch it for anything that involves
floating point or other complex processing.

Regards
Dave :)

>>> w9sz@w9sz... 09/06/2004 2:39:05 pm >>>
I tried programming a PIC with C a few times and then wrote the same
programs in MPASM. Due to the little tricks I'd learned in programming

with the assembler language and due to unneeded repetition in the C
generated code, my MPASM program was about 4/5 the size of the C
generated code. I write programs in assembler mainly because I'm
trying
to conserve space in the program memory.

I haven't tried this with an AVR yet but I'm assuming the same thing
will
happen. When you learn to "think like" the microcontroller with its
native assembler, there are lots of little tricks and shortcuts you can

take that the higher level program won't do.

Zack On Wed, 9 Jun 2004, Mark Jordan wrote: > Hi,
>
> AVR assembler is my third language. :-))
> I do things in assembler that can't be made in C.
> Not in the time available.
> And the AVR assembler is so easy to write!
>
> Mark Jordan
>
> On 9 Jun 2004 at 9:19, David Jones wrote:
>
> > Personally I don't know why anyone would program in pure assembler
any
> > more except unless absolutely necessary.

Yahoo! Groups Links




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: writing the code in C - Graham Davies - Jun 9 16:08:00 2004

--- In avrclub@avrc..., Eric <erichards@c...> wrote:

> Does anybody write their code in C? ...

Obviously, from other replies, they do. I definitely do. Whether
you should depends on your goals. If you want to create a lot of
functionality in a short time and be able to maintain it easily, use
C. If you want to squeeze a lot into a small amount of memory or push
the execution speed limit, use assembly. If you just want to test the
waters around MCU programming in C, I think you will find them warm
and comfortable.

Regarding WinAVR (AVR-GCC) being hard to use, this is true but you
can't beat the price (free). It is what I use and I didn't really
have much trouble. Don't install it in a directory with a space in
the pathname. Browse around all the documentation before you start,
some information is in unexpected places. Read everything
entitled "frequently asked questions" from start to finish. If you
don't like it, you can always throw it out and you've only lost some
time.

Graham.




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] Re: writing the code in C - mpdickens - Jun 9 16:50:00 2004


> Regarding WinAVR (AVR-GCC) being hard to use, this
> is true

I think that what should be said about winavr is that:

1.) Winavr can be (Not always...) hard to set up.
This portion of using winavr is dependent on
the version of windows, what the windows
installation is like (Is it a mess?) and
the version of winavr being installed. Also,
installation can be dependent on the skill level
of the user regarding software installation (Just
like any other software).
2.) Many first time users of winavr are not familiar
with unix make files. Learning to use make files
can have a learning curve (Although, not much of
one).

Other than these issues, I've never had a problem with
gcc for the avr (On windows or linux). Regards

Marvin Dickens

=====
Registered Linux User No. 80253
If you use linux, get counted at:
http://www.linuxcounter.org

__________________________________





(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] Re: writing the code in C - Alex Gibson - Jun 13 8:53:00 2004

For those who want to use win avr
but have hassles setting it up
pay the few dollars and get atmanavr

http://www.atmanecl.com/EnglishSite/SoftwareEnglish.htm

Always get a few people complaining that it should be free.

But for those who have trouble with setting up winavr
it would be worth it.

Would be nice if the registration for it was a bit more
flexible though For those who want a free ide, there are a few

http://www.avrside.fr.pl/eng/ind_eng.html

another option is bloodshed / dev c++ as the ide
www.bloodshed.net/devcpp.html

http://www.fixedsys.com/context
http://www.fixedsys.com/context/download.html
has a ton of files forhighlighting

others are using eclipse
http://www.eclipse.org/
http://www.eclipse.org/community/plugins.html

non free - sharware

my old favourite textpad www.textpad.com
similar to context

non free
http://www.amctools.com/vmlab.htm
http://www.amctools.com/download.htm
The other real pain with make files and gcc versions is when
you have multiple versions of gcc.
eg at the moment I have installed

normal cygwin , cygwin + arm gcc , mingw + msys , winavr ,
arm gcc 3 versions(keil, croswworks and armmingw) ,
microchips c30 compiler (modified gcc)

The installs for some of these drive me nuts as they add
themselves to the path.
So after installing a new version and forgetting to remove
the path entries, go to make a windows project
and win avr gets used or arm gcc.

Thinking of when the via nano itx boards (12cm by 12cm) come
out of getting a couple and having seperate boxes for
different tools.

windows
1 for arm
1 for pic , avr and 8051

1 for linux or freebsd

+ a 4 way kvm switch

keep exisitng boxes
for windows dev + cad and other software(protel, xilinx,
altera, matlab etc)

Alex

mpdickens wrote: >
>>Regarding WinAVR (AVR-GCC) being hard to use, this
>>is true > I think that what should be said about winavr is that:
>
> 1.) Winavr can be (Not always...) hard to set up.
> This portion of using winavr is dependent on
> the version of windows, what the windows
> installation is like (Is it a mess?) and
> the version of winavr being installed. Also,
> installation can be dependent on the skill level
> of the user regarding software installation (Just
> like any other software).
> 2.) Many first time users of winavr are not familiar
> with unix make files. Learning to use make files
> can have a learning curve (Although, not much of
> one).
>
> Other than these issues, I've never had a problem with
> gcc for the avr (On windows or linux). > Regards
>
> Marvin Dickens




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - Alex Gibson - Jun 13 9:38:00 2004

Eric wrote:
> Hi
> Does anybody write their code in C?
> A few years ago I did C and C++, quite a few years ago I was right up to
> speed in writing code for 6802 micro in Hexadecimal, but I seem to need
> a bit of help with writing a bit of basic code in C for these micro's.
> Are there any tutorials around.

For pics I use asm , some c and jal(bit like pascal).
Avr basic or c usually. Arm7 c.

Remembering more than one asm language is the hassle for
me.Pic is easy enough and I use it regularly.
Just started learning asm for dspic.

16f pics 35 asm instructions 14 bit instructions 8 bit data

18f pics 77 asm instructions 16 bit instructions , 8 bit data

dspic 84 base instructions + dsp 24 bit instruction
word(some instructions double word)
40 bit accumulator, 17x17 bit int / frac multiplier

avr 115 asm instructions

8051 approx 44 ?? not sure

arm7 16 bit thumb approx 104
32 bit arm approx 97

differs depending on implementation
and peripheral features. most of the arm7 chips like the
philips lpc2000 have both arm and thumb instruction sets.

Learning one instruction for one architecture is enough
thanks, unless someone is going to pay me to.

Comes down to what you need to do, and what the
considerations are.

Micro code size, cost of tools, does the code need to be
reusable, number of micros or units to be shipped , time to
write the code ?

That is why there are still lots of 4 bit micros being used
and shipped, programmed in asm or forth.
Comes down to cost for those projects, saving a few cents
can make a major difference to the amount of profit.

For smaller companies / smaller projects
using a larger micro with more resources and
using a hll makes it easier and quicker, but
those aren't always the requirements. Alex




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )

Re: [AVR club] writing the code in C - John Johnson - Jun 13 11:26:00 2004

C has been called the "Portable Assembler."

I guess that could be a compliment, or not :-)

Regards,
JJ

On Sunday, June 13, 2004, at 09:38 AM, Alex Gibson wrote:

> Eric wrote:
>> Hi
>> Does anybody write their code in C?
>> A few years ago I did C and C++, quite a few years ago I was right up
>> to
>> speed in writing code for 6802 micro in Hexadecimal, but I seem to
>> need
>> a bit of help with writing a bit of basic code in C for these micro's.
>> Are there any tutorials around.
>
> For pics I use asm , some c and jal(bit like pascal).
> Avr basic or c usually. Arm7 c.
>
> Remembering more than one asm language is the hassle for
> me.Pic is easy enough and I use it regularly.
> Just started learning asm for dspic.




(You need to be a member of avrclub -- send a blank email to avrclub-subscribe@yahoogroups.com )