PDA

View Full Version : 8 Bit output



barkerben
- 17th November 2004, 00:30
Ok - promise this is my last question!

I need to increment a counter in my PIC code, and output the value as an 8 bit number on the pins of the PIC. I didn't think this would be a problem - however,It appears I need to use pin 0 on port B as the interrupt pin, and port A has less than 8 pins available it seems. This means I need to output my number across two ports, which sounds a bit tricky.

Is there a way around this problem? Is it as tricky as I think, or not ...?

Cheers,

Ben

Ingvar
- 17th November 2004, 14:09
Hi Ben,

No biggie, just do......

PortA.0 = OutputValue.0
PortB = OutputValue

PortA.0 will now output the LSB and PortB.1-7 will output the rest.

You should be aware that there will be a slight delay between the transition on Porta.0 and the transition on PortB. If you need it to happen EXACTLY at the same time you're in bad luck. Then you'll need an external bufferchip or a bigger Pic.

There might be a way to get an external interrupt without using PortB.0. Often you can use Timer0 configured as an external counter, causing an interrupt. If you preload it with $ff, all that's needed is one pulse on PortA.4 to rollover the counter and trigger an interrupt. When you're handling the interrupt you need to preset the counter to $ff again. Now it's ready to trigger again.

/Ingvar

barkerben
- 17th November 2004, 14:14
Thanks for that - great! One question :

Normally, If I used the line:

PortB = OutputValue

Then all of port B would be written to. Is the PIC 'clever' enough to only output to the available pins, and not try to output on the interrupt pin then?

Frm what you are saying, it will always ouput as much as it can, starting from the MSB. Is this right...?

Cheers,


Ben

Ingvar
- 17th November 2004, 15:39
If you configure a pin as an input, that pin will not output anything. The output buffer will be disabled, thats what TRIS does for you.

If you wanted PortB.0 configured as an output but not be affected, you could do .....

PortA.0 = OutputValue.0
OutputValue.0 = PortB.0
PortB = OutputValue

/Ingvar