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

Doing a printf for *getenv("bit:xxxx")

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



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

Doing a printf for *getenv("bit:xxxx")
PostPosted: Sun Apr 24, 2022 3:25 am     Reply with quote

I will be using a PIC18LF46K22 MCU, and CCS PCWHD compiler v5.078 within MPLAB IDE v8.92.

I have a "#use RS232" directive and, out of curiosity, wanted to see how the CCS compiler sets some registers, by doing a printf.

I first used this code and was able to print out the settings (TXSTA1 = 0xA4, BAUDCON1 = 0x48, SYNC = 0, BRGH = 1, BRG16 = 1):
Code:
#include "18LF46K22.h"
#use rs232(UART1, baud=115200, errors, stream=UART1)

#byte TXSTA1=getenv("SFR:TXSTA1")
#byte BAUDCON1=getenv("SFR:BAUDCON1")
#bit SYNC=getenv("bit:SYNC")
#bit BRGH=getenv("bit:BRGH")
#bit BRG16=getenv("bit:BRG16")

void main()
{
   ...
   
   printf("TXSTA1 = %LX\n", TXSTA1);
   printf("BAUDCON1 = %LX\n", BAUDCON1);
   printf("SYNC = %u\n", SYNC);
   printf("BRGH = %u\n", BRGH);
   printf("BRG16 = %u\n", BRG16);
   
   ...
}

I then tried to do the printf without first defining the registers, as follows:
Code:
#include "18LF46K22.h"
#use rs232(UART1, baud=115200, errors, stream=UART1)

void main()
{
   ...
   
   printf("TXSTA1 = %LX\n", *getenv("SFR:TXSTA1"));
   printf("BAUDCON1 = %LX\n", *getenv("SFR:BAUDCON1"));
   printf("SYNC = %u\n", *getenv("bit:SYNC"));
   printf("BRGH = %u\n", *getenv("bit:BRGH"));
   printf("BRG16 = %u\n", *getenv("bit:BRG16"));
   
   ...
}

The printf for TXSTA1 and BAUDCON1 works fine, but not for the SYNC, BRGH, and BRG16 bits. The compiler says "Expecting a , or )".

How should I write the printf statement for *getenv("bit:xxxx")?
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sun Apr 24, 2022 3:41 am     Reply with quote

Do them as you originally did!... Very Happy

Problem is that bit definitions are a rather special thing. Getenv for
a byte register, merrily returns the address.. So when you ask for
the 'contents' of this it can be used as a pointer. However a 'bit',
cannot be used as an address.
In your original version it is displaying the value stored inside the
actual bit in the physical register. Not something that can be accessed
as a pointer.
kgng97ccs



Joined: 02 Apr 2022
Posts: 97

View user's profile Send private message

PostPosted: Mon Apr 25, 2022 8:01 pm     Reply with quote

Thank you, Ttelmah, for your advice and explanation.
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