Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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!! :D

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!.
 
Joel Rainville said:
Jay.slovak said:
Try TRISA = 255;
:lol:

Hey, not bad Jay, not bad... :D You've been reading datasheets, don't you? We can tell!... :p:lol:
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).
 
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...
 
Exo said:
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.
 
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.

Latest threads

New Articles From Microcontroller Tips

Back
Top