|
|
View previous topic :: View next topic |
Author |
Message |
low
Joined: 04 Feb 2014 Posts: 28 Location: Malaysia
|
|
Posted: Wed Apr 23, 2014 11:20 am |
|
|
Hi master,
My hardware able to send the SMS and the LCD also working well.Below is the coding for sending SMS. I kept trying and study Gabriel library code for GSM but still fail to success to read the receive SMS and display on LCD....
Code: | #include <18F4550.h> // PIC18F4550 HEADER FILE
#include <stdlib.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING
#use delay (clock=20M) // 20 MHZ CRYSTAL
#include <lcd.c> // LCD DISPLAY HEADER FILE
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=GSM)
////////////////////////////////////////////////////////////////////////////////
// //
// I/O DECLARATION //
// //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// //
// Output :LED //
// //
////////////////////////////////////////////////////////////////////////////////
#define LED1 PIN_B6 // LED 1
#define LED2 PIN_B7 // LED 2
#define alarm PIN_A0 // LED 2
////////////////////////////////////////////////////////////////////////////////
// //
// Input : SWITCH //
// //
////////////////////////////////////////////////////////////////////////////////
#define MIC PIN_B0 // PRESET SW1
#define PIR PIN_B1 // PRESET SW2
#define TRIG PIN_B4 // PIN TRIG
#define ECHO PIN_B3 // PIN ECHO
////////////////////////////////////////////////////////////////////////////////
// //
// LCD DISPLAY //
// //
////////////////////////////////////////////////////////////////////////////////
#define LCD_E PIN_D0 // PIN E
#define LCD_RS PIN_D1 // PIN RS
#define LCD_RW PIN_D2 // PIN RW
#define LCD_D4 PIN_D4 // PIN D4
#define LCD_D5 PIN_D5 // PIN D5
#define LCD_D6 PIN_D6 // PIN D6
#define LCD_D7 PIN_D7 // PIN D7
////////////////////////////////////////////////////////////////////////////////
int32 distance, time;
void SMS();
void SMS1();
void ultrasonic();
void main()
{
////////////////////////////////////////////////////////////////////////////////
// //
// LOCAL VARIABLE //
// //
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// //
// PORT INITIALIZE //
// //
////////////////////////////////////////////////////////////////////////////////
lcd_init(); //INITIALISE LCD
delay_ms(3000);
////////////////////////////////////////////////////////////////////////////////
// //
// MAIN PROGRAM //
// //
////////////////////////////////////////////////////////////////////////////////
lcd_putc("\f....WELCOME.....");
delay_ms(1000);
lcd_putc("\f");
lcd_putc("\n...loading...!");
delay_ms(1000);
lcd_putc("\f");
lcd_putc("\f....Ready");
delay_ms(1000);
while(TRUE) // always repeat program
{
printf(lcd_putc,"\fSystem On!!!."); // DISPLAY VR VALUE AT LCD DISPLAy
delay_ms(30);
ultrasonic();
if (!input(MIC) && input(PIR) && distance<=59 ) // when press button 1
{
output_high(LED1); // turn on LED1
output_high(LED2); // turn on LED2
output_high(alarm); // turn on ALARM
lcd_gotoxy(5,1);
lcd_putc("\fSensors Detected");
delay_ms(2000);
SMS();
delay_ms(2000);
SMS1();
lcd_putc("\fSend Message..");
delay_ms(3000);
lcd_putc("\fSend Completed");
delay_ms(3000);
output_low(LED1);
lcd_gotoxy(5,1);
lcd_putc("\fChild Dectected");
lcd_putc(0x01);
delay_ms(20000);
output_low(LED2);
output_low(alarm); // turn off ALARM
}
else if (!input(MIC)) // when press button 1
{
output_high(alarm); // turn on ALARM
output_high(LED1); // turn on LED1
lcd_gotoxy(5,1);
lcd_putc("\fSound Detected");
delay_ms(200);
output_low(LED1);
lcd_putc(0x01);
delay_ms(200);
output_low(alarm); // turn off ALARM
}
else if (input(PIR))
{
output_high(alarm); // turn on ALARM
output_high(LED2);
lcd_putc("\f");
lcd_gotoxy(5,2);
lcd_putc("\nPIR Detected");
delay_ms(200);
output_low(LED2);
lcd_putc(0x01);
delay_ms(200);
output_low(alarm); // turn off ALARM
}
}
}
void SMS()
{
printf("AT+CMGF=1\n\r"); //It inhabits the text mode sms
delay_ms (500);
fprintf(GSM, "at+cmgs=\"0174366043\"\r\n");
delay_ms (2000);
printf ("Go back check your car KBH8255!!!");
delay_ms (500);
putchar (0x1a); //Ctrl-Z(send)
delay_ms (300);
}
void SMS1()
{
printf("AT+CMGF=1\n\r"); //It inhabits the text mode sms
delay_ms (500);
fprintf(GSM, "at+cmgs=\"0109262818\"\r\n");
delay_ms (2000);
printf ("Go back check your car KBH8255!!!");
delay_ms (500);
putchar (0x1a); //Ctrl-Z(send)
delay_ms (300);
}
void ultrasonic()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // initiating timer
output_high(trig); // ping the sonar
delay_us(20); // sending 20us pulse
output_low(trig);
while(!input(ECHO)) // wait for high state of echo pin
{}
set_timer1(0); // setting timer zero
while(input(ECHO)) // Wait for high state of echo pin
{}
time=get_timer1(); // Getting the time
distance=time*0.028 + 1.093 ; // Calculating the distance
//printf(LCD_PUTC, "\fTime :%Lu \nDistance = %Lu",time,distance); // Putting the time and
//distance to the LCD
delay_ms(200);
}
|
Regards |
|
|
low
Joined: 04 Feb 2014 Posts: 28 Location: Malaysia
|
|
Posted: Wed Apr 23, 2014 11:31 am |
|
|
Hi ezflyz,
What the mean of cabling problem "straight-thru vs null-modem"??
Regards |
|
|
low
Joined: 04 Feb 2014 Posts: 28 Location: Malaysia
|
|
Posted: Wed Apr 23, 2014 11:52 am |
|
|
Hi master,
When i the Gabriel sample code and the library...
It have alots warning due to
(Warning:Condition always TRUE)
Regards |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9272 Location: Greensville,Ontario
|
|
Posted: Wed Apr 23, 2014 12:12 pm |
|
|
'Warnings' are just messages telling you of a certain condition but the code DOES compile.
Think of them as yellow CAUTION signs.
'ERROR' messages STOP the compiler from finishing due to a fatal error. Think of them as red STOP signs.
You can run a program with hundreds of 'warnings'. You cannot run a program with ONE 'error'.
A 'straight through' cable connect pin 1-1,2-2,3-3,4-4,etc. while a 'null modem cable connects logical pairs of signals based on their function. IE. 2-3,3-2. This set connects the rcv of one device('A') to the xmt of another device('B') and the xmt of device 'A' to the rcv of device 'B'.
hth
jay |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Wed Apr 23, 2014 1:31 pm |
|
|
low wrote: | Hi master,
When i the Gabriel sample code and the library...
It have alots warning due to
(Warning:Condition always TRUE)
Regards |
Not that it makes a huge difference (see Temtronic's post), but you can replace those with:
and the warnings should disappear. It doesn't change how the code works, but at least for my version it doesn't complain. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Apr 23, 2014 1:37 pm |
|
|
Hi low,
OK, so you've directly connected the PIC board to the GSM modem board, and you can SEND an SMS message from the PIC, but you cannot RECEIVE an SMS message to the PIC. If that is true, it's unlikely that your interconnect cable is the problem (unless it's defective).
Just to be clear, can you send and receive data to/from the PIC when it's connected directly to the PC?
You have all the hardware right in front of you, so YOU need to determine if this is a hardware is or a software issue. I know that you've done a lot of this before, but I'd step back and do the following:
1. Test the PIC in Tx and Rx while directly connected to the PC. Does this work?
2. Test the GSM modem in Tx and Rx while directly connected to the PC. does this work?
3. Connect the PIC board to the GSM modem board, and verify that you can *really* send an SMS via the PIC. Does this work? Verify that you can *really* receive an SMS via the PIC. Does this work?
If you can send an SMS, but not receive an SMS then this suggests one of several possibilities: (1) some breakdown in the connection between the GSM Tx output, and the PIC Rx input - have you got a scope?, (2) some configuration issue (baud rate, etc.) that is preventing the PIC from receiving the GSM data, (3) some other code issue.
At some point, your troubleshooting is going to point you in a direction for further examination. At this point, everything is in question.
John |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu Apr 24, 2014 9:25 am |
|
|
If he can send and SMS but not Receive one from the PIC, then I would assume hardware is fine and take a closer look at the code.
Sending an SMS is pretty straight up... just pour commands out of the UART blindly and it should/can work.
Receiving is much harder as it involves detecting a string, sending commands, evaluating the responses, requesting to read the particular SMS memory location, and so on..
if his code is hard coded to only check Memory location 1 and he receives more than one SMS without deleting the previous one, the second SMS will be in location 2, and thus the Expected SMS will not be read. _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|