PortA as Inputs in PIC16F628A program


Closed Thread
Results 1 to 13 of 13
  1. #1
    JackBauer2424's Avatar
    JackBauer2424 Guest

    Cool PortA as Inputs in PIC16F628A program

    I'm working on the following simple piece of code that serouts the states (high or low) of its PortA and PortB pins. Right now it's successfully sending the PortB states but I'm not getting accurate PortA states. Please tell me what I'm doing wrong and feel free to comment if you think there's a better way to do this.
    Thanks

    SYMBOL PortA = 5
    SYMBOL TrisA = $85
    SYMBOL PortB = 6
    SYMBOL TrisB = $86
    SYMBOL CmCom = $1F
    SYMBOL Ready = 2
    SYMBOL Load = 1
    SYMBOL Xmit = 3

    POKE TrisA,%11111111 'only using PORTA.0-PORTA.3 in real application
    POKE TrisB,%11110101
    POKE CmCom,%00000111


    Main:
    IF Pin2 = 1 THEN Transmit

    GOTO Main


    Transmit:
    HIGH Load
    PEEK PortB,B0
    PEEK PortA,B1

    LOW Load

    SEROUT Xmit, N9600, ("A","B",B0,B1) '"A" and "B" are qualifiers
    GOTO Main

    'End of Program

  2. #2
    Join Date
    Feb 2005
    Location
    Kolkata-India
    Posts
    563


    Did you find this post helpful? Yes | No

    Default Turn off the comparators on PORTA

    Hi,

    Your chip has an onboard voltage comparator. You can turn this off by inserting:

    CMCON = 7

    This may solve your problem.

    Regards

    Sougata

  3. #3
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    The books shows

    Symbol CMCON = $1f
    Poke COCON ,7

    or

    poke $1f,7 (one line version)

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


    Did you find this post helpful? Yes | No

    Default

    As i can't say how read from a pin in PBC and you have correctly POKE the CMCON register in your code example in the first post, my question is... how do you connect your switch to the PORT? Any pull-up/pull-down resistor?

    I guess one day i'll buy PBC myself too just for fun
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    let's do a try... sorry if i'm wrong.. i try
    Code:
    Main: 
        peek PORTA,B0
        if Bit1=1 then transmit ' iF PORTA.1=1 then transmit
        GOTO Main
    Steve

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

  6. #6
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Code:
    Main: 
        peek PORTA,B0
        if Bit1=1 then transmit ' iF PORTA.1=1 then transmit
        GOTO Main
    The peek reads porta into B0 (you did not include where you have porta defined (unless PB has it defined.. I doubt it, maybe PBP does, I made an include to drop in my code since BP is not a complete product). B0 is byte 0 in the chip.

    Now that it is in B0, you need to IF against B0. So you can AND it (as it is a byte not a bit) with %00000010.

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


    Did you find this post helpful? Yes | No

    Default

    i based my example on a PBC code example on the Melabs Website.
    adcx.bas ==> http://www.melabs.com/resources/samples/x1/pbc/adcx.bas

    Our friend already defined PORTA, TRISA and so on on his First post. Read back everything.

    As far as i know B0 is a pre-define variable in PBC

    BIT1... comes from the PBC code example ( ... ok ok it was BIT2) and nowhere it was pre-define. By their example it seems to return or set the Bit value of B0 variable.

    As i said, i tried. I don't have and i don't use PBC.

    Let's see what are the result of someone using PBC.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Smile

    Hello,

    If I recall correctly B0 is a byte variable that can be tested for its individual bits. So Mister E is correct. If you peek at a port and have the byte put into the variable B0, then you test the individual pins of the port by testing the bits. Bit0 would be the same as PortA.0 for example. This should also be able to be done with variable B1. It has been a few years since I worked with PBC.

    It is a complete product. It serves a specific purpose. Is it the answer to programming with Basic, NO. But it does fill a need if you use it correctly. In my case it didn't fill my need because of what I was trying to accomplish so I bought the upgrade to PBP.

    BobK

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


    Did you find this post helpful? Yes | No

    Default

    BobK, i think our friend mramos is in a kind of PMS or bad mood anyway... http://www.picbasic.co.uk/forum/show...05&postcount=3
    Steve

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

  10. #10
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by BobK
    Hello,

    If I recall correctly B0 is a byte variable that can be tested for its individual bits. So Mister E is correct. If you peek at a port and have the byte put into the variable B0, then you test the individual pins of the port by testing the bits. Bit0 would be the same as PortA.0 for example. This should also be able to be done with variable B1. It has been a few years since I worked with PBC.

    It is a complete product. It serves a specific purpose. Is it the answer to programming with Basic, NO. But it does fill a need if you use it correctly. In my case it didn't fill my need because of what I was trying to accomplish so I bought the upgrade to PBP.

    BobK
    What are PBC's limitations? I've just bought it and wondered what extra goodies which might be useful to me, might be in PBP?



    Tim

  11. #11
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Full comparison can be made from the MeLabs website and downloading and comparing the manuals from the two products, but as a (incomplete) summary...

    Handy commands such as LCDOut (and others) that save a lot of hassle.

    No restrictions on PIC pins and the ability in being able to alias them sensibly.

    No restrictions on assigment of variables (RAM) and the ability to alias them.

    Powerful IF THEN ELSE ENDIF structure permitting unrestricted nesting.

    Easy and direct access to PICs Registers without convoluted PEEKs and POKES.

    Ability to embed Programmer CONFIG directives.

    The list goes on...

    The paradox is that it is the Professional Programmers who have the knowledge and expertise to make PBC do anything they want, yet it is a product aimed at the bottom-end hobbyist. Whilst it is PBP that has all the easy to use features a novice needs, but it is aimed at the Professional. Time is money and life is short... how much of your life do you want to devote to your programming?

  12. #12
    mramos's Avatar
    mramos Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie
    Full comparison can be made from the MeLabs website and downloading and comparing the manuals from the two products, but as a (incomplete) summary...

    Handy commands such as LCDOut (and others) that save a lot of hassle.

    No restrictions on PIC pins and the ability in being able to alias them sensibly.

    No restrictions on assigment of variables (RAM) and the ability to alias them.

    Powerful IF THEN ELSE ENDIF structure permitting unrestricted nesting.

    Easy and direct access to PICs Registers without convoluted PEEKs and POKES.

    Ability to embed Programmer CONFIG directives.

    The list goes on...

    The paradox is that it is the Professional Programmers who have the knowledge and expertise to make PBC do anything they want, yet it is a product aimed at the bottom-end hobbyist. Whilst it is PBP that has all the easy to use features a novice needs, but it is aimed at the Professional. Time is money and life is short... how much of your life do you want to devote to your programming?
    No PMS, I feel IF and ENDIF are part of a good compiler (is one every on I have). And I will make PBC do all I need now that I know its limits.

  13. #13
    timmoore47's Avatar
    timmoore47 Guest


    Did you find this post helpful? Yes | No

    Default

    IF THEN ELSE etc would be Brilliant but as I've got the Compiler version not Pro, I'll do it long hand.

    I Just wanted to avoid assembler, due to ease of maintenance of Basic Programs. My needs are not too complex once I've mastered intputing and decisions.

    Thanks everyone for your help!



    Tim

Similar Threads

  1. Erratic analog inputs .
    By timseven in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 10th October 2009, 22:34
  2. Problem with porta for 16F886(PIC 28X1)
    By Anghel Cosmin in forum Off Topic
    Replies: 2
    Last Post: - 26th February 2009, 13:07
  3. Help Pic16f628a
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 26th August 2008, 23:22
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  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