Click here to Skip to main content
15,885,910 members
Articles / Desktop Programming / MFC

A PIC C Code Wizard

Rate me:
Please Sign up or sign in to vote.
4.94/5 (27 votes)
5 May 2003CPOL5 min read 156.1K   7.9K   46  
Creates C code templates for PIC microcontrollers. The default templates are for use with the Hi-Tech (tm) PICC compiler.
// IOPortA.cpp : implementation file
//

#include "stdafx.h"
#include "..\\picwiz.h"
#include "IOPortA.h"

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

/////////////////////////////////////////////////////////////////////////////
// CIOPortA property page

IMPLEMENT_DYNCREATE(CIOPortA, CPropertyPage)

CIOPortA::CIOPortA() : CPropertyPage(CIOPortA::IDD)
{
	//{{AFX_DATA_INIT(CIOPortA)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

CIOPortA::~CIOPortA()
{
}

void CIOPortA::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CIOPortA)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CIOPortA, CPropertyPage)
	//{{AFX_MSG_MAP(CIOPortA)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CIOPortA message handlers

BOOL CIOPortA::OnKillActive() 
{
	wizInfo.sfr.TRISA = 0;
	wizInfo.sfr.PORTA = 0;
	for ( int i=0;i<6;i++ ) {
		wizInfo.sfr.TRISA |= (IsDlgButtonChecked(IDC_PA_IO1+i)<<i);
		wizInfo.sfr.PORTA |= (IsDlgButtonChecked(IDC_PA_1+i)<<i);
	}
	return CPropertyPage::OnKillActive();
}

BOOL CIOPortA::OnSetActive() 
{
	int k = 1;
	for ( int i=0;i<6;i++ ) {
		CheckDlgButton( IDC_PA_IO1+i, wizInfo.sfr.TRISA&k );
		CheckDlgButton( IDC_PA_1+i, wizInfo.sfr.PORTA&k );
		k = k<<1;
	}
	((CPICWiz*)(wizInfo.pPICWiz))->EnableWindow( GetWindow(GW_CHILD),wizInfo.bHasPortA );
	int e = 0;
	switch( wizInfo.sfr.ADCON1&0x0F ) {
	case 2:
	case 3:
	case 12:
		e = 0xE0;
		break;
	case 4:
	case 5:
		e = 0xF4;
		break;
	case 6:
	case 7:
		e = 0xFF;
		break;
	case 9:
	case 10:
	case 11:
		e = 0xC0;
		break;
	case 13:
		e = 0xF0;
		break;
	case 14:
		e = 0xFE;
		break;
	case 15:
		e = 0xF2;
		break;
	}
	k = 1;
	for ( i=0;i<6;i++ ) {
		GetDlgItem(IDC_PA_IO1+i)->EnableWindow(e&k);
		k = k<<1;
	}
	if ( wizInfo.sfr.OPTION&0x20 ) {
		GetDlgItem(IDC_PA_IO5)->EnableWindow( FALSE );
		GetDlgItem(IDC_PA_5)->EnableWindow( FALSE );
		CheckDlgButton( IDC_PA_5, 1 );
		CheckDlgButton( IDC_PA_IO5, 1 );
	}
	else {
		GetDlgItem(IDC_PA_IO5)->EnableWindow();
		GetDlgItem(IDC_PA_5)->EnableWindow();
	}
	return CPropertyPage::OnSetActive();
}

BOOL CIOPortA::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// Adds tooltips text, if exists, to dialog control
	m_cToolTip.Create( this );
	CRect rc(5,5,5,5);
	m_cToolTip.SetMargin(&rc);
	m_cToolTip.SetTipBkColor( RGB(228,233,255) );
	m_cToolTip.SetTipTextColor( RGB(89,79,191) );
	m_cToolTip.SetDelayTime( TTDT_AUTOPOP, 20000 );
	CWnd* pWnd = GetWindow( GW_CHILD );
	CString stitle, stooltip;
	while ( pWnd ) {
		int nID = pWnd->GetDlgCtrlID();
		if ( stooltip.LoadString(nID) ) {
			int pos = stooltip.Find( _T("\n") );
			stooltip.Remove( _T('\n') );
			stitle = stooltip.Left( pos );
			stooltip.Delete( 0, pos );
			if ( !stitle.IsEmpty() )
				SetDlgItemText( nID, stitle );
			if ( !stooltip.IsEmpty() )
				m_cToolTip.AddTool( pWnd, stooltip );
		}
		pWnd = pWnd->GetWindow( GW_HWNDNEXT );
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Delphi
United States United States
Carlos Buelna works in the automotive industry.

Comments and Discussions