Click here to Skip to main content
15,896,606 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.3K   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 "piccpc.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)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

BOOL CIOPortA::OnKillActive() 
{
	PICInfo.sfr.TRISA = 0;
	PICInfo.sfr.PORTA = 0;
	for ( int i=0;i<6;i++ ) {
		PICInfo.sfr.TRISA |= (IsDlgButtonChecked(IDC_PA_IO1+i)<<i);
		PICInfo.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, PICInfo.sfr.TRISA&k );
		CheckDlgButton( IDC_PA_1+i, PICInfo.sfr.PORTA&k );
		k = k<<1;
	}
	int e = 0;
	switch( PICInfo.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 ( PICInfo.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();
}

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