?? newcomdlg.cpp
字號:
// NewComDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NewCom.h"
#include "NewComDlg.h"
#include "ser.h"//關于硬件地址的映射的定義
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
volatile IOPreg *v_pIOPRegs;
volatile ADCreg *v_pADCreg;
CString strRec;
/////////////////////////////////////////////////////////////////////////////
// CNewComDlg dialog
CNewComDlg::CNewComDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewComDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNewComDlg)
m_ad = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CNewComDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewComDlg)
DDX_Text(pDX, IDC_EDIT1, m_ad);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNewComDlg, CDialog)
//{{AFX_MSG_MAP(CNewComDlg)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewComDlg message handlers
BOOL CNewComDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
//映射寄存器地址
v_pIOPRegs = (volatile IOPreg*)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPRegs == NULL)
{
DEBUGMSG (1,(TEXT("v_pIOPRegs is not allocated\n\r")));
return TRUE;
}
if (!VirtualCopy((PVOID)v_pIOPRegs, (PVOID)IOP_BASE, sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE)) {
DEBUGMSG (1,(TEXT("v_pIOPRegs is not mapped\n\r")));
return TRUE;
}
DEBUGMSG (1,(TEXT("v_pIOPRegs is mapped to %x\n\r"), v_pIOPRegs));
v_pADCreg = (volatile ADCreg*)VirtualAlloc(0, sizeof(ADCreg), MEM_RESERVE, PAGE_NOACCESS);
if (v_pIOPRegs == NULL)
{
DEBUGMSG (1,(TEXT("v_pADCreg is not allocated\n\r")));
return TRUE;
}
if (!VirtualCopy((PVOID)v_pADCreg, (PVOID)ADC_BASE, sizeof(ADCreg), PAGE_READWRITE|PAGE_NOCACHE)) {
DEBUGMSG (1,(TEXT("v_pADCreg is not mapped\n\r")));
return TRUE;
}
DEBUGMSG (1,(TEXT("v_pADCreg is mapped to %x\n\r"), v_pADCreg));
//myinit_beep();
return TRUE; // return TRUE unless you set the focus to a control
}
void CNewComDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//static int prevCh=-1;
int ad,i,preScaler;
int rADCCON_save = v_pADCreg->rADCCON;
preScaler = 50000000/2500000 -1;
v_pADCreg->rADCCON = (1<<14)|(preScaler<<6)|(0<<3); //setup channel
for(i=0;i<10000;i++); //delay to set up the next channel
v_pADCreg->rADCCON |=0x1; //start ADC
while(v_pADCreg->rADCCON & 0x1); //check if Enable_start is low
while(!(v_pADCreg->rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high
ad=(int)v_pADCreg->rADCDAT0 & 0x3ff;
v_pADCreg->rADCCON = rADCCON_save;
m_ad=ad;
UpdateData(FALSE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -