LED timing


Closed Thread
Results 1 to 6 of 6

Thread: LED timing

Hybrid View

  1. #1
    Join Date
    Jun 2008
    Posts
    3

    Default LED timing

    Hi,
    We are trying to program our PIC 16F88 so that we can time our LED when triggered by a switch. We want the LED to stay on for five seconds everytime the switch is turned on.
    This is the code we have so far:
    '---------------------
    DEFINE OSC 20

    TRISB = %00000000 'setup PORTB; 0 for output, 1 for input
    TRISA.0=1

    loop:

    IF PORTA.0 = 1 Then ledon
    PORTB.0=0 'turn off LED

    GOTO loop

    ledon:

    PORTB.0=1 'light LED
    PAUSE 5000 'pause for 2 seconds
    PORTB.0=0 'turn off LED
    GOTO loop

    END
    '------------------------------------------


    We have connected the switch to port A0 and the led to port B0. We would appreciate any help.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hello elen-group,
    this should get you started:
    ADCON0 = 0
    ADCON1=0
    CMCON = 7
    ANSEL = 0
    edit: pause 5000 = 5 seconds
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by elen-group View Post
    We have connected the switch to port A0 and the led to port B0. We would appreciate any help.
    So, what's the problem?

  4. #4
    Join Date
    Jun 2008
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Our circuit is not conditioned to the switch. Everytime we turn on the circuit our led comes on regardless if we use the switch or not. We tried the suggested help but still did not fix it. I am thinking that there is some issue with the if statement which is not implementing the switch we want.

  5. #5
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by elen-group View Post
    Our circuit is not conditioned to the switch. Everytime we turn on the circuit our led comes on regardless if we use the switch or not. We tried the suggested help but still did not fix it. I am thinking that there is some issue with the if statement which is not implementing the switch we want.
    Code:
    DEFINE OSC 20
    PortA = %00000000
    TRISB = %00000000 'setup PORTB; 0 for output, 1 for input
    TRISA.0=1
    
    loop:
    
    IF PORTA.0 = 1 Then ledon
    PORTB.0=0 'turn off LED
    
    GOTO loop
    
    ledon:
    
    PORTB.0=1 'light LED
    PAUSE 5000 'pause for 2 seconds
    PORTB.0=0 'turn off LED
    GOTO loop
    
    END
    put a pulldown resistor on porta.0
    and a pullup on PortB.0
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Here, I think, what is needed.

    Code:
    <font color="#0000FF"><i>'All the usual stuff here.
    '....
    '....
    '....
    
    </i></font><b>Sw  </b><font color="#000080"><b>VAR </b></font><b>PORTA.</b><font color="#FF0000"><b>0 </b></font><font color="#0000FF"><i>' Switch is connected to RA0.
    </i></font><b>LED </b><font color="#000080"><b>VAR </b></font><b>PORTB.</b><font color="#FF0000"><b>0 </b></font><font color="#0000FF"><i>' LED is connected to RB0. 
    </i></font><b>Flag </b><font color="#000080"><b>VAR BIT    </b></font><font color="#0000FF"><i>' Use a flag to have a virtual falling-edge,rising-edge thingie.
    
    </i></font><b>Begin:
        </b><font color="#000080"><b>INPUT </b></font><b>Sw    </b><font color="#0000FF"><i>' Switch pin is an input pin. Tie it to V+ with a resistor.
        </i></font><b>Flag = </b><font color="#FF0000"><b>0
    
    </b></font><b>Loop:
    
    </b><font color="#0000FF"><i>' When button is pressed, the LED turns ON, stays ON 5 secs and then turns OFF.
    ' While button is being pressed, the led does NOT repeat Turn ON action. 
    ' When the button is released then Flag is cleared. Thus, what happens?
    
        </i></font><font color="#000080"><b>IF </b></font><b>Sw = </b><font color="#FF0000"><b>0 </b></font><font color="#000080"><b>AND </b></font><b>Flag = </b><font color="#FF0000"><b>0 </b></font><font color="#000080"><b>THEN </b></font><b>LedOn      </b><font color="#0000FF"><i>' SW is pressed.
    
        </i></font><font color="#000080"><b>IF </b></font><b>Sw = </b><font color="#FF0000"><b>1 </b></font><font color="#000080"><b>AND </b></font><b>Flag = </b><font color="#FF0000"><b>1 </b></font><font color="#000080"><b>THEN </b></font><b>Flag = </b><font color="#FF0000"><b>0   </b></font><font color="#0000FF"><i>' SW is released. 
    
    
    </i></font><font color="#000080"><b>GOTO </b></font><b>Loop
    
    
    
    LedOn:
    
        LED = </b><font color="#FF0000"><b>1     </b></font><font color="#0000FF"><i>' Turn ON led.
        </i></font><font color="#000080"><b>PAUSE </b></font><font color="#FF0000"><b>5000  </b></font><font color="#0000FF"><i>' Wait 5 secs.
        </i></font><b>LED = </b><font color="#FF0000"><b>0     </b></font><font color="#0000FF"><i>' Turn OFF Led.
    
        </i></font><b>Flag = </b><font color="#FF0000"><b>1 
    
        </b></font><font color="#000080"><b>GOTO </b></font><b>Loop
    
    </b><font color="#000080"><b>END
    
    </b></font>
    Last edited by sayzer; - 28th June 2008 at 10:59. Reason: typo
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Conway's Game Of Life
    By wellyboot in forum mel PIC BASIC Pro
    Replies: 45
    Last Post: - 28th May 2020, 06:14
  2. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  3. For next loop using: Led var Byte
    By quester in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th March 2008, 10:16
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. can't even flash an LED
    By bruno333 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2005, 13:27

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