Hello,
I have a TouchScreen display setup with a simple button using microchip graphics library. When the button is pressed the LED is supposed to turn on when initially off and if the button is pressed again the LED should turn off and so on...The problem I'm having is that the port is not changing state when I press the button, only the text is changing correctly.
Maybe someone can give me a hand. It seems as if the TRISD register was stuck as an input and won't change over to output state. Bellow is the code for the main routine.
I have a TouchScreen display setup with a simple button using microchip graphics library. When the button is pressed the LED is supposed to turn on when initially off and if the button is pressed again the LED should turn off and so on...The problem I'm having is that the port is not changing state when I press the button, only the text is changing correctly.
Maybe someone can give me a hand. It seems as if the TRISD register was stuck as an input and won't change over to output state. Bellow is the code for the main routine.
Code:
#include "main_BasicLCDsetup.h"
#include "GDD_Screens.h"
#include "periphDev.h"
extern float voltage_x1000;
// Configuration bits
_CONFIG2(FNOSC_PRI & POSCMOD_XT & IESO_ON & FCKSM_CSDCMD & OSCIOFNC_OFF) // Primary XT OSC with PLL
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF & GCP_OFF & BKBUG_OFF & COE_OFF & ICS_PGx2 & WINDIS_OFF) // JTAG off, watchdog timer off
int updateBTN1 = 1; //Goes low when BTN1 on display is pressed
int main(void)
{
TRISDbits.TRISD3 = 0; //Set PORTD pin3 to output.
LATDbits.LATD3 = 1; // When LOW LED = ON, Initialy OFF
char val[10];
double voltAVG;
int i;
int ledstat = 0; //Changes stat when LED is ON/OFF
GOL_MSG msg; // GOL message structure to interact with GOL
EEPROMInit(); // initialize EEPROM
TouchInit(); // initialize touch screen
GOLInit(); // initialize graphics library &
if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(EEPROM_VERSION)){
TouchCalibration();
TouchStoreCalibration();
EEPROMWriteWord(GRAPHICS_LIBRARY_VERSION,EEPROM_VERSION);
}
TouchLoadCalibration();
/****************************************************************
Initialize the main screen created with Graphips Display Designer
this function resides in the GDD_Screens.c file which is automatically
generated by the designer.
*****************************************************************/
CreatemainScrn();
TRISDbits.TRISD3 = 0; //Set the PORT D pin 3 to output
LATDbits.LATD3 = 1; // Set PORT D pin 3 initially high.
while(1)
{
if (GOLDraw()) { // Draw GOL object
TouchGetMsg(&msg); // Get message from touch screen
GOLMsg(&msg); // Process message
}
if (!updateBTN1)
{
if(!ledstat)
{
LATDbits.LATD3 = 0; // Turn LED ON
Bar( 25, 135, 55, 150 );
SetColor(RED);
OutTextXY((55)>>1,(275)>>1, "ON"); //x starting point, y starting point
updateBTN1 = 1;
ledstat = 1; //1 indicates LED is ON
}
else
{
LATDbits.LATD3 = 1; //Turn LED OFF
Bar( 25, 135, 55, 150 );
SetColor(YELLOW);
//(x-position of lft top corner, y-position of lft top corner, x-position of rgt btm corner, y-position of rgt btm corner
OutTextXY((55)>>1,(275)>>1, "OFF");
updateBTN1 = 1;
ledstat = 0; //0 indicates LED is ON
}
}
}
}
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg){
WORD objectID;
objectID = GetObjID(pObj);
if (objectID == mainScrn_BTN1) {
if (objMsg == BTN_MSG_PRESSED) // check if button is pressed
{
//Debounce the touch screen press
__delay_ms(50);
if (objMsg == BTN_MSG_PRESSED)
__delay_ms(50);
updateBTN1 = 0; //Button has been pressed
}
}
return 1;
}
WORD GOLDrawCallback(){
return 1;
}
Last edited: