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

📄 test6dlg.cpp

📁 WINCE 5.0 下GPIO测试程序
💻 CPP
字号:
// test6Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "test6.h"
#include "test6Dlg.h"
#include "newdialog.h"
 #include   <time.h>  

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
volatile IOPreg *v_pIOPRegs;
/////////////////////////////////////////////////////////////////////////////
// CTest6Dlg dialog

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

void CTest6Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTest6Dlg)
	DDX_Control(pDX, IDC_COMBO2VALUE, m_GPVALUE);
	DDX_Control(pDX, IDC_COMBOGPIO, m_IOSEL);
	DDX_Text(pDX, IDC_EDITIN, m_tes);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTest6Dlg, CDialog)
	//{{AFX_MSG_MAP(CTest6Dlg)
	ON_WM_HELPINFO()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
	ON_CBN_EDITCHANGE(IDC_COMBOGPIO, OnEditchangeCombogpio)
	ON_BN_CLICKED(IDC_STATIC1, OnStatic1)
	ON_EN_CHANGE(IDC_EDITOUT, OnChangeEditout)
	ON_CBN_EDITCHANGE(IDC_COMBO2, OnEditchangeCombo2)
	ON_EN_CHANGE(IDC_EDITIN, OnChangeEditin)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTest6Dlg message handlers
int	GPIOctl()
{


	v_pIOPRegs = (volatile IOPreg*)VirtualAlloc(0, sizeof(IOPreg), MEM_RESERVE, PAGE_NOACCESS);
	 if (v_pIOPRegs == NULL) 
	 {
	 
	 // MessageBox("v_pIOPRegs is not allocated\n\r",NULL,MB_OK);

	  return TRUE;
	 }
	 if (!VirtualCopy((PVOID)v_pIOPRegs, (PVOID)IOP_BASE, sizeof(IOPreg), PAGE_READWRITE|PAGE_NOCACHE)) 
	 {
	 
	 // MessageBox(_T("v_pIOPRegs is not mapped\n\r"));
	  return TRUE;
	 }
	 //DEBUGMSG (1,(TEXT("v_pIOPRegs is mapped to %x\n\r"), v_pIOPRegs));
	//	MessageBox(_T("v_pIOPRegs is  mapped to %x\n\r"));

	// 例如:设置GPB的控制寄存器为全部Output
//	v_pIOPRegs->rGPHCON = 0x1AAAA5;




	return	0;

}
BOOL CTest6Dlg::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
	GPIOctl();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTest6Dlg::OnHelpInfo()
{
	// TODO: implement help here
	MessageBox(_T("Help"));
	
}



 
void CTest6Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
//	newdialog kk;
//	kk.DoModal();

 int   i;   
    
        /*   Seed   the   random-number   generator   with   current   time   so   that   
          *   the   numbers   will   be   different   every   time   we   run.   
          */   
   //     srand(   (unsigned)time(   NULL   )   );   
    srand(   (unsigned int)sin(GetTickCount())   ); 
	
        /*   Display   10   numbers.   */   
        for(   i   =   0;       i   <   10;i++   )   
              printf(   "     %6d\n",   rand()   );   

}

void CTest6Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	//	设置GPB的数据寄存器输出高电平
//v_pIOPRegs->rGPHDAT |=0x400;
//	m_tes=v_pIOPRegs->rGPHDAT;
	

