PORT pin state not changin

Status
Not open for further replies.

drkidd22

Member
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.

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:
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;
	}

Sorry about the edit but I make the tabs line up so we can read it...

All I can suggest at this point is to make sure the PSP is disabled ( parallel port mode, its controlled in the TRISE register)

Ian

I haven't seen this code before.. but " if (!updateBTN1 )".. I take it this is changed on an interrupt somewhere?
 
Last edited:
!updateBTN1 is changed when the button on the display is pressed, is in the GOLMsgCallback(); funcction at the end
 
I think my problem might be that the pin should be an input instead of an output. RD3 is the cathode of the LED, thus will be sinking the current. If you guys have any clue please let me know.
 
No! you are correct.. it needs to be an output (you give the LED a ground) I am going through the data sheet it has something to do with the JTAG configuration.
Sorry about the earlier post.. I assumed pic18 for some reason.

Are you using the pic24 dev board? if so, half the LED's are connected to the JTAG and this needs to be disabled.

Ian

Scratch that sorry that was port A... still looking!! the pin is also the PMPBE so my first though may have been right try disabling the PM in the PMCON register
 
Last edited:
Yes, Most of I did it following microchip's instructions and added other stuff like the touch screen driver and SS1928 driver from another place. Everything is working ok so far, but for this issue that i've encountered. Attached is a zip of the entire project.
 

Attachments

  • BasicLCDsetup.zip
    886.8 KB · Views: 107
There four setting on these chips
I would say it because its open drain is whats happening

You may want to read this because the data sheet doesn't tell you all you need to set
the ports up. https://www.electro-tech-online.com/custompdfs/2011/05/39711b.pdf

 
Last edited by a moderator:
Burt! I'm not sure about that as the pullup won't even come into it, there is a current resistor already! the pin only needs to ground. It's configured as an output anyway.

Ian
 
Reactions: 3v0
I'm still stuck trying to get this going. I noticed that if I modify this lines.
Code:
// if (GOLDraw()) {				// Draw GOL object
     	TouchGetMsg(&msg);   		// Get message from touch screen
      	GOLMsg(&msg);        		// Process message
//     }
which comments out the GOLDraw function then the LED is initially off as it shoud be, but since the GOLDraw function is not being called then there is nothing displayed on the display.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…