PIC 16F877A code not working

Thread Starter

sayf alawneh

Joined Aug 4, 2014
20
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:
void repetition(char ww,int yy)
{
char y,x;
for(y=0;y<10;y++){
PORTB=ww;
for(x=0;x<yy;x++)delay_ms(1);//delay one second since the value of yy is 1000
PORTB=0;
delay_ms(1000);
}
}
void main()
{
TRISB=0;
repetition(255,1000);
}
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:

MrChips

Joined Oct 2, 2009
30,824
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;

to

int y, x;
 

tshuck

Joined Oct 18, 2012
3,534
[...]but the real circuit dont do the needed job[...]
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.
 

Thread Starter

sayf alawneh

Joined Aug 4, 2014
20
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.
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
 

Thread Starter

sayf alawneh

Joined Aug 4, 2014
20
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
 
Top