PortA , PortB


Closed Thread
Results 1 to 18 of 18

Thread: PortA , PortB

  1. #1
    DiGGi's Avatar
    DiGGi Guest

    Unhappy PortA , PortB

    Hello,
    I have a problem. I'm using PIC16F627A and PicBasic-Compiler (NOT PRO!!).
    If I use e.g. the commands 'PINx' , 'Button' or 'High/Low' they all work only on PortB. Is there a possibility that they work on PortA ??

    Dirk

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi DiGG,

    Did you remember to disable the analog and comparator features on PortA?

    BobK

  3. #3
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    How can i disable them?

  4. #4
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi DiGGi,

    It usually depends on what's in the data sheet for the particular PIC you are using. These are something like: ADCON1 = 7 to disable the analog inputs and make the pins digital and CMCON = 7 to disable the comparators. There is a section in the PIC datasheet for each of these 2 items. Go to www.microchip.com and in the search field enter the part number you want a manual for. example: PIC16F628. This will give you selections on all the available documents for that part.

    ADCON1 and CMCON are then placed in your initialization section of your program.

    Please bear in mind that PICs that have analog ports don't necessarily have comparators. This is why you need to have the datasheet handy to refer to.

    BobK

  5. #5
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    Hi,
    fiorst ThX for your help, but in my data sheet there is no ADCON1 and CMCON.

    is there an other solution , for PIC16F627A?

    Diggi

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by DiGGi
    ...If I use e.g. the commands 'PINx' , 'Button' or 'High/Low' they all work only on PortB. Is there a possibility that they work on PortA ??
    No - As I remember, PBC does not have predefined pins or directions for PORTA. You must do them directly (make sure you turn off any analog presets as Bob has noted – this requirement is PIC specific).

    For example to make RA0 high,

    Code:
    poke $85, %00000000	' make all PORTA outputs
    poke $05, %00000001	' set RA0 high
    to turn off RA0 and turn on RA1, you could then do this

    Code:
    poke $05, %00000010
    Ask if you need more and good luck
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Ok i do a try, PicBasic is far different from PBP...

    try
    Code:
    POKE $1F,7 ' disable comparator
    refer to figure 4-2 of the datasheet for the memory map, and section 10 for the comparator module

    About 'Pin' Statement... i guess it's valid but i can't confirm how and why... time for me to purchase PBC. I hate to guess..
    Last edited by mister_e; - 10th September 2006 at 17:46.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    hi

    Thank you both.

    @paul borgmeier, yes i know but i want to read the pin states seperately

    @mister_e the command you sent is working in PB but how can i controle the Pins on PortA with comands like Button/Pin ?

    Dirk

  9. #9
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by mister_e
    i guess it's valid but i can't confirm how and why... time for me to purchase PBC. I hate to guess..
    Hi Steve,
    No need to buy PBC or guess - the manual is free online on MELABs site.

    http://www.melabs.com/resources/index.htm#Manuals
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  10. #10
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by DiGGi
    @paul borgmeier, yes i know but i want to read the pin states seperately
    Not tried but should work

    Code:
    poke $85, $04	' make RA2 an input 
    ...
    peek $05, B0	' read all of PORTA
    B0=B0 & $04	' isolate bit 2
    IF B0 = 0 then TurnOFF
    do something here if B0 = 1
    goto IFEXIT
    TurnOFF:
    do something  here if B0 = 0
    IFEXIT:
    ...
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  11. #11
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    hi

    The text in '2.2. The Pins' chapter says that PIN, Button - Commands only work on PortB. That is annoying.

    If I would use PEEK the stats of every pin would be written in a var.
    E.G. Pin 4 and Pin 6 are high , tha var would look like %01010000.
    Is that right?

  12. #12
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by DiGGi
    If I would use PEEK the stats of every pin would be written in a var.
    E.G. Pin 4 and Pin 6 are high , tha var would look like %01010000.
    Is that right?
    Yes - BITWISE operate to find what you want. See the LET command for more in the PBC manual and my example above your last post.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  13. #13
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks a lot @ all
    I'll try this suggestion and i'll let you know the result.

    Dirk

  14. #14
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Edit: nevermind... too late
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  15. #15
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi DiGGi,

    What has been said to you in the last few replies has been correct. If you want to get real basic here you can read porta like this:

    Peek PortA, B0 Read PortA and put results in Variable B0
    If Bit0 = 1 then task 1 'Reads PortA pin 0, if 1 then goto task 1
    If Bit1 = 1 then task 2 'Reads PortA pin 1, if 1 then goto task 2
    If Bit2 = 0 then task 3 'Reads PortA pin 2, if 1 then goto task 3

    This is really the basic way I started. You can do the BITWISE operations like Paul was showing you also. Whatever you are comfortable with.

    Variable B0 now represents a reading of the pins on PortA. you can now look at each pin individually.

    Do you have a copy of the PBC manual? If not goto www.melabs.com and download a copy. There is a 2 page explanation on PEEK and a small explanation of POKE.

    BobK

  16. #16
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default

    thx

    i read that manual allready. And found the Bitx command. But i haven't time to test it yet. I'll tiy it later. And let you know if it works or not.

    Dirk

  17. #17
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by BobK
    ...If you want to get real basic here you can read porta like this:

    Peek PortA, B0 Read PortA and put results in Variable B0
    If Bit0 = 1 then task 1 'Reads PortA pin 0, if 1 then goto task 1
    If Bit1 = 1 then task 2 'Reads PortA pin 1, if 1 then goto task 2
    If Bit2 = 0 then task 3 'Reads PortA pin 2, if 1 then goto task 3

    ...
    Bob,
    Nice addition - your approach is certainly easier and faster to write. Utilizing the fact that Bit0, Bit1, etc. are predifeined as the bits of B0 is the better approach for straightforward (i.e., normal) operations. Thanks for adding - now Dirk has lots of options. If it were me, I would skip the bitwise stuff and use what Bob has above.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  18. #18
    DiGGi's Avatar
    DiGGi Guest


    Did you find this post helpful? Yes | No

    Default workin

    hi,

    my prog i working by using Peek and Bit0, Bit1 ...

    Thanks for your help!

    Diggi

Similar Threads

  1. PICs can do more if use others than delays instructions
    By hardcore in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th February 2010, 19:52
  2. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  3. shifting problem
    By helmut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2007, 06:11
  4. Output PIC module
    By freelancebee in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th September 2005, 20:10
  5. Can anyone help a beginner in a struggle?
    By douglasjam in forum mel PIC BASIC
    Replies: 1
    Last Post: - 5th May 2005, 23:29

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