Forums MPLAB XC8 Tutorial Discussions LED blinking problem

This topic contains 5 replies, has 2 voices, and was last updated by  Bitahwa Bindu 2 weeks ago.

  • Author
    Posts
  • #3196

    CrtSuznik
    Participant

    Hey guys, I’ve no idea what I’m doing wrong or if it’s even a mistake I made. I followed the video exactly https://www.youtube.com/watch?v=mUofSucHx_E&t=2s

    (I’m pretty sure at least)
    The only difference is I’m using a PIC18F4520.  Here’s a link to the datasheet http://ww1.microchip.com/downloads/en/devicedoc/39631a.pdf

     

    From what I can tell, the OSCCON is the same. I tried both 0x76 and 0b01110110 and there’s no difference. In the simulation (as in the video), my led blinks normally, however when I upload the code to an actual PIC18F4520, the led blinks reeeeally fast.

    Changing the delay doesn’t seem to have an effect.

    Also, since It doesn’t seem to work while it’s connected to my pickit2 (maybe it does, I just don’t know how to get it working), I disconnected the pic, transferred it to a breadboard and put 5V to VCC and gnd to VSS. I connected a led with a resistor to the appropriate pin, but did nothing else. I’m not sure if i need to pull the MCLR high or low or if it doesn’t matter, so I tried both (just touched the MCLR pin to VCC and then to GND with a wire) but it had no effect.

    I’m not sure what to do, since from what I can tell, the code should work. Maybe it’s a software issue. Oh, I should mention I’m using XC8 version 2.0 and mplab version 4.00

    I’ve attached my mplab code.

    Attachments:
    You must be logged in to view attached files.
  • #3199

    Bitahwa Bindu
    Keymaster

    Hi, Can you post the full zipped project, not just the individual C and H files.

  • #3200

    CrtSuznik
    Participant

    Ok, I’ve zipped the whole project now.

    Attachments:
    You must be logged in to view attached files.
  • #3202

    Bitahwa Bindu
    Keymaster

    Try to make these few coinages and see if will make a difference:

    1.  In Proba.h, switch OFF the LVP: Change #pragma config LVP = OFF
    2. In Prob.c change int main(void) to void main(void)
    3. Remove the loop in the delay function, I used the loop in the past because the old XC8 compiler did not accept high delay values, but this limitation has been resolved in new compilers. Write: __delay_ms(1000);
    4. Do you experience the same problem even if you connect your LED to a different pin or PORT?
  • #3203

    CrtSuznik
    Participant

    O M G

    I did all of the above and also saw that I wasn’t actually building and uploading this project, but a different one. It now works fine! Is there a way that I could select this project folder as my main one so I don’t have to right click on it and then click build and upload…I would very much like to just use the icons at the top to do so, but they seem to want to build and upload a different project by default.

     

    Thank you again for your help! 😀

  • #3204

    Bitahwa Bindu
    Keymaster

    😆

    To make this project as the main project: Right click it and select : Set as Main Project.

You must be logged in to reply to this topic.