We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello iam working on cygnal microcontrollers c8051f124,iam performing checksum as i written below. The datas are written in external memoryarea when iam performing checksum at 4th byte operation iam exeeding the 8 bit register value ie sum=7b+ff=17a(378 inn decimal) but microcontroller is holding only 0x007a its ignoring overflow 1.but i defined sum as unsigned short int its not holding the overflow of ff value what i have to do now? johne char xdata test_string[100]_at_ 0x5555={0x0f,0x2e,0x3e,0xff,0xff,0x00,0xfe,0xff}; void main() { int x=8,y; unsigned short int sum=0; for(y=0;y<8;++y) { sum=sum+test_string[y]; if(sum>0xff) { sum=sum-0xff; } } test_string[y]=0xff-sum; test_string1[100]=test_string[100]; printf("checksum=%x\n",test_string[y]); }
Which toolset are you using? The first thing I would try is:
unsigned int sum=0;
Hello Mr Graham Cole Thanks for your reply ,iam using C51 TOOLSET i forgotten to mention in my querry. amazingly when i comipled the programme in turbo c it showing result correctly but iam compiling with c8051f124 then iam getting wrong checksum value,is this is compiler limitation. REGARDS JOHN E
"amazingly when i comipled the programme in turbo c it showing result correctly" That is completely irrelevant! Turbo-C is for 16/32-bit x86 processors. You do understand that the size of an 'int' is implementation-defined - as are the byte ordering, alignment requiremtns, and many other target-dependent things. Therefore it is no surprise at all when code written without specifically considering these things behaves differently on different targets with different compilers!
"microcontroller is holding only 0x007a its ignoring overflow" How do you know this? Are you relying on your printf output?
printf("checksum=%x\n",test_string[y]);
test_string1[100]=test_string[100];
See these threads for some ways to isolate your code from implementation-dependencies: http://www.keil.com/forum/docs/thread2472.asp http://www.keil.com/forum/docs/thread2836.asp http://www.keil.com/forum/docs/thread3097.asp
Hello mr neil thanks for your reply john e