Page 1 of 1

PIC 18f452 PORTD problem sorted

Posted: Wed Jul 18, 2012 12:41 pm
by Enamul
Hi team,
I was struggling with my employees to sort the issue of portd in PIC 18f452..I had interfaced LCD in PORTD but it was not working. We are dealing with that for last 10 days as I thought FC should not have problem as I have used FC for other product and that was fine. But I didn't noticed that I have used LCD in PORTB in that working product but here in PORTD..

So the problem in FCD file in both V4 and V5....PORTD has parallel slave port option which can be enabled and disabled by TRISE<4>..WHICH HAS TO BE DISABLED.

I have sorted the problem and tested in hardware..please update that in v4 and v5 master file..

Code: Select all

Initialise="adcon1 = 0x07;\ncr_bit(trise,PSPMODE);\n"
Thanks,
Enamul

Re: PIC 18f452 PORTD problem sorted

Posted: Thu Aug 02, 2012 3:33 pm
by Steve
Hi Enamul,

According to the datasheet of this device from Microchip, the PSPMODE defaults to '0' on startup (i.e. General purpose I/O mode). So I don't really know why setting this to zero in the initialise statement is needed.

Could there be something else going on? For example, are you reading the whole of PORTE within your flowchart and perhaps this is setting this bit to '1'?

Re: PIC 18f452 PORTD problem sorted

Posted: Thu Aug 02, 2012 4:16 pm
by Steve
I've looked into this a bit more. Reading PORTE into a variable produces this code, which will set the PSPMODE to be enabled and prevent PORTD from being used as i/o:

Code: Select all

	//Input
	//Input: PORTE -> var
	trise = trise | 0xFF;
	FCV_VAR = porte;
To get around this, we will need to alter the "InputCmdFull" code in the appropriate FCD files so it doesn't have this problem.

At the moment, this FCD line looks like:

Code: Select all

InputCmdFull="tris%p = tris%p | %m;\n%o = port%p;\n"
The change I'm proposing is this:

Code: Select all

InputCmdFull="#if ('%p' == 'e')\n  tris%p = tris%p | (%m & 0x0F);\n  %o = port%p & 0x0F;\n#else\n  tris%p = tris%p | %m;\n  %o = port%p;\n#endif\n"
Which will produce code similar to this:

Code: Select all

	//Input
	//Input: PORTE -> var
	#if ('e' == 'e')
	  trise = trise | (0xFF & 0x0F);
	  FCV_VAR = porte & 0x0F;
	#else
	  trise = trise | 0xFF;
	  FCV_VAR = porte;
	#endif
It complicates the C code a little, but should get around this problem. Any thoughts?

Re: PIC 18f452 PORTD problem sorted

Posted: Thu Aug 02, 2012 4:20 pm
by Enamul
Hi Steve,
As you said, I have seen the same in datasheet. But I have spoiled one day in sorting the problem in hardware..There was nothing connected to porte..
That's why I feel that just a single command could save someone's time..
Your last post seems nice for solving the issue of PORTE as input
Enamul