📄 复件 avricp.c
字号:
data = getc();
if(G_device == AT89C51)
{
VPP(1);
SetVPP5V();
PORTA|= _BV(PA6); //RST=H
OutCONBit(PSEN,0); //PSEN=L
OutP2Bit(P26,0);
OutP3Bit(P36,1);
OutP3Bit(P37,1);
OutP2Bit(P27,1);
SetVPP12V();
OutCONBit(PROG,1);
unsigned int addr;
//char highbyte,lowbyte;
addr = G_pgaddrh;
addr <<= 8;
addr |= G_pgaddrl;
addr <<= 1;
if(command == 0x48) addr++;
OutAddress(addr >> 8,addr & 0xff);
OutP0(data);
Time48Tclcl();
OutCONBit(PROG,0);
Time48Tclcl();
OutCONBit(PROG,1);
Wait(g_deviceSupported[G_index].twd_flash);
}
else
{
//if (data != 0xff || g_deviceSupported[G_index].wPageSize != 0)
//{
SPIWrite(command);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
SPIWrite(data);
//no delay if m103,m83,m603,m161,m163
if (g_deviceSupported[G_index].wPageSize == 0)
{
unsigned char waittime = g_deviceSupported[G_index].twd_flash;
do
{
wait_1ms(1);
SPIWrite((command & 0x0f) | 0x20);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
if(data == SPIRead())break;
}while(waittime--);
}
//}
}
return;
}
/* +---------------------------------------------------------------------+ */
void Write_program_memory_low_byte(void)
{
//G_pgmode == TRUE;
Write_program_memory_byte(0x40);
putc(13);
return;
}
/* +---------------------------------------------------------------------+ */
void Write_program_memory_high_byte(void)
{
//G_pgmode == TRUE;
Write_program_memory_byte(0x48);
if(!(++G_pgaddrl))G_pgaddrh++;
putc(13);
return;
}
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | | ID | host | programer | Note | */
/* | Issue Page Write | 'm' | | | 13d | | */
/* +-----------------------------------+-----+-------+------+-----+------+ */
void Issue_Page_Write(void)
{
//G_pgmode == TRUE;
SPIWrite(0x4c);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
SPIWrite(0x00);
//delay(0x6f); //wait_1ms(twd_flash);
wait_1ms(g_deviceSupported[G_index].twd_flash);
//delay(0xff);
putc(13);
return;
}
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | | ID | host | programer | Note | */
/* | Read program memory | 'R' | |dd(dd)| | 4 | */
/* +-----------------------------------+-----+-------+------+-----+------+ */
//多功能函数2
unsigned char ParaReadByte(unsigned char ah,unsigned char al)
{
DDRC = 0;
OutAddress(ah,al);
Time48Tclcl();
return PINC;
}
void Read_program_memory(void)
{
//G_pgmode == TRUE;
if(G_device == AT89C51)
{
//unsigned int readw;
SetVPP5V();
VPP(1);
PORTA|= _BV(PA6); //RST=H
OutCONBit(PSEN,0); //PSEN=L
OutCONBit(PROG,1);
OutP2Bit(P26,0);
OutP3Bit(P36,1);
OutP3Bit(P37,1);
OutP2Bit(P27,0);
Time48Tclcl();
unsigned int addr;
char highbyte,lowbyte;
addr = G_pgaddrh;
addr <<= 8;
addr |= G_pgaddrl;
addr <<= 1;
lowbyte = ParaReadByte(addr >> 8,addr & 0xff);
addr++;
highbyte = ParaReadByte(addr >> 8,addr & 0xff);
putc(highbyte);
putc(lowbyte);
}
else
{
SPIWrite(0x28);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
putc(SPIRead());
SPIWrite(0x20);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
putc(SPIRead());
}
if(!(++G_pgaddrl))G_pgaddrh++;
return;
}
/*=============================读出===============================
unsigned char BinToHex(unsigned char c)
{
if (c > 9) return(c+55);
else return(c+48);
}
*/
/*void Read(void)
{ Read code with the number of bytes set by 's' command
unsigned int i;
unsigned char Readdata_h,Readdata_l,c;
P26=0;
P36=1;
P37=1;
P27=0;
VP=1;
PROG=1;
Time48Tclcl();
for (i = 0; i < count; i++){
c=ParaReadByte(i);
Readdata_h = c>>4;
Readdata_h=BinToHex(Readdata_h);
Putch(Readdata_h);
Readdata_l = c&0x0f;
Readdata_l=BinToHex(Readdata_l);
Putch(Readdata_l);
}
VP=1;
return;
}*/
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | | ID | host | programer | Note | */
/* | Write data memory | 'D' | dd | | 13d | | */
/* | Read data memory | 'd' | | dd | | | */
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | Read data memory byte | */
/* +---------------------------------------------------------------------+ */
unsigned char Read_data_memory_byte(void)
{
//G_pgmode == TRUE;
SPIWrite(0xA0);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
return(SPIRead());
}
/* +---------------------------------------------------------------------+ */
void Write_data_memory(void)
{
//G_pgmode == TRUE;
unsigned char data;
data = getc();
SPIWrite(0xC0);
SPIWrite(G_pgaddrh);
SPIWrite(G_pgaddrl);
SPIWrite(data);
unsigned char waittime = g_deviceSupported[G_index].twd_eeprom;
do
{
wait_1ms(1);
if(data != 0xff)if(data == Read_data_memory_byte())break;
}while(waittime--);
if(!(++G_pgaddrl))G_pgaddrh++;
putc(0x0D);
return;
}
/* +---------------------------------------------------------------------+ */
void Read_data_memory(void)
{
//G_pgmode == TRUE;
putc(Read_data_memory_byte());
if(!(++G_pgaddrl))G_pgaddrh++;
return;
}
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | | ID | host | programer | Note | */
/* | Chip erase | 'e' | | | 13d | | */
/* +-----------------------------------+-----+-------+------+-----+------+ */
//多功能函数3
void Chip_erase(void)
{
//G_pgmode == TRUE;
if(G_device == AT89C51)
{
//SetVPP12V();
OutCONBit(PROG,1);
VPP(1);
PORTA|= _BV(PA6); //RST=H
OutCONBit(PSEN,0); //PSEN=L
OutP2Bit(P26,1);
OutP3Bit(P36,0);
OutP3Bit(P37,0);
OutP2Bit(P27,0);
SetVPP12V();
OutCONBit(PROG,0);
//VPP(1);
wait_1ms(g_deviceSupported[G_index].twd_erase);
OutCONBit(PROG,1);
SetVPP5V();
}
else
{
SPIWrite(0xAC);
SPIWrite(0x80);
SPIWrite(0x04);
SPIWrite(0x00);
wait_1ms(g_deviceSupported[G_index].twd_erase);
}
putc(0x0D);
return;
}
/* +-----------------------------------+-----+-------+------+-----+------+ */
/* | | ID | host | programer | Note | */
/* | Write lock bits | 'l' | dd | | 13d | | */
/* +-----------------------------------+-----+-------+------+-----+------+ */
/*=============================锁位===============================
void Lock(void)
only protection mode 3,i.e., disabled further
program and verify, can be programmed
{
P26=1;
P36=1;
P37=1;
P27=1;
VPP();
PROG=0;
Time100us();
PROG=1;
P26=1;
P36=0;
P37=0;
P27=1;
VPP();
PROG=0;
Time100us();
PROG=1;
P26=1;
P36=1;
P37=0;
P27=0;
VPP();
PROG=0;
Time100us();
PROG=1;
VP=1;
return;
}
*/
//多功能函数4
void Write_lock_bits(void)
{
//G_pgmode == TRUE;
unsigned char data;
data = getc();
if(G_device == AT89C51)
{
//SetVPP12V();
VPP(1);
PORTA|= _BV(PA6); //RST=H
OutCONBit(PSEN,0); //PSEN=L
if(data & _BV(1))
{
OutP2Bit(P26,1);
OutP3Bit(P36,1);
OutP3Bit(P37,1);
OutP2Bit(P27,1);
SetVPP12V();
OutCONBit(PROG,0);
delay(1);
OutCONBit(PROG,1);
SetVPP5V();
}
if(data & _BV(2))
{
OutP2Bit(P26,1);
OutP3Bit(P36,0);
OutP3Bit(P37,0);
OutP2Bit(P27,1);
SetVPP12V();
OutCONBit(PROG,0);
delay(1);
OutCONBit(PROG,1);
SetVPP5V();
}
if(data & _BV(3))
{
OutP2Bit(P26,1);
OutP3Bit(P36,1);
OutP3Bit(P37,0);
OutP2Bit(P27,0);
SetVPP12V();
OutCONBit(PROG,0);
delay(1);
OutCONBit(PROG,1);
SetVPP5V();
}
}
else
{
SPIWrite(0xAC);
SPIWrite(0xe0);
SPIWrite(0x00);
//SPIWrite((data & 0x2f)|0xE0); //atmega16
SPIWrite(data |0xc0);
wait_1ms(g_deviceSupported[G_index].twd_fuse);
}
putc(0x0D);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -