View previous topic :: View next topic |
Author |
Message |
cashworth
Joined: 06 Jul 2012 Posts: 3
|
output_high(int16 a) doesn't work |
Posted: Fri Jul 06, 2012 5:31 pm |
|
|
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
|
|
Posted: Fri Jul 06, 2012 7:23 pm |
|
|
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
|
|
Posted: Mon Jul 09, 2012 10:37 am |
|
|
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
|
|
Posted: Mon Jul 09, 2012 4:28 pm |
|
|
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
|
|
Posted: Mon Jul 09, 2012 4:52 pm |
|
|
I just reported the bug. Your workaround is fine for my application. Thanks much!! |
|
|
|