Pointer point to the wrong address!!!!!!!!!

General discussion on mikroC.
Post Reply
Author
Message
faz_hamed
Posts: 1
Joined: 19 Oct 2011 09:57

Pointer point to the wrong address!!!!!!!!!

#1 Post by faz_hamed » 19 Oct 2011 10:10

hi,

i write code for send and receive SMS by PIC16F876A.everything work fine except a pointer.this pointer have address of array that contain Mobile Phone number,fetch from GSM Module when sms arrive. i need this for sending confirm sms.
but this pointer point to another address and in my program write anything else.

this Function is for fetching mobile phone number:
//////////////////////////////////////////////////////////////////////////////////////////
unsigned char Num_Read(){
unsigned short int e=0,d=0,quote_Detect_Start=1;
char quote_Detect;
unsigned char Num[20];
USART_Write_Text("AT");
USART_Write(CR); //Enter
USART_Write(LF);
Delay_ms(500);
USART_Write_Text("AT+CMGF=1");
USART_Write(CR);
USART_Write(LF);
Delay_ms(500);
USART_Write_Text("AT+CMGR=1");
USART_Write(CR);
while(1){
if (USART_Data_Ready() == 1)
{
if(quote_Detect_Start){
quote_Detect=USART_Read();
if (quote_Detect==44) e++ ;
if (e==1) quote_Detect_Start=0;
}
else {
Num[d]=USART_Read();
if (Num[d]==44) {
Num[d]=144;
break ;
}
d++;
}
}
}//End of While()

return Num;

}//End of Num_Read()
/////////////////////////////////////////////////////////////////////////////////////////////////////
and main()

void main()
{

unsigned char *SMS;
unsigned char *M_Num;

Port_init();
USART_Init(9600);

portc.f3=1; //RS485 Enable for DMX Sending

PWM1DMX=0;PWM2DMX=0;PWM3DMX=0;
Send_DMX();

while(1){

if(!portc.f2) {

M_Num=Num_Read();
SMS=Sms_Read();

if( !(Compare_Text(SMS, "Lama@R")) ) {PWM1DMX=255;PWM2DMX=0;PWM3DMX=0;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@G")) ) {PWM1DMX=0;PWM2DMX=255;PWM3DMX=0;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@B")) ) {PWM1DMX=0;PWM2DMX=0;PWM3DMX=255;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@RG")) ) {PWM1DMX=255;PWM2DMX=255;PWM3DMX=0;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@GB")) ) {PWM1DMX=0;PWM2DMX=255;PWM3DMX=255;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@RB")) ) {PWM1DMX=255;PWM2DMX=0;PWM3DMX=255;Sms_Send(2,M_Num);}
else if( !(Compare_Text(SMS, "Lama@RGB")) ) {PWM1DMX=255;PWM2DMX=255;PWM3DMX=255;Sms_Send(2,M_Num);}
else Sms_Send(1,M_Num);

Send_DMX();

}

}//End of While()
}//End of main()

Could anyone help me?
sorry for any mistake in writing because my English is not well

Post Reply

Return to “mikroC General”