跪求大神指导!!!我把这个boot loader程序烧进去为什么看不到从0x0080~0x0100处从0~127!!!求大神指导我错在哪里!!!我不甚感激 谢谢你了
#include "iom16v.h"
#include "macros.h"
#define Con_true 1
void iap (void);
union char_int
{
unsigned char chr_dat[2];
unsigned int int_dat;
};
#define char_h 1
#define char_l 0
void write_rw_ok(void)
{
while(SPMCR&0x40)
{
while(SPMCR&0x01);
SPMCR=0x11;
asm("spm\n");
}
}
void main (void)
{
iap();
}
void fill_tb (unsigned int dat, unsigned int addr)
{
unsigned char lw,hi;
hi=addr>>8;
lw=addr;
asm("mov R31,%hi");
asm("mov R30,%lw");
hi=dat>>8;
lw=dat;
asm("mov R1,%hi");
asm("mov R0,%lw");
asm("ldi R16,0x01");
asm("sts 0x57,R16");
asm("spm");
while(SPMCR&(1));
}
void erase_page (unsigned int addr)
{
unsigned char lw,hi;
hi=addr>>8;
lw=addr;
asm("mov R31,%hi");
asm("mov R30,%lw");
asm("ldi R16,0x03");
asm("sts 0x57,R16");
asm("spm");
write_rw_ok();
}
void prog_page (unsigned int addr)
{
unsigned char lw,hi;
hi=addr>>8;
lw=addr;
asm("mov R31,%hi");
asm("mov R30,%lw");
asm("ldi R16,0x05");
asm("sts 0x57,R16");
asm("spm");
write_rw_ok();
}
void iap (void)
{
unsigned char counter;
union char_int iap_dat;
CLI();
for(counter = 0 ; counter < 64; counter++) //缓冲页面填充
{
iap_dat.chr_dat[char_h] = counter*2+1;
iap_dat.chr_dat[char_l] = counter*2;
fill_tb(iap_dat.int_dat, (unsigned int)(2*counter));
}
erase_page(0x0080); //页面擦除
prog_page(0x0080); //页面写入
while(Con_true); //由于FLASH第一个页面已经擦除,程序无法返回main函数
} |