Hot!Program LED + BP with PIC16F18345

Author
Jonathan_G
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2018/03/07 06:24:16
  • Location: 0
  • Status: offline
2018/03/08 01:58:39 (permalink)
0

Program LED + BP with PIC16F18345

Hello everyone,

I have a small problem on my program. It dials a red (RB7) using a push button (RC5). When I press the button, the LED lights up after a certain time and goes off after several presses.
.main.c I can not turn on and off a led with this push button. I use MPLAB X IDE v4.01 for PIC programming. If anyone can help me, with pleasure!

Attachment(s)

Attachments are not available: Download requirements not met
#1

4 Replies Related Threads

    katela
    Super Member
    • Total Posts : 956
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: Program LED + BP with PIC16F18345 2018/03/08 15:10:12 (permalink)
    0
    First if all you are connecting incorrectly your push-button, I don't see how you gonna get a '1' with it. When you press it, it will short RC5 to ground giving you a '0' but in your code you are expecting a '1' if pressed: (if (BP == 1){       // Si le bouton est appuyé ...)
    You must use a pull-up resistor to RC5 and and read: if (BP == 0){ // Si le bouton est appuyé ...
     
    In your first IF statement it won't evaluate to true, so variable etat_Bp  will remain 0 and LED red will remain OFF even if you press your button and the second IF statement won't evaluate as well.
    In your second IF statement what the purpose of variable unite ? Even if the push button works, with 20ms delay, I don't think you'll notice if the LED red is ON.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/user/StudentCompanionSA
    #2
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: Program LED + BP with PIC16F18345 2018/03/08 15:35:04 (permalink)
    +1 (1)
    katela
    First if all you are connecting incorrectly your push-button, I don't see how you gonna get a '1' with it.

    This PIC has weak pull ups avaiable on most pins.
    The 0x20 written to WPUC will enable the pullup on RC5, so the push button circuit is ok.
     
    The config settings are setting the internal oscillator to 32MHz, but the _XTAL_FREQ define is specifying 8MHz, so all the compiler delay routines will take a quarter of the specified time.
    Make it #define _XTAL_FREQ  32000000
     
    The config settings have MCLR on and LVP on. The schematic does not show any pullup resistor on MCLR.
    If there isn't one, then you should change both MCLRE and LVP to off.
     
    Personally, to start with I would remove the pushbutton test, and simplify the code to simply toggle the LED every 500ms, so you should get a steady 1 second flash if it's running correctly.
    Only once you succeed with that, add the pushbutton test back in.
     
    The secret to effective debugging is to reduce how many unknown problems you are testing at each step.
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #3
    katela
    Super Member
    • Total Posts : 956
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: online
    Re: Program LED + BP with PIC16F18345 2018/03/08 15:58:03 (permalink)
    0
    qɥb
    This PIC has weak pull ups avaiable on most pins.
    The 0x20 written to WPUC will enable the pullup on RC5, so the push button circuit is ok.
     

    Didn't notice that.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/user/StudentCompanionSA
    #4
    PStechPaul
    Super Member
    • Total Posts : 2042
    • Reward points : 0
    • Joined: 2006/06/27 16:11:32
    • Location: Cockeysville, MD, USA
    • Status: offline
    Re: Program LED + BP with PIC16F18345 2018/03/08 17:03:56 (permalink)
    +1 (1)
    Also I think this and other more recent PICs have an internal pullup on MCLR, a Schmitt trigger, and a filter to ignore spikes. But it is good practice to use an external pullup and perhaps a small capacitor.

     
    #5
    Jump to:
    © 2018 APG vNext Commercial Version 4.5