User defined flags in AVR memory - possible?

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

Hello friends,

I had been using 8051 controllers, which have several general purpose bits in the RAM that can be set, cleared and tested for conditional loops. In the AVR series (specially Atmega 64/128) such bits are not available. In order to have flags the only method I see is to reserve a complete byte in RAM of AVR. Other bits of this byte may be used as other flags, but the code increases. Is there any method of having such user defined flags, which can be set/reset etc, with very less code?

Thanks

Parthasaradhi Nayani

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

You said RAM, but did you mean registers?

Imagecraft compiler user

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

Nope not registers! I mean the RAM in the chip. AVR provides IO space bit set/reset functions. What I am looking for is something similar but in RAM. One way to test a bit in that byte is to mask off the unwanted bits and then check if the bit is 0 or 1. But this proces takes a lot of code, instead is there any simpler method of testing/setting/resetting a bit in a byte of RAM?

Regards

Parthasaradhi Nayani

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

check out the SBRC and SBRS instructions

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

with the AVR you probably WILL want to use the general purpose registers (note that they're seperate from IO registers, which use IN/OUT/etc to access). since there are 32 of 'em surely there are a few you're not using that you can use for flags.

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

Do not fall into the trap of comparing an operation with the 8051 and the AVR, say that the AVR takes a lot of code to carry out the same operation, then fall into the it takes longer pit. If you do a compare in real time of setting or clearing a bit in a ram location within the AVR and deciding if that bit is set or cleared against the cycles per operation of the 8051, you may decide it is just not an issue.
Mike

Keep it simple it will not bite as hard