?? flashprom.c
字號:
#include "define.h"
// a,b--address
unsigned char read_flash(unsigned char a,unsigned char b)
{
#asm
.equ spmcr=0x37
ldd r30,y+1
ld r31,y
lpm
mov r30,r0
#endasm
}
// a--address
unsigned char read_fuse(unsigned char a)
{
#asm
ld r30,y
ldi r31,0
ldi r22,0x09;
out spmcr,r22
lpm
mov r30,r0
#endasm
}
// a,b--address c,d--data
unsigned char write_flashbuf(unsigned char a,unsigned char b,unsigned char c,unsigned char d)
{
#asm
in r22,spmcr
ldi r30,0
sbrc r22,0
rjmp wwend
ldd r30,y+3
ldd r31,y+2
ldd r0,y+1
ld r1,y
ldi r22,0x01
cli
out spmcr,r22
spm
sei
ldi r30,1
wwend:
#endasm
}
// 0--wait 1--finish
unsigned char erase_doing(unsigned char a,unsigned char b)//
{
#asm
in r22,spmcr
ldi r30,0
sbrc r22,0
rjmp erend
ldd r30,y+1
ld r31,y
ldi r22,3
cli
out spmcr,r22
spm
sei
ldi r30,1
erend:
#endasm
}
// 0--wait 1--finish
unsigned char write_doing(unsigned char a,unsigned char b)
{
#asm
in r22,spmcr
ldi r30,0
sbrc r22,0
rjmp wrend
ldd r30,y+1
ld r31,y
ldi r22,5
cli
out spmcr,r22
spm
sei
ldi r30,1
wrend:
#endasm
}
// 0--wait 1--finish
unsigned char read_enable(unsigned char a,unsigned char b)
{
#asm
in r22,spmcr
ldi r30,0
sbrc r22,0
rjmp rdend
ldd r30,y+1
ld r31,y
ldi r22,0x11
cli
out spmcr,r22
spm
sei
ldi r30,1
rdend:
#endasm
}
unsigned char i_write;
void write_flash(void)
{
unsigned char a,b,c,d,i,j;
a=rt_buffer[1]&0x7f;
b=a>>2;
a<<=6;
switch (step)
{
case 1:
j=erase_doing(a,b);
i_write=0;
if (j>0)
step++;
break;
case 2:
c=rt_buffer[i_write+2];
d=rt_buffer[i_write+3];
j=write_flashbuf(a+i_write,b,c,d);
if (j>0)
{
i_write+=2;
if (i_write>=64)
{
step++;
}
}
break;
case 3:
j=write_doing(a,b);
if (j>0)
{
step++;
}
break;
case 4:
j=read_enable(a,b);
if (j>0)
{
step++;
}
break;
case 5:
write_timeover=0;
b_tx_sign=1;
break;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -