Help with code, button


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    If I make the code like tis:

    Code:
    @   device  pic16F648A, hs_osc, wdt_off, mclr_on, lvp_off, protect_off
    DEFINE OSC 20
    
    LED1 var PORTB.1
    PRESS var PORTA.1
    CMCON=7
    
    
    loop:
    
    If press=0 then       
                high led1  
                else
                low led1  
                endif      
                goto loop   
                end
    Should it be like this?


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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by xobx View Post
    If I make the code like tis:

    Code:
    @   device  pic16F648A, hs_osc, wdt_off, mclr_on, lvp_off, protect_off
    DEFINE OSC 20
    
    LED1 var PORTB.1
    PRESS var PORTA.1
    CMCON=7
    
    
    loop:
    
    If press=0 then       
                high led1  
                else
                low led1  
                endif      
                goto loop   
                end
    Should it be like this?

    No. The first way is what you want. When the switch is open the pin is "0"LOW. When the switch is closed the pin is "1"HIGH.

    If you are using push buttons, you will need to use either a normally open "NO" or a normally closed "NC".

    The resistor keeps the pin LOW (no float). High resistance is used to minimize the current through the switch (just a little short).

    Depending on how you look at it this is called a pull up or a pull down.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. TSA5512/5511 code for PIC16F877/84
    By Marin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th August 2013, 06:16
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43

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