int IndexR=m_IOSEL.GetCurSel();

	
	switch(IndexR)
	{
		case 0://GPB1
			//	v_pIOPRegs->rGPBCON &= (0x01 << 2);
			//	v_pIOPRegs->rGPBCON |= (0x3 << 2);
				v_pIOPRegs->rGPBCON &= ~(0x3 << 2);
				v_pIOPRegs->rGPBUP  |=0X02;
				m_tes=((v_pIOPRegs->rGPBDAT)&(0x1<<1))?1:0;;

			//	if(outval)
			 //   &=0x02 ;
			//	else
			//	v_pIOPRegs->rGPBDAT |= 0x7FD;
				
		break;
		case 1://GPB5
			
				v_pIOPRegs->rGPBCON &= ~(0x3 << 10);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<5))?1:0;

		  break;
		case 2://GPB6
				v_pIOPRegs->rGPBCON &= ~(0x3 << 12);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<6))?1:0;

		break;
		case 3://GPB7
				v_pIOPRegs->rGPBCON &= ~(0x3 << 14);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<7))?1:0;

		
		break;
		case 4://GPB8
				v_pIOPRegs->rGPBCON &= ~(0x3 << 16);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<8))?1:0;

		
		break;
		case 5://GPB9
				v_pIOPRegs->rGPBCON &= ~(0x3 << 18);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<9))?1:0;

		break;
		case 6://GPB10
				v_pIOPRegs->rGPBCON &= ~(0x3 << 20);
				m_tes=(v_pIOPRegs->rGPBDAT & (0x1<<10))?1:0;

			
		break;
	    case 7://GPC5
				v_pIOPRegs->rGPCCON &= ~(0x3 << 10);
				m_tes=(v_pIOPRegs->rGPCDAT & (0x1<<5))?1:0;

			
		case 8://GPC6
				v_pIOPRegs->rGPCCON &= ~(0x3 << 12);
				m_tes=(v_pIOPRegs->rGPCDAT & (0x1<<6))?1:0;
			
		break;
		case 9://GPC7
				v_pIOPRegs->rGPCCON &= ~(0x3 << 14);
				m_tes=(v_pIOPRegs->rGPCDAT & (0x1<<7))?1:0;
		
		break;
		case 10://GPE11
				v_pIOPRegs->rGPECON &= ~(0x3 << 22);
				m_tes=(v_pIOPRegs->rGPEDAT & (0x1<<11))?1:0;
			
		break;
		case 11://GPE12
				v_pIOPRegs->rGPECON &= ~(0x3 << 24);
				m_tes=(v_pIOPRegs->rGPEDAT & (0x1<<12))?1:0;

		
		break;
		case 12://GPE13
				v_pIOPRegs->rGPECON &= ~(0x3 << 26);
				m_tes=(v_pIOPRegs->rGPEDAT & (0x1<<13))?1:0;;
		
		break;
		case 13://GPG2
				v_pIOPRegs->rGPGCON &= ~(0x3 << 4);
				m_tes=(v_pIOPRegs->rGPGDAT & (0x1<<2))?1:0;
		
		break;
		case 14://beep GPH10
				
				v_pIOPRegs->rGPHCON &=(~(0x3 << 20)); 
				m_tes=(v_pIOPRegs->rGPHDAT & (0x1<<10))?1:0;
			
		break;
		default:    // illegal
			{
		ASSERT(FALSE);
	//	return 0;
			}
	}
	UpdateData(false);
//	v_pIOPRegs->rGPHDAT &=~0x400;
}

void CTest6Dlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
//	CString m_str;
	int temp=m_IOSEL.GetCurSel();
//	m_IOSEL.GetLBText(temp,m_str);
	int outval=m_GPVALUE.GetCurSel();
	switch(temp)
	{
		case 0://GPB1
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 2);
				v_pIOPRegs->rGPBCON |= (0x3 << 2);
				v_pIOPRegs->rGPBCON &= (~0x2 << 2);
				if(outval)
			    v_pIOPRegs->rGPBDAT |= (0x1 << 1) ;
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1 << 1);
			}	
		break;
		case 1://GPB5
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 10);
				v_pIOPRegs->rGPBCON |= (0x3 << 10);
				v_pIOPRegs->rGPBCON &= (~(0x2 << 10));
				if(outval)
				v_pIOPRegs->rGPBDAT |= (0x1<<5);
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1<<5);
			}
		break;
		case 2://GPB6
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 12);
				v_pIOPRegs->rGPBCON |= (0x3 << 12);
				v_pIOPRegs->rGPBCON &= ~(0x2 << 12);
				if(outval)
				 v_pIOPRegs->rGPBDAT |= (0x1 << 6) ;
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1 << 6);
			}
		break;
		case 3://GPB7
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 14);
				v_pIOPRegs->rGPBCON |= (0x3 << 14);
				v_pIOPRegs->rGPBCON &= ~(0x2 << 14);
				if(outval)
				 v_pIOPRegs->rGPBDAT |= (0x1 << 7) ;
				else
				v_pIOPRegs->rGPBDAT &= (~0x1 << 7);
			}
		break;
		case 4://GPB8
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 16);
				v_pIOPRegs->rGPBCON |= (0x3 << 16);
				v_pIOPRegs->rGPBCON &= ~(0x2 << 16);
				if(outval)
				 v_pIOPRegs->rGPBDAT |= (0x1 << 8);
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1 << 8);
			}
		break;
		case 5://GPB9
			{
			//	v_pIOPRegs->rGPBCON &= (0x01 << 18);
				v_pIOPRegs->rGPBCON |= (0x3 << 18);
				v_pIOPRegs->rGPBCON &= ~(0x2 << 18);
				if(outval)
			    v_pIOPRegs->rGPBDAT |= (0x1 << 9) ;
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1 << 9);
			}
		break;
		case 6://GPB10
			{
			//v_pIOPRegs->rGPBCON &= (0x01 << 20);
				v_pIOPRegs->rGPBCON |= (0x3 << 20);
				v_pIOPRegs->rGPBCON &= ~(0x2 << 20);
				if(outval)
				v_pIOPRegs->rGPBDAT |= (0x1 << 10);
				else
				v_pIOPRegs->rGPBDAT &= ~(0x1 << 10);
			}
		break;
	    case 7://GPC5
			{
			//	v_pIOPRegs->rGPCCON &= (0x01 << 10);
				v_pIOPRegs->rGPCCON |= (0x3 << 10);
				v_pIOPRegs->rGPCCON &= ~(0x2 << 10);
				if(outval)
				v_pIOPRegs->rGPCDAT |= (0x1 << 5) ;
				else
				v_pIOPRegs->rGPCDAT &= ~(0x1 << 5);
			}
		case 8://GPC6
			{
		    	//v_pIOPRegs->rGPCCON &= (0x01 << 12);
				v_pIOPRegs->rGPCCON |= (0x3 << 12);
				v_pIOPRegs->rGPCCON &= ~(0x2 << 12);
				if(outval)
				v_pIOPRegs->rGPCDAT |= (0x1 << 6) ;
				else
				v_pIOPRegs->rGPCDAT &= ~(0x1 << 6);
			}
		break;
		case 9://GPC7
			{
		//	v_pIOPRegs->rGPCCON &= (0x01 << 14);
				v_pIOPRegs->rGPCCON |= (0x3 << 14);
				v_pIOPRegs->rGPCCON &= ~(0x2 << 14);
				if(outval)
				v_pIOPRegs->rGPCDAT |= (0x1 << 7);
				else
				v_pIOPRegs->rGPCDAT &= ~(0x1 << 7);
			}
		break;
		case 10://GPE11
			{
			//	v_pIOPRegs->rGPECON &= (0x01 << 22);
				v_pIOPRegs->rGPECON |= (0x3 << 22);
				v_pIOPRegs->rGPECON &= ~(0x2 << 22);
				if(outval)
				v_pIOPRegs->rGPEDAT |= (0x1 << 11);
				else
				v_pIOPRegs->rGPEDAT &= ~(0x1 << 11);
			}
		break;
		case 11://GPE12
			{
				v_pIOPRegs->rGPECON |= (0x3 << 24);
				v_pIOPRegs->rGPECON &= ~(0x2 << 24);
				//v_pIOPRegs->rGPECON &= (0x01 << 24);
				if(outval)
				v_pIOPRegs->rGPEDAT |= (0x1 << 12);
				else
				v_pIOPRegs->rGPEDAT &= ~(0x1 << 12);
			}
		break;
		case 12://GPE13
			{
				v_pIOPRegs->rGPECON |= (0x3 << 26);
				v_pIOPRegs->rGPECON &= ~(0x2 << 26);
			//v_pIOPRegs->rGPECON &= (0x01 << 26);
				if(outval)
				v_pIOPRegs->rGPEDAT |= (0x1 << 13);
				else
				v_pIOPRegs->rGPEDAT &= ~(0x1 << 13);
			}
		break;
		case 13://GPG2
			{
				v_pIOPRegs->rGPGCON |= (0x3 << 4);
				v_pIOPRegs->rGPGCON &= ~(0x2 << 4);
				if(outval)
				v_pIOPRegs->rGPGDAT |= (0x1 << 2);
				else
				v_pIOPRegs->rGPGDAT &= ~(0x1 <<2 );
			}
		break;
		case 14://beep GPH10
			{
			//	v_pIOPRegs->rGPHCON = 0x1AAAA5;
			//	v_pIOPRegs->rGPHCON = 0x2aaaa5;
				v_pIOPRegs->rGPHCON |= (0x3<<20);
				v_pIOPRegs->rGPHCON &= ~(0x2<<20);
				if(outval)
				v_pIOPRegs->rGPHDAT |=0x400;
				else
				v_pIOPRegs->rGPHDAT &=~0x400;
			}
		break;
		default:    // illegal
		{
		ASSERT(FALSE);
//		return 0;
		}
	}
	

	//	v_pIOPRegs->rGPHDAT &=~0x400;

}




void CTest6Dlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnChangeEdit2() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnEditchangeCombogpio() 
{
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnStatic1() 
{
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnChangeEditout() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnEditchangeCombo2() 
{
	// TODO: Add your control notification handler code here
	
}

void CTest6Dlg::OnChangeEditin() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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