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

📄 console_pci2.cpp

📁 msp430F413用DS18B20测温
💻 CPP
字号:
// console_pci2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "atmd_pci.h"
#include "conio.h"
#include "console_pci2.h"
#include "math.h"
#include "winbase.h"

#include "stdio.h"

void writeRegQuiet ( WORD, int, DWORD);


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int mc(WORD);

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
  int nRetCode;
  int i,iBoardCount;
  char ch;
  WORD atmd_pci_base_address[10],base;
  BOOL AtmdOK = FALSE, quit = FALSE;
  DWORD dwTemp;


  //  Your variables
  WORD  FIFO0, FIFO1,Chan;
  DWORD TimeBins;
  DOUBLE Time;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
    // **************************************************************** 
	// ************* Start of application code ************************
	// detect ATMD PCI (call GetATMDPCIBoardCount() to detect number of ATMD-PCI boards)
		iBoardCount = GetATMDPCIBoardCount();
		printf("No. of ATMD PCI boards found = %d\n",iBoardCount);
		
		i=0;
		while((!AtmdOK) || (i>4))
		{
			AtmdOK = GetATMDPCIBaseAddr(i,dwTemp);
			atmd_pci_base_address[i] = (WORD) dwTemp;
			i++;
		}
		if (AtmdOK)
		{
			printf("ATMD PCI Board found on 0x%x\n",atmd_pci_base_address[i-1]);
			base = atmd_pci_base_address[i-1];  		// base = base address 
			if(!EnablePortAccess())
			{
				AfxMessageBox("Giveio.sys couldn't be opened");
			}
		}
		else
		{
			AfxMessageBox("ATMD-PCI interface not found");
		}

    }  
	//  ******************** board-reset ******************
	_outpw(base+0xC,0x0101);
	Sleep(1);
	_outpw(base+0xC,0x0000);

//  *********************** Your Code ********************************************************

	
	// ****************** Setup ***************************
	//                     _LSB                  ___Address
	//                    |                     | _____MSB 
	//                 ...|                     ||..
	_outpw(base+0x0, 0x00ab);_outpw(base+0x2, 0x0000);//Reg 0, Start ring oscillator, enable rising edges
	_outpw(base+0x0, 0x0520);_outpw(base+0x2, 0x1062);//Reg 1, Channel adjust
	_outpw(base+0x0, 0x0004);_outpw(base+0x2, 0x2000);//Reg 2, R-Mode	
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x3800);//Reg 3, use LVTTL inputs
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x4600);//Reg 4, Mtimer begins with Start, EF high-Z
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x5820);//Reg 5, Start retrigger, Disable Stop until Start
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0x6000);//Reg 6, Switch off ECL inputs
	_outpw(base+0x0, 0x1FC3);_outpw(base+0x2, 0x7014);//Reg 7, Resolution = 72.62ps, MTimer = 1祍
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xB400);//Reg 11,PLL not locked -> Err
	_outpw(base+0x0, 0x0000);_outpw(base+0x2, 0xC200);//Reg 12,MTimer -> Int

	//******************** Measurement ********************
	 
	_outpw(base+0x0,0x0000);_outpw(base+0x2,0x4640);		//TDC-GPX MasterReset
	
	_outpw(base+0xC, 0x0202); 								//Burst mode on
	
	do 
	{
			
		while(!(_inpw(base+0x8) & 0x0101));

		FIFO0 = _inpw(base+0xA);
		FIFO1 = _inpw(base+0xC);
		
		//printf("%X\n",FIFO1);

		Chan = ((FIFO1 & 0x4000)>>14);
		TimeBins = ((FIFO1 & 0x7F)<<16) + FIFO0;
		Time = float(TimeBins) * 72.62 / 3 / 1000;
		
		printf("%d  %X %5.3f\n",Chan,TimeBins,Time);

    // Tastatur: "i" = interrupt measurement, "q" = quit measurement
		if(kbhit())
		{
			ch=getch();
			if(ch=='q')
				quit=true;
				
			if(ch=='i')
			{
				while(!kbhit());
				quit=false;
			}
		}
	} while ( !quit );

// ********************************* End of Your code *****************************************
	_outpw(base+0xC, 0x0000); 	//Burst mode off
	return nRetCode;
}

⌨️ 快捷键说明

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