PIC 16F877A code not working

Discussion in 'Embedded Systems and Microcontrollers' started by sayf alawneh, Sep 24, 2014.

  1. sayf alawneh

    Thread Starter New Member

    Aug 4, 2014
    this is a simple code to call a function named repetition when i call him 8 leds attached to port b go on and off for 10 times given that am using mikroc pro for pic
    Code (Text):
    2. void repetition(char ww,int yy)
    3. {
    4. char y,x;
    5. for(y=0;y<10;y++){
    6. PORTB=ww;
    7. for(x=0;x<yy;x++)delay_ms(1);//delay one second since the value of yy is 1000
    8. PORTB=0;
    9. delay_ms(1000);
    10. }
    11. }
    12. void main()
    13. {
    14. TRISB=0;
    15. repetition(255,1000);
    16. }
    but the simulation is not doing the needed task
    i also have another problem guys some times the simulation works fine but the real circuit dont do the needed job this happens when i am calling a function to do a certain job
    my pic (16f877a) is programming well and my circuit is 100% accurate is it a problem in my MIKROc or in my programmer but my programmer programs well :/
    Last edited by a moderator: Sep 24, 2014
  2. MrChips


    Oct 2, 2009
    Before we tackle your problem, here are a couple of forum tips.

    1) A subject title of "please help" is of no use to anyone. Use a more descriptive title such as"PIC 16F877A code not working".

    2) Enclose your code using CODE tags.

    Now about your problem, change

    char y, x;


    int y, x;
    Chalma likes this.
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    What is it doing? Are the LEDs flashing at all? How fast?

    I don't use MikroC - how did you define the oscillator frequency?

    What value oscillator/crystal did you attach to the PIC? If you used a crystal, what value of capacitors?

    What do you have for your configuration bits? Is MCLR enabled? If so, do you have a pullup resistor on pin 1?

    Once those things are addressed, take a look at the software, in particular, what MrChips suggested.
  4. sayf alawneh

    Thread Starter New Member

    Aug 4, 2014
    thanks for ur reply am using mikroc pro for pic and i just need to set the value of the crystal in the preset of it
    and yeah every thing u mentioned is ok and connected fine the value of the capacitors attacked to the crystal are 22 pF both
    and the pull up resistor is fine and attached to pin #1
    when i operate the program on proteus the leds flash but dont turn off !!
    thats the problem am gonna try what mrchip said and give u a reply
    arigato :D
  5. sayf alawneh

    Thread Starter New Member

    Aug 4, 2014
    aha thanks mrchip every thing works fine now :D didnt note that x will have the value of 999 -_- :D :D
    and about the forum tips consider it done :D