??? 09/28/04 09:47 Read: times |
#78239 - Keil strncpy function doubt????? |
Dear all, Very good Afternoon,
I am interfacing an Encoder with AT89C52 and taken both the encoder outputs on the Pin 12 & 13 (INT0 & INT1) For incrementing the pulse counter I am using a simple loop as void increment() { if(counted_pulses[0]>=9) { counted_pulses[0]=0; if(counted_pulses[1]>=9) { counted_pulses[1]=0; if(counted_pulses[2]>=9) { counted_pulses[2]=0; if(counted_pulses[3]>=9) counted_pulses[3]=0; else counted_pulses[3]++; } else counted_pulses[2]++; } else counted_pulses[1]++; } else counted_pulses[0]++; } I am incrementing the count in this fation because I am suppose to display them on the 7 Seg LCD controlled by MAX7211. Now to get the pulse count in the display buffer the code writen by me is void convert_to_display() { unsigned char i; unsigned long int vol,amt; unsigned int rt; strncpy(volume_disp,counted_pulses,6); } unsigned char Volume_display[6]; With this the problem was when an increment function is calld & the current value of the volume_disp[x] is 9 the entire volume is shown as 000000 on the LCD screen & sometimes the count use to start from 0 again without physically resetting the count. After that I just tried the following code and it worked correctly volume_disp[0]=counted_pulses[0]; volume_disp[1]=counted_pulses[1]; volume_disp[2]=counted_pulses[2]; volume_disp[3]=counted_pulses[3]; volume_disp[4]=counted_pulses[4]; volume_disp[5]=counted_pulses[5]; If I am not mistaken both the functions should have similar output. Please correct if! Please let me know is there any problem with Keils strncpy function or its the mistake in code which created such behaviour. Thanks, Sachin |