PIC controller doubt about programming

Thread Starter

embpic

Joined May 29, 2013
189
i am confuse when using PORTBbits.xxx and LATBbits.xxx resister.
when i used this words PORTBbits then structure get dropdown type come out.
so what is used for what i am really confused.

 

JohnInTX

Joined Jun 26, 2012
4,787
For 18F and enhanced midrange:

The TRIS registers set the direction of the port pin 1=IN, 0=OUT. Writing TRIS is usually done during power up initialization.

PORT and LAT refer to the IO pins themselves. For inputs always read PORT and for writes (including bit set/clear) specify LAT to avoid read-modify-write problems. (PORT and LAT refer to the same pin but work differently to handle these different actions). Never bsf/bcf PORTx always bsf/bcf LATx.

Many pins have multiple functions that must be considered. For example, some are ANALOG on power up and must be explicitly configured to be a digital port.

The IO chapter in the databook covers all of this in detail, providing tables of shared functions and registers used to configure the ports.
 
Last edited:

Thread Starter

embpic

Joined May 29, 2013
189
yes sir this is clear but when i type in editor as:
TRISBbits. then what should i select whether
Rich (BB code):
TRISBbits.RB0
or

Rich (BB code):
TRISBbits.TRISB0
 

THE_RB

Joined Feb 11, 2008
5,438
It looks likely they are both 0-7 range, so they will both work the same.

However I would still use;
TRISBbits.TRISB0
because it is not possible to confuse that with something else.
 

ErnieM

Joined Apr 24, 2011
8,415
yes sir this is clear but when i type in editor as:
TRISBbits. then what should i select ...
A complete answer would require knowing what compiler and what device you are using, as these symbols are defined inside the dot h file the compiler supplies for each device.

However, for a PIC18 device under XC8 you could use either the TRISB0 or the RB0.

Additionally, I agree with RB here, TRISB0 is preferable for readability for reasons of tradition at the very least.
 
Top