CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Weak pullups problem in 18f46k80

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ömer Faruk



Joined: 15 Nov 2018
Posts: 42
Location: Çanakkale

View user's profile Send private message Send e-mail

Weak pullups problem in 18f46k80
PostPosted: Mon Dec 17, 2018 4:32 am     Reply with quote

Hello dear friends. I am having a problem about setting weak pullups on port b. Although I set the right code only two pins have weak pullups, pin_b0 and pin_b5. What is the possible problem ? İ need your help.
Code:

   port_b_pullups(pin_b0);
   port_b_pullups(pin_b1);
   port_b_pullups(pin_b3);
   port_b_pullups(pin_b4);
   port_b_pullups(pin_b5);
   port_b_pullups(pin_b6);
   port_b_pullups(pin_b7);

   set_tris_b(0xFF);

here the related parts of my code.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 6:05 am     Reply with quote

I don't use that PIC but in general...
some possible things that can be the cause
1) defective PIC
2) bad PCB layout
3) bridged traces
4) compiler error
5) wrong header file
6) not disabling peripherals attacehed to pins
7) incorrect startup duw to marginal PSU
8) loading on pin due to external devices
9) if PIC has PPS, that needs to be looked at very carefully

re: #6. some PICs for some compiler versions default to analog and comaparator peripherals, so you need to disable to use as I/O pins

I'm sure there are other reasons...
empty



Joined: 13 Jan 2018
Posts: 15

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 6:29 am     Reply with quote

Doing port_b_pullups(pin_b7); has no meaning!

As written in the device header file 18F46K80.h:
port_b_pullups(int8 upmask);

Replacing 'upmask' by 'pin_b7' is the same as doing this:
port_b_pullups(31759);

upmask can vary from 0x00 to 0xFF which decides which pin pull-up is enabled or not, for example enable only RB1 weak pull-up:
port_b_pullups(0x02);

so enabling all PORTB pin pull-ups should be;
port_b_pullups(0xFF);

It's the same as writing to WPUB (WEAK PULL-UP PORTB ENABLE REGISTER) or PORTB.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 6:47 am     Reply with quote

and to do 'B7', would need:

port_b_pullups(0b10000000);
//Just turn on B7 pullup
Ömer Faruk



Joined: 15 Nov 2018
Posts: 42
Location: Çanakkale

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 17, 2018 10:11 am     Reply with quote

empty wrote:
Doing port_b_pullups(pin_b7); has no meaning!

As written in the device header file 18F46K80.h:
port_b_pullups(int8 upmask);

Replacing 'upmask' by 'pin_b7' is the same as doing this:
port_b_pullups(31759);

upmask can vary from 0x00 to 0xFF which decides which pin pull-up is enabled or not, for example enable only RB1 weak pull-up:
port_b_pullups(0x02);

so enabling all PORTB pin pull-ups should be;
port_b_pullups(0xFF);


It's the same as writing to WPUB (WEAK PULL-UP PORTB ENABLE REGISTER) or PORTB.


İ find out what is wrong, thank you very much . But why the compiler doesn't give an error when i write int16 instead of int8 ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Mon Dec 17, 2018 12:56 pm     Reply with quote

Of course not.

In C, the language will always automatically cast types.
If you use an incorrect type, the language automatically converts. This is
a very powerful feature of the language, but requires _you_ to verify
that what you are passing is what is expected....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group