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

PCD set_open_drain_x()

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



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PCD set_open_drain_x()
PostPosted: Tue Sep 28, 2021 3:17 pm     Reply with quote

I found a reference to "set_open_drain_x()" in the General Purpose IO section of the manual, but no details on what x is. I assume it is the port, like other similar calls. Also, header file:

Code:
_bif void set_open_drain_b(unsigned int16 value);
_bif void set_open_drain_c(unsigned int16 value);
_bif void set_open_drain_d(unsigned int16 value);
_bif void set_open_drain_e(unsigned int16 value);
_bif void set_open_drain_f(unsigned int16 value);
_bif void set_open_drain_g(unsigned int16 value);


But what is the value? From this article:

https://simple-circuit.com/pic24fj64gb002-lcd-interfacing-ccs-c/

...they write:

Quote:
For example if I want pin RB0 to be an open-drain output I just write:
set_open_drain_b(1);
For pins RB7, RB8 and RB9 I used:
set_open_drain_b(0x380);
where 0x380 = 896 = 0b0000001110000000


It appears the expected value is a bit pattern. The define for PIN_E4 is 1 0111 0001 0100 so that must not be what it is expecting.

Any tips on where I can find some documentation on this?

Thanks, much.
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 28, 2021 4:21 pm     Reply with quote

Open the CCS manual pdf file. Make sure the PDF file is opened
at the starting page (the cover). Press Ctrl-F to open up a search
box within the Adobe reader. Type in set_open_drain and press
enter. It will highlight the table of contents entry for:
Quote:
set_open_drain_x(value)

Click on that entry with your mouse.

It will take you to the entry for set_open_drain_x(value) in the text.
That entry tells you what you need to know about the parameter.

CCS manual:
http://www.ccsinfo.com/downloads.php
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Sep 29, 2021 12:45 am     Reply with quote

and seriously, just use binary. It makes things so much easier.
So for B7, B8 & B9:
set_open_drain_b(0b0000001110000000);

While for E4:
set_open_drain_e(0b0000000000010000);

Much easier to understand what pin is involved.

Understand this only applies on chips that have the ability to set pins to
open_drain mode.
allenhuffman



Joined: 17 Jun 2019
Posts: 552
Location: Des Moines, Iowa, USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 29, 2021 8:22 am     Reply with quote

Ttelmah wrote:
and seriously, just use binary. It makes things so much easier.
So for B7, B8 & B9:
set_open_drain_b(0b0000001110000000);

While for E4:
set_open_drain_e(0b0000000000010000);

Much easier to understand what pin is involved.

Understand this only applies on chips that have the ability to set pins to
open_drain mode.


Looks like another case of "not in the help file."

I noticed the bits, but what are the high bits in the #defines? 5904 for bit four, but what do the 59 bits mean?
_________________
Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Wed Sep 29, 2021 9:34 am     Reply with quote

What #defines?.

I think you are confusing bit numbers with port masks.
The #define for PIN_E4, is the value to be fed to things like the output_high
and output_low functions. Nothing to do with a port mask for things like
this, and TRIS.

Functions that have _a, _b etc. at the end are just talking directly to
the registers associated with the single port. So 'output_b', just talks
to the whole of port B. It expects to receive a byte value to send to the port.
(or int16 for PCD).
The TRIS functions, and this open_drain function, again talk to the registers
for a single port, and expect a byte (or int16 for PCD) value with each
bit corresponding directly to the bit in the port.
This is completely separate from things like output_high, and output_low,
which expect to receive a value that is actually the register address of the
output register (*8 for PCM/PCH, and *16 for PCD), plus the bit number
to operate in this register.

The manual makes this very clear. If you look at the entry for the
open_drain function, it says:
Quote:

Parameters:
value – is an 8-bit int with each bit representing a bit of the I/O port.

[PCD] value – is a 16-bit int with each bit representing a bit of the I/O port.



While if you look as 'output_high', it says:
Quote:

Parameters:
The PIN could also be a variable. The variable must have a value equal to one of the constants (like PIN_A1) to work properly. The tristate register is updated unless the FAST_IO mode is set on port A. Note that doing I/O with a variable instead of a constant will take much longer time.

[PCD] pin to write to. Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 0x2C2) bit 3 would have a value of 0x2C2*8+3 or 5651. This is defined as follows: #DEFINE PIN_A3 5651.


You must not mix the two types of value.

The open_drain function is a port_wide function, not a function that works
or accepts single bit defines.
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