Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.
There are no hard and fast rules as to what ports you use, though generally PortA is handy for inputs /adc, PortB for outputs and / or Inputs with interrupts.
PortC for data transmission like USART,SPI,I2C and PortD for General purpose i/o - typically a lcd.
TRIS sets the Direction of a Port, 0 for Output 1 for Input.
However for Ports with the ADC function, need to be switched to Digital function with the ADCON1 instruction as they default to Analogue Inputs at Power on.
See the datasheet I/O Port section for code examples.
INTCON relates to enabling the Interrupt functions of various things including PORTB interrupts.
If this confuses you now, I suggest you get some tutorial on PIC to get you started before going into anything deeper.
To answer you question:
You decide what port to use according to your design requirements. As a general digital input/output it makes no difference, tho there are some limitations to consider because all internal hardware (PWM, UART, ADC, etc.) is multiplexed over port pins. For example if you want to use UART, than PORTB pins 6 & 7 (depends on mcu) must be used to allow UART to communicate with the outside, and those pins are not available as general digital I/O.
TRIS registers are used to set direction on corresponding port pins (input or output). For example TRISA=0b00001111 will set pins 0,1,2,3 on PORTA as inputs and 4,5,6,7 as outputs.
ADCON registers (ADCON0 and ADCON1) are used to configure the analog-to-digital converter
INTCON registers (together with PIE registers) are used to configure interrupts.
Study the Midrange PIC tutorials covering both Assembly or C languages. While the tutorials cover the Midrange PIC16F series, 90% is transferable to the 18F series.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.