PIC 18f452 PORTD problem sorted

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

PIC 18f452 PORTD problem sorted

Post 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
Attachments
18F452.fcd
Flowcode V5 FCD
(15.01 KiB) Downloaded 244 times
18F452.fcd
Flowcode V4 FCD
(13.29 KiB) Downloaded 230 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: PIC 18f452 PORTD problem sorted

Post 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'?

User avatar
Steve
Matrix Staff
Posts: 3433
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: PIC 18f452 PORTD problem sorted

Post 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?

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

Re: PIC 18f452 PORTD problem sorted

Post 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
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply