2006-10-17 05:44 AM
2006-10-17 03:51 AM
I have found using the 16k compiler that to pass an unsigned long variable to a function I have to prototype the function properly or the value passed to the function is not always correct.
Sadly I have no meaningful debug on this circuit or I would investigate further. The code is as follows: void delay(unsigned long len){ unsigned long tstart = 0; unsigned char tnew = 0; for(tstart = 0; tstart < len; tstart++){ tnew = 0; for(tnew = 0; tnew < 2; tnew++); WDGCR = 0xff; for(tnew = 0; tnew < sizeof(len); tnew++){ SCI1DR = (unsigned char) (len >> (tnew * 8)); while(!(SCI1SR & 0x40)) WDGCR = 0xff; } } PDDR &= 0xef; } This gets locked in an endless loop unless I include the following line at the start of the program: void delay(unsigned long); The clue is that the final line before returning (i.e. outside both for loops) is not executed so I presume the test tstart < len always fails. I have sent the contents of the variable along RS232. When I send decimal 15 I get 26 00 00 00 when I left-shift the variable and CD 4F 06 00 when I right-shift. Either way, the test fails. When the function is properly protoyped the test passes and the code executes as I would expect.2006-10-17 04:24 AM
2006-10-17 05:44 AM
My bad.
Thanks Luca