how to set portA/B of pic18f1320

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
saravana_3
Posts: 61
Joined: Thu Dec 20, 2007 4:23 pm
Location: singapore
Contact:

how to set portA/B of pic18f1320

Post by saravana_3 »

hi friends,
now I am working with the pic18f1320, but I dont know how to set the portA and portB as the I/O ports, in the assembly language.
also I am not verysure how to configure the pic in assembly,
please share your experience.
thanks
saran

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: how to set portA/B of pic18f1320

Post by Benj »

Hello Saran

I wouldn't recommend assembler language unless you must have direct control over every single instruction. However if you have your heart set on it you must do the following.

Find the bit in the status register that controls the bank switching. This is normally named RP0.

Set this bit to move into Bank1.

When in bank 1 you can write a value to the TrisA and TrisB registers which will configure the I/O operation. 1=Input, 0=output.

Then Switch back to bank 0 by clearing the bit in the status register.

Then read or write to registers PortA and PortB to control the I/O functionality.

Microchip C would use the same method but is much easier to code. BoostC is even easier as it does all of the bank switching functionality for you.

Eg in BoostC you would do the following.

Write value to tris register
Read / Write value to port register.

Post Reply