PIC never reacts to Button


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2008
    Posts
    2

    Default PIC never reacts to Button

    Hello everybody,

    I have worked on this programme to select between two PWM values on PortB + display and by pressing a button on PORTA.0.

    Unfortunately, and after pressing the button I don't get the change I want. I tried a lot but no success. I need a generous help.

    Here is the code:

    'PWM

    include "modedefs.bas"
    DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 0 'Define first pin of portb connected to LCD DB4
    DEFINE LCD_RSREG PORTB 'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 5 'Define PIC prot used for E line of LCD
    DEFINE LCD_EREG PORTB 'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT 4 'Define PortB pin used for E connection
    DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 4 'Define using a 4 line LCD
    DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50 'Define delay time between data sent
    W0 var word


    ADCON1=7
    TRISA=1

    TRISB=0
    PORTB=0
    PORTA=0
    'W0=0
    'W0=PORTA.0

    loop:
    if PORTA.0 then
    LCDOUT $FE,1,"PWM1",#W0," "
    pwm PORTB.6,127,100


    else
    LCDOUT $FE,1, "PWM2",#W0," "
    pwm PORTB.7,127,100
    endif

    goto loop

    END

    Many thanks in advance.

  2. #2
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Do you have a pull up resistor to RA.0?

    Try putting a pause 1000 to see the changes before goto loop.
    Last edited by Pic2008; - 30th November 2008 at 12:52.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Question Context needed !!!

    Hi,

    The problem could be ... at first, once you release you button ... value comes back to the default.

    you ,may be, have to memorize the last button press action ...


    Now ... dependinding on your PIC ( BTW ... Which one do you use ??? ) PortB.6 and 7 can be shared with ADC, ( ADCON1 <> 7 !!! ) , clock ... or sthg else.

    Osc settings are also necessary to understand how your circuit is REALLY working ...

    Your scheme could be useful, in the end, to see if any pulldown on your inputs ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Nov 2008
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Hi again
    Thanks a lot for the reply and to all,

    I use the pic16f876, PortB outputs an LCD pins 0 to 5, pulse out are on 6 and 7.
    PORTA.0 input where a button with a 10 K pull up resistor connected.
    No master clear connection.

    But even with or without pull ups or master clears nothing changes. I think I have to learn how to activate or disable internal pullups too.

    I'll consider your remarks and try them out and come back later.

    Regards

    Alfonso

Similar Threads

  1. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  2. Replies: 5
    Last Post: - 12th September 2007, 15:59
  3. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

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