C Code in PIC

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
allenkkwong
Posts: 20
Joined: Mon Apr 24, 2017 3:26 am
Has thanked: 1 time
Been thanked: 3 times

C Code in PIC

Post by allenkkwong »

Hi Benj,

I am new to FC6. Recently I have also upgraded to FC7. I put below C code in the main() intended to set the port pulled high internally.
LATG |= 0xc0;

However, after compilation and tested the hardware, the port is not pulled high. Can you tell if I made any mistakes?

Thanks a lot
Allen

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: C Code in PIC

Post by Benj »

Hi Allen,

What chip are you using?

When you say pulled high do you want to output high or simply pull up high using the internal pull up resistors?

The output high will give you 20mA of pull, the internal pull up's will give you significantly less that this in terms of current.

allenkkwong
Posts: 20
Joined: Mon Apr 24, 2017 3:26 am
Has thanked: 1 time
Been thanked: 3 times

Re: C Code in PIC

Post by allenkkwong »

Hi Benj,

I am using PIC18F67J111. I want to simply pull high using the internal pull up resistors.

For the current, I understand this. I do not need high current.

Thanks.

allenkkwong
Posts: 20
Joined: Mon Apr 24, 2017 3:26 am
Has thanked: 1 time
Been thanked: 3 times

Re: C Code in PIC

Post by allenkkwong »

Hi Benj,

I am using PIC18F67J111 and want to use the internal pull resistor.

I do not need high current and understand that the current is less than 20mA which is far more than required.

Thanks

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: C Code in PIC

Post by Benj »

Hello,

The following applies to the PIC18F67J11 device family and Flowcode 7. The Weak pull up is usually something like 100K Ohm though this can vary from one device family to the next. 80uA - 400uA specified in the datasheet.

To enable PortB pullups.

Code: Select all

INTCON2 &= 0x7F;
To enable PortD pullups.

Code: Select all

PORTG |= 0x80;
To enable PortE pullups.

Code: Select all

PORTG |= 0x40;
To enable PortJ pullups.

Code: Select all

PORTG |= 0x20;

allenkkwong
Posts: 20
Joined: Mon Apr 24, 2017 3:26 am
Has thanked: 1 time
Been thanked: 3 times

Re: C Code in PIC

Post by allenkkwong »

Hi Benj,

Thanks and it works.

Rgds

Post Reply