📄 program.cpp
字号:
// Program.cpp: implementation of the CProgram class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "proc.h"
#include "Program.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CProgram::CProgram()
{
/* Store each latch data out */
DataLatch[5] = 0x0;
/* store ctrl status */
ControlState = 0x08;
/* Store last states of latch */
DataLatchEnable = 0;
bWhichChip = WM100028PINS; //select WM1000 40p or 28p
wFlashSize = 0x2000; //8192
}
CProgram::~CProgram()
{
}
/*-------------------- Control Function --------------------*/
void CProgram::Tvia_ControlTempDataLatch(BYTE bONorOFF)
{
ControlState = (bONorOFF == ON) ? (ControlState|0x01) : (ControlState & 0xfe);
Tvia_Out(LPTA, ControlState);
}
void CProgram::Tvia_ControlOutputControlLatch(BYTE bONorOFF)
{
ControlState = (bONorOFF == ON) ? (ControlState|0x02) : (ControlState & 0xfd);
Tvia_Out(LPTA, ControlState);
}
void CProgram::Tvia_ControlInputControlLatch(BYTE bONorOFF)
{
ControlState = (bONorOFF == ON) ? (ControlState|0x04) : (ControlState & 0xfb);
Tvia_Out(LPTA, ControlState);
}
void CProgram::Tvia_ControlDataLatchOut(BYTE bONorOFF, int WhichLatch)
{
if (bONorOFF)
{
if(WhichLatch >= 4)
DataLatchEnable |= 0xf0; /*enable latch0/1/2/4 out at one time */
else
DataLatchEnable |= BIT((WhichLatch + 4));
}
else
{
if (WhichLatch >= 4)
DataLatchEnable &= ~0xf0;
else
DataLatchEnable &= ~BIT((WhichLatch + 4));
}
Tvia_Out(LPT8, DataLatchEnable);
}
void CProgram::Tvia_ControlDataLatchIn(BYTE bONorOFF, int WhichLatch)
{
if (bONorOFF)
{
if( WhichLatch >= 4 )
DataLatchEnable |= 0x0f; /*enable latch0/1/2/3 In at one time*/
else
DataLatchEnable |= BIT(WhichLatch);
}
else
{
if (WhichLatch >= 4)
DataLatchEnable &= ~0x0f; /*disable latch0/1/2/3 In at one time*/
else
DataLatchEnable &= ~BIT(WhichLatch);
}
Tvia_Out(LPT8, DataLatchEnable);
}
/*-------------------- Operation Function --------------------*/
void CProgram::Tvia_WriteDataLatch(BYTE WhichLatch, BYTE bData)
{
/* step1: write data into temp data latch */
Tvia_Out(LPT8, bData);
Tvia_ControlTempDataLatch(ON);
Tvia_ControlTempDataLatch(OFF);
/* step2: enable Data Latch IN */
/* prepare control in data */
Tvia_ControlDataLatchIn(ON, WhichLatch);
/* Enable output control latch */
Tvia_ControlOutputControlLatch(ON);
/* Hold data disable Data Latch */
Tvia_ControlDataLatchIn(OFF, WhichLatch);
/* Disable Output control latch */
Tvia_ControlOutputControlLatch(OFF);
}
void CProgram::Tvia_SendData(BYTE bData)
{
BYTE bTmp = 0;
switch(bWhichChip)
{
case WM100040PINS:
/* Data should be sent to data latch 3 */
Tvia_WriteDataLatch(LATCH3, bData);
DataLatch [LATCH3] = bData;
/* prepare Latch 3 out control data */
Tvia_ControlDataLatchOut(ON, LATCH3);
break;
case WM100028PINS:
/* Data should be sent to data latch 0/3 */
bTmp = ((bData & 0x0f) << 2);
bTmp |= ((bData & 0x30) >> 4);
DataLatch[LATCH0] = bTmp;
DataLatch[LATCH3] = bData & 0xc0;
Tvia_WriteDataLatch(LATCH0, DataLatch[LATCH0]);
Tvia_WriteDataLatch(LATCH3, DataLatch[LATCH3]);
/*Data Latch 0/3 can oputput to WM1000*/
// Tvia_EnableDataLatchOut(1, 0xff);
DataLatchEnable |= 0x90;
Tvia_Out(LPT8, DataLatchEnable);
break;
case WG200040PINS:
case WG200064PINS:
default:
break;
}
/* enable */
Tvia_ControlOutputControlLatch(ON);
Tvia_ControlOutputControlLatch(OFF);
}
void CProgram::Tvia_SendDecCode(BYTE bDecode)
{
BYTE bTmp = 0;
switch(bWhichChip)
{
case WM100040PINS:
/* Store for next operation */
DecodeBuffer = bDecode;
/* Protect unchanged bits of data latch 2 */
bTmp = DataLatch[LATCH2] & 0xf0;
bTmp |= (bDecode & 0x0F);
DataLatch[LATCH2] = bTmp;
break;
case WM100028PINS:
/* protect unchanged bits of data latch 2 */
bTmp = DataLatch[LATCH2] & 0x33;
/* decode[0] */
bTmp |= ((bDecode & 0x01) << 3);
DataLatch[LATCH2] = bTmp;
/* decode[1] */
DataLatch[LATCH2] |= ( (bDecode & 0x02) << 1 );
/* decode[2] */
DataLatch[LATCH2] |= ( (bDecode & 0x04) << 5 );
/* decode[3] */
DataLatch[LATCH2] |= ( (bDecode & 0x08) << 3 );
break;
case WG200040PINS:
case WG200064PINS:
default:
break;
}
/* Write Low 4 bits to the data latch 2 */
Tvia_WriteDataLatch( LATCH2, DataLatch[LATCH2] );
/* prepare Latch 2 out control data */
Tvia_ControlDataLatchOut(ON, LATCH2);
/* enable */
Tvia_ControlOutputControlLatch(ON);
Tvia_ControlOutputControlLatch(OFF);
}
void CProgram::Tvia_SendAddr(WORD wAddr)
{
/* Address should be sent to data latch
0_<7:2> = A5:A0
1_<1,0> = A7,A6
2_<5,4> = A9,A8
1_<4,3,2>=A12,A11,A10*/
WORD Address;
BYTE TAddr;
/* Store wAddr into Address Buffer for next operation */
AddressBuffer = wAddr;
Address = wAddr;
TAddr = (BYTE) wAddr;
switch(bWhichChip)
{
case WM100028PINS:
case WM100040PINS:
TAddr = (TAddr & 0x3F) << 2;
/* also we should protect unchanged old data */
TAddr = (TAddr & 0xFC) | (DataLatch[LATCH0] & ~0xFC);
/* store for next use*/
DataLatch[LATCH0] = TAddr;
/* Send data latch 0 */
Tvia_WriteDataLatch(LATCH0 , TAddr);
/* Get A7 & A6 */
TAddr = (Address & 0xc0) >> 6;
TAddr |= DataLatch[LATCH1] & 0xfc;
DataLatch[1] = TAddr;
/* Get A12:A10*/
TAddr = (BYTE) (Address >> 8);
TAddr = TAddr & 0x1C;
TAddr |= (DataLatch[LATCH1] & ~0x1c);
/* store for next use*/
DataLatch[LATCH1] = TAddr;
/* Write data into latch 1 */
Tvia_WriteDataLatch(LATCH1, TAddr);
/* Get A9,A8 */
Address = ((Address & 0x0300) >> 4) | (DataLatch[LATCH2] & 0xCF);
TAddr = (BYTE) Address;
/* store for next use*/
DataLatch[LATCH2] = TAddr;
/* write data into latch 2 */
Tvia_WriteDataLatch(LATCH2, TAddr);
/* prepare Latch0/1/2 out control Data */
// Tvia_ControlDataLatchOut(ON, 0xff);
DataLatchEnable |= 0x70;
Tvia_Out(LPT8, DataLatchEnable);
break;
case WG200040PINS:
case WG200064PINS:
default:
break;
}
/* enable */
Tvia_ControlOutputControlLatch(ON);
Tvia_ControlOutputControlLatch(OFF);
}
void CProgram::Tvia_SetPGZ(BYTE bONorOFF)
{
BYTE bTmp;
switch(bWhichChip)
{
case WM100040PINS:
/* Protect unchanged bits of data latch 2 */
bTmp = (bONorOFF == ON) ? DataLatch[LATCH2] | 0x80 : DataLatch[LATCH2] & 0x7f;
DataLatch [LATCH2] = bTmp;
Tvia_WriteDataLatch(LATCH2, bTmp);
/* Prepare Latch 2 out control data */
Tvia_ControlDataLatchOut(ON, LATCH2);
break;
case WM100028PINS:
/* Protect unchanged bits of data latch 2 */
bTmp = (bONorOFF == ON) ? DataLatch[LATCH1] | 0x04 : DataLatch[LATCH1] & 0xfb;
DataLatch [LATCH1] = bTmp;
Tvia_WriteDataLatch(LATCH1, bTmp);
/* Prepare Latch 2 out control data */
Tvia_ControlDataLatchOut(ON, LATCH1);
break;
case WG200040PINS:
case WG200064PINS:
default:
break;
}
/* Enable */
Tvia_ControlOutputControlLatch(ON);
Tvia_ControlOutputControlLatch(OFF);
}
void CProgram::Tvia_SetRST(BYTE bONorOFF)
{
BYTE bTmp;
/* Protect unchanged bits of data latch 1 */
bTmp = DataLatch[LATCH1];
if( bONorOFF )
bTmp |= 0x80;
else
bTmp &= ~0x80;
DataLatch [LATCH1] = bTmp;
Tvia_WriteDataLatch(LATCH1, bTmp);
/* Prepare Latch 1 out control data */
Tvia_ControlDataLatchOut(ON, LATCH1);
/* Enable */
Tvia_ControlOutputControlLatch(ON);
Tvia_ControlOutputControlLatch(OFF);
}
BYTE CProgram::Tvia_Read3StateGate(BYTE WhichGate)
{ /* 2: gate 2 ; 3:gate 3*/
BYTE bData;
Tvia_Out(LPT8, WhichGate); /*select gate x*/
/* Enable Input control latch , let gate selecting control data in */
Tvia_ControlInputControlLatch(ON);
bData = Tvia_In(LPT9); /*high 4 bits valid*/
/* disable Input control latch */
Tvia_ControlInputControlLatch(OFF);
return bData ;
}
BYTE CProgram::Tvia_ReadData(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -