avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] GCC Functions


From: Victor Sluiter
Subject: Re: [avr-gcc-list] GCC Functions
Date: Tue, 27 Nov 2001 09:50:29 +0100 (MET)

Hi Patrick!

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). The second thing is the use of '0x0', which would stand for binary
'0000'. Nothing wrong with four bits, but since the AVRs are 8-bit
microcontrollers it is better to always use 8-bit numbers, so that will be two 
hexadecimal
characters, ranging from 0x00 to 0xFF. You can of course use decimal numbers
from 0 to 255! 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. When I program something I start with 'typedef
unsigned char BYTE', so I only have to write 'BYTE' if I want to use an unsigned
char.

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..... A simple 'ledlight
= 0x01' in your led1() function will turn on the first LED on PORTB...

By the way, including interrupt.h has no use in this program, but it won't
harm it ...

Greetings, Victor


#include <io2313.h>

void led1(void);
unsigned char ledlight;

int main(void) {
  outp(0xff, DDRB);           // port B all outputs
  outp(0xff, PORTB);          // turn all leds off
  led1();
  for(;;){
    outp(ledlight, PORTB);        // turn led on
  }
}

void led1(void){
  ledlight = 0x01;
}



> It appears that when I start using functions the code stops working.  Why?
> 
> /*
> *************************************************************************
> avr-gcc -O0 -Wall -mmcu=at90s2313 -c demo2c.c -o demo1.o
> avr-gcc -o demo1.elf demo1.o
> avr-objcopy -O ihex demo1.elf demo1.hex
> **************************************************************************
> */
> 
> #include <io2313.h>
> #include <interrupt.h>
> 
> void led1(void);
> int ledlight;
> 
> int main(void) {
>   outp(0xff, DDRB);           // port B all outputs
>   outp(0xff, PORTB);          // turn all leds off
>   led1();
>   for(;;){
>     outp(ledlight, PORTB);        // turn led on
>   }
> }
> 
> void led1(void){
>   ledlight = 0x0;
> };
> 
> 
> Patrick Lanphier
> The Artemis Group
> http://www.artemisgroup.com
> phone: 814-235-0444
>   fax: 800-582-9710
> 
> 
> 
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
> 

-- 
-------------------------------------------------------
Een gewaarschuwd schizofreen telt voor vier.
      - Fons Jansen
-------------------------------------------------------

GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net




reply via email to

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