how to program the tris and status bit of pic 16f877?

Status
Not open for further replies.
genkiyan said:
how to program the tris and status bit of pic 16f877? by using c language. thanx!!

You don't program the STATUS word, it's controlled by the PIC itself, you merely check the bits to see results.

Can't help you on C, but presumably the compiler comes with a helpfile and examples?, just look at those!.
 
Yep, as always 8)
But I wrote this because I am also learning C language - C18~C30 (by my self), and I still find Assembly easyer to program and understand (not including C's HW resources).
 
And in case you neet to bit-bang the TRIS register, I believe this should work

Code:
TRISBbits.TRISB7=1;
 
Jay.slovak said:
And in case you neet to bit-bang the TRIS register, I believe this should work

Code:
TRISBbits.TRISB7=1;

That's in C18, since he's using a 16F877 he is using a 3rd party compiler wich may use completely diffirent names.

Some even dont allow bit manipulation this way and only allow it by AND'ing and OR'ing the byte...
 
Hmm that sucks, I prefer to use Microchips toolsuits...
 
Exo said:
That's in C18, since he's using a 16F877 he is using a 3rd party compiler wich may use completely diffirent names.

I never realized Microchip did not have a C compiler for the PIC16... :shock:

Sure enough, all the C sample code for the PIC16 on microchipc.com is for the Hi Tech compiler : https://www.microchipc.com/HiTechCFAQ/#_Toc475127498

It looks like bit banging is done the same way as C18 (based on what Jay posted at least), but uses a whole different syntax.
 
Personally I hate how to bit-bang in C18, I would prefer something like:

Code:
TRISB7=true or
TRISB.7=false
 
It's done like this with the Hi Tech compiler :

Code:
RA0=1;         //produce 5V on RA0, pin 2 of micro
RA0=0;         //produce 0V on RA0, pin 2 of micro

Pretty straightforward...
 
Joel Rainville said:
It's done like this with the Hi Tech compiler :

Code:
RA0=1;         //produce 5V on RA0, pin 2 of micro
RA0=0;         //produce 0V on RA0, pin 2 of micro

Pretty straightforward...
Hmm, that's much better than C18 :?
 
No it isnt.
Using a name for every bit causes massive namespace pollution.

C18's way is much cleaner, by grouping the bits in a bitfield struct...
I agree the names are a bit long though...
 
Exo said:
No it isnt.
Using a name for every bit causes massive namespace pollution.

C18's way is much cleaner, by grouping the bits in a bitfield struct...
I agree the names are a bit long though...
That's true, but it's much harder o do it C18 way (especially for beginner).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…