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

using variable with output_low
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 29, 2005 12:45 pm     Reply with quote

Here's a revised function which works better. It now sets the TRIS.
Also you don't need the switch-case statement shown in the previous
code. Just give this function the CCS pin value and the state, and
it handles everything.

Code:

// do_pin_io() --
// This function will perform an i/o action on a CCS pin.
// The ccs_pin parameter must be a value defined in the .H
// file for your PIC, such as PIN_B0, PIN_C5, etc.
// The CCS pin value and state can be passed in variables.
//
// The action must be as follows:
// Action = 0:  Set the specified pin = 0
// Action = 1:  Set the specified pin = 1
// Action = 2:  Read the specified pin and return
//                   its value (0 or 1).

// Any action value > 2 will be treated as 2.  For actions
// 0 and 1, the return value has no meaning (but 0 is
// returned).

// This function only works for the 16F series PICs, in
// which the i/o ports are at addreses 5 to 9, and the
// corresponding TRIS registers are known to be at
// 0x85 to 0x89, respectively.

int8 do_pin_io(int8 ccs_pin, int8 action)
{
int8 io_port;
int8 bitmask;
int8 retval;
int8 const bitmask_table[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

retval = 0;
io_port = ccs_pin >> 3;   // Get the i/o port address     
bitmask = bitmask_table[ccs_pin & 7];

if(action < 2)  // Is this an output action ?
  {
   *(io_port | 0x80) &= ~bitmask; // Set TRIS = output

   if(action)
     {
      *io_port |= bitmask;    // Set pin = 1
     }
   else
     {
      *io_port &= ~bitmask;   // Set pin = 0
     }
  }
else  // If not, we will read the pin  (action = 2)
  {
   *(io_port | 0x80) |= bitmask;     // Set TRIS = input

   retval = !!(*io_port & bitmask);  // Read pin (ret. 0 or 1)
  }

return(retval);   // This only has meaning if action = 2
}
 
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Wed Jan 18, 2006 10:30 pm     Reply with quote

I need help again, I ported my program over to an 18f452 because I needed the code space but didn't catch the comments about this code only working on 16f parts. Is it possible to modify it so it will work on the 18f series?

Thanks
Ringo
_________________
Ringo Davis
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 18, 2006 11:18 pm     Reply with quote

See this thread for the code:
http://www.ccsinfo.com/forum/viewtopic.php?t=25591
Ringo42



Joined: 07 May 2004
Posts: 263

View user's profile Send private message

PostPosted: Thu Jan 19, 2006 7:53 am     Reply with quote

Thank you very much.
Ringo
_________________
Ringo Davis
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 5:26 am     Reply with quote

How can I replace output_float ( PIN_A0)?

is that do_pin_io ( PIN_A0 , 2 )?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 01, 2006 10:21 am     Reply with quote

Yes, that would set the pin to be an input.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Jun 02, 2006 8:39 am     Reply with quote

I'm sorry to say, but I think your software is buggy as it does strange things to my program. I am sure the adding of that function is the reason.

The phenomenon I have is that when I use

Code:
//********************** E3 AAN OF UIT SCHAKELEN *****************************//
//Het E3 bord kan aan- of uitgeschakeld worden door de lijn 100uS laag te
//trekken.
void TOGGLE_E3 ()
{
   int8 j;

   output_low (EXP_ONOFF);     // Zet hem uit door laag te trekken
   //do_pin_io (EXP_ONOFF, 0);
   delay_ms (1000);
   //do_pin_io (EXP_ONOFF, 1);
   output_high (EXP_ONOFF);    // Maak de pin open drain
}


that function, the Pic is toggling some pins, hard to say what is going wrong. Perhaps the delay function is the problem... strange ..

edit: delay_ms (x) is not the problem. Just seems to be the use of the do_io_pin() function AND when a special thing happens in my program. I think the toggle() function is ok though. If you desire full details, I'll PM you my full program.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 02, 2006 10:51 am     Reply with quote

1. The do_pin_io program posted in this thread is only intended for
the 16F series PICs, which have the TRIS registers at specific
addresses (PORT register address + 0x80). This program won't
work with a PIC that has the TRIS registers at a different offset.
What PIC are you using ? Are you using an 18F pic ?

2. The do_pin_io program is intended to be used with a variable
as the parameter that holds the CCS pin number. You are
using it with constants. There's no reason to use do_pin_io()
in that case. Just use the CCS pin functions, such as:
output_low()
output_high()
output_float()

3. If you post or PM me a program, don't send me a large program.
Post a very small program that demonstrates the problem, such as
20 lines of code at most. Show your #include statement, and also
the #fuses and #use statements. Show all necessary variable
declarations and #define statements. The program should be
compilable. I should be able to copy and paste it into MPLAB and
click the compile button, and it should compile with no errors.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Jun 06, 2006 3:38 am     Reply with quote

1. PIC16LF877A

2. Somewhere else in my program, I do use do_pin_io(). That works fine. Only when I receive "SLEE" command and go to function TOGGLE_E3 () an error happens.

3. I'll try to do that.
jeeshenlee



Joined: 15 Apr 2011
Posts: 3

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

Reading pin state without changing the direction/tris of pin
PostPosted: Fri Apr 15, 2011 11:14 pm     Reply with quote

Hello,

Thanks for the code snippet. I'm trying to use your code snippet to read the state (like input_state(pin)) without changing the direction of the pin. How to do i modify your code snippet to do so?

Thanks.

Regards,
Jeeshen Lee
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 15, 2011 11:23 pm     Reply with quote

Why do you need that code ? It's for version 3.xxx of the compiler.
Version 4.xxx can accept a variable to hold the CCS pin value for
the i/o functions. What's your version of the compiler ?
jeeshenlee



Joined: 15 Apr 2011
Posts: 3

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

PostPosted: Fri Apr 15, 2011 11:37 pm     Reply with quote

I'm using PCM 4.088.

Ya, i tried input_state(variable) and it gave me "Expression need to be in constant..."
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 16, 2011 12:43 am     Reply with quote

Try using the read_bit_var() macro. For the PCM compiler, the variable
parameter must be an int8. For PCH, it must be an int16.

If you have problems, I can't really do anything more about it now.
Maybe later in the weekend.
jeeshenlee



Joined: 15 Apr 2011
Posts: 3

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

PostPosted: Sat Apr 16, 2011 1:19 am     Reply with quote

Alright. Thanks.
net_hw



Joined: 17 Oct 2012
Posts: 6

View user's profile Send private message

trying to use the function do_pin_io( ) some doubts
PostPosted: Tue Nov 06, 2012 4:00 am     Reply with quote

Hello all

I swear that I tried
with based on this examples:

http://www.ccsinfo.com/forum/viewtopic.php?t=48590&highlight=ccspin+pintable+pinn

http://www.ccsinfo.com/forum/viewtopic.php?
t=25591&postdays=0&postorder=asc&start=0

http://www.ccsinfo.com/forum/viewtopic.php?t=25280&start=4

http://www.ccsinfo.com/forum/viewtopic.php?t=27445&highlight=ccspin+pintable+pinn

https://www.ccsinfo.com/forum/viewtopic.php?t=222

http://www.ccsinfo.com/forum/viewtopic.php?t=25280&highlight=ccspin+pintable+pinn


transpose to my job function
but as I'm using a 16F628
and I can not success

Code:
//----------------------------------------------------------------
#include <16f628.h>
#fuses HS,INTRC_IO, NOLVP, NOWDT, PUT
#use delay (clock=4000000)

#define  .... bla bla bla....

 
//int8 pin_table[6]  = {PIN_A2,PIN_A3,PIN_B0,PIN_B1,PIN_B2,PIN_B3};  //my inputs

           int8 leds[6] = {PIN_A1,PIN_A0,PIN_B7,PIN_B6,PIN_B5,PIN_B4}; //my outputs


// ...do_pin_io( )  as  http://www.ccsinfo.com/forum/viewtopic.php?t=25280&start=4


int myfunction_teste(int8 pinn) {

int8 ccs_pin;

ccs_pin = leds[pinn];

do_pin_io(ccs_pin,0);
delay_ms(500);
do_pin_io(ccs_pin,1);

 return 1; }

void main () {

int8 pX; 
for(pX=0;pX<6;pX++) {      myfunction_teste(pX);    }
   
}
//-------------------------------------------------------------
PCWHD Compiler
IDE PCB PCM PCH PCD v 4.114
//-------------------------------------------------------------
in proteus simulation
works only with the first 2 pins of array
thank you for any help

[]´s hw
_________________
[]´s
hw
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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