Code:
'pic18f45k20
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 4/14/2015 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2015 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 4/14/2015 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
#CONFIG
CONFIG FOSC = INTIO67
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOREN = SBORDIS
CONFIG BORV = 18
CONFIG WDTEN = ON
CONFIG WDTPS = 512
CONFIG CCP2MX = PORTC
CONFIG PBADEN = OFF
CONFIG LPT1OSC = OFF
CONFIG HFOFST = ON
CONFIG MCLRE = ON
CONFIG STVREN = ON
CONFIG LVP = OFF
CONFIG XINST = OFF
CONFIG DEBUG = OFF
CONFIG CP0 = OFF
CONFIG CP1 = OFF
CONFIG CP2 = OFF
CONFIG CP3 = OFF
CONFIG CPB = OFF
CONFIG CPD = OFF
CONFIG WRT0 = OFF
CONFIG WRT1 = OFF
CONFIG WRT2 = OFF
CONFIG WRT3 = OFF
CONFIG WRTC = OFF
CONFIG WRTB = OFF
CONFIG WRTD = OFF
CONFIG EBTR0 = OFF
CONFIG EBTR1 = OFF
CONFIG EBTR2 = OFF
CONFIG EBTR3 = OFF
CONFIG EBTRB = OFF
#ENDCONFIG
define OSC 64
osccon=$70 '64 mhz
OSCTUNE.6=1
pause 2000
Serout2 PORTb.7,84,["ready",13,10]
Addr var word
Char var byte
cnt var byte
inbuff var byte[30]
buff var byte[30]
Clear
goto StartLoop ' Required
String1:
@ da "This is a string",0
AnotherString:
@ da "Here is another string",0
'------------GetAddress Macro - Location insensitive -------------------------
ASM
GetAddress macro Label, Wout ; Returns the Address of a Label as a Word
CHK?RP Wout
movlw low Label
movwf Wout
movlw High Label
movwf Wout + 1
endm
ENDASM
StartLoop: ' This loop repeats continuously just as a test.
@ GetAddress _String1, _Addr ' Get address of String
cnt=0
gosub StringOut ' Send the String
Serout2 PORTb.7,84, [13,10] ' New Line
Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line
@ GetAddress _AnotherString, _Addr ' Get address of String
cnt=0
gosub StringOut ' Send the String
Serout2 PORTb.7,84,[13,10] ' New Line
Serout2 PORTb.7,84, ["inbuff ",str inbuff\cnt ,13,10] ' New Line
pause 500
goto StartLoop ' Repeat
StringOut: ' Send the string out via Hserout
Readcode Addr, Char ' Get a character
if Char = 0 then StringDone ' Look for Null char, Stop if found
buff[cnt]=char
cnt=cnt+1
Serout2 PORTb.7,84, [Char] ' Send char
Addr = Addr + 1 ' Point to next character
goto StringOut ' Continue with rest of the string
StringDone:
ARRAYWRITE inbuff,cnt,,[str buff]
return
end
I do it this way , and use the bounds checking features of arraywrite
Bookmarks