Leds on/off


Closed Thread
Results 1 to 17 of 17

Thread: Leds on/off

Hybrid View

  1. #1

    Default Leds on/off

    Hello forum friends,

    I have 4 buttons connected to PORTB and 4 LEDs to PORTB, I turn on and off with the same button for the LED but independently, with this code does not work properly any suggestions?.

    Code:
    start:
    IF PORTB.0=0 then
        HIGH PORTB.4
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    IF PORTB.0=0 then
        LOW PORTB.4
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
        
    iF PORTB.1=0 then
        HIGH PORTB.5
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    IF PORTB.1=0 then
        LOW PORTB.5
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    iF PORTB.2=0 then
        HIGH PORTB.6
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    IF PORTB.2=0 then
        LOW PORTB.6
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    iF PORTB.3=0 then
        HIGH PORTB.7
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
    IF PORTB.3=0 then
        LOW PORTB.7
        WHILE PORTB.0=0 : Wend : pause 50
        ENDIF
        
          
    goto start
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default

    How do you have the TRIS set for this?
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    How do you have the TRIS set for this?
    TRIS Series I have not configured but the code does not work well.

  4. #4
    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 set the TRIS for the port. That will tell what pins are input or out puts.
    Try adding this near the top of your code.
    Code:
    TRISB = %00001111
    That will make PORTB 0 to 3 an input and 4 to 7 an output.
    Dave
    Always wear safety glasses while programming.

  5. #5


    Did you find this post helpful? Yes | No

    Default

    Hello mackrackit,

    I have added TRISB =% 00001111 but as usual the code does not work well.

    Thanks
    Leonardo


    Quote Originally Posted by mackrackit View Post
    You will need to set the TRIS for the port. That will tell what pins are input or out puts.
    Try adding this near the top of your code.
    Code:
    TRISB = %00001111
    That will make PORTB 0 to 3 an input and 4 to 7 an output.

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


    Did you find this post helpful? Yes | No

    Default

    Can you post the whole code and exactly what is it doing or not doing?
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Run a string of LEDs from the mains
    By The Master in forum Off Topic
    Replies: 30
    Last Post: - 1st October 2009, 18:55
  2. Replies: 14
    Last Post: - 26th April 2007, 15:12
  3. Using LEDs as light sensors
    By skimask in forum Code Examples
    Replies: 3
    Last Post: - 30th December 2006, 22:19
  4. controlling leds with the switches
    By ilteris in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th October 2005, 21:02
  5. Replies: 5
    Last Post: - 16th February 2005, 11:57

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