Help with code, button


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Posts
    48

    Default Help with code, button

    When I give PORTA.1 +5V, LED1 dosent shine..

    Whats wrong with my code?

    Code:
    LED1 var PORTB.1
    PRESS var PORTA.1
    
    loop:
    
    If press = 1 then       
                high led1   
                else
                low led1   
                endif      
                goto loop   
                end

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


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    I dont know its a PIC16F648A

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


    Did you find this post helpful? Yes | No

    Default

    According to the data sheet it has two comparators.
    The above links will explain why
    CMCON=7
    is needed.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Jul 2007
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    Ok, thanks.

    But it still dosent work as I want it :/

    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=1 then       
                high led1  
                else
                low led1  
                endif      
                goto loop   
                end
    When i transfer it LED1 starts to shine directly even if PortA.1 doesnt have +5V

    :/

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


    Did you find this post helpful? Yes | No

    Default

    Maybe the LED is backwards

    Do you have PORTA.1 tied to ground with a resistor (10K) so it is not floating?
    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