File "Configuration.cpp"
Full Path: /home/analogde/www/PIC18F452/Configuration.cpp
File size: 14.46 KB
MIME-type: text/x-c
Charset: utf-8
/**********************************************************************/
/* */
/* File name: Configuration.cpp */
/* */
/* Since: 2002/12/03 */
/* */
/* Version: 1.02 */
/* */
/* Author: MONTAGNE Xavier [XM] {link xavier.montagne@wanadoo.fr} */
/* */
/* Purpose: Manage the Configuration Window to program easily the */
/* the configuration fields of the PIC18. */
/* */
/* Distribution: This file is part of PP18. */
/* PP18 is free software; you can redistribute it */
/* and/or modify it under the terms of the GNU General */
/* Public License as published by the Free Software */
/* Foundation; either version 2, or (at your option) */
/* any later version. */
/* */
/* PP18 is distributed in the hope that it will be */
/* useful, but WITHOUT ANY WARRANTY; without even the */
/* implied warranty of MERCHANTABILITY or FITNESS FOR A */
/* PARTICULAR PURPOSE. See the GNU General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with PP18; see the file */
/* COPYING.txt. If not, write to the Free Software */
/* Foundation, 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/* History: */
/* 2002/12/03 [XM] Create this file */
/* 2003/06/26 [XM] Fixed a bug in the lock/unlock process. */
/* */
/**********************************************************************/
/***********************************************************************
* INCLUDES
**********************************************************************/
#include <vcl.h>
#include "Configuration.h"
#include "DLL_interface.h"
#pragma hdrstop
/***********************************************************************
* Function prototypes.
**********************************************************************/
extern "C" void ConfigWindow_Show(unsigned int uiFrom);
/***********************************************************************
* Global variables.
**********************************************************************/
extern TConfigWindow *ConfigWindow;
extern HexFile_t HEX_from_file;
extern HexFile_t HEX_from_PIC;
#pragma package(smart_init)
#pragma resource "*.dfm"
TConfigWindow *ConfigWindow;
unsigned int uiFromGlobal;
unsigned int IsLocked;
/***********************************************************************
* Window constructor.
*
* @param TComponent* Owner IN Parent object reference
* @return none
**********************************************************************/
__fastcall TConfigWindow::TConfigWindow(TComponent* Owner)
: TForm(Owner)
{
}
/***********************************************************************
* Quit the window without saving.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::ButtonCancelClick(TObject *Sender)
{
ConfigWindow->Close();
}
/***********************************************************************
* Quit the window and save the data into DLL structures.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::ButtonOKClick(TObject *Sender)
{
pHexFile_t p_hfFile;
if (uiFromGlobal == FromFile)
p_hfFile = &HEX_from_file;
else
p_hfFile = &HEX_from_PIC;
p_hfFile->pConfig->szFosc = (unsigned char)(ComboBox_OSC->ItemIndex);
p_hfFile->pConfig->szBorv = (unsigned char)(ComboBox_BORV->ItemIndex);
p_hfFile->pConfig->szWdtps = (unsigned char)(ComboBox_WDTPS->ItemIndex);
p_hfFile->pConfig->szCcp2mx = (unsigned char)(ComboBox_CCP2MX->ItemIndex);
if (ComboBox_CPP->ItemIndex == 3)
p_hfFile->pConfig->szCodeProtected = 0xC7;
if (ComboBox_CPP->ItemIndex == 2)
p_hfFile->pConfig->szCodeProtected = 0xC3;
if (ComboBox_CPP->ItemIndex == 1)
p_hfFile->pConfig->szCodeProtected = 0xC1;
if (ComboBox_CPP->ItemIndex == 0)
p_hfFile->pConfig->szCodeProtected = 0x00;
if (ComboBox_CPP->ItemIndex == 4)
p_hfFile->pConfig->szCodeProtected = 0xCF;
if (ComboBox_CPP->ItemIndex == 5)
p_hfFile->pConfig->szCodeProtected = 0x4F;
if (ComboBox_CPP->ItemIndex == 6)
p_hfFile->pConfig->szCodeProtected = 0x8F;
if (ComboBox_WRT->ItemIndex == 3)
p_hfFile->pConfig->szWriteProtected = 0xC7;
if (ComboBox_WRT->ItemIndex == 2)
p_hfFile->pConfig->szWriteProtected = 0xC3;
if (ComboBox_WRT->ItemIndex == 1)
p_hfFile->pConfig->szWriteProtected = 0xC1;
if (ComboBox_WRT->ItemIndex == 0)
p_hfFile->pConfig->szWriteProtected = 0x00;
if (ComboBox_WRT->ItemIndex == 4)
p_hfFile->pConfig->szWriteProtected = 0xEF;
if (ComboBox_WRT->ItemIndex == 5)
p_hfFile->pConfig->szWriteProtected = 0x6F;
if (ComboBox_WRT->ItemIndex == 6)
p_hfFile->pConfig->szWriteProtected = 0xAF;
if (ComboBox_WRT->ItemIndex == 7)
p_hfFile->pConfig->szWriteProtected = 0xCF;
if (ComboBox_ETBR->ItemIndex == 3)
p_hfFile->pConfig->szTableReadProtected = 0xC7;
if (ComboBox_ETBR->ItemIndex == 2)
p_hfFile->pConfig->szTableReadProtected = 0xC3;
if (ComboBox_ETBR->ItemIndex == 1)
p_hfFile->pConfig->szTableReadProtected = 0xC1;
if (ComboBox_ETBR->ItemIndex == 0)
p_hfFile->pConfig->szTableReadProtected = 0x00;
if (ComboBox_ETBR->ItemIndex == 4)
p_hfFile->pConfig->szTableReadProtected = 0x4F;
if (ComboBox_ETBR->ItemIndex == 5)
p_hfFile->pConfig->szTableReadProtected = 0x0F;
p_hfFile->pConfig->szOscsen = CB_OSCSwitch->Checked;
p_hfFile->pConfig->szPwrten = CB_PowerUp->Checked;
p_hfFile->pConfig->szBoren = CB_BrownOut->Checked;
p_hfFile->pConfig->szWdten = CB_WatchDog->Checked;
p_hfFile->pConfig->szStvren = CB_StackFull->Checked;
p_hfFile->pConfig->szLVP = CB_LVP->Checked;
p_hfFile->pConfig->szDebug = CB_Debug->Checked;
ConfigWindow->Close();
}
/***********************************************************************
* Display and initialize the window.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::FormShow(TObject *Sender)
{
pHexFile_t p_hfFile;
if (uiFromGlobal == FromFile)
p_hfFile = &HEX_from_file;
else
p_hfFile = &HEX_from_PIC;
ComboBox_OSC->ItemIndex = p_hfFile->pConfig->szFosc;
ComboBox_BORV->ItemIndex = p_hfFile->pConfig->szBorv;
ComboBox_WDTPS->ItemIndex = p_hfFile->pConfig->szWdtps;
ComboBox_CCP2MX->ItemIndex = p_hfFile->pConfig->szCcp2mx;
ComboBox_CPP->ItemIndex = 0;
if (p_hfFile->pConfig->szCodeProtected == 0xC7)
ComboBox_CPP->ItemIndex = 3;
if ((p_hfFile->pConfig->szCodeProtected == 0xC3))
ComboBox_CPP->ItemIndex = 2;
if ((p_hfFile->pConfig->szCodeProtected == 0xC1))
ComboBox_CPP->ItemIndex = 1;
if (p_hfFile->pConfig->szCodeProtected == 0xCF)
ComboBox_CPP->ItemIndex = 4;
if (p_hfFile->pConfig->szCodeProtected == 0x00)
ComboBox_CPP->ItemIndex = 0;
if (p_hfFile->pConfig->szCodeProtected == 0x4F)
ComboBox_CPP->ItemIndex = 5;
if (p_hfFile->pConfig->szCodeProtected == 0x8F)
ComboBox_CPP->ItemIndex = 6;
ComboBox_WRT->ItemIndex = 0;
if (p_hfFile->pConfig->szWriteProtected == 0xC7)
ComboBox_WRT->ItemIndex = 3;
if ((p_hfFile->pConfig->szWriteProtected == 0xC3))
ComboBox_WRT->ItemIndex = 2;
if ((p_hfFile->pConfig->szWriteProtected == 0xC1))
ComboBox_WRT->ItemIndex = 1;
if (p_hfFile->pConfig->szWriteProtected == 0xEF)
ComboBox_WRT->ItemIndex = 4;
if (p_hfFile->pConfig->szWriteProtected == 0x00)
ComboBox_WRT->ItemIndex = 0;
if (p_hfFile->pConfig->szWriteProtected == 0x4F)
ComboBox_WRT->ItemIndex = 5;
if (p_hfFile->pConfig->szWriteProtected == 0xAF)
ComboBox_WRT->ItemIndex = 6;
if (p_hfFile->pConfig->szWriteProtected == 0xCF)
ComboBox_WRT->ItemIndex = 7;
if (p_hfFile->pConfig->szTableReadProtected == 0xC7)
ComboBox_ETBR->ItemIndex = 3;
if ((p_hfFile->pConfig->szTableReadProtected == 0xC3))
ComboBox_ETBR->ItemIndex = 2;
if ((p_hfFile->pConfig->szTableReadProtected == 0xC1))
ComboBox_ETBR->ItemIndex = 1;
if (p_hfFile->pConfig->szTableReadProtected == 0x4F)
ComboBox_ETBR->ItemIndex = 4;
if (p_hfFile->pConfig->szTableReadProtected == 0x00)
ComboBox_ETBR->ItemIndex = 0;
if (p_hfFile->pConfig->szTableReadProtected == 0x8F)
ComboBox_ETBR->ItemIndex = 5;
CB_OSCSwitch->Checked = p_hfFile->pConfig->szOscsen;
CB_PowerUp->Checked = p_hfFile->pConfig->szPwrten;
CB_BrownOut->Checked = p_hfFile->pConfig->szBoren;
CB_WatchDog->Checked = p_hfFile->pConfig->szWdten;
CB_StackFull->Checked = p_hfFile->pConfig->szStvren;
CB_LVP->Checked = p_hfFile->pConfig->szLVP;
CB_Debug->Checked = p_hfFile->pConfig->szDebug;
if ((CB_BrownOut->Checked == true) && (IsLocked == 0))
ComboBox_BORV->Enabled = true;
else
ComboBox_BORV->Enabled = false;
if ((CB_WatchDog->Checked) && (IsLocked == 0))
ComboBox_WDTPS->Enabled = true;
else
ComboBox_WDTPS->Enabled = false;
}
/***********************************************************************
* Enabled or disbaled the option BrownOut.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::CB_BrownOutClick(TObject *Sender)
{
if (CB_BrownOut->Checked == true)
{
CB_BrownOut->Checked == false;
ComboBox_BORV->Enabled = true;
}
else
{
CB_BrownOut->Checked == true;
ComboBox_BORV->Enabled = false;
}
}
/***********************************************************************
* Enabled or disabled the option Watchdog.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::CB_WatchDogClick(TObject *Sender)
{
if (CB_WatchDog->Checked == true)
{
CB_WatchDog->Checked == false;
ComboBox_WDTPS->Enabled = true;
}
else
{
CB_WatchDog->Checked == true;
ComboBox_WDTPS->Enabled = false;
}
}
/***********************************************************************
* Enabled or disabled the option LVP.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::CB_LVPClick(TObject *Sender)
{
if (CB_LVP->Checked == true)
{
CB_LVP->Checked == false;
}
else
{
CB_LVP->Checked == true;
}
}
/***********************************************************************
* Enabled or disabled the option StackFull.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::CB_StackFullClick(TObject *Sender)
{
if (CB_StackFull->Checked == true)
{
CB_StackFull->Checked == false;
}
else
{
CB_StackFull->Checked == true;
}
}
/***********************************************************************
* Function called by the application through the interface.
*
* @param u_int uiFrom IN FromFile or FromPIC
* @return none
**********************************************************************/
void ConfigWindow_Show(unsigned int uiFrom)
{
if (ConfigWindow == NULL)
ConfigWindow = new TConfigWindow(Application);
uiFromGlobal = uiFrom;
ConfigWindow->ShowModal();
}
/***********************************************************************
* Lock the configuration bits settings.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::BB_UnlockClick(TObject *Sender)
{
BB_Lock->Visible = true;
BB_Unlock->Visible = false;
ComboBox_OSC->Enabled = false;
ComboBox_BORV->Enabled = false;
ComboBox_WDTPS->Enabled = false;
ComboBox_CCP2MX->Enabled = false;
ComboBox_CPP->Enabled = false;
ComboBox_WRT->Enabled = false;
ComboBox_ETBR->Enabled = false;
CB_OSCSwitch->Enabled = false;
CB_PowerUp->Enabled = false;
CB_BrownOut->Enabled = false;
CB_WatchDog->Enabled = false;
CB_StackFull->Enabled = false;
CB_LVP->Enabled = false;
CB_Debug->Enabled = false;
IsLocked = true;
}
/***********************************************************************
* Unlock the configuration bits settings.
*
* @param TObject *Sender IN Caller object reference
* @return none
**********************************************************************/
void __fastcall TConfigWindow::BB_LockClick(TObject *Sender)
{
BB_Unlock->Visible = true;
BB_Lock->Visible = false;
ComboBox_OSC->Enabled = true;
if (CB_BrownOut->Checked == true)
ComboBox_BORV->Enabled = true;
else
ComboBox_BORV->Enabled = false;
if (CB_WatchDog->Checked == true)
ComboBox_WDTPS->Enabled = true;
else
ComboBox_WDTPS->Enabled = false;
ComboBox_CCP2MX->Enabled = true;
ComboBox_CPP->Enabled = true;
ComboBox_WRT->Enabled = true;
ComboBox_ETBR->Enabled = true;
CB_OSCSwitch->Enabled = true;
CB_PowerUp->Enabled = true;
CB_BrownOut->Enabled = true;
CB_WatchDog->Enabled = true;
CB_StackFull->Enabled = true;
CB_LVP->Enabled = true;
CB_Debug->Enabled = true;
IsLocked = false;
}
//---------------------------------------------------------------------------
/* End of file */