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

couldn't use "getenv"

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



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

couldn't use "getenv"
PostPosted: Mon Jun 24, 2019 10:38 am     Reply with quote

18F25K40, v5.081
Hi guys, starting to write a new code, nothing to work yet, blank main function, only fuses and definitions. Problem is when I use "getenv" to define a register I get following error
Code:
*** Error 103 "TEST_APP_v0.1.c" Line 20(5,8): Constant out of the valid range  000 is reserved by the compiler

but if I use
Code:
#BYTE TRISA=0x0F88
it compiles. Ok register names are already predefined I know but also I know it normally works fine, I used it before but I can't understand why I cant use it this time.

c file
Code:

#include <Test_inc.h>


void main()
{
      delay_ms(1);
}


h file
Code:

#include <18F25K40.h>
#device ADC=10

#FUSES NOWDT                    //No Watch Dog Timer
#fuses NOEXTOSC              //External Oscillator not enabled
#fuses RSTOSC_HFINTRC_64MHZ  //Internal Osc 64MHz
#fuses NOCLKOUT              //I/O function on OSC2
#fuses NOCKS                 //Clock Switching Disabled
#fuses MCLR                  //Master Clear pin enabled
#fuses PUT                   //Power Up Timer
#fuses NOFCMEN               //Fail-safe clock monitor disabled
#fuses NOBROWNOUT            //No brownout reset
#fuses ZCDDIS                //Zero-cross detect circuit is disabled at POR
#fuses NOPPS1WAY             //Allows multiple reconfigurations of peripheral pins
#fuses NOSTVREN              //Stack full/underflow will not cause reset

#BYTE TRISA=GETENV("BYTE:TRISA")

#use delay(internal=64MHz)


_________________
There is nothing you can't do if you try
elcrcp



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 10:50 am     Reply with quote

Quick update,
Code:
#BYTE TRISA=GETENV("SFR:TRISA")
works, but again, i was able to use "BYTE:TRISA" with a 16F1933 before. What is the difference?

Oookey, another quick update. Looks like 16 and 18 series differs on this point. You need to use SFR on 18 series it seems.
_________________
There is nothing you can't do if you try
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 12:58 pm     Reply with quote

You claim that using "BYTE:TRISA" works with the 16F1933.
Code:
#include <16F1933.h>
#use delay(internal=4M)

#BYTE TRISA=GETENV("BYTE:TRISA")

//===============================
void main()
{
TRISA = 0x55;

while(TRUE);
}


When I compile the above test program with CCS vs. 5.085, I get
the following .LST file:
Quote:
...... TRISA = 0x55;
0014: MOVLW 55
0015: MOVWF 00 // This is the INDF register, not the TRISA reg
......

It fails. It "compiles", but it does not produce the correct code.

But if we change the getenv() statement to use "SFR", which is the
correct method for all PICs, then we get the correct result for the
16F1933:
Quote:
...... TRISA = 0x55;
0014: MOVLW 55
0015: MOVLB 01 // Bank 1
0016: MOVWF 0C // Register address 0x8C
.......
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 1:01 pm     Reply with quote

BYTE: is not a standard getenv construct.
The standard forms are BIT: and SFR:
Sounds as if BYTE: may have existed for some specific register names
on some chips in the past.
SFR: is the normal construct, and is what should be used.

I see PCM posted while I was typing. Very Happy
elcrcp



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

PostPosted: Mon Jun 24, 2019 4:21 pm     Reply with quote

PCM programmer wrote:
You claim that using "BYTE:TRISA" works with the 16F1933.
Code:
#include <16F1933.h>
#use delay(internal=4M)

#BYTE TRISA=GETENV("BYTE:TRISA")

//===============================
void main()
{
TRISA = 0x55;

while(TRUE);
}


When I compile the above test program with CCS vs. 5.085, I get
the following .LST file:
Quote:
...... TRISA = 0x55;
0014: MOVLW 55
0015: MOVWF 00 // This is the INDF register, not the TRISA reg
......

It fails. It "compiles", but it does not produce the correct code.

But if we change the getenv() statement to use "SFR", which is the
correct method for all PICs, then we get the correct result for the
16F1933:
Quote:
...... TRISA = 0x55;
0014: MOVLW 55
0015: MOVLB 01 // Bank 1
0016: MOVWF 0C // Register address 0x8C
.......


That is interesting, I never had any problems with 1933 code I mentioned but I'll check my old compiled code tomorrow.

And I really don't remember why did I used BYTE in that code, probably I did a mistake while ctrl+c ctrl+v XD but again, I swear it was working just fine!
_________________
There is nothing you can't do if you try
elcrcp



Joined: 11 Mar 2016
Posts: 62
Location: izmir / Turkey

View user's profile Send private message

PostPosted: Tue Jun 25, 2019 2:25 am     Reply with quote

Hi, I checked my old lst file, I dont know what is the difference but looks like it compiles right. I think I was lucky with that project XD

Code:
....................    PIE1=0;
0050:  MOVLB  01
0051:  CLRF   11
....................    PIE2=0;
0052:  CLRF   12
....................    PIE3=0;
0053:  CLRF   13
....................    INTEDG=0;
0054:  BCF    15.6
....................    TRISA=0b10111111;
0055:  MOVLW  BF
0056:  MOVWF  0C

_________________
There is nothing you can't do if you try
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