我遇到了很奇怪的問題?
使用的MCU為PIC18F6520
程式段落如下:
副程式一:
unsigned char com2_check_recv(void)
{
unsigned char com2_check_temp1;
unsigned int com2_check_temp2,com2_check_temp3;
com2_check_temp1=0;
com2_check_temp2=modbus_crc(rxbuf2,0,6);
com2_check_temp3=a8(rxbuf2[6],rxbuf2[7]);
if(com2_check_temp2==com2_check_temp3)
{
com2_check_temp1=rxbuf2[1];
}
return com2_check_temp1;
}
副程式二:
unsigned int modbus_crc(unsigned char buf[],int starts,int cnt)
{
unsigned char crc_i,crc_j;
unsigned int crc_temp,crc_temp2,crc_flag;
crc_temp=0xFFFF;
for(crc_i=starts;crc_i<cnt;crc_i++)
{
crc_temp=crc_temp ^ buf[crc_i];
for (crc_j=1;crc_j<=8;crc_j++)
{
crc_flag=crc_temp & 0x0001;
crc_temp=crc_temp >> 1;
if(crc_flag) {crc_temp=crc_temp^0xA001;}
}
}
crc_temp2=crc_temp >> 8;
crc_temp=(crc_temp << 8)|crc_temp2;
crc_temp &= 0xFFFF;
return crc_temp;
}
當我的程式跑到副程式一時....會再呼叫副程式二.....但是..當副程式二跑完後,回到副程式一時...我發現原本副程式一所宣告的變數位址會不一樣!
請問一下為什麼會這樣子?