Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Failure to interface LG phone with PIC16f877, Please help!

Status
Not open for further replies.

Eng.Mohd.Salah

Newbie level 2
Joined
Dec 13, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,329
Hi all....
i have completed my project to send and receive messages between Mobile LG "GW300" and Pic16f877 using UART for controlling two relays. I used frequency of 8MHZ and baud rate 9600 using the program MikroC Pro. I faced big problem with my code which`s attached below. I can`t read the message, there is no action happens when i received the desired SMS "Relayxx", (where xx=Relay Number). Note that, i works on the Proteus Simulation program.
==>The Code Idea represents at when i receive SMS "Relay01", Relay no.(01) must be activated.
==> At this stage of my code just i need to read the received SMS only; ignoring the SMS_Send portion.
Does anybody has experience can help me to correct my code ??????????
Please help me casue really i need help.

my code:

Code: Select all
// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections



void sms_read();
void sms_send();
void Get_Relay_Number();

char i=0, tmp, gsm_state=0;
char relay_no[3]; // Message that contains relay number
char relay; // Relay number

void main() {
TRISB=0;
trisd=0;
portd=0;
PORTB=0;
lcd_init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
LCD_out(1,1,"Welcome");
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
sms_read();
}



void sms_read()
{
UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("ATE0\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGR=1\n\r");
delay_ms(500);
while (1)
{
if (UART1_Data_Ready())
{
tmp = UART1_Read(); // get received byte
if(tmp == 'O') {
switch (gsm_state) {
case 0: {
if (tmp == 'O'){ // we have 'O', it could be "OK"
gsm_state = 1; // expecting 'K'
delay_ms(100);
}
break;
}
case 1: {
if (tmp == 'K') { // we have 'K' ->
gsm_state = 2; // expecting CR+LF
}
else
gsm_state = 0; // reset state machine
break;
}
case 2: {
if (tmp == 13) // we have 13, it could be CR+LF
gsm_state = 3; // expecting LF
else
gsm_state = 0; // reset state machine
break;
}
case 3: {
gsm_state = 0; // reset state machine
break;
}
default: { // unwanted character
gsm_state = 0; // reset state machine
break;
}
}
}


if(tmp=='R') {
switch (gsm_state) {
case 0: {
if (tmp == 'R') // we have 'R'
gsm_state = 10; // expecting 'e'
break;
}
case 10: {
if (tmp == 'e') // we have 'e'
gsm_state = 11; // expecting 'l'
else
gsm_state = 0; // reset state machine
break;
}
case 11: {
if (tmp == 'l') // we have 'l'
gsm_state = 12; // expecting 'a'
else
gsm_state = 0; // reset state machine
break;
}
case 12: {
if (tmp == 'a') // we have 'a'
gsm_state = 13; // expecting 'y'
else
gsm_state = 0; // reset state machine
break;
}
case 13: {
if (tmp == 'y') { // we have 'y'
gsm_state = 14; // expecting first digit
}
else
gsm_state = 0; // reset state machine
break;
}
case 14: {
relay_no[0] = tmp; // setting first digit into array
gsm_state = 15; // expecting second digit
break;
}
case 15: {
relay_no[1] = tmp; // setting first digit into array
relay_no[2] = 0; // setting null
gsm_state = 0; // reset state machine
Get_Relay_Number();
break;
}
default: { // unwanted character
gsm_state = 0; // reset state machine
break;
}
}
}


}
}


}

// Converting relay number text into byte
void Get_Relay_Number(){
char rn;
if(relay_no[0] == 48){ // If first number is 0
rn = relay_no[1]-48;
return rn;
sms_send();
}

}

// =================================================================

// SMS Send Portion
void sms_send()
{
int i;
/*UART1_Write_Text("AT\n\r");
delay_ms(500);
UART1_Write_Text("AT+CMGF=1\n\r");
delay_ms(500); */
UART1_Write_Text("AT+CMGS=");
UART1_Write(0x22);
UART1_Write_Text("+249912677207");
UART1_Write(0x22);
UART1_Write_Text("\n\r");
delay_ms(500);
UART1_Write_Text(relay_no);
UART1_Write(26);// send ctrl + Z

}



The Proteus Cuircuit:

SMSRC1.png

SMSRC2.png
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top