using same pin for multiple purposes


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2014
    Posts
    1

    Default using same pin for multiple purposes

    ADCON1 = 000111
    TRISA = %111111
    TRISB = %00000000
    TRISC = %00000000
    PORTC = %00000000
    PORTB = %00000000
    PORTA = %0000000
    '***********************************************
    #CONFIG
    __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF
    #ENDCONFIG
    '***********************************************
    Symbol PBUP = PORTA.0
    SYMBOL PBDN = PORTA.1
    symbol MCB = PORTA.2
    SYMBOL S1 = PORTA.3
    '***************************
    SEQ VAR BYTE
    LED1 VAR PORTC.0
    LED2 VAR PORTC.1
    LED3 VAR PORTC.2
    LED4 VAR PORTC.3
    LED5 VAR PORTC.4
    LED6 VAR PORTC.5
    LED7 VAR PORTC.6
    LED8 VAR PORTC.7
    b1 var byte
    '********************
    SEQ = 0
    'CMCON = 7
    'ADCON1 = %0
    '***************************************




    ' MCB=1
    'LOOP4:
    ' WHILE(mcb!=0)
    ' PBUP=0
    ' PBDN=0
    ' WEND

    'AGAIN:
    'IF MCB=0 THEN PORTA=0 : PORTB=0: PORTC=0
    'IF MCB=1 THEN PORTA=1 : PORTB=1 : PORTC=1


    'GOTO MAINLOOP
    'GOTO LOOP4

    FOR MCB=0 TO 1 STEP 1
    PORTB=0
    PORTC=0
    MCB=MCB-1
    NEXT

    FOR MCB= 1 TO 0 STEP -1
    PORTB=1
    PORTC=1
    MCB=MCB+1
    NEXT





    MAINLOOP:

    IF PBUP = 0 THEN GOSUB UPP
    IF PBDN = 0 THEN GOSUB DNN
    PAUSE 200
    GOSUB ACTIONS
    GOTO MAINLOOP

    '**************************
    UPP:
    IF SEQ = 9 THEN RRT
    SEQ = SEQ + 1
    PAUSE 10
    GOTO RRT
    DNN:
    IF SEQ = 0 THEN RRT
    SEQ = SEQ -1
    PAUSE 20
    RRT : RETURN

    '****************************************
    ACTIONS:
    IF seq =0 THEN
    LED1=0:LED2=0:LED3=0:LED4=0:LED5=0:LED6=0:LED7=0
    PORTB=%01111110
    ENDIF


    IF SEQ = 1 THEN
    LED1 = 1 : LED2 = 0 : LED3 = 0 : LED4 = 0 : LED5 = 0 : LED6 = 0 :
    LED7 = 0
    PORTB=%00001100
    ENDIF


    IF SEQ = 2 THEN
    LED1 =0 : LED2 = 1 : LED3 = 0 : LED4 = 0 : LED5 = 0 : LED6 = 0 :
    LED7 = 0
    PORTB=%10110110
    ENDIF

    IF SEQ = 3 THEN
    LED1 = 0 : LED2 = 0 : LED3 = 1 : LED4 = 0 : LED5 = 0 : LED6 = 0 :
    LED7 = 0
    PORTB=%10011111
    ENDIF


    IF SEQ = 4 THEN
    LED1 = 0 :LED2 = 0 :LED3 = 0 :LED4 = 1 :LED5 = 0 :LED6 = 0 :
    LED7 = 0
    PORTB=%11001100
    ENDIF


    IF SEQ = 5 THEN
    LED1 = 0 :LED2 = 0 :LED3 = 0 :LED4 = 0 :LED5 = 1 :LED6 = 0 :
    LED7 = 0
    PORTB=%11011010
    ENDIF

    IF SEQ = 6 THEN
    LED1 = 0 :LED2 = 0 :LED3 = 0 :LED4 = 0 :LED5 = 0 :LED6 = 1 :
    LED7 = 0
    PORTB=%11111010
    ENDIF

    IF SEQ = 7 THEN
    LED1 = 0 :LED2 = 0 :LED3 = 0 :LED4 = 0 :LED5 = 0 :LED6 = 0 :
    LED7 = 1
    PORTB=%00001110
    ENDIF

    IF SEQ = 8 THEN
    LED1 = 1 :LED2 = 0 :LED3 = 0 :LED4 = 0 :LED5 = 1 :LED6 = 0 :
    LED7 = 1
    PORTB=%11111111
    ENDIF

    IF SEQ = 9 THEN
    LED1 = 0:LED2 = 1 :LED3 = 0 :LED4 = 0 :LED5 = 0 :LED6 = 1 :
    LED7 = 0
    PORTB=%11011110

    ENDIF
    PAUSE 100
    return

    HOW TO USE MCB AS ENABLE AS WELL AS DISABLE?

  2. #2
    Join Date
    Dec 2011
    Location
    IO93ok
    Posts
    190


    Did you find this post helpful? Yes | No

    Default Re: using same pin for multiple purposes

    From the manual.

    INPUT Make pin an input.
    OUTPUT Make pin an output

    Also PBP convention:-

    MCB VAR PORTA.2

    Symbol is Stamp compatibility, not that it really matters if you so wish.

    You also have missing parameters in first lines for ADCON, TRIS etc either % or 0 or 1's
    Last edited by tasmod; - 10th April 2014 at 15:42. Reason: Speeling
    Rob.

    The moment after you press "Post" is the moment you actually see the typso

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,597


    Did you find this post helpful? Yes | No

    Default Re: using same pin for multiple purposes

    FOR MCB= 1 TO 0 STEP -1
    PORTB=1
    PORTC=1
    MCB=MCB+1
    NEXT
    At first glance, this will run forever.

    But, MCB is a bit; it can be 0 or 1. What happens first time through the loop when 1 is added to MCB when it is 1?

    Robert

  4. #4
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: using same pin for multiple purposes

    In a loop (for/ next in this case) MCB will increment/ decrement by the step value automatically - no need to add or subtract the value. As:

    For LP = 0 to -1 step -1
    NOP
    Next LP

    LP will be set to 0 the first time through, "loop" and set the value of LP to -1, repeat the enclosed code, and then exit because the "to" condition (LP= -1) is met. Manipulating LP manually is not necessary and only bungs up the sequence. In the case where you subtract 1 from MCB: The initial loop starts with LP=0, in the code you reduce MCB to -1 (by subtracting 1), so the exit condition is met and the "loop" fails to repeat. NONE of the looping code is ever executed with LP equal to -1.

Similar Threads

  1. Programming multiple pics with multiple programs
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 3rd April 2013, 17:47
  2. question about the pin to pin connections on a SPI interface
    By wdmagic in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th January 2013, 13:03
  3. Multiple IF-THEN statements
    By DavidK in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 20th June 2007, 18:28
  4. Multiple Data on to USART RX pin
    By Squibcakes in forum Serial
    Replies: 2
    Last Post: - 20th July 2006, 00:37
  5. Multiple HW Interrupts
    By Radiance in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th August 2003, 22:35

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