A few questions I still have.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This a list of questions I still have about AVR programming that I have not been able to answer on my own.

#1
Often I see a SFR set using syntax like this: ldi r16, (1>>SFR1|2>>SFR2). I am having trouble understanding the full functionality of this but I understand how it basically works provided the number is only a 1. Anything above I don’t understand. Could anyone help me with this? Pointing me to a resource will be great. I have had a hard time searching for it because it contains no searchable terms and I don’t know the name for this method. I have only seen it used. I also don’t believe it is in the AVR Studio help file unless it is in a corner I haven’t look in yet.

#2
Sometimes I see the terms ‘high register’ and ‘low register’. I am wondering what these are and why they are significant.

#3
I sometimes see the routine the reset vector points to at the very bottom of the code. I’m just wondering why this is. My guess is that this is a failsafe in case, for whatever reason the program counter falls through the end of the code. In which case it would run into the initialization block and pretty much end up doing a reset.

#4
A couple of people have told me that it is wise to include something like this when programming a wait routine for the 8051:

Loop: sjmp, $
sjmp Loop

The second sjmp is there as a backup in the unlikely event (@ 1Mhz, unlikely events suddenly become likely ;) ) that the value pushed onto the stack is the address just after the sjmp instruction instead of address of the loop label. I haven’t seen this in any AVR program, I haven’t seen it in a lot of 8051 Programs either, actually. I’m wondering if this is true for the 8051, and more importantly, if it’s true for the AVR.

Thank you for any help you may be able to offer.

Will

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wilbertone wrote:
Often I see a SFR set using syntax like this: ldi r16, (1>>SFR1|2>>SFR2).

I think it's probably somethine more like: ldi r16, (1<<SFR1|1<<SFR2). Basically, this syntax is being used to set specific bits in a register. When you have something like 1<<4, this means shift a 1 bit four positions to the left. Thus 0b00000001 becomes 0b00010000. So why would you want to do something like this? It's because in the AVR family, many times register bit positions change from one device to another, but the name stays the same. For example, a UART receive interrupt might be in bit position 3 in one device but bit position 5 in another. To keep from having to change your code when you change devices, you can simply refer to the bit position as (1<<RXCIE) and let your MCU definition pull in the correct definition file that sets the bit position.

wilbertone wrote:
Sometimes I see the terms ‘high register’ and ‘low register’. I am wondering what these are and why they are significant.

Registers in the AVR family are 8 bits wide. However, sometimes you may need to work with a 16 bit value, such as when you are using the value as a memory address. The AVR architecture allows you to create up to three16 bit registers from a pair of 8 bit registers; r26 and r27 can be combined to become the 'X' register, r28 and r29 become the 'Y' register, and r30 and r31 become the 'Z' register.

wilbertone wrote:
I sometimes see the routine the reset vector points to at the very bottom of the code. I’m just wondering why this is.

If you are not using interrupts, the only thing you really need is the reset vector, which is located at location 0x0000. If you are using interrupts, this area will consist of jump vectors to the appropriate code; if you're not, this can be code area.

wilbertone wrote:
A couple of people have told me that it is wise to include something like this when programming a wait routine for the 8051:

Loop: sjmp, $
sjmp Loop

I've got no idea about this one.

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#1 has had some detailed explanations in past threads. See if you can search them out.

#2 It >>might<< be what dharper suggested--the combination of the two registers to make 16-bits--but dpending on the context it is probably the distinction between registers 0-15 and registers 16-31. The AVR instruction set is not totally orthoganal, and certain instructions are only allowed certain registers for operands. [If you look at the bit encoding for the instruction, you may find only 4 bits for register designation.] An perfect example is LDI--only a "high" register 16-31 can be the destination.

#3 Where you put the destination of your vectors is up to you or your compiler. Are you referring to an example that has it at the end of the code in flash, or at the very end of flash with intervening empty space? A reason to have it near the end is for bootloading purposes.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you both for your help. That clears things up.

Regards,

Will