Регистрация | Вход

[ Новые сообщения · Участники · Правила форума · Поиск · RSS ]
  • Страница 1 из 1
  • 1
Модератор форума: demanik, ivan_fd  
Форум Picbasic.ru » Программирование МК » Proton PicBasic » SIM900 (конфигурируем и шлём SMS-ки)
SIM900
DNM Дата: Вс, 25.02.2018, 09:52  |                                                                                                                Сообщение # 1
Группа: Проверенные
Ранг:  Понимаю
Сообщений: 75
Репутация: 0   ±
Замечания:   ±
На сайте с 29.09.2011

Статус: Offline

Код
Device = 18F452
Xtal =  20

Declare Adin_Res 10
Declare Adin_Tad 2_FOSC
Declare Adin_Stime 50 '
                    
Declare LCD_Type=0         
Declare LCD_DTPin PORTB.4         
Declare LCD_ENPin PORTB.3         
Declare LCD_RSPin PORTB.2         
Declare LCD_Interface 4             
Declare LCD_CommandUs 2000        
Declare LCD_DataUs 50             
Declare LCD_Lines 2               

TRISA = %00000111
TRISD = %00000010
ADCON1 = %10000000

Clear
' настроим аппаратный RX/TX модуль
Declare Hserial_Baud = 9600 ' Set baud rate to 9600
Declare Hserial_RCSTA = %10010000 ' Enable continuous receive
Declare Hserial_TXSTA = %00100000 ' Enable transmit and asynchronous mode
Declare Hserial_Clear = On ' Clear the buffer before receiving
'

Dim dummy[10] As Byte
Dim dat[10] As String * 15
Dim nn As Dword
Dim ll As Byte
Dim STRING1 As String * 19  'AT - команда посылки данных  "AT+CIPSEND=0,N", N - количество посылаемых символов
Dim STRING2 As String * 32  'Длина посылаемой строки
Symbol CARRY_FLAG = STATUS.0  ' high if microcontroller does not have control over the buffer
Symbol ATTACHED_STATE = 6     ' is USB attached

Print At 1,1,"Sim900"     

DelayMS 5000
Cls
Print At 1,1,"Send"
DelayMS 5000

' настроим модуль Sim900
Main1:
Clear
Cls
    HSerOut["AT", 13, 10]               'ответ от модуля
    HSerIn [Wait ("OK"), dummy[0]]
    Print At 1,1,"AT"
    Print At 2,1,"OK"
DelayMS 1000
Cls
    HSerOut["AT+CMGF=1", 13, 10]        'включить текстовый режим
    HSerIn [Wait ("OK"), dummy[0]]
    Print At 1,1,"AT+CMGF=1"
    Print At 2,1,"OK"
DelayMS 1000
Cls
    HSerOut["AT+CSCS=",34,"GSM",34, 13, 10]    'установить кодировку текстового режима
    HSerIn [Wait ("OK"), dummy[0]]
    Print At 1,1,"AT+CSCS=GSM"
    Print At 2,1,"OK"
DelayMS 1000

Cls
    HSerOut["AT+COPS?", 13, 10]        'получить информацию об операторе
    HSerIn [Wait("+COPS: "),Dec dummy[0], Dec dummy[1], dat]
    Print At 1,1,"AT+COPS?"
    Print At 2,1,Dec dummy[0], ",",Dec dummy[1],",", Str dat
DelayMS 1000
Cls
    HSerOut["AT+CREG?", 13, 10]        'проверить тип регистрации сети
    HSerIn [Wait("+CREG: "), Dec dummy[2], Dec dummy[3]]
    Print At 1,1,"AT+CREG?"
    Print At 2,1,Dec dummy[2], ",",Dec dummy[3]
DelayMS 1000
Cls
    HSerOut["AT+CSQ", 13, 10]        'проверить уровень сигнала
    HSerIn [Wait("+CSQ: "),Dec dummy[4], Dec dummy[5]]
    Print At 1,1,"AT+CSQ"
    Print At 2,1,Dec dummy[4], ",",Dec dummy[5]
DelayMS 1000

LOO:
Cls
ll=LL+1
HSerOut["AT+CMGS=",34,"+79600000049",34, 13, 10]
DelayMS 500
HSerOut[34,"This is the message ",34,Dec ll, $1a]

Print At 1,1,">"
DelayMS 5000
Cls
GoTo LOO

Config_Start
  OSC = HS   ;HS oscillator
  OSCS = OFF   ;Oscillator system clock switch option is disabled (main oscillator is source)
  PWRT = On   ;PWRT enabled
  BOR = OFF   ;Brown-out Reset disabled
  BORV = 20   ;VBOR set to 2.0V
  WDT = OFF   ;WDT disabled (control is placed on the SWDTEN bit)
  WDTPS = 128   ;1:128
  CCP2MUX = OFF   ;CCP2 input/output is multiplexed with RC1
  STVR = OFF   ;Stack Full/Underflow will cause RESET
  LVP = OFF   ;Low Voltage ICSP disabled
  Debug = OFF   ;Background Debugger disabled. RB6 and RB7 configured as general purpose I/O pins.
  CP0 = OFF   ;Block 0 (000200-001FFFh) not code protected
  CP1 = OFF   ;Block 1 (002000-003FFFh) not code protected
  CP2 = OFF   ;Block 2 (004000-005FFFh) not code protected
  CP3 = OFF   ;Block 3 (006000-007FFFh) not code protected
  CPB = OFF   ;Boot Block (000000-0001FFh) not code protected
  CPD = OFF   ;Data EEPROM not code protected
  WRT0 = OFF   ;Block 0 (000200-001FFFh) not write protected
  WRT1 = OFF   ;Block 1 (002000-003FFFh) not write protected
  WRT2 = OFF   ;Block 2 (004000-005FFFh) not write protected
  WRT3 = OFF   ;Block 3 (006000-007FFFh) not write protected
  WRTC = OFF   ;Configuration registers (300000-3000FFh) not write protected
  WRTB = OFF   ;Boot Block (000000-0001FFh) not write protected
  WRTD = OFF   ;Data EEPROM not write protected
  EBTR0 = OFF   ;Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks
  EBTR1 = OFF   ;Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks
  EBTR2 = OFF   ;Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks
  EBTR3 = OFF   ;Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks
  EBTRB = OFF   ;Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks
Config_End

End

Просто шлём данные в СМС - на телефон ...


Более подробно здесь: http://asemlab.net/
Сообщение отредактировал DNM - Вс, 25.02.2018, 09:53
ЯНДЕКС Дата: 25.02.2018
Форум Picbasic.ru » Программирование МК » Proton PicBasic » SIM900 (конфигурируем и шлём SMS-ки)
  • Страница 1 из 1
  • 1
Поиск: