help with interrupt and registers

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

help with interrupt and registers

Post by ulao » Sun Jul 26, 2009 12:47 am

Just want to make sure I have this understood right


is this right
cli()
//doing stuff here will be done with the usb interrupt disabled
// you have 25 clocks to do what you need with a 12mhz
sei()


also what registers are safe? I found this helpful guide
http://www.nongnu.org/avr-libc/user-man ... _reg_usage
under "What registers are used by the C compiler?"
I gathered form this info that a few groups of registers are ok to use., namely(r18-r27, r30-r31):
but when using them my data seems to be a bit random. and some of those registers seem to cause issues when changed.

Assuming I'm using the registers right, what registers can I use? I really need a few 8 bits or possible two 32 bits. Is there any info around here that would show what is available and what data types they are?

another thing I dont understand is how to init these registers with data?

If I do

Code: Select all

   register int *result1 asm ("r26")= 0xff  ;
   register int *result2 asm ("r30")= 0xff ;

I get that data put in there, but I can no longer change them when I do something like..

Code: Select all

   asm volatile
   (
   "in  r21, %0\n"// get data from port c
   "BST r21, 5 \n"//put the 5th bit
   "BLD r26, 0 \n"//into r26 0th bit.
   "BST r21, 4 \n"//put the 4th bit
   "BLD r30, 0 \n"//into r30 0th bit
   : : "I" (_SFR_IO_ADDR(PINC))    );

Te data stays at FF , did I do something wrong?



BTW: I have an atmega 168

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: help with interrupt and registers

Post by christian » Thu Aug 06, 2009 3:50 pm

Maybe you're mixing infos here. Most of the high registers are used by the compiler and you can use them in your inline assembler as well (if you tell the compiler that you modify them). However, if you need a static or global variable in a register, you must choose something below r8 (and not r0 and not r1). The compiler may still need these registers, but it's rather unlikely if you don't use floating point.

Post Reply