PortA as Inputs in PIC16F628A program


Closed Thread
Results 1 to 13 of 13

Hybrid View

  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.

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 : 0

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