Hi,
I find this code in proton pb, can any one please change this to pbp? (have try to do it but have a lot of errors)
Code:
************************************************** *****************
Device = 16F628
XTAL = 4
Symbol Led1 PORTB.4 ' Leds are used to indicate errors and debug
Symbol Led2 PORTB.5
Symbol Tx PORTB.2 ' Serial transmit 9600,8,N,1
Symbol Rx PORTB.1 ' Serial Receive 9600,8,N,1
Dim textmsg[20] As Byte
Dim mobno[20] As Byte
Dim nn As Byte ' used as a counter
Dim bitcnt As Byte ' used as a counter
Dim Bcnt As Byte ' used as a counter
Dim temp As Byte ' temporary storage when moving bytes about
Dim rotates As Byte ' the number of rotates to be done
Dim source As Byte ' indirect pointer to source string
Dim target As Byte ' indirect pointer to target string
Init:
Low Led1
Low Led2
DelayMS 500 ' Wait for .5 sec
High Led1 ' SMS sent
High Led2 ' Error Led
StrN mobno = "447799999999" ' Put your mobile number here
' If the mobile number is an odd number, then add an F to the end of it making it an
' even number eg: 4477999999991F
StrN textmsg = "N5413518W0135690" ' Put SMS text here
jump_over_subroutines:
GoTo WaitForRing
septets_to_octets: ' Uses a single string and converts in situ
' with lots of shuffling of bytes - a bit slow maybe ??
target = VarPtr(textmsg)' pointer to target byte of string
FSR = target
If INDF = 0 Then done ' zero length string - nothing to do
source = target + 1 ' pointer to source byte of string
FSR = source
If INDF = 0 Then done ' single byte string - nothing to do
movlw 1
movwf rotates ' sets number of rotates to 1
movwf nn ' sets counter nn to 1
loop:
FSR = source ' point indirection register at source
clrf temp ' set temp to all 0s
For nn = 1 To rotates '
clrc ' ensure carry is clear
ror INDF ' rotate nn bits right through carry
ror temp ' into msb of temp
Next
incf rotates ' do 1 more rotate next time round
FSR = target ' set pointer to target
movfw temp ' move temp into the w register
xorwf INDF ' exclusive or the contents of w with the contents of target and store in target
incf source ' add 1 to source pointer
incf target ' add 1 to target pointer
If rotates > 7 Then ' if we have done 7 rotates already then
movlw 1 ' reset number of rotates back to 1
movwf rotates
nn = source ' temporarily store the source pointer
FSR = source
While INDF <> 0 ' We have now converted 8 Septets into 7 Octets in the string
' leaving the 8th byte full of 0s so we now have to
' shuffle the remaining bytes to the left before we can continue
' looping round until reaching the null byte terminator of the string
temp = INDF ' temporarily store source
FSR = target ' set pointer to target
INDF = temp ' retrieve source from temp and store in target
incf source ' increment source pointer
incf target ' increment target pointer
FSR = source ' set pointer back to source
Wend
FSR = target ' set pointer to target and
INDF = 0 ' put a new null byte to terminate the now shorter string
source = nn ' restore the source byte position
target = nn - 1 ' and the target byte position
EndIf
FSR = source ' set pointer to source
If INDF > 0 Then loop ' loop back until we have reached the null byte terminator
done:
output_msg:
bitcnt = 0
Repeat
Inc bitcnt
Until textmsg[bitcnt] = 0
SerOut Tx, 84, [HEX2 bitcnt+1] ' Set the length of the encoded text
bitcnt = 0
Repeat
SerOut Tx, 84, [HEX2 textmsg[bitcnt]]
Inc bitcnt
Until textmsg[bitcnt] = 0
SerOut Tx, 84, [HEX2 textmsg[bitcnt]]
Return
output_mobileno:
bitcnt = 0
Repeat
Inc bitcnt
Until mobno[bitcnt] = 0
SerOut Tx, 84, [HEX2 bitcnt] ' Set the length of the mobile number
SerOut Tx, 84, ["91"] ' Set mobile number to international type
For Bcnt = 0 To bitcnt -1 Step 2 ' Swap digits around...
SerOut Tx, 84, [mobno[Bcnt+1]]
SerOut Tx, 84, [mobno[Bcnt]]
Next
Return
WaitForRing: ' Wait for someone to ring the mobile before send a SMS
Low Led1
SerIn Rx, 84, [Wait("RING")]
For Bcnt = 1 To 30
Low Led1
DelayMS 500
High Led1
DelayMS 500
Next
GoTo SendSMS
SendSMS:
SerOut Tx, 84, ["AT",13,10] ' Check if mobile is responding
SerIn Rx, 84,3000, Timeout, [Wait("O")]
Low Led1
DelayMS 500
High Led1
SerOut Tx, 84, ["AT+CMGS="]
bitcnt = 0
Bcnt = 0
Repeat
Inc bitcnt
Inc Bcnt
Until textmsg[Bcnt] = 0
Bcnt = 0
Repeat
Inc bitcnt
Inc Bcnt
Until mobno[Bcnt] = 0
SerOut Tx, 84, [Dec bitcnt+5,13,10] ' Set SMS pdu mode with PDU length
SerIn Rx, 84, 3000, Timeout, [Wait(">")]
Low Led1
DelayMS 500
High Led1
SerOut Tx, 84, ["001100"] ' Start of PDU protocol
GoSub output_mobileno
SerOut Tx, 84, ["0000FF"] ' Middle part of PDU protocol
GoSub septets_to_octets
SerOut Tx, 84, [26,13,10]
SerIn Rx, 84, 3000, Timeout, [Wait("O")]
Low Led1
DelayMS 4000
High Led1
GoTo WaitForRing ' Need to put a reset phone command here....
Timeout: ' An error has occurred trying to send a SMS
Low Led2
DelayMS 4000
High Led2
GoTo TheEnd
TheEnd:
Stop
************************************************** ******************
Thanks
Bookmarks