[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] GCC Functions

From: Joerg Wunsch
Subject: Re: [avr-gcc-list] GCC Functions
Date: Tue, 27 Nov 2001 13:48:37 +0100 (MET)

Victor Sluiter <address@hidden> wrote:

> First of all some notes on your code... When you end a function it
> is at least unusual to end it with a semicolon (might even be
> erronous - I've never tried).

It's causing a global null declaration.  But you're right, it's bad
style, i didn't spot this.

> The second thing is the use of '0x0', which would stand for binary
> '0000'.

Nope.  0x0 is another expression for the integer constant 0, as well
as 0x0000 or 000 would be.  Syntactically, it has the size of a
default integer for the target machine, 16 bits in our case.

There's no way to express a »plain« 4-bit constant or variable in
avr-gcc.  (You can declare a bit field variable that is four bits
wide, but that looks quite more complicated.)

> By the way, you declared 'ledlight' as an integerer (int), which is
> a 16-bit number. it is better to use an unsigned char, which is an
> 8-bit number, from 0 to 255.

That's basically right, however.  Btw., the avr-gcc header files
declare the type "uint8_t", it's certainly good practice to use it.
Unlike BYTE (which can have a meaning other than 8 bits for some
people -- ever wondered why all the network standards talk about
"octets", not "bytes"?), it immediately tells the reader something
about the implied bit width of the variable.

> So much for the grammar :-).... The 'error' in your code, is that
> 'ledlight' never gets a value higher than zero. That means, that the
> value on PORTB never gets higher than zero, and the LEDs won't turn
> on.

No, that wasn't an error.  PORTB has been sent out a 0xff initially,
so the first outp(0, PORTB) changes this to 0.  Of course, whether
this turns the LEDs on or off depends on whether the LED is connected
between the output pin and Vcc or the output pin and GND.

J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]