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
Author Message
thanhhavdt

Joined: 09 Oct 2006
Posts: 12
Location: hoangsam

temtronic

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

 Posted: Wed Nov 15, 2023 11:31 am My head hurts just looking at the code..... Please simply just read the entire portB and use a 'mask' to compare to your test values. You'll have clear, easy to read code, even for a 'dinosaur' like me !
Ttelmah

Joined: 11 Mar 2010
Posts: 19264

 Posted: Wed Nov 15, 2023 11:47 am Agreed it is awful code. However there is a very fundamental problem with this maths: Data_DKX = ((10000*a)+(1000*(b+25))+(100*c)+d)/12.5; The very first part of this returns values up to 39. You multiply this by 10000 using 16bit arithmetic (since 10000 is a 16bit value). 39*10000 = 390000. Largest value that can fit in an int16 is 65535. Instant overflow. b should work, but then c, will be using int8 arithmetic (since 100 is an int8, and c is an int8). Again overflow. Fundamentally flawed maths.
thanhhavdt

Joined: 09 Oct 2006
Posts: 12
Location: hoangsam

 Posted: Thu Nov 16, 2023 6:29 am Thanks for support!!!!
Ttelmah

Joined: 11 Mar 2010
Posts: 19264

Posted: Thu Nov 16, 2023 8:13 am

As a comment to this. Consider:
 Code: void read_4bit_tram_kHz_DKX() {    int val;    val=(input_d() & 0b111100)>>2; //mid four bits from port D    //Masked and Moved to the bottom    val^= 0b1111; //inverted    c=val; }

Honestly also would be better to have the functions return the values
rather than using global values.

Same applies to each of the other functions
thanhhavdt

Joined: 09 Oct 2006
Posts: 12
Location: hoangsam

 Posted: Fri Nov 17, 2023 10:41 am Thanks for Ttelmah. I'm newbie, my code is awful. Can you help me rewrite the functions: read_5bit_tram_chuc_MHz_DKX(); read_4bit_donvi_MHz_DKX(); Thanks for support!!!
Humberto

Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

 Posted: Wed Dec 13, 2023 10:54 am I don't think someone will write your code upon request, generally the help provided in this forum is of an excellent level, while the consultation warrants it. If you are a newbie, I suggest you take a look and learn how manages the data handler, that shift register logic circuit, file 74595.c located in the CCS compiler Drivers folder. best wishes_________________Humber
bkamen

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

 Posted: Mon Dec 18, 2023 11:54 am Oh lordy. Always remember when you're coding: * If it's hard to read, it's hard to debug. * If you had to look at this code 10yrs from now, how quickly would you be able to make sense of it? * Compilers can have bugs. All kinds of bugs. Keep the code in manageable chunks because the error/issue you might be running into might not be the code, but some bug of the compiler -- and then look back at the first rule item I listed._________________Dazed and confused? I don't think so. Just "plain lost" will do. :D
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 6 Hours Page 1 of 1

 Jump to: Select a forum Software----------------General CCS C DiscussionCode LibraryEZ App LynxBest OfKnown Issues Hardware----------------CCS ICD / Mach X / Load-n-Go
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