⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avrprog.h

📁 上位机软件 for avricp 根据功能设定熔丝
💻 H
📖 第 1 页 / 共 2 页
字号:
			com.Write(&c,1);
			
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			} //  Dont use High byte.
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			}
			hexf.setData( address-1, c );//low byte.
		}
		p->SetPos(0);
		return true; // Indicate supported command.
}

	bool verifyFlash(CProgressCtrl *p)//( HEXFile * data )
	{
		long start, end; // Data address range.
		bool autoincrement; // Bootloader supports address autoincrement?
		long address;
		long readhigh,readlow;
		
		if( pagesize == -1 )
			AfxMessageBox( "Programmer pagesize is not set!" );
		
		/* Get range from HEX file */
		start = hexf.getRangeStart();
		end = hexf.getRangeEnd();
		
		/* Check autoincrement support */
		char c;
		c='a';
		com.Write(&c,1);
		
		if(!com.GetCharWait(&c))
		{
			AfxMessageBox( "超时!");
			return false;
		}
		else	if( c == 'Y' )
			autoincrement = true;
		else
			autoincrement = false;
		
		/* Set initial address */
		setAddress( start >> 1 ); // Flash operations use word addresses.
		
		/* Need to read one odd byte first? */
		address = start;
		if( address & 1 )
		{
			/* Read both, but use only high byte */
			c='R';
			com.Write(&c,1);
			
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			}
			readhigh=c;
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			} // Dont use low byte.
			if(!verifyIsOk(address, readhigh))return false;
			
			
			address++;
		}
		
		/* Get words */
		do
		{
			/* Need to set address again? */
			if( !autoincrement )
				setAddress( address >> 1 );
			
			/* Get words */
			c='R';
			com.Write(&c,1);
			
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			}
			//if(!verifyIsOk(address+1, c))return false;
			readhigh=c & 0xff;
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			}
			readlow=c & 0xff;
			if(!verifyIsOk(address, readhigh<<8 | readlow))return false;
			
			
			address += 2;
			
		p->SetPos(100*(address)/(end+1));
			
		} while( address < end );
		
		/* Need to read one even byte before finished? */
		if( address == end )
		{
			/* Read both, but use only low byte */
			c='R';
			com.Write(&c,1);
			
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			} //  Dont use High byte.
			if(!com.GetCharWait(&c))
			{
				AfxMessageBox( "超时!");
				return false;
			}
			//low byte.
			readlow=c & 0xff;
			if(!verifyIsOk(address,readlow))return false;
		}
		p->SetPos(0);
		return true; // Indicate supported command.
}

bool writeEEPROM( CProgressCtrl *p )
{
	long start, end; // Data address range.
	bool autoincrement; // Bootloader supports address autoincrement?
	long address;
	
	/* Get range from HEX file */
	start = hexf.getRangeStart();
	end = hexf.getRangeEnd();
	
	/* Check autoincrement support */
	char c;
	c='a';
	com.Write(&c,1);
	
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if( c == 'Y' )
		autoincrement = true;
	else
		autoincrement = false;
	
	/* Set initial address */
	setAddress( start );
	
	/* Send data */
	address = start;
	do
	{
		/* Need to set address again? */
		if( !autoincrement )
			setAddress( address );
		
		/* Send byte */
		c='D';
		com.Write(&c,1);
		c=(char)( hexf.getData( address ) );
		com.Write(&c,1);
		/* 应该返回 CR */
		if(!com.GetCharWait(&c))
		{
			AfxMessageBox( "超时!");
			return false;
		}
		else	if(c != '\r' )
		{
			AfxMessageBox( "不能(命令:D)!");
			return false;
		}
		
		address++;
		p->SetPos(100*(address)/(end+1));
	} while( address <= end );
	p->SetPos(0);
	return true; // Indicate supported command.
}
bool readEEPROM( CProgressCtrl *p )
{
	long start, end; // Data address range.
	bool autoincrement; // Bootloader supports address autoincrement?
	long address;
	
	/* Get range from HEX file */
	start = hexf.getRangeStart();
	end = hexf.getRangeEnd();
	
	/* Check autoincrement support */
	char c;
	c='a';
	com.Write(&c,1);
	
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if( c == 'Y' )
		autoincrement = true;
	else
		autoincrement = false;
	
	/* Set initial address */
	setAddress( start );
	
	/* Send data */
	address = start;
	do
	{
		/* Need to set address again? */
		if( !autoincrement )
			setAddress( address );
		
		/* Get byte */
		c='d';
		com.Write(&c,1);
		
		if(!com.GetCharWait(&c))
		{
			AfxMessageBox( "超时!");
			return false;
		}
		
		hexf.setData( address, c );		
		
		
		address++;
		p->SetPos(100*(address)/(end+1));
	} while( address <= end );
	p->SetPos(0);
	return true; // Indicate supported command.
}
bool verifyEEPROM(CProgressCtrl *p)
{
	long start, end; // Data address range.
	bool autoincrement; // Bootloader supports address autoincrement?
	long address;
	
	/* Get range from HEX file */
	start = hexf.getRangeStart();
	end = hexf.getRangeEnd();
	
	/* Check autoincrement support */
	char c;
	c='a';
	com.Write(&c,1);
	
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if( c == 'Y' )
		autoincrement = true;
	else
		autoincrement = false;
	
	/* Set initial address */
	setAddress( start );
	
	/* Send data */
	address = start;
	do
	{
		/* Need to set address again? */
		if( !autoincrement )
			setAddress( address );
		
		/* Get byte */
		c='d';
		com.Write(&c,1);
		
		if(!com.GetCharWait(&c))
		{
			AfxMessageBox( "超时!");
			return false;
		}
		
		if(c!=(char)hexf.getData( address))
		{
			char mss[50];
			sprintf(mss,"地址:%04X 读出:%02X 应该:%02X !",address,c,hexf.getData( address));
			AfxMessageBox( mss);
			return false;
		}
				
		address++;
		p->SetPos(100*(address)/(end+1));
	} while( address <= end );
	p->SetPos(0);
	return true; // Indicate supported command.

}

// 写锁定位
bool writeLockBits( long bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command 'l' */
	c='l';
	com.Write(&c,1);
	c=bits & 0xff;
	com.Write(&c,1);
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能锁位(命令:l)!");
		return false;
	}
	return true;
	
}	
// 写锁定位1
bool writeLockBits1( long bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xac;
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xe0;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = (char)bits | 0xc0;	
	com.Write(&c,1);
	if(!com.GetCharWait(&c)) // Ignore return code from SPI communication.
	{AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能写扩展熔丝(命令:.)!");
		return false;
	}
	return true;
}
// 读锁定位
bool readLockBits( long * bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command 'r' */
	c='r';
	com.Write(&c,1);
	if(com.GetCharWait(&c))
	{
		*bits = c;
		return true;
	}
	AfxMessageBox( "超时!");
	return false;
}
// 读锁定位1
bool readLockBits1( long * bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = 0x58;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1);
	if(com.GetCharWait(&c)) * bits = c;
	else {AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能读锁定位(命令:.)!");
		return false;
	}
	return true;
}

bool writeFuseBits( long bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xac;
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xa0;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = (char)( bits & 0xff );	
	com.Write(&c,1);
	if(!com.GetCharWait(&c)) // Ignore return code from SPI communication.
	{AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else if(c != '\r' )
	{
		AfxMessageBox( "不能写熔丝(命令:.)!");
		return false;
	}
	
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xac;
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xa8;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = (char)( bits >> 8 );	
	com.Write(&c,1);
	if(!com.GetCharWait(&c)) // Ignore return code from SPI communication.
	{AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能写熔丝(命令:.)!");
		return false;
	}
	
	return true;
}
bool readFuseBits( long * bits )
{
	if(!com.IsOpen())return false;
	char c;
	long low, high;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = 0x50;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1);
	if(com.GetCharWait(&c)) low = c;
	else {AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能读熔丝(命令:.)!");
		return false;
	}
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = 0x58;
	com.Write(&c,1);
	Sleep(10);
	c = 0x08;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1);
	if(com.GetCharWait(&c)) high = c;
	else {AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能读扩展熔丝(命令:.)!");
		return false;
	}
	/* Put low and high together */
	*bits =(high << 8)  | ( low & 0xff ) ;
	return true;
}
bool writeExtendedFuseBits( long bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xac;
	com.Write(&c,1);
	Sleep(10);
	c = (char)0xa4;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = (char)bits;	
	com.Write(&c,1);
	if(!com.GetCharWait(&c)) // Ignore return code from SPI communication.
	{AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能写扩展熔丝(命令:.)!");
		return false;
	}
	return true;
}
bool readExtendedFuseBits( long * bits )
{
	if(!com.IsOpen())return false;
	char c;
	/* Send command '.' */
	c = '.';
	com.Write(&c,1);
	Sleep(10);
	c = 0x50;
	com.Write(&c,1);
	Sleep(10);
	c = 0x08;
	com.Write(&c,1);
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1); 
	Sleep(10);
	c = 0x00;			// Dummy.
	com.Write(&c,1);
	if(com.GetCharWait(&c)) * bits = c;
	else {AfxMessageBox( "通用命令超时!");return false;}
	
	/* 应该返回 CR */
	if(!com.GetCharWait(&c))
	{
		AfxMessageBox( "超时!");
		return false;
	}
	else	if(c != '\r' )
	{
		AfxMessageBox( "不能读扩展熔丝(命令:.)!");
		return false;
	}
	return true;
}


bool programmerSoftwareVersion( long * major, long * minor )
{
	if(!com.IsOpen())return false;
	char c,s[2];
	/* Send command 'V' */
	c='V';
	com.Write(&c,1);
	if(com.GetStrWait(s,2)!=2)
	{
		AfxMessageBox( "未知软件版本(命令:V)!");
		return false;
	}
	else 
	{
		*major=s[0];
		*minor=s[1];
		return true;
	}
	AfxMessageBox( "超时!");
	return false;
	
}
bool programmerHardwareVersion( long * major, long * minor )
{
	if(!com.IsOpen())return false;
	char c,s[2];
	/* Send command 'v' */
	c='v';
	com.Write(&c,1);
	if(com.GetStrWait(s,2)!=2)
	{
		AfxMessageBox( "未知硬件版本(命令:v)!");
		return false;
	}
	else 
	{
		*major=s[0];
		*minor=s[1];
		return true;
	}
	AfxMessageBox( "超时!");
	return false;
	
}
};


#endif
////////////////////////////////////////////////


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -