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

📄 qq2440daextdlg.cpp

📁 用QQ2440板子的SPI功能实现了DA7631芯片功能的DA转换
💻 CPP
字号:
// QQ2440DaExtDlg.cpp : implementation file
//

#include "stdafx.h"
#include "QQ2440DaExt.h"
#include "QQ2440DaExtDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CQQ2440DaExtDlg dialog

CQQ2440DaExtDlg::CQQ2440DaExtDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CQQ2440DaExtDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CQQ2440DaExtDlg)
	m_fVoltage = 0.0f;
	m_uDigValue = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CQQ2440DaExtDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CQQ2440DaExtDlg)
	DDX_Text(pDX, IDC_EDIT_VOLTAGE, m_fVoltage);
	DDX_Text(pDX, IDC_EDIT_DIG, m_uDigValue);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CQQ2440DaExtDlg, CDialog)
	//{{AFX_MSG_MAP(CQQ2440DaExtDlg)
	ON_BN_CLICKED(IDC_RSTDAC7631, OnRstdac7631)
	ON_BN_CLICKED(IDC_OUT_DAC7631, OnOutDac7631)
	ON_BN_CLICKED(IDC_OUT_DAC7MAX, OnOutDac7max)
	ON_BN_CLICKED(IDC_BUTTON_CS, OnButtonCs)
	ON_BN_CLICKED(IDC_BUTTON_CS2, OnButtonCs2)
	ON_BN_CLICKED(IDC_BUTTON_RST, OnButtonRst)
	ON_BN_CLICKED(IDC_BUTTON_RST2, OnButtonRst2)
	ON_BN_CLICKED(IDC_BUTTON_LOAD, OnButtonLoad)
	ON_BN_CLICKED(IDC_BUTTON_LOAD2, OnButtonLoad2)
	ON_BN_CLICKED(IDC_BUTTON_LDAC, OnButtonLdac)
	ON_BN_CLICKED(IDC_BUTTON_LDAC2, OnButtonLdac2)
	ON_BN_CLICKED(IDC_BUTTON_ANY, OnButtonAny)
	ON_BN_CLICKED(IDC_BUTTON_DIG, OnButtonDig)
	ON_BN_CLICKED(IDC_BUTTON_MOSI, OnButtonMosi)
	ON_BN_CLICKED(IDC_BUTTON_MOSI2, OnButtonMosi2)
	ON_BN_CLICKED(IDC_BUTTON_CLK2, OnButtonClk2)
	ON_BN_CLICKED(IDC_BUTTON_CLK, OnButtonClk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CQQ2440DaExtDlg message handlers

BOOL CQQ2440DaExtDlg::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
	if(! (bIsInitialOK = m_IoDac7631.InitSPI()))
	{
		MessageBox(_T("Error init spi!"));
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CQQ2440DaExtDlg::OnRstdac7631() 
{
	if(bIsInitialOK)
	{
		m_IoDac7631.InitDAC7631RST();
		DEBUGMSG (1,(TEXT("InitDAC7631RST\n\r")));
	}
}

void CQQ2440DaExtDlg::OnOutDac7631() 
{
	if(bIsInitialOK)
	{
		m_IoDac7631.SPI_Write(0);
		DEBUGMSG (1,(TEXT("SPI_Write\n\r")));
	}
}

void CQQ2440DaExtDlg::OnOutDac7max() 
{
	if(bIsInitialOK)
	{
		m_IoDac7631.SPI_Write(65535);
		DEBUGMSG (1,(TEXT("SPI_Write\n\r")));
	}
}

void CQQ2440DaExtDlg::OnButtonCs() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631CS(0);
}

void CQQ2440DaExtDlg::OnButtonCs2() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631CS(1);
}

void CQQ2440DaExtDlg::OnButtonRst() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631RST(0);
}

void CQQ2440DaExtDlg::OnButtonRst2() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631RST(1);
}

void CQQ2440DaExtDlg::OnButtonLoad() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631LOAD(0);
}

void CQQ2440DaExtDlg::OnButtonLoad2() 
{
	
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631LOAD(1);
}

void CQQ2440DaExtDlg::OnButtonLdac() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631LDAC(0);
}

void CQQ2440DaExtDlg::OnButtonLdac2() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631LDAC(1);
}

void CQQ2440DaExtDlg::OnButtonAny() 
{
	if(bIsInitialOK)
	{
		UpdateData();
		if(m_fVoltage>5.0f)
		{
			m_fVoltage = 5.0f;
			UpdateData(FALSE);
		}
		if(m_fVoltage<-5.0f)
		{
			m_fVoltage = -5.0f;
			UpdateData(FALSE);
		}
		
		unsigned short ushortValue;
		ushortValue = (unsigned short)(((m_fVoltage/2.0f+2.5f)/5.0f)*65535);
		m_IoDac7631.SPI_Write(ushortValue);
		m_uDigValue = ushortValue;
		UpdateData(FALSE);
	}
}

void CQQ2440DaExtDlg::OnButtonDig() 
{
	if(bIsInitialOK)
	{
		UpdateData();
		if(m_uDigValue<0)
		{
			m_uDigValue = 0;
			UpdateData(FALSE);
		}
		if(m_uDigValue>65535)
		{
			m_uDigValue = 65535;
			UpdateData(FALSE);
		}
		m_fVoltage = (float)((m_uDigValue*1.0/65535)*10.0f-5.0f);
		UpdateData(FALSE);
		m_IoDac7631.SPI_Write(m_uDigValue&0xFFFF);
	}
}

void CQQ2440DaExtDlg::OnButtonMosi() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631SPI_MOSI(0);
}

void CQQ2440DaExtDlg::OnButtonMosi2() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631SPI_MOSI(1);
}


void CQQ2440DaExtDlg::OnButtonClk() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631SPI_CLK(0);
}

void CQQ2440DaExtDlg::OnButtonClk2() 
{
	if(bIsInitialOK)
		m_IoDac7631.SetDAC7631SPI_CLK(1);
}

⌨️ 快捷键说明

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