Starting Programming PIC16f877 with C

spinnaker

Joined Oct 29, 2009
7,830
pls check old post i don't have Proteus...
It looks like Proteus. That is why nerdguru thought you wanted to do it in Proteus. It doesn't matter. You are doing it for real in post #55. Why do you now why to simulate it? Just do it for real now.

If you really want to simulate the code then it can be done with MPLab.
 

spinnaker

Joined Oct 29, 2009
7,830
How, to simulate in MAP LAB i mean ...

Why do you want to simulate it? Do it for real and get you problem solved first.

MPLab simulator is not easy to use. It won't show you a blinking light or anything. You will need to know how to use the debugger to show the values of registers.

But to use it, you first have to have your code compiled for debug. Then select Debugger/Select Tool/MPLab Sim. Program the virtual chip. Then run and debug.

But why complicate things? You almost have it now just finish it.
 

spinnaker

Joined Oct 29, 2009
7,830
But how the code is right do u think problem in hardware......
Did you make the change nerdguru suggested?

Then fix the hardware. This is an extremely simple program. It should work.

Have you checked all of your connections?

Do you have a scope, logic probe or even a volt meter? Put it the code in debug, step through the code and check the pin to see if the value is changing.

Have you checked your datasheet? Are you certain the pin you are using is a output pin? Some pins are input only.
 

spinnaker

Joined Oct 29, 2009
7,830
Better yet.


Temporarily change this line:

PORTB = !PORTB;

to this

PORTB = 255;


See if the light comes on and stays on. Better yet check the output on the pin.

And did you check you datasheet? Is the pin you are using output capable?
 

spinnaker

Joined Oct 29, 2009
7,830
but the code is right....believe me.
If it is as it is in post #55 then it is NOT right. Or at least may not working depending on which bit of the port the led is connected to.

You have a logical not and it will only not the first bit. So the LED would have to be connected to the first bit or pin zero of the port. The correct way to do it is with a bitwize not and that is what nerdguru suggested. This will not all bits.


Please follow the advice of those that gave it to you. Nerdguru is very knowledgeable and he would not give you incorrect information.
 

t06afre

Joined May 11, 2009
5,934
The problem here might be due to the read-modify-write construction of the chip.
Try this
Rich (BB code):
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);

#define _XTAL_FREQ 4000000
char dummy;
void main (void)
{
TRISB=0;//all pins set as ouput
while (1)
 {//endless loop
dummy=~dummy;
  PORTB = dummy;
  __delay_ms(1000);
 }
}
 

spinnaker

Joined Oct 29, 2009
7,830
FYI

I confirmed that PortB is a bidirectional Port for the PIC16f877, so the fact that it could be input only is NOT the issue.
 

spinnaker

Joined Oct 29, 2009
7,830
The problem here might be due to the read-modify-write construction of the chip.
Try this
Rich (BB code):
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);

#define _XTAL_FREQ 4000000
char dummy;
void main (void)
{
TRISB=0;//all pins set as ouput
while (1)
 {//endless loop
dummy=~dummy;
  PORTB = dummy;
  __delay_ms(1000);
 }
}

My suggestion is to just get the light to turn on all the time as I suggested in post 73 the OP can then worry about turning it off.
 

t06afre

Joined May 11, 2009
5,934
My suggestion is to just get the light to turn on all the time as I suggested in post 73 the OP can then worry about turning it off.
Something like this
Rich (BB code):
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_XT);
 
#define _XTAL_FREQ 4000000
void main (void)
{
TRISB=0;//all pins set as ouput
while (1)
{//endless loop
PORTB = 0xff;
}
}
Good idea. By this the OP will confirm that the "system" is working OK. If this works. Then let us go for blinking
 

bertus

Joined Apr 5, 2008
22,277
Hello,

Wich PIC are you using?
The title of the tread states PIC16F877, but in the thread you mention the PIC16F877A.
There are some slight differences between them.

Bertus
 
Top