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 support@ccsinfo.com

PIC18F46J11 EECON2 undefined identifier

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



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PIC18F46J11 EECON2 undefined identifier
PostPosted: Sun Aug 09, 2009 7:21 am     Reply with quote

Hello !

I want to assign USART2 on a PIC18F46J11 that has PPS with this code:
Code:

//*************************************
// Unlock Registers
//*************************************
#asm
; PPS registers are in BANK 14
MOVLB 0x05
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; PPS Write Protect off
BCF PPSCON, IOLOCK, BANKED
#endasm
//***************************
// Configure Input Functions
// (See Table 9-13)
//***************************
//***************************
// Assign RX2 To Pin RP0
//***************************
#asm
MOVLW 0x00
MOVWF RPINR16, BANKED
#endasm
//***************************
// Configure Output Functions
// (See Table 9-14)
//***************************
//***************************
// Assign TX2 To Pin RP1
//***************************
#asm
MOVLW 0x05
MOVWF RPOR1, BANKED
#endasm
//*************************************
// Lock Registers
//*************************************
#asm
MOVLW 0x55
MOVWF EECON2, 0
MOVLW 0xAA
MOVWF EECON2, 0
; PPS Write Protected
BSF PPSCON, IOLOCK, BANKED
#endasm

But I get undefined identifier EECON2, why is that? Thanks.

AC
Ttelmah
Guest







PostPosted: Sun Aug 09, 2009 12:19 pm     Reply with quote

Because you have not defined it.....
Register names are not basically defined for you in CCS. Some now are (basic timers etc.), but most are not.
You need to have a #byte definition, with the register address and name.

Worth then adding, first, you don't need to access the bank registers. Once CCS 'knows' a register address is in a particular bank, it will automatically generate the bank access code for you, in it's assembler.
Then, there is no point in using assembler at all. Simply have the #byte defining where the register is, and write a value to it in C.

Best Wishes
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Sun Aug 09, 2009 8:38 pm     Reply with quote

Hi, thanks for your help. I tried to include #byte EECON2 = 0x0FA7
and I get >> expecting an opcode mnemonic << error on the first
instruction that uses EECON2. Any idea why ? I took the ASM copy-paste
from the datasheet. That's why I have ASM but I could use C instead. But I think they need to be in ASM these unlock and lock control regs. But I'm not sure of that. Anyway it's frustrating because my program works with a 18F4620 but not on the 18F46J. I use a couple RPx pins to interface to a SHT11 Temp/Hum sensor and I get bad readings. It's my first program with the 18F46J11 and the only reason I'm using it, it's because of 2$ cheaper. I think it's worth it. It has everything that the 4620 has + other interesting stuff. If anyone has a good understanding of the 18F46J11 and knows how to put it down in couple of sentences I would be very grateful or else I will jump back to the good old (not too much) 18F4620. Thanks AC.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 12:18 am     Reply with quote

Don't reinvent the wheel unless you need to.

This has already been accomplished for you with the #pin_select directive.

I just finished a project with the 46j11... it's a great chip.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 7:14 am     Reply with quote

Hi bkamen, thanks for this piece of info really appreciate i didn't know this
but what if i need to use these remappable pins just as normal inputs or outputs, is there something special to do to configure them beside setting
there tris reg? tks AC
Ttelmah
Guest







PostPosted: Mon Aug 10, 2009 8:56 am     Reply with quote

Key problem, is that CCS, uses CCS ASM, not Microchip ASM.
The CCS ASM, is significantly different (as already mentioned handling back switching automatically for example), so 'copy paste', of Microchip ASM, won't work....

On these devices, you add at the top of your file, lines with:

#pin_select FNAME=PIN_NAME

'FNAME', is the logical I/O function name, and 'PIN_NAME', is the physical pin name. The compiler does the rest.

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 11:14 am     Reply with quote

Ttelmah wrote:
Key problem, is that CCS, uses CCS ASM, not Microchip ASM.
The CCS ASM, is significantly different (as already mentioned handling back switching automatically for example), so 'copy paste', of Microchip ASM, won't work....


And it's not that you can't do it - there is a little bit of a difference.

When the 18F46J11 was added into CCS's Device list, I assisted in weeding out the bugs... #pin_select was one of the bugs.

To make it easier to CCS, I duplicated the ASM needed to do the pin selection... and it works just fine. But why continue doing it that was when CCS fixed that bug and it's now working as expected.

Ttelmah wrote:

On these devices, you add at the top of your file, lines with:

#pin_select FNAME=PIN_NAME

'FNAME', is the logical I/O function name, and 'PIN_NAME', is the physical pin name. The compiler does the rest.


Yep!

One caveat is that anywhere you put in a #pin_select, the unlock/lock code is DUPLICATED. If for some reason you need to pin_select on the fly, keep that in mind and consider writing a routine to do it (in ASM)...

I don't think your case will need it, but I thought I would mention it.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 2:23 pm     Reply with quote

Thanks this is great information, this forum is very responsive that cool !
my two USART are working, but i still can't get my SHT11 sensor to work
on pins B.1 and B.2 . I got this as init code:
Code:

 
 ANCON0=0xFF;  // Select digital pins
 ANCON1=0xFF; // for all of portB


Is this the only thing needed to set portB as digital pins , i'm not sure.
Anyway i tried to interface my SHT11 to PORTB.1 and PORTB.2 and also
on pins C.0 and C.3 and got the same bad results -40.0 degC and -4.6 % hum. I know the program works because i tried it on a 4620 everything
is good, but on the 46J11 it doesn't work?? Is there some special consideration to use these RPx pins just as simple digital without no peripheral map to it, this is my question, hope someone could help me
thanks AC
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 2:46 pm     Reply with quote

Chibouraska wrote:

but i still can't get my SHT11 sensor to work
on pins B.1 and B.2 . I got this
Code:
PORTB=0;
 LATB=0;
 ADCON0=0x00;
 ADCON1= 0x3F;
 TRISB = 0x00;
 ANCON0=0xFF;
 ANCON1=0xFF;


I remember those... (well, I worked on an SHT75 I think) I2C, but not quite. Yeesh!

You have the datasheet? http://www.sensirion.ch/en/pdf/product_information/Datasheet-humidity-sensor-SHT1x.pdf

It's a bidirectional data setup a lot LIKE I2C, but it's not the same protocol.

So this means you'll be driving the clock line (unless you want to have fun and do it by toggling TRIS instead of LAT to make it input vs output@0vdc)... but you'll definitely want to consider that "fun" for the data line.

Make sure you have pull-up resistors on the clock and data lines (just for what-if).

I think for PORTB, you only need mess with ANCON0 to switch RB1, RB2 to digital I/O's, per the datasheet.

Now that you're set for Digital, your code above sets up the system for RB1 and RB2 for OUTPUT... and you don't want that.

You want RB1 (if it's SCLK) to be output or input on1 and output on 0 (with PORTB.1 set to 0)

For RB2 (if it's the dataline) I would make it an input by default (TRIS == 0x02) and only drive it to 0 when sending data using the TRIS control while PORTB.2 == 0.

Then you can use a couple of pullups (like 4.7K) and be fine. (the portB pullups are normally pretty weak and might not have the RC risetime for the clock/data happiness of the SHT11)

Am I making sense yet? Am I talking too much?

:D

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Chibouraska



Joined: 11 May 2007
Posts: 57
Location: Montreal,Canada

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 6:48 pm     Reply with quote

Hey Ben hi, my program is up and running perfect (tested on a 18f4620)
but it doesn't on the 18f46j11. I am using portB.1 and B.2 (analog port 8 and 10). I tried connecting an led on portB.2 and it doesn't come on, so I must mean that the port is not configured as digital, why?? I used setup_adc( ADC_OFF ) and ANCON1=0xFF to set the port B <8-12> to digital. Am I missing the boat here at some point? Oh and I set the TRISB
to 0x00 for all outputs. I need some help on this one. I just don't get it.
Why should be so hard to set up a simple port pin? Any input will be very appreciated, tks AC
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Aug 10, 2009 10:21 pm     Reply with quote

So far, it sounds like it should work --- we definitely want 1's for digital ports in ANCON1 (not ADCONx).

If you're not using analog at all though, you could set ANCON1 to 0x1F to shut off the bandgap reference.

How are you controlling the LED?

Write for me a very stripped down example and send it along to me for to see..

Just do the bare minimum do accomplish what you want.

Do you have a scope? how is the LED hooked up?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Imaginos



Joined: 26 Aug 2009
Posts: 6

View user's profile Send private message

PostPosted: Thu Aug 27, 2009 6:36 am     Reply with quote

I've been reading this thread with some interest. I'm attempting to configure PPS on an 18F24J11 (of the 18F46J11 family). #pin_select returns the "invalid pin" error. I've tried the #byte route to control the relevant registers however, quoth the data sheet
Quote:

Because the unlock sequence is timing critical, it must be executed as an assembly language routine. If the bulk of the application is written in C or another highlevel language, the unlock sequence should be performed by writing in-line assembly.


My desire is to find the series of #defines/whatnot that would enable #pin_select to work correctly for this PIC.

I'm also curious, that if #pin_select repeats the unlocking code with each call, how was it designed to interract with IOL1WAY?
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Aug 27, 2009 9:28 am     Reply with quote

What version of the compiler are you using?

The J11 family was added in (and refined) in the 4.08x series of version (rough estimate).

Otherwise, #pin_select works.

if you want to do it yourself (and you can, cause I had to when helping CCS get the J11's implemented), you write assembly routines to do it all-at-once.

Otherwise, I would agree, you don't want IOL1WAY to be set. Otherwise the CCS code will have issues.

-Ben

p.s. The Datasheet for the J11 has a pretty complete code/ASM example for setting the selectable (RP) pins. It just needs to be CCS'ized and it's good. At some point (I'm out of town doing research for 2 more weeks) I could post my unlock/relock code here (in the 'Code Library') if someone else hasn't already.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Imaginos



Joined: 26 Aug 2009
Posts: 6

View user's profile Send private message

PostPosted: Thu Aug 27, 2009 3:19 pm     Reply with quote

bkamen wrote:
What version of the compiler are you using?
PCH 4.088. I played with #pin_select most of the afternoon and near as I can tell there's something important missing that's making it not accept the pin_xx. I didn't find anything in the library that addresses #pin_select or EECON2, so I assumes that means posting it would probably be helpful.

In the mean time, I can't seem to find a CCS assembly manual. I've concocted the below off what's available in the compiler help, but it doesn't seem to be working. I'm trying to get SDO2 and SCK2 mapped to B0(RP3) and B1(RP4) to use setup_spi2 so as not to interfere with i2c.

EDIT: What's below appears to work (at face value) because I can read out and display 0x09 and 0x0A from RPOR3 and RPOR4. Now it's an MSSP drill to figure out why spi2 isn't talking on those pins. Thanks for the help.

Code:

#define EECON2   0xFA7
#define PPSCON   0xEFF
#define RPOR3    0xEC9
#define RPOR4    0xECA
#define IOLOCK   0

[...]

void main(void)
{
     [...some vars...]
// Set up remappable pins to have SDO2 and SCK2 at B0(RP3) and B1(RP4)
#asm
MOVLB 0x0E            // Bank 14
MOVLW 0x55            // 1st unlock code into W
MOVWF EECON2         // 1st unlock code from W to EECON2
MOVLW 0xAA            // 2nd unlock code into W
MOVWF EECON2         // 2nd unlock code from W into EECON2
BCF   PPSCON, IOLOCK   // Clear IOLOCK of PPSCON, unlocking PPS

MOVLW 0x09            // Set value 9 (SDO2) in W
MOVWF RPOR3            // Move W into RPOR3
MOVLW 0x0A            // Set value 10 (SCK2) in W
MOVWF RPOR4            // Move W into RPOR4

MOVLW 0x55            // 1st lock code into W
MOVWF EECON2         // 1st lock code from W to EECON2
MOVLW 0xAA            // 2nd lock code into W
MOVWF EECON2         // 2nd lock code from W into EECON2
BSF   PPSCON, IOLOCK   // Set IOLOCK of PPSCON, locking PPS
#endasm//*/
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Aug 28, 2009 12:30 am     Reply with quote

I'll have to look at my code when I get home -- I'm far away with now with no VPN...

Otherwise, that looks correct.

blah. I hate being miles away from my code library and no vpn tunnel. (it's the local ISP here)

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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