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

output_high(int16 a) doesn't work

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



Joined: 06 Jul 2012
Posts: 3

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

output_high(int16 a) doesn't work
PostPosted: Fri Jul 06, 2012 5:31 pm     Reply with quote

Pin addresses greater than 8 bits don't work with the output_high() function call. I'm using a PIC16F1947.

int8 pin addresses work just fine, for example:
Code:

int16 a=104; //Pin_B0
output_high(a); //sets Pin_B0 high

However the pin does NOT set high when the pin address is greater than
Code:
int8 values:
int16 a=5228; //Pin_G4
output_high(a); //sets Pin_G4 high

A workaround is a table, but it is not ideal:
Code:

int16 a=5228; //Pin_G4
if(a==5228)
{
   output_high(5228);
}

Any thoughts on why output_high function does not work with variables greater than int8 values? I need this to work to enable variable passing in function calls.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 06, 2012 7:23 pm     Reply with quote

What is your CCS compiler version ? It's given at the top of the .LST
file, which will be in your project directory after a successful compilation.
This page shows some Version numbers:
http://www.ccsinfo.com/devices.php?page=versioninfo
cashworth



Joined: 06 Jul 2012
Posts: 3

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

PostPosted: Mon Jul 09, 2012 10:37 am     Reply with quote

My compiler version is 4.132. My co-worker has 4.134 and gets the same problem.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 09, 2012 4:28 pm     Reply with quote

It's a bug and you need to report it to CCS support. Maybe they can fix it
in the next version.

In the code below, I've written two macros to replace the output_high()
and output_low() functions. But be aware that these seemingly small
macros will expand to a large and time-consuming amount of ASM code.
But so do the built-in CCS functions. If you want speed, you should not
use variables to pass the pin numbers.
Code:

#include <16F1947.h>
#fuses INTRC_IO,NOWDT,BROWNOUT,PUT,NOVCAP
#use delay(clock=8M)
#use rs232(baud=9600, UART1, ERRORS)
 
int16 io_port;
int8 bitmask;
int8 const bitmask_table[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

#define output_high(ccs_pin)           \
io_port = ccs_pin >> 3;                \
bitmask = bitmask_table[ccs_pin & 7];  \
*(io_port + 0x80) &= ~bitmask;         \
*io_port |= bitmask;                   


#define output_low(ccs_pin)            \
io_port = ccs_pin >> 3;                \
bitmask = bitmask_table[ccs_pin & 7];  \
*(io_port + 0x80) &= ~bitmask;         \
 *io_port &= ~bitmask;                     



//====================================
void main()
{
int16 my_pin;

my_pin = PIN_G4;
output_high(my_pin);

output_low(my_pin);

while(1);
}
 
cashworth



Joined: 06 Jul 2012
Posts: 3

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

PostPosted: Mon Jul 09, 2012 4:52 pm     Reply with quote

I just reported the bug. Your workaround is fine for my application. Thanks much!!
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