PortA input and outputs


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2007
    Posts
    23

    Default PortA input and outputs

    I am using a 16F676 with all of PORTC and PORTA.0 driving a 7 segment display. All is fine if I simply display a digit or count up. I would like to read a dip switch using 4 other bits of PORTA, such as PORTA.1,2,4,5 (.3 is MCLR). I have configured those particular pins as inputs (TRISA) . I am getting strange results. Should I be able to do this? Or are there some possible issues. I have done similar with an LCD, so I would think this should work.

    How do I insert code into this message?

    Thanks, Scott
    Last edited by chips123; - 7th June 2010 at 04:00.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You will need to add this near the beginning of your code
    Code:
    ANSEL = %00000000
    CMCON0 = %00000111
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2007
    Posts
    23


    Did you find this post helpful? Yes | No

    Default

    I got it figured out. I needed to get my port bits and ANDING to coorelate correctly. I did have the CMCON and ANSEL set correctly. I am using a rotary binary switch with the common pulled to 5V and the port inputs pulled low w/ 1K resistors. OK, here is the code if anyone wants to peek. I am sure there are better ways, I just needed to know how to read the port. Thanks and take it easy, Scott
    Code:
    CMCON = %00000111
    ANSEL = %00000000
    TRISA = %00111110
    TRISC = %00000000
    
    temp var byte
    digit var byte
    A var byte
    C var byte
    
    PORTA = %00000000
    PORTC = %00000000
    pause 1000
                  
     start:     temp = PORTA & %00110110
                if temp = 34 then digit = 9
                if temp = 32 then digit = 8
                if temp = 22 then digit = 7
                if temp = 20 then digit = 6
                if temp = 18 then digit = 5
                if temp = 16 then digit = 4
                if temp = 6 then digit = 3
                if temp = 4 then digit = 2
                if temp = 2 then digit = 1
                if temp = 0 then digit = 0
                        
                lookup digit,[0,0,1,1,1,1,1,0,1,1],a
                lookup digit,[63,6,27,15,38,45,61,7,63,39],c
                PORTA = a
                PORTC = C
                PAUSE 50
                goto start  
                 
    End

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