mcuhost 发表于 2007-12-28 11:38:32

马老师,晚辈向您请教,有关avr寄存器的问题

To write a word to the Page Buffer, load the word into the R1:R0 Registers. Set the Zregister
to point to the correct word and set only the SPMEN bit in the SPMCR Register.
The SPM instruction must then be executed within four cycles.
程序实现为:
void boot_page_fill(unsigned int address,int data)
{
    asm("mov r30,r16\n"   
      "mov r31,r17\n"   //前两句是使z寄存器指向要写入的字 即: Set the Zregister to point to the correct word         
      "mov r0,r18\n"
      "mov r1,r19\n"); //这句话应该是把上面要写入的字,存入r0,r1寄存器 即:load the word into the R1:R0 Registers            
    SPMCSR = 0x01;       //set only the SPMEN bit in the SPMCR Register
    asm("spm\n");
}

我想问的是,r16,r17和 r18,r19有什么关系? 我觉得r18,r19要是换成了r17,r18倒是和手册中说的一样了呢?

马老师请指教!

第二个问题:
The Z-register is used to select the page to be erased. Set up the Z-register to point to a
byte in the page to be erased. The lower bits selecting the byte within the page are
ignored. For instance, on a device with a page size of 32 words (64 bytes), the lower six
bits of the Z-register are ignored.

其中:
上面提到的例子,为什么z寄存器的低6位被忽略?

谢谢马老师!!

machao 发表于 2007-12-29 02:05:48

第1个问题:
英文说明: R0.R1中要写的数据,Z寄存器是地址.

下面的程序是我编写的<M128>书中的例子,是在ICC平台下嵌入汇编的函数:

void boot_page_fill(unsigned int address,int data)   
{   
    asm("mov r30,r16\n"   
      "mov r31,r17\n"   //前两句是使z寄存器指向要写入的字 即: Set the Zregister to point to the correct word            
      "mov r0,r18\n"   
      "mov r1,r19\n"); //这句话应该是把上面要写入的字,存入r0,r1寄存器 即:load the word into the R1:R0 Registers            
    SPMCSR = 0x01;       //set only the SPMEN bit in the SPMCR Register
    asm("spm\n");   
}   

在ICC中,调用函数时,第一个参数是使用R16.R17传递的,第2个参数是使用r18.r19传递的(参见ICC的所带的使用帮助).
第1个参数为地址,放入Z寄存器中(r30.r31),第2个参数是数据,放入r0.r1中,后面就是英文所讲的,写入到FLASH中.

第2个问题:
AVR中写FLASH的操作是按页操作的,不同的AVR,每页所含的单元不一样.如果一个页有64个字节(32字)那么需要6个BIT表示.
对FLASH操作时,Z寄存器中为FLASH的地址.因此低6位表示64个字节(实际1-5位表示字地址,0位表示高位字节或低位字节).而高位表示页地址.对于擦除FLASH的操作,是整页擦除的,因此只需要高位的页地址,低6位没有意义了.

mcuhost 发表于 2008-1-4 13:24:30

真的很感谢马老师,马老师这么晚还在工作,真是可敬啊!
页: [1]
查看完整版本: 马老师,晚辈向您请教,有关avr寄存器的问题