Setting GPIO and TRISIO


Results 1 to 6 of 6

Threaded View

  1. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Setting GPIO and TRISIO

    Is there a way to define LEDXs' TRISIO and GPIO and then call LEDX. It would make the repeated use of individual LEDs alot easier.
    Not just as you wrote it, but you can semplify this way:

    Code:
    LED_T_1 VAR BYTE
    LED_G_1 VAR BYTE
    LED_T_2 VAR BYTE
    LED_G_2 VAR BYTE
    
    LED_T_1 = %00011110
    LED_G_1 = %00000001
    
    LED_T_2 = %00011110
    LED_G_2 = %00100000
    
    main:
    TRISIO = LED_T_1
      GPIO = LED_G_1
    pause 500
    TRISIO = LED_T_2
      GPIO = LED_G_2
    pause 500
    goto main
    end
    Now since you don,t need to change the TRISIO then you can write:

    Code:
    LED_G_1 VAR BYTE
    LED_G_2 VAR BYTE
    
    TRISIO = %00011110
    LED_G_1 = %00000001
    LED_G_2 = %00100000
    
    main:
    GPIO = LED_G_1
    pause 500
    GPIO = LED_G_2
    pause 500
    goto main
    end
    .. or in a normal way you can write:

    Code:
    LED1 VAR GPIO.0
    LED2 VAR GPIO.6
    
    TRISIO = %00011110
    
    main:
    LED1 = 1
    LED2 = 0
    PAUSE 500
    LED1 = 0
    LED2 = 1
    PAUSE 500
    GOTO MAIN
    
    END
    .. again in a more sophisticated way:

    Code:
    LED1 VAR GPIO.0
    LED2 VAR GPIO.6
    
    TRISIO = %00011110
    
    main:
    LED1 = !LED1
    LED2 = !LED1
    PAUSE 500
    GOTO MAIN
    
    END
    Cheers

    Al.
    Last edited by aratti; - 9th March 2011 at 20:20.
    All progress began with an idea

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