Hi! Please forgive me for not knowing the English language! Forced to use the computer translator. Want to offer for consideration a small library to work with the controller GSM/GPRS SIM900, which is located on the module GBoard Pro http://imall.iteadstudio.com/im130514001.html .
\ \ sim900.f \ ~ilya \ 12.02.2014 \ SIM900_TXD - PH0 \ SIM900_RXD - PH1 \ SIM900_RST - PL2 \ SIM900_PWR - PL3 \ Для начала общения с sim900 надо выдать в порт "AT" marker =sim900= \ USART2 &214 constant UDR2 \ USART I/O Data Register &208 constant UCSR2A \ USART Control and Status Register A $80 constant UCSR2A_RXC2 \ USART Receive Complete $40 constant UCSR2A_TXC2 \ USART Transmitt Complete $20 constant UCSR2A_UDRE2 \ USART Data Register Empty $10 constant UCSR2A_FE2 \ Framing Error $08 constant UCSR2A_DOR2 \ Data overRun $04 constant UCSR2A_UPE2 \ Parity Error $02 constant UCSR2A_U2X2 \ Double the USART transmission speed $01 constant UCSR2A_MPCM2 \ Multi-processor Communication Mode &209 constant UCSR2B \ USART Control and Status Register B $80 constant UCSR2B_RXCIE2 \ RX Complete Interrupt Enable $40 constant UCSR2B_TXCIE2 \ TX Complete Interrupt Enable $20 constant UCSR2B_UDRIE2 \ USART Data register Empty Interrupt Enable $10 constant UCSR2B_RXEN2 \ Receiver Enable $08 constant UCSR2B_TXEN2 \ Transmitter Enable $04 constant UCSR2B_UCSZ22 \ Character Size $02 constant UCSR2B_RXB82 \ Receive Data Bit 8 $01 constant UCSR2B_TXB82 \ Transmit Data Bit 8 &210 constant UCSR2C \ USART Control and Status Register C $C0 constant UCSR2C_UMSEL2 \ USART Mode Select $30 constant UCSR2C_UPM2 \ Parity Mode Bits $08 constant UCSR2C_USBS2 \ Stop Bit Select $06 constant UCSR2C_UCSZ2 \ Character Size $01 constant UCSR2C_UCPOL2 \ Clock Polarity &212 constant UBRR2 \ USART Baud Rate Register Bytes &102 constant USART2__RXAddr \ USART2, Rx Complete &258 constant PORTH \ PORT H Data Register &267 constant PORTL \ PORT L Data Register 250 constant rbufsize \ размер буфера PORTH 0 portpin: SIM900_RXD \ PORTH 1 portpin: SIM900_TXD \ PORTL 2 portpin: SIM900_RST \ PORTL 3 portpin: SIM900_PWR \ rbufsize buffer: rx-buf \ Приёмный буфер / Receive buffer rbufsize buffer: tx-buf \ variable b-count \ кол-во принятых байт / The number of bytes received variable cr-flag \ флаг конца строки / the flag of the end of the line \ Включаем/выключаем питание / Included on/off power : sim900-pwr SIM900_PWR low 100 ms SIM900_PWR high 1000 ms SIM900_PWR low ; \ Ини : usart2-init ( n -- ) \ Где n - константа скорости COM-порта / Where n is the rate constant of the COM port UBRR2 c! \ [ UCSR2B_RXCIE2 \ Прерывение по получению символа UCSR2B_RXEN2 \ Прием вкл. UCSR2B_TXEN2 \ Передача вкл. or or ] literal UCSR2B c! ; \ Начинаем писать в буфер с начала : b2begin rx-buf rbufsize erase 0 b-count ! ; \ Помещаем байт в буфер : b2buf ( n -- ) rx-buf b-count @ + c! ; \ Проверяем/устанавливаем флаг конца строки : ?cr rx-buf b-count @ 1 cells - + @ $0a0d = cr-flag ! ; \ Принимаем один байт в буфер : 1b-rcv UDR2 c@ b-count @ rbufsize < if b2buf 1 b-count +! else b2begin \ Стираем буфер и счетчик байт b2buf then ?cr ; \ Отправляем один байт / Send one byte : 1b-send ( n -- ) 1000 0 \ Тупой таймаут do UCSR2A c@ UCSR2A_UDRE2 and if leave then loop UDR2 c! ; : cr-send $0d 1b-send $0a 1b-send ; \ Посылаем счетную строку (RAM) / Send counting string (RAM) : _str-send ( adr n -- ) b2begin over + swap ?do i c@ 1b-send loop cr-send ; : str-send tx-buf asciiz> _str-send ; \ Посылаем счетную строку (FLASH) / Send counting string (FLASH) : fstr-send ( adr n -- ) tx-buf dup rbufsize erase imove str-send ; \ Добавить скомпилированную строку в буфер / Add compiled a string to the buffer : +txf ( adr n -- ) tx-buf +buff ; \ Добавить скомпилированную строку с начала буфера / Add compiled a row since the beginning of the buffer : >txf ( adr n -- ) tx-buf rbufsize erase +txf ; : +tx tx-buf +buf ; \ Добавить символ в буфер : +txc ( c -- ) tx-buf +sym ; char " constant \q : \" \q +txc ; : sim900-init SIM900_RXD pin_input SIM900_TXD pin_output SIM900_PWR pin_output SIM900_RST pin_output ['] 1b-rcv USART2__RXAddr int! +int \ Устанавливаем прерывание ; Usage example: \ Инициализация GSM (SIM900) : gsm-init 0 cr-flag ! b2begin sim900-init 103 usart2-init \ Скорость 9600 / Speed 9600 sim900-pwr \ Включаем модуль / Power on 1000 ms s" AT+CMGF=1" fstr-send s" AT+CSCS=" ( rx-tx-buf imove) >txf s" GSM" +txf \" str-send \ tx-buf asciiz> str-send \ Устанавливаем GSM кодировку / Installed GSM encoding s" ATE0" fstr-send \ Убираем эхо / Remove the echo s" AT+CNMI=2,2,0,0,0" fstr-send \ Сразу видим текст SMS / Go see text SMS ; : main gsm-init s" ATI" fstr-send 200 ms rx-buf asciiz> type cr \ Display Product Identification Information s" AT+CCLK?" fstr-send 200 ms rx-buf asciiz> type cr \ Get the value of the built-in clock ; The library is the word from the library strm.f \ String manipulations \ ~ilya \ 19.12.12 marker =mystring= : zlen dup begin dup c@ while 1+ repeat swap - ; : asciiz> dup zlen ; : zplace ( a u buf -- ) swap over over + 0 swap c! cmove ; : +zplace ( a u buf -- ) asciiz> + zplace ; \ Добавить символ c в конец строки adr : +sym ( c adr -- ) asciiz> + c! ; : +buf ( adr n adr1 -- ) +zplace ; \ Копируем строку из flash в ram : fmove ( f-adr r-adr n -- ) rot swap dup 2/ swap over 2* - + over + swap ?do i @i over ! cell+ loop drop ; : +buff ( adr n adr1 -- ) asciiz> + swap fmove ; -- Bye! Илья ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amforth-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amforth-devel