[译]逻辑电路和逻辑门模拟器
By robot-v1.0
本文链接 https://www.kyfws.com/applications/logical-circuits-and-logical-gates-simulator-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 3 分钟阅读 - 1065 个词 阅读量 0[译]逻辑电路和逻辑门模拟器
原文地址:https://www.codeproject.com/Articles/5100/Logical-circuits-and-logical-gates-simulator
原文作者:MH2538
译文由本站 robot-v1.0 翻译
前言
Logical circuits and logical gates simulator. A program similar to PSpice.
逻辑电路和逻辑门模拟器.与PSpice类似的程序.
介绍(Introduction)
这是一个用于模拟基本逻辑电路的简单示例(我希望我也可以为FLIP-FLOP开发该示例).该程序有所有的大门.(This is a simple sample to simulate basic logical circuits (I hope I can develop this for FLIP-FLOPs too). There are all the main gates in this program.)
盖茨的名单是:(The list of Gates is :)
- 不(NOT)
- 和(AND)
- 要么(OR)
- 与非(NAND)
- 也不(NOR)
- 异或(XOR)
- 异或(XNOR)
- 简单的从左到右的点子.(Simple left to right pip.)
- 简单上下上下点.(Simple Up to down and down to up pip.)
- 两种方式.(Two way pip.) 在板上画好门后,右键单击板上的" TRACE"菜单.选择跟踪以查看最终结果.您可以从左上角的对话框中更改跟踪模式的两种模式:1-快速模式. 2分步操作.(After drawing your gates on the board, right click on the board for TRACE menu. Select trace to see final result . You can change your trace mode from left top dialog in two modes : 1 - Fast mode. 2 - Step By Step .)
注意(Note):您可以通过从左侧工具箱中选择删除工具来删除任何绘制的门.您可以通过单击工具箱左上方和左侧按钮的指针按钮来最小化/还原工具箱.(: You can deleted any drawn gates by selecting delete tool from the left-side toolbox. And you can minimize/restore toolbox by clicking the pointer button on top left and button left side of toolbox.)
代码清单(Code Listing)
// This is a function that select correc cursor for mouse pointer .
BOOL CLCView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
m_pViewWnd=pWnd;
switch (m_dToolBox.CursorValue){
case AND:
lhCursor=AfxGetApp()->LoadCursor(IDC_AND);
SetCursor(lhCursor);
ShowFlag=TRUE;
break;
case NAND:
lhCursor=AfxGetApp()->LoadCursor(IDC_NAND);
SetCursor(lhCursor);
...........
}
// This a function to draw selected gates on board
// (after you click this gate on board)
void CLCView::ShowBitmap(int x,int y,int kind)
{
CDocument* pDoc = GetDocument();
CClientDC dc(this);
CBitmap bitmap;
CDC dcMemory;
BITMAP bm;
switch (kind) {
case AND :
bitmap.LoadMappedBitmap(IDB_AND,0);
break;
case NAND :
bitmap.LoadMappedBitmap(IDB_NAND,0);
// Call main calculator function
void CLCView::OnCalc()
{
m_dToolBox.UpdateData(TRUE);
if (m_dToolBox.m_rOption==0)
FastTrace=TRUE;
else
FastTrace=FALSE;
m_dToolBox.UpdateData(FALSE);
Calc();
}
// This function is like a snapper grid
boolean CLCView::Snaper(int x, int y,int kind)
{
x=(x/32)*32;
y=(y/32)*32;
if(ShowFlag==TRUE)
{
ShowBitmap(x,y,m_dToolBox.CursorValue);
ScreenMap(x,y,m_dToolBox.CursorValue);
}
else
if (kind==_DEL)
{
ShowBitmap(x,y,m_dToolBox.CursorValue);
.....
.....
}
...
}
// This function save your drawes gates for calculate
boolean CLCView::ScreenMap(int x, int y,int kind)
{
int xMem,yMem;
xMem=x/32;
yMem=y/32;
switch (kind) {
case AND :
screen[xMem][yMem].Gate=AND;
screen[xMem][yMem].SGate="AND";
screen[xMem][yMem].Group=1;
screen[xMem][yMem].lunched=1;
break;
case NAND :
screen[xMem][yMem].Gate=NAND
...
...
// and this is calculatore of program
void CLCView::Calc()
{
for (int i=0;i<32;i++)
for (int j=0;j<24;j++)
if (screen[i][j].lunched==1)
{
UpdateData(FALSE);
switch (screen[i][j].Gate)
{
case AND :
{
switch (screen[i-1][j].Gate)
{
case DLR :
screen[i][j].inValue1=screen[i-1][j].outValue1;
...........
.............
..............
}
结论(Conclusion)
如果您发现任何错误或可以改进代码,请通过以下电子邮件与我联系:(If you have found any bug or if you can improve the code please contact me by my email at :)mh2538@yahoo.com(mh2538@yahoo.com)要么(or)XpolitiX@yahoo.com(XpolitiX@yahoo.com).谢谢,再见.(. Thanks and bye.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Windows Win2K Visual-Studio Dev 新闻 翻译