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

CCS produce a wrong code!

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



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message Send e-mail

CCS produce a wrong code!
PostPosted: Sun Apr 04, 2004 4:04 pm     Reply with quote

Hello
I wrote a simple function which receives a number, 0-256 (char) and makes a division to separate its ten digit and it's unit digit (example: 65=6 ten + 5 unit)
simple, isnt it?
here it is:

Code:

                div_t x;
                x=div(65,10);
                righ=5;
                midd=x.rem;
                left=x.quot;

dum, simple, every starting programmer should know that
but...
the values "righ","midd","left" are transfered to 3 different functions, each use a lookup table , to convert the value (0-9) to 7 segment format, then to portb.
simple.. yet...
when I run the code the variable "midd" gets the value of the variable "left", no metter what value I use.

Originaly the "div" function divided a variable that way:
char t;
x=div(t,10);
when it didnt work, I did "x=div(65,10)" to see if the problem lies in the div function.
I even built a division function of my own - but the result was the same.

Help me out here
Am I vaiolating some kind of CCS PIC "C" Compiler rull?

I even did

Code:

                righ=displayed_val._fraction;
                midd=6;
                left=5;


and again, "midd" gets the value 5
Ttelmah
Guest







Re: CCS produce a wrong code!
PostPosted: Mon Apr 05, 2004 3:04 am     Reply with quote

chava wrote:
Hello
I wrote a simple function which receives a number, 0-256 (char) and makes a division to separate its ten digit and it's unit digit (example: 65=6 ten + 5 unit)
simple, isnt it?
here it is:

Code:

                div_t x;
                x=div(65,10);
                righ=5;
                midd=x.rem;
                left=x.quot;

dum, simple, every starting programmer should know that
but...
the values "righ","midd","left" are transfered to 3 different functions, each use a lookup table , to convert the value (0-9) to 7 segment format, then to portb.
simple.. yet...
when I run the code the variable "midd" gets the value of the variable "left", no metter what value I use.

Originaly the "div" function divided a variable that way:
char t;
x=div(t,10);
when it didnt work, I did "x=div(65,10)" to see if the problem lies in the div function.
I even built a division function of my own - but the result was the same.

Help me out here
Am I vaiolating some kind of CCS PIC "C" Compiler rull?

I even did

Code:

                righ=displayed_val._fraction;
                midd=6;
                left=5;


and again, "midd" gets the value 5


There are a lot of things wrong with your code.
First (which won't cause a problem with the value '65', but will latter), the 'div' function is only specified for _signed_ integers. Secondly (and hopefully just a typing error), an integer, can only hold 0-255, not 0-256.
These faults will 'bite you' latter, but should not cause your problem.
As written, the code should give left=6, midd=5, and righ=5. If this is not what you see, I have to then ask how you are actually 'checking' this. I have set up the same code to 'printf' the digits + 0x30, to an RS232, and this is exactly what is generated...
The correct sequence for a three digit conversion is:
x=div(65,10);
righ=x.rem;
x=div(x.quot,10);
midd=x.rem;
left=x.quot;

Which gives 065 for the three digits.

Best Wishes
chava



Joined: 07 Sep 2003
Posts: 56

View user's profile Send private message Send e-mail

I did too
PostPosted: Wed Apr 07, 2004 12:45 am     Reply with quote

Hello
I also run this code but instead of printing the value on a 7 segment display I transmitted the data to a LCD, the result was as axpected:65.
but note: the program which I did with the LCD is for pic16f877a, and the one for the 7 segment is for 16f76
does that metter?
do you think that the pic16f76 is defected in someway?
Chava
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