Re: [AVR-Chat] Re: Sample "c" code
2007-06-18 by np np
Never thought I would hear the day when someone slagged off macros. Much of my PIC code was macros. 16 bit add's, BNC, BNE, BGE etc etc load16bits etc etc etc For me it got rid of silly mistakes. Its not needed so much no C is used a lot.
Show quoted textHide quoted text
----- Original Message ----
From: "microbrix@gmail.com" <microbrix@gmail.com>
To: AVR-Chat@yahoogroups.com
Sent: Monday, 18 June, 2007 4:49:08 PM
Subject: Re: [AVR-Chat] Re: Sample "c" code
i've never been a big fan of macros. i like to see the actual code.
normally there's only a few points in the code that actually talk to
the i/o directly anyway, so just fixing them by hand is easy.
On 6/18/07, Don Kinzer <dkinzer@easystreet. com> wrote:
> --- In AVR-Chat@yahoogroup s.com, "David VanHorn" <microbrix@. ..>
> wrote:
> > One easy way to code it, is to use IN and OUT everywhere,
> > and fix them when the assembler complains.
>
> A more efficient alternative is to use a macro that expands to
> either IN/OUT or LDS/STS depending on the port address. This method
> has the additional advantage of automatically using the shortest
> instruction for the AVR you're using.
>
> An example GNU Assembler macro for input is shown below. The
> corresponding macro for output is similar. If you are using the AVR
> assembler you may be able to implement something like this.
>
> // Macro to input from an I/O port to a register. Example use:
> //
> // inPort r24, UDR0
> //
> .macro inPort _reg, _port
> .if (_SFR_IO_ADDR( \_port) < 64)
> in \_reg, _SFR_IO_ADDR( \_port)
> .else
> lds \_reg, \_port
> .endif
> .endm
>
> Don Kinzer
> ZBasic Microcontrollers
> http://www.zbasic. net
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
<!--