uuprog开发教程:芯片操作函数
编程器的芯片编程其实就是对芯片的各项操作的集成,读、擦除、写、校验、加密等,编程就是对这些操作的统称。下面几个函数处理的就是相应的功能。afx_msg void OnDeviceReadId();
afx_msg void OnDeviceCheckBlank();
afx_msg void OnDeviceReadData();
afx_msg void OnDeviceErase();
afx_msg void OnDeviceWriteData();
afx_msg void OnDeviceVerify();
afx_msg void OnDeviceLockBit();
afx_msg void OnDEVICEAutoProg();
看函数名该很容易理解其功能了。下面就介绍下每个函数的基本框架。
1、读取
这里指的就是读取芯片的数据。
void CUUProgDlg::OnDeviceReadData()
{
DWORD dwElapseTime;
// TODO: Add your command handler code here
if(m_bProgLink)
{
SetAppLog("读芯片数据开始...");
dwBeginTime = ::GetTickCount();
//发送读取命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("读取完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
2、读芯片id
这个对于某些芯片来说的,有这个功能该函数才有效。
void CUUProgDlg::OnDeviceReadId()
{
DWORD dwElapseTime;
// TODO: Add your command handler code here
if(m_bProgLink)
{
SetAppLog("读芯片ID开始...");
dwBeginTime = ::GetTickCount();
//发送读取命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("读取完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
3、查空
检查芯片内是否有数据,当然有些芯片加密了就无法判断了。
void CUUProgDlg::OnDeviceCheckBlank()
{
DWORD dwElapseTime;
// TODO: Add your command handler code here
if(m_bProgLink)
{
SetAppLog("芯片查空开始...");
dwBeginTime = ::GetTickCount();
//发送查空命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("查空完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
4、写入
就是将上位机的缓冲数据写入芯片。
void CUUProgDlg::OnDeviceWriteData()
{
DWORD dwElapseTime;
if(m_bProgLink)
{
// TODO: Add your command handler code here
SetAppLog("写入芯片开始...");
if(m_bCounton)
{
if (m_iMaxNum == m_iCurNum)
{
SetAppLog("编程已到设定数目,退出编程");
AfxMessageBox("编程已到设定数目,退出编程");
return;
}
}
dwBeginTime = ::GetTickCount();
//发送写命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("写入完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bCounton)
{
if (m_iMaxNum == m_iCurNum)
{
AfxMessageBox("编程已到设定数目,退出编程");
return;
}
m_iCurNum += 1;
m_iSuccessNum += 1;
SetCount();
}
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
5、擦除
将芯片上的现有数据清除,或者复位flash、加密位等。
void CUUProgDlg::OnDeviceErase()
{
DWORD dwElapseTime;
// TODO: Add your command handler code here
if(m_bProgLink)
{
SetAppLog("擦除芯片开始...");
dwBeginTime = ::GetTickCount();
//发送擦除命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("擦除完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
6、校验
通过比较缓冲的数据与芯片上的数据是否一致来确定是否写入正常。
void CUUProgDlg::OnDeviceVerify()
{
DWORD dwElapseTime;
if(m_bProgLink)
{
// TODO: Add your command handler code here
SetAppLog("校验芯片数据开始...");
dwBeginTime = ::GetTickCount();
//发送校验命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("校验完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
7、加密
大多数芯片都支持加密,例如24类就没法用该函数了。
void CUUProgDlg::OnDeviceLockBit()
{
DWORD dwElapseTime;
// TODO: Add your command handler code here
if(m_bProgLink)
{
SetAppLog("加密芯片开始...");
dwBeginTime = ::GetTickCount();
//发送加密命令
//读取结果
dwEndTime = ::GetTickCount();
//显示结果
dwElapseTime = dwEndTime-dwBeginTime;
dwAllTime += dwElapseTime;
SetAppLog("加密完成。");
SetAppLog("耗时:"+Int2Str(dwElapseTime)+" ms");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon && m_bOneKeyMode) sndPlaySound("chord.wav",SND_ASYNC);
}
}
8、一键编程
这个是出于方便考虑的,一次实现擦除芯片数据、将缓冲的数据写入芯片、校验数据正确性、加密等操作,适合量产。
void CUUProgDlg::OnDEVICEAutoProg()
{
// TODO: Add your command handler code here
dwAllTime = 0;
dwEndTime = 0;
dwBeginTime = 0;
m_bOneKeyMode = false;
if(m_bProgLink)
{
SetAppLog("一键编程开始...");
if(m_bReadID) OnDeviceReadId();
if(m_bCheckBlank) OnDeviceCheckBlank();
if(m_bErase) OnDeviceErase();
if(m_bPrograme) OnDeviceWriteData();
if(m_bVerify) OnDeviceVerify();
if(m_bLockbit) OnDeviceLockBit();
SetAppLog("一键编程完成。");
SetAppLog("总耗时:"+Int2Str(dwAllTime)+" ms");
if(m_bBeepon) sndPlaySound("ding.wav",SND_ASYNC);
}
else
{
SetAppLog("未找到编程器,请检查编程器USB线是否连接!");
if(m_bBeepon) sndPlaySound("chord.wav",SND_ASYNC);
}
m_bOneKeyMode = true;
}
你这个编程器有ID么?
页:
[1]