Maker Pro
Maker Pro

C programming on PIC16F877A

This is depends on my own preference for which my output is connected to ?
If LED=RA0
then PORTA=0b00000001

Correct ?

That makes no sense(because you fail to tell us or show us what your ports are set as input/output) and you don't tell us what you expect from this code. I can't seem to understand why you keep asking the same question? There is nothing right about your question because it is barely a question at all...

LED==RA0==PORTA bit 0 (only because you defined LED as RA0)
PORTA=0b00000001 sets bit 0 of PORTA to 'HIGH' IF TRISA bit 0 is an output.

It doesn't get any clearer!!!!
 
Last edited:
That makes no sense(because you fail to tell us or show us what your ports are set as input/output) and you don't tell us what you expect from this code. I can't seem to understand why you keep asking the same question? There is nothing right about your question because it is barely a question at all...

LED==RA0==PORTA bit 0 (only because you defined LED as RA0)
PORTA=0b00000001 sets bit 0 of PORTA to 'HIGH' IF TRISA bit 0 is an output(1).

It doesn't get any clearer!!!!

Ok.Let me show u the whole coding

Code:
#include <pic.h>

__CONFIG ( 0x3F32 );

#define LED_1 RA0
#define LED_2 RA1


void init(void);
void delay(unsigned long data);

void main(void)
{
init();


for(int i=0;i<10;i++)
{
LED_1=1;
LED_2=0;
delay(10000);
LED_1=0;
LED_2=1;
delay(10000);
}




}



void init()
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;

}

void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); //depend on the given value

Is this the same as :
Code:
#include <pic.h>

__CONFIG ( 0x3F32 );

#define LED_1 RA0
#define LED_2 RA1


void init(void);
void delay(unsigned long data);

void main(void)
{
init();


for(int i=0;i<10;i++)
{
PORTA=0b00000001;
PORTA=0b00000000;
delay(10000);
PORTA=0b00000000;
PORTA=0b00000010;
delay(10000);
}






}



void init()
{
TRISA=0b00000000;
TRISB=0b00000000;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;

}

void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); //depend on the given value
 
I am curious as to why you would ask that? Is the output different? Have you tried running that code with real components to see? Above all else, you should know this answer. :)

If you are looking for a straight answer you are not gonna get it from me. That is how you learn by answering your own questions.

Also, you do know there is a delay_ms() delay_us() functions built into the IDE
 
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
one of your pieces of code changes 1 bit at a time, the other all 8 at a time.

the closest equivalent is something like this

PORTA=PORTA || 0b00000001;
PORTA=PORTA && 0b11111101;
delay(10000);
PORTA=PORTA && 0b11111110;
PORTA=PORTA || 0b00000010;
delay(10000);

Each pair of lines code be replaced with 1 line, and simplified if the other 6 bits were unused.
 
I also thought in the newest versions of Hi-tech compiler pic.h was replaced by htc.h, but I am unsure since I don't really use PICC very much
 
How do I determine whether it is in uS or ms ?

I would ask so abt PORTA because I thought PORTA=0b00000000 is the same as TRISA=0b00000000..

Well, I will try running both code and see how :)

Thanl you
 
one of your pieces of code changes 1 bit at a time, the other all 8 at a time.

the closest equivalent is something like this

PORTA=PORTA || 0b00000001;
PORTA=PORTA && 0b11111101;
delay(10000);
PORTA=PORTA && 0b11111110;
PORTA=PORTA || 0b00000010;
delay(10000);

Each pair of lines code be replaced with 1 line, and simplified if the other 6 bits were unused.

I never seen code like this ><

1 isnt that it means HIGH ?
 
If you blink and LED too fast it will appear as always on. I would suggest a 500mS delay to start with. You should be able to see a half second blink rate.

Steve brings up a good point in his post. I tried to stay away from that atm, but here is a couple good articles that do a really good job at explaining. It even goes over the dely_ms function. Maybe you will read these http://www.gooligum.com.au/tutorials/baseline/PIC_Base_C_1.pdf

Page 67 of the simonbramble link will explain the bitwise operators

edit: was forced to remove the simonbramble link because he has decided to charge for his e-book and that would break the sites commercial advertising policy
 
Last edited:
void delay(unsigned long data) //delay function, the delay time
{
for( ;data>0;data-=1); wrong !
change to : for( ;data>0;data--)}


good luck!
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
both of those are OK.

for (; data>0; data = data - 1); is also OK

Any optimising compiler is going to make them all the same anyway.
 
hey steve, what would it probably be when I switch on my PIC development board, the LED connected between the I/O pins and GND will give a dim light a while then off ?

Advice me.

Thank you :)
 
Top