View previous topic :: View next topic |
Author |
Message |
qve
Joined: 30 Jan 2010 Posts: 5
|
16f1936 and output_bit |
Posted: Sun May 02, 2010 5:05 pm |
|
|
It seems that the compiler really likes bank 3. Twice now the compiler has selected the incorrect bank, Once with asm code and now with the output_bit function. The asm code was fixed with asis but the following is just strange.
C code:
Code: |
output_bit( 1137, 0 ); // tris C
|
Disassembly:
Code: |
429: output_bit( 1137, 0 ); // tris C
02D7 0023 MOVLB 0x3
02D8 108E BCF 0xe, 0x1
|
TrisC is in bank 1 not 3. what is it about the number 3?
Unless I misunderstand the addressing scheme this seems to be a bug.
-tom |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 02, 2010 5:18 pm |
|
|
Quote: | output_bit( 1137, 0 ); // tris C
|
Please explain this '1137' parameter. What pin are you trying to set low ?
The manual says:
Quote: | output_bit( )
Syntax: output_bit (pin, value)
Parameters: Pins are defined in the devices .h file. |
You're supposed to give it a pin constant, such as PIN_C0. |
|
|
qve
Joined: 30 Jan 2010 Posts: 5
|
|
Posted: Sun May 02, 2010 5:25 pm |
|
|
TRISC, BIT 1 is what I'm after. Pin names are just defines in the .h file based on below.
clipped this from the help
Pins are defined in the devices .h file. The actual value is a bit address. For example, port a (byte 5) bit 3 would have a value of 5*8+3 or 43. This is defined as follows: #define PIN_A3 43.
I'd do this with a 16F883 and previous compiler all the time. Not sure why it no longer works. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 02, 2010 5:35 pm |
|
|
Don't compute the numbers yourself. Use the CCS pin constants from
the 16F1936.h file.
Quote: | c:\program files\picc\devices\16f1936.h |
Here's a test program:
Code: |
#include <16F1937.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
//======================================
void main(void)
{
output_bit(PIN_C1, 0);
while(1);
}
|
Here's the .LST file for that line:
Code: |
.......... output_bit(PIN_C1, 0);
001C 0022 00602 MOVLB 02
001D 108E 00603 BCF 0E.1 // LATC.1 = 0
001E 0021 00604 MOVLB 01
001F 108E 00605 BCF 0E.1 // TRISC.1 = 0 (output)
|
It's correct. This was tested with compiler vs. 4.107. |
|
|
qve
Joined: 30 Jan 2010 Posts: 5
|
|
Posted: Sun May 02, 2010 5:49 pm |
|
|
Code: |
#define PWM2_TRIS 1137
unsigned int readjumperpos() // read jumper pos 0 = no jumper, 1 = jumper low (gnd), 2 = Jumper hi (+5)
{
char p = 0;
char tt;
output_bit( PWM2_TRIS, 0 ); // tris C
output_bit( PWM2, 0 );
output_bit( PWM2_TRIS, 1 );
delay_cycles(1);
tt = input_state( PWM2);
if( tt == 1) // jumper is hi
p = 2;
output_bit( PWM2_TRIS, 0 ); // tris C
output_bit( PWM2, 1);
output_bit( PWM2_TRIS, 1 );
delay_cycles(1);
tt = input_state( PWM2 ); // jumper is low
if( tt == 0 )
p = 1;
return p;
}
|
The bigger picture. Basically changing the state and then reading to determine if there is a jumper or no jumper.
Not a big deal, I have fixed with asm code but curious why it no longer works. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 02, 2010 6:00 pm |
|
|
Quote: | #define PWM2_TRIS 1137 | I still have no idea what you're doing with this 1137 biz. The 16F1936.h
file defines pin C1 as 113. For some reason you tacked a '7' on the end:
And if you did want to define a pin, the correct way to do it is this:
Code: | #define PWM2_TRIS PIN_C1
|
There are several reasons for using the CCS constants as parameters:
1. The CCS functions expect you to use their constants. If you use
anything else, it probably won't work.
2. The constants use English names to describe their function, so your
code becomes self-documenting.
3. The constants hide the hardware level from you, so you don't have
to worry about figuring out the correct magic number. Using the
constants saves you from making mistakes.
But for some reason, you don't want to do this. I can't help any more on this thread. |
|
|
|