8 Bit output


Closed Thread
Results 1 to 4 of 4

Thread: 8 Bit output

  1. #1
    barkerben's Avatar
    barkerben Guest

    Default 8 Bit output

    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

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    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

  3. #3
    barkerben's Avatar
    barkerben Guest


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    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

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Bit Banging input to output on PIC16F876A
    By Bronurstomp in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 26th June 2008, 19:50
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts