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

1 problem and 2 suggestion
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

1 problem and 2 suggestion
PostPosted: Fri Aug 04, 2017 7:50 am     Reply with quote

I have been accessing registers directly through pointers, but there is a problem when using the binary operator "^" and MPLAB X. I don't believe the problem is from MPLAB.

When I write "*pointer ^= 0b000001", the resut is not recorded in the register.
When I write "*pointer = 0x01" everything is OK.

Suggestions:

Please change this "#use delay(clock=8M)" to "#use delay(clock=8MEG)".
"M" is used for "mili" on a lot of things and other softwares (like Orcad) and it causes minor problems sometimes. When you wirte "MEG" its certain.

Please change this "set_adc_channel (0)" to "setup_adc_channel (0)".
Its bad when the first functions are:
"setup_adc (ADC_CLOCK_INTERNAL);"
"setup_adc_ports (sAN0);"

and the last one is "set_adc_channel (0)". It causes again minor problems. You might write "setup_adc_channel (0)".

CCS version 5.61, since the newer ones are bad! I am thinking of going to a lower one, maybe about 5.10.

Windows 8 is junk, Windows 8 apps are also junk!
Its time to pass on Linux, like MPLAB :D.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 8:21 am     Reply with quote

re:
..."M" is used for "mili" on a lot of things and other softwares (like Orcad... Caps have always been LARGE values( ie: >0) while small letters signify small values( IE: < 0 ). It's one of them 'Metric' things, though I suppose someone may have changed the rules in the past 60 years....

well that's 'silly'..., the others are wrong !

BIG 'M' has always been Mega...
little 'm' has been milli...

re:

When I write "*pointer ^= 0b000001", the resut is not recorded in the register.

What happens when you try

*pointer ^=0b00000001;

I put 7 zeros in front of the one.
In my case I have a '1', in yours you may have a '4' or a '1' depending on how the compiler interprets the 0bxxxxxxxx syntax.
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Fri Aug 04, 2017 8:26 am     Reply with quote

temtronic wrote:
re:
..."M" is used for "mili" on a lot of things and other softwares (like Orcad... Caps have always been LARGE values( ie: >0) while small letters signify small values( IE: < 0 ). It's one of them 'Metric' things, though I suppose someone may have chnged the rules in the past 60 years....

well that's 'silly'..., the others are wrong !


Not exactly, it is "M" you are write, but on software for simulation its made with "MEG" i guess in order to avoid using both capital and small letters and to make it clear.

temtronic wrote:
re:
re:

When I write "*pointer ^= 0b000001", the resut is not recorded in the register.

What happens when you try

*pointer ^=0b00000001;

I put 7 zeros in front of the one.
In my case I have a '1', in yours you may have a '4' or a '1' depending on how the compiler interprets the 0bxxxxxxxx syntax.


The same. I already figured this out, when I was playing with unions. I was wondering and wondering and wondering and I finaly figured out why does my result go bad when I use a 6 bit union.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 1:09 pm     Reply with quote

This problem:

"*pointer ^= 0b000001"

Is C operator precedence. Not a compiler fault. This is why:

*ptr++

and

*ptr+=1

do not give the same result....

You would need to override the precedence to get the result you expect.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 1:36 pm     Reply with quote

It works for me. I ran the test program shown below in MPLAB vs. 8.92
simulator and got the following output:
Quote:
temp = 00
temp after XOR = 01

Test program:
Code:

#include <18F46K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//=====================================
void main(void)
{
int8 temp;
int8 *pointer;

temp = 0;
pointer = &temp;

printf("temp = %x \r", temp);

*pointer ^= 0b000001;
printf("temp after XOR = %x \r", temp);

while(TRUE);
}


Last edited by PCM programmer on Fri Aug 04, 2017 1:36 pm; edited 1 time in total
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Fri Aug 04, 2017 1:36 pm     Reply with quote

Ttelmah wrote:
This problem:

"*pointer ^= 0b000001"

Is C operator precedence. Not a compiler fault. This is why:

*ptr++

and

*ptr+=1

do not give the same result....

You would need to override the precedence to get the result you expect.


I already know how to solve it. But what precedence is there here?
There is only one "^=" which is binary equal? Or is the precedence from right to left here? I thought in "C" its forbidden to write "0b00000001 ^= *ptr".

And for the "metric" system, its the best system ever created, unlike the "inch" system! In "metric" 1km = 1000m, 1m = 1000mm, 1mm = 1000um, etc.....
In inch 1 mile is who knows how many feet.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Fri Aug 04, 2017 1:39 pm     Reply with quote

PCM programmer wrote:
It works for me. I ran the test program shown below in MPLAB vs. 8.92
simulator and got the following output:
Quote:
temp = 00
temp after XOR = 01

Test program:
Code:

#include <18F46K22.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//=====================================
void main(void)
{
int8 temp;
int8 *pointer;

temp = 0;
pointer = &temp;

printf("temp = %x \r", temp);

*pointer ^= 0b000001;
printf("temp after XOR = %x \r", temp);

while(TRUE);
}


I am using "MPLAB X, v3.55". But I think its not the IDE's fault.
If its caused by the "C" precedence problem, its OK. I know how to solve it anyway.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 1:57 pm     Reply with quote

there's 5280 feet in a mile... Very Happy

It's easy stuff if you're taught it.

My pet peeve is with all the Canadian governments, who threw metric at us, DECADES ago.

In the first year THEY got all the conversions wrong concerning fertilizer spread rates. Tens of thousands of farmers lost crops because of it...

next one...
Whenever THEY want a bad guy, They report him as being x feet, y inches tall, weighs about z pounds Sad Sad


Jay
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Fri Aug 04, 2017 2:07 pm     Reply with quote

I disagree. The metric system is better.
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 2:36 pm     Reply with quote

At heart the metric system is far better.
It suffers though from some units that were decided 'arbitrarily' at it's inception (such as the meter), not being very useful sizes....

I was having a laugh today. A little item I was looking at:

From the published description: 1 1/2" bore, 19.5cm high.....

Aaargh.

I'd just use precedence brackets:

(*pointer) ^= 1;

Which ensures the precedence order applied.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 6:56 pm     Reply with quote

re:
Please change this "#use delay(clock=8M)" to "#use delay(clock=8MEG)".

It would actually make more sense of it to be
clock=8MHz or clock=500KHz

It'd be nice to change
#USE RS232(...)
to
#USE SIO(...)

As for the 'interesting' mix of Imperial and Metric, that is quite common on this side of the pond, as well as 'soft' Metric conversions like 19mm==3/4",where == means 'almost or close enough'.
What I've never understood is 5.5mm sockets! Seems just silly to me, use 5mm or 6mm. Course the older I get the harder it is to see itty bitty things, sigh.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 04, 2017 7:22 pm     Reply with quote

temtronic wrote:

It would actually make more sense of it to be
clock=8MHz or clock=500KHz

It already is. Read the CCS manual in the #use delay() section:
Quote:

clock=speed speed is a constant 1-100000000 (1 hz to 100 mhz).
This number can contains commas. This number also supports the
following denominations: M, MHZ, K, KHZ
Arakel



Joined: 06 Aug 2016
Posts: 107
Location: Moscow

View user's profile Send private message Visit poster's website AIM Address

PostPosted: Sat Aug 05, 2017 4:44 am     Reply with quote

temtronic wrote:
re:

It'd be nice to change
#USE RS232(...)
to
#USE SIO(...)


I don't like this one, what is "SIO". If it was up to me there would be almost no changes whatsoever. One thing I despise is for someone to just change things that work. Like the Microsoft control panel, which is the same as the previous Windows, with the same functions but different names, so we pretend we are doing something and computer repairmans can have more to suffer unnecessary.

temtronic wrote:
re
As for the 'interesting' mix of Imperial and Metric, that is quite common on this side of the pond, as well as 'soft' Metric conversions like 19mm==3/4",where == means 'almost or close enough'.
What I've never understood is 5.5mm sockets! Seems just silly to me, use 5mm or 6mm. Course the older I get the harder it is to see itty bitty things, sigh.

Jay


They make it like this, because its good for them, the machine produces 5.5mm details or once upon a time they had more 5.5mm details, or they wanted to use less material and made it 0.5mm less. Some mechanical engineer decided.

The problem is that you are used to the "English/Imperial" system. But if you were using the metric one, it would be much better and easier.
Once you get used to something wrong it becomes much more difficult to start doing whats right.

You are using the "Imperial" system, because Europe and the US have to always be different (mutual hatred), if one of them picks one thing, the other one will pick the other thing.

This is why you use Fahrenheit also, and if you ask me you are just screwed with this system of temperature measurement.

Sorry if I offend you somehow with all my comments!
_________________
Yo! I love learning and technology! I just do not have experience so do not be angry if I ask a stupid question about a detail! From so much to remember sometimes I forget the details in order to remember the big problems!
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Aug 05, 2017 7:01 am     Reply with quote

SIO is short for Serial Input Output. Which is a generic term for Inputting and/or Outputing data in a Serial method.
RS232 is a defined substandard of serial communications with well documented requirements.
The PIC by itself is NOT an RS232 device and the CCS C #USE RS232(...) is really a misnomer, again as the PIC is a TTL logic level device and does not run at RS232 logic levels.

There has been (and always will be) a LOT of confusion over this on the forum. It could be that 25 years ago when CCS cut the compiler that they figured everyone would automatically use 1488s and 1489s to connect PICs to the 'outside World'.

Jay
newguy



Joined: 24 Jun 2004
Posts: 1900

View user's profile Send private message

PostPosted: Sat Aug 05, 2017 9:07 am     Reply with quote

Canadian. Just before I started school Canada switched to the metric system. My parents and older siblings grew up with the imperial system. I've had a mix of units my whole life; temperature is in Celsius, driving distance is either miles or hours, and if I'm building something with wood, I deal in feet, inches and fractions of an inch. I have a metric tape measure but I hate it. When I lay out a PCB I deal in thousandths of an inch.

I can mentally convert pretty much any measure - weight, length, distance, etc but I've never been able to get a grasp of temperatures in Fahrenheit. Then I took up the hobby of homebrewing. Every book available at the time came from a US author and every measure was in imperial units, including temperature. When I brew, I measure out grain in kg, water in liters, hops in grams. When it comes to mashing, I know that my sacch rest has to be at about 150F, and when I "mash out" I need to hit 175F. Don't ask me what those temperatures are in Celsius. A comfortable day will have a high of about 20C but I have no idea what that is in F. Laughing
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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