PDA

View Full Version : Question AVR Question: Low() High() explanation


DONGO
Sep 30, 2008, 10:52 PM
Hello,

I have a question about what Low() and High() do in AVR asembly. Most programs out there use it to set up the stack pointer and they do the following with the pretty standard comment next to it:

ldi SPL, low(RAMEND) ;stack pointer to RAMEND
ldi SPH, high(RAMEND)

I have seen low() and high() used else where as well, but haven't found a good discription of what exactly they are and what they do. Are they subroutines? What can go in the ()? What do they return or do? Are they defined somewhere were I can look at them (They aren't in the include file)? I've searched around but I mostly end up with, "sets the stack" or "sets the stack pointer to ramend" or something like that.

Thanks,

Daniel.

clicky
Oct 01, 2008, 03:52 AM
SPL and SPH are 8 bit registers. RAMEND is 16 bit (logical - constant) number.

low(RAMEND) takes low 8 bits of that constant while high(RAMEND) takes high 8 bits. Mind you - that conversion (low and high functions) are only directives to the assembler and everything happens way before code gets to the processor O: )

Where X is constant:
low(X) = X mod 256
high(X) = X div 256 assuming that X < 65536

Cheers,
Clicky

DONGO
Oct 01, 2008, 05:35 PM
Hey,

I got it now. Thanks Clicky.

Daniel.

clicky
Oct 02, 2008, 03:50 AM
Out of curiosity - what environment are you using for development (hardware/software)? I think I have found relatively good editor/compiler balance (aside of ability to debug, but that's different story) if you are interested...

DONGO
Oct 02, 2008, 07:21 PM
Out of curiosity - what environment are you using for development (hardware/software)? I think I have found relatively good editor/compiler balance (aside of ability to debug, but that's different story) if you are interested...


Hey,

I'm using the free programmer provided by Andrewm1937 seen here:

http://www.rcgroups.com/forums/showthread.php?t=630746

I am programing in assembly using AVR Studio.

Although I have programmed before, microcontrollers and assembly are new to me. When I use other people's examples I try to make sure I understand what the microcontroller is doing instead of just blindly copying the code without knowing what it does.

I wanted to use the reset pin on a Attiny45 as I/O but the programmer I have can't do that. Aside from that, the hardware/software I have works fine. I'm open to suggestions though.

Hope that answers your question.

Daniel.

fredhs
Oct 03, 2008, 01:54 AM
Hi Daniel,

programming "high fuse" bit 7 (RSTDISBL) provides access to the non-RESET functions of PB5. It is conceivable that your programming software does not let you change RSTDISBL, because removing the RESET function disables any further ISP. Only a high-voltage programmer can restore "normal" RESET functionality (and thereby ISProgrammability) when the RSTDISBL fuse is programmed.

Regards,

Fred

DONGO
Oct 03, 2008, 01:22 PM
Hi Daniel,

programming "high fuse" bit 7 (RSTDISBL) provides access to the non-RESET functions of PB5. It is conceivable that your programming software does not let you change RSTDISBL, because removing the RESET function disables any further ISP. Only a high-voltage programmer can restore "normal" RESET functionality (and thereby ISProgrammability) when the RSTDISBL fuse is programmed.

Regards,

Fred

Hi Fred,

That's the problem. I need a high-voltage programmer in order to utilize the reset pin if I want to program the chip multiple times. However, my use of the reset pin was for nothing critical, so I haven't bothered with it. If I really have to use it, I will look into a high-voltage programer.

Daniel.

fredhs
Oct 03, 2008, 02:46 PM
Hi Daniel,
... I will look into a high-voltage programer. ...
if you don't mind a little extra work building adapters for your favorite AVRs, I'd recommend the AVR Dragon, which is also capable of JTAG programming/debugging.

Regards,

Fred