RE-using PGC and PGD on 18f4455 with an M74HC374B1

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
In my project, I want to use two PORTS of 8 bits for output (I believe that setting a PORTB=0xff, would be faster than PORTB.A0=1, PORTB.A1=1.....PORTB.A7=1?)
I want to use the onboard serial mode, so this means that C6 and C7 cannot be used above (as would need to be left bi-directional). This leaves A0-A5, E0-E2, B0-7, C0-5, D0-7

However, I would like to be able to program using ICSP, which unfortunately uses D6 and D7 as PGC and PGD.

I will be using the Microchip ICD2 to in-circuit program, however given the nature, I do not believe that I will be able to debug, so this is not an issue.

These (PGC and PGD) pins, I am looking to attach to an M74hc374b1, I think that these are high impedance pins, so, as long as I am pulling MCLR to VDD with a resistor, they should be usable as normal IO pins, and whilst programming it should be 'safe' to leave them connected to the M74hc374?
I think the datasheet is available here: http://www.datasheetarchive.com/pdf-datasheets/Datasheets-20/DSA-388285.pdf

I think that it should work, but the datasheet specifies that there will be a 10pico farad input max capacitance on PGC and PGD in this layout (possibly 60pico farads max in the layout I am thinking about). The ICD datasheet specifies there must be no diodes on PGC/D, which I think this is not in contradiction to. I would rather not have to jumper PGC and PGD if I can avoid it, space is going to be a premium.


Edit:
Unless someone can tell me that using A0-A4 +E0-3 would be no extra assembly instructions, just more of a pain to program
 
Last edited:

Vaughanabe13

Joined May 4, 2009
102
I believe that setting a PORTB=0xff, would be faster than PORTB.A0=1, PORTB.A1=1.....PORTB.A7=1?
Yes, it is faster to write to all pins of a port in one instruction, you're right about that. It wouldn't be too hard to use two ports instead of one, but it may affect the timing, if that is an important design constraint for you.


The setup you described will work as long as you disconnect the programmer from the circuit when you apply power to the target circuit. This means you won't be able to debug with the ICD2 or use it as a power source, but it sounds like you won't need to(?). The ICD2 will still program the chip fine.
 

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
Brill, thanks. My intention is to use the ICD2 to power the PIC during programming.

I suspect that I could work-around timing differences, the 'ports' would be independant of each other, it would be so much easier not to have to though.
Thanks,
 

Vaughanabe13

Joined May 4, 2009
102
A0-A4 +E0-3 is not hard to do. You could do something like this in C (translate to asm if you want to):

Rich (BB code):
char variables = 0b01101100;  //Assume these are the states you want to output on ports A and E
PORTA = (variables & 0b00011111); //Assign the first 5 bits of "variables" to port A, so RA0 = 0, RA1 = 0, RA2 = 1, RA3 = 1, RA4 = 0
PORTE = variables >> 5; //Assign the last 3 MSBits of "variables" to port E, so RE0 = 1, RE1 = 1, RE2 = 0.
 

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
Ok, thanks. I don't think this will be 'usable', as I believe that if I were to do:
Rich (BB code):
variable=0b11111111;
PORTA = (variables & 0b00011111);
PORTE = variables >> 5;
this would be equivalent to:
Rich (BB code):
PORTA=0b00011111;
PORTE=0b00000111;
which would not leave the other registers un-touched, and could lead to unexpected behavior. Thanks for the suggestion though. I suppose what I really need is
PORTE=(PORTE&0b11111000)|(variables>>5)
which I guess is 4+ instructions.
 

Vaughanabe13

Joined May 4, 2009
102
Ok, thanks. I don't think this will be 'usable', as I believe that if I were to do:
Rich (BB code):
variable=0b11111111;
PORTA = (variables & 0b00011111);
PORTE = variables >> 5;
this would be equivalent to:
Rich (BB code):
PORTA=0b00011111;
PORTE=0b00000111;
which would not leave the other registers un-touched, and could lead to unexpected behavior. Thanks for the suggestion though. I suppose what I really need is
PORTE=(PORTE&0b11111000)|(variables>>5)
which I guess is 4+ instructions.
Ok... Actually I don't know how you have the rest of your circuit wired up, and I don't remember you specifying that the ports must be multifunction. My code was assuming you weren't using the other pins of those ports. If you are running your PIC at a modest operating speed and you don't need to generate any high-frequency signals, 4 instructions instead of 1 will not be a big deal. But there's also my original advice, or you could do research and choose a PIC that is more suitable for your application.
 

Thread Starter

coldpenguin

Joined Apr 18, 2010
165
Ok... Actually I don't know how you have the rest of your circuit wired up, and I don't remember you specifying that the ports must be multifunction
They are not multifunction, possibly it is my mis-reading of the datasheet, and incorrectly getting confused with the 16f877a.
On this chip, the PIC18F4455, PORTE.7 is the bit which controls pull-ups on the ports.
This would be a minor inconvenience. On the 16F877a I am sure that it controls the interrupts.
PORTE REGISTER



R-0 U-0 U-0 U-0 R/W-1 R/W-1 R/W-1 R/W-1

RDPU
— — — RE3 RE2 RE1 RE0

bit 7 bit 0

 
They are not multifunction, possibly it is my mis-reading of the datasheet, and incorrectly getting confused with the 16f877a.
On this chip, the PIC18F4455, PORTE.7 is the bit which controls pull-ups on the ports.
This would be a minor inconvenience. On the 16F877a I am sure that it controls the interrupts.
If it's a bit that never changes, like the pullup enable bit, you can easily just write a constant 0 or 1 to them while you are writing the rest of the port, so that's a non-issue that doesn't require any extra instructions.
 
Top