Maker Pro
Maker Pro

C programming on PIC16F877A

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
In general, if you don't understand it, turn it off.

when you decide you need those things (watchdog timers, etc) then you can turn them on.

DO NOT turn off Low Voltage Programming (LVP).
 
In general, if you don't understand it, turn it off.

when you decide you need those things (watchdog timers, etc) then you can turn them on.

DO NOT turn off Low Voltage Programming (LVP).

But what is watchdog timer all that ? when to used them ?

why do not turn off LVP ?

But I see the code from some web they disable it ?

Code:
__CONFIG(HS &			// External Crystal at High Speed
		 WDTDIS &		// Disable Watchdog Timer.
		 PWRTEN &		// Enable Power Up Timer.
		 BORDIS &		// Disable Brown Out Reset.
		 MCLREN &		// MCLR function is enabled
		 LVPDIS);		// Disable Low Voltage Programming.

Thank you
 
But what is watchdog timer all that ? when to used them ?

why do not turn off LVP ?

But I see the code from some web they disable it ?

Code:
__CONFIG(HS &			// External Crystal at High Speed
		 WDTDIS &		// Disable Watchdog Timer.
		 PWRTEN &		// Enable Power Up Timer.
		 BORDIS &		// Disable Brown Out Reset.
		 MCLREN &		// MCLR function is enabled
		 LVPDIS);		// Disable Low Voltage Programming.

Thank you

Please help steve :)
 
@steve,
just to ask, why for the configuration 0x3F32 works when I load the program to my PIC using PICKIT2 but after some times I load it it says verification failed and I have to change the configuration bits ? Is it due to the different version of the Hi-Tech Compiler or ?
Because this problem happens after I downloaded another version of Hi-Tech

Am I correct ?

Thank you
 
Hey guys,

TRISA=0b00000000;

and

PORTA=0b00000000;

Is this two the same things with same functions or different ? Just need to write either one only ?

Thank you
 
Oh..Now I understand.

I seldom use PORTA=0b00000010.

It is the same as if I define my LED = RA1, then in my code I wan it to get high I can just write LED =1.

Same thing right ?

Correct me if I am wrong :)
 
Oh..Now I understand.

I seldom use PORTA=0b00000010.

It is the same as if I define my LED = RA1, then in my code I wan it to get high I can just write LED =1.

Same thing right ?

Correct me if I am wrong :)

I think you will find out though that the header file for your pic defines RA1 as PORTA bit 1. So in a sense your program is still using PORTA but the work is done behind the scene. You could just as well use PORTA = 0b0000010
 
Last edited:
No..I just wan to ask

PORTA=0b00000010 means that I light up the LED at pin RA1 rite ?

My way is that :
#define LED RA1

void main()
{
LED=1;
delay(10000);
LED=0;
}

which is same as

void main()
{
PORTA=0b00000010;
delay(10000);
PORTA=0b00000000;
}

Both are same rite ?
 
No..I just wan to ask

PORTA=0b00000010 means that I light up the LED at pin RA1 rite ?

My way is that :
#define LED RA1

void main()
{
LED=1;
delay(10000);
LED=0;
}

which is same as

void main()
{
PORTA=0b00000010;
delay(10000);
PORTA=0b00000000;
}

Both are same rite ?

You would answer your own question if you looked at the header file included in the above code for your pic. Read again what I said and then go look at the header file. Prove it to yourself that the above is true.

C:\Program Files (x86)\HI-TECH Software\PICC\9.83\include is where the headers can be found for the pic's on my computer. Your location should be similar if you are using MPLAB and the C compiler.
 
Last edited:
You would answer your own question if you looked at the header file included in the above code for your pic. Read again what I said and then go look at the header file. Prove it to yourself that the above is true.

C:\Program Files (x86)\HI-TECH Software\PICC\9.83\include is where the headers can be found for the pic's on my computer. Your location should be similar if you are using MPLAB and the C compiler.

What header should I find ?
 
Yea..the header file is this :

Untitled-1.png



But what does that means ? Yes, RA1 is 1
RA2 is 2..so means ?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Then presuming all bits are outputs, you're turning one on and seven off. I'll leave it to you to determine which one you're turning on (high) and which seven you're setting low.

Perhaps you should try to pick up something like "123 PIC Microcontroller experiments for the evil genius". It does a reasonable job of explaining the basics even if you don't make any of the projects.
 
Then presuming all bits are outputs, you're turning one on and seven off. I'll leave it to you to determine which one you're turning on (high) and which seven you're setting low.

Perhaps you should try to pick up something like "123 PIC Microcontroller experiments for the evil genius". It does a reasonable job of explaining the basics even if you don't make any of the projects.

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

Correct ?
 
Top