資源簡(jiǎn)介
SIM800C模塊參考例程,Arduino、STC12、STC15、STC89、STM32都有例程,親測(cè)可用,僅供參考。
代碼片段和文件信息
/*
?GSM.cpp?-?library?for?the?GSM?Playground?-?GSM?Shield?for?Arduino
?Released?under?the?Creative?Commons?Attribution-Share?Alike?3.0?License
?http://www.creativecommons.org/licenses/by-sa/3.0/
?www.hwkitchen.com
*/??
#include?“WProgram.h“
#include?“NewSoftSerial.h“
#include?“GSM_Shield.h“
extern?“C“?{
??#include?
}
NewSoftSerial?mySerial(4?5);??//rx?tx
#ifdef?DEBUG_LED_ENABLED
??int?DEBUG_LED?=?25;????????????????//?LED?connected?to?digital?pin?25
void??GSM::blinkDebugLED?(byte?num_of_blink)
??{
????byte?i;
????pinMode(DEBUG_LED?OUTPUT);??????//?sets?the?digital?pin?as?output
????for?(i?=?0;?i?ink;?i++)?{
??????digitalWrite(DEBUG_LED?HIGH);???//?sets?the?LED?on
??????delay(50);
??????digitalWrite(DEBUG_LED?LOW);???//?sets?the?LED?off
??????delay(500);
????}
??}
#endif
#ifdef?DEBUG_PRINT
/**********************************************************
Two?methods?print?out?debug?information?to?the?standard?output
-?it?means?to?the?serial?line.
First?method?prints?string.
Second?method?prints?integer?numbers.
Note:
=====
The?serial?line?is?connected?to?the?GSM?module?and?is?
used?for?sending?AT?commands.?There?is?used?“trick“?that?GSM
module?accepts?not?valid?AT?command?strings?because?it?doesn‘t
understand?them?and?still?waits?for?some?valid?AT?command.
So?after?all?debug?strings?are?sent?we?send?just?AT?as
a?valid?AT?command?and?GSM?module?responds?by?OK.?So?previous?
debug?strings?are?overwritten?and?GSM?module?is?not?influenced
by?these?debug?texts?
string_to_print:??pointer?to?the?string?to?be?print?out
last_debug_print:?0?-?this?is?not?last?debug?info?we?will
??????????????????????continue?with?sending...?so?don‘t?send
??????????????????????AT(see?explanation?above)
??????????????????1?-?we?are?finished?with?sending?debug?info?
??????????????????????for?this?time?and?finished?AT?
??????????????????????will?be?sent(see?explanation?above)
**********************************************************/
void?GSM::DebugPrint(const?char?*string_to_print?byte?last_debug_print)
{
??if?(last_debug_print)?{
????Serial.println(string_to_print);
????SendATCmdWaitResp(“AT“?500?50?“OK“?1);
??}
??else?Serial.print(string_to_print);
}
void?GSM::DebugPrint(int?number_to_print?byte?last_debug_print)
{
??Serial.println(number_to_print);
??if?(last_debug_print)?{
????SendATCmdWaitResp(“AT“?500?50?“OK“?1);
??}
}
#endif
/**********************************************************
Method?returns?GSM?library?version
return?val:?100?means?library?version?1.00
????????????101?means?library?version?1.01
**********************************************************/
int?GSM::LibVer(void)
{
??return?(GSM_LIB_VERSION);
}
/**********************************************************
??Constructor?definition
***********************************************************/
GSM::GSM(void)
{
??//?set?some?GSM?pins?as?inputs?some?
評(píng)論
共有 條評(píng)論