AVR Assembler

Jun 23, 2006 9 Replies

I am using a mega8 and have 2 IR receivers connected to it on different pins. Is it possible to have the same routine to process each pin without having to have 2 nearly identical copies?



For instance, one routine uses sbic PINC,ExtIR



and the other uses sbic PIND,IntIR


-Mike


Sort of, but - off the top of my head - I think it will be slightly less speed/byte-efficient. At the entry to the routine, determine which pin you're interested in. Create a mask in a temp register that masks out all but that one bit. Use the mask instead of an immediate constant.

I think you'll be juggling values through read-modify-write scratch registers, though.

If you have a good macro assembler and it's duplicate source you're worried about rather than code space -- write a macro. The actual machine code will be duplicated, but you'll only be maintaining one bit of source.

Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html

anything is possible...

It is easier if they are pins on the same port, as then you can use a mask system (and can code up to 8 one-at-a-time IRs on one port ).

If they are on different ports, you will need conditional jumps around lines like your ones above.

If this is not carrier decode, but the lower speed data-decode, then you might simply put call GetIR_Bit's in the code whereever you tested a single pin, and then in the subroutine, selectively ready the physical pin.

-jg

Thanks for the replies.

I think a CheckPin routine will probably suit me best. I already have a Flags register with a couple of spare bits. Neither code space or speed are a problem. I just don't like code duplication.

The macro idea would be good but macros in AVR Studio seem too limited based on the small amount of documentation I can find.

-Mike

Yes, very well. I do this for 4 inputs. I maintain the data of each software uart in a datastructure. using the bst instruction, I get the state of the particular pin into the T bit, load a pointer to the appropraite datastructure into Z and call my soft-uart routine which processes the bit in T, storing the state and eventually received byte in the structure pointed to by Z. Given enough processing power, I can serve as many serial inputs I need with only one software-uart routine.

Meindert

Your problem is entirely in the realm of the psychological. Duplicate the code and be done with it. The result will be better performance and easier to understand souce code. Would anyone in his/her right mind ever call you on this? Any fool can parameterize a function, but only a chosen few can get the job done on time.

-- Joe Legris

And much worse to maintain. AVR studio is not the best programming environment to do it this way. Last time I tried it, it wouldn't accept local labels in a macro. So writing the same code 4 times is very tedious since you have to number all the labels.

Meindert

"Meindert Sprang" skrev i meddelandet news: snipped-for-privacy@corp.supernews.com...

It does now!

.listmac

.macro incr_loop foo: inc @0 cpi @0, @1 breq foo .endm

.macro decr_loop foo: dec @0 cpi @0, @1 brne foo .endm

reset: rjmp foo .org 0x100 foo:

incr_loop r16,0 decr_loop r17,1 incr_loop r18,2 rjmp foo

------ Output of *,map

AVRASM ver. 2.1.5 D:\Dokument\project\AVR\Test\local_label\local_label.asm Tue Jul 04 20:57:46 2006

CSEG reset 00000000 CSEG foo 00000100 CSEG foo@incr_loop@23 00000100 CSEG foo@decr_loop@30 00000103 CSEG foo@incr_loop@37 00000106

Best Regards, Ulf Samuelsson This is intended to be my personal opinion which may, or may not be shared by my employer Atmel Nordic AB

tedious

Very good! But too late, I switched to Imagecraft two years ago ;-)

Meindert

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required