Here's my own version. Not as brilliant as all the above but allow to send String and numeric value. Have fun!
[html]
' ///////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' Embedded String and Data handling
' =================================
' Steve Monfette
' Mister E Enr
'
' This program show how to use/define/send a combination of String and Data
' to a PC terminal or else @9600 bauds.
'
' We can still use HSEROUT and do the same thing, of course but the
' following use another approach wich :
' 1. Allow to modify one or all string/data in a snap when needed.
' 2. Call a string many time only by calling his name with the macro.
' That is still more code efficient than if you create and use
' a specific SUBROUTINE.
'
' Also, if you compare this method to the use of multiple HSEROUT,
' you'll notice a slight difference in the size of the generated code.
'
' This program could also be usefull to send string/data to various device
' like I2C, LCD,...
' ///////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
@ errorlevel 0,-207 ' avoid anoying MPASM error message
' -- found label after column 1 --
' PIC Definition
' ==============
' Done with an old & dusty PIC16F877 @ 20MHZ
'
DEFINE LOADER_USED 1
DEFINE OSC 20
' Hardware define
' ===============
'
TRISC=%10111111
' Serial Comm definition
' ======================
'
RCSTA=$90 ' Enable USART, continuous receive
TXSTA=$24 ' Enable transmit, BRGH=1
SPBRG=129 ' 9600 Bauds
' Variable definition
' ===================
'
Char var byte ' Character to be read/send
SAddr var word ' String adress pointer
' Software initialisation
' =======================
'
clear ' set all variable to 0
goto Start ' Skip any Macro And string Definition
' String Definition
' =================
' String must be defined as follow
' <label> dt <data>,0
'
' could also be
' <label> dt <data>
' dt <data>
' .........
' dt <data>,0
'
' Any String must be NULL terminated. Can contain text and numeric value
'
asm
s1 dt "String #1",13,10,0
s2 dt "String #2",13,10
dt "********************",13,10,0
s3 dt "String #3",13,10,0
s4 dt "String #4..... THE LAST ONE",13,10,0
endasm
' Macro Definition
' ================
'
' SendString:
' ===========
' This send the according string via USART
' Format:
' =======
' SendString <StringName>
'
asm
SendString macro StringLabel
CHK?RP _SAddr ; Reach the right BANK of SAddr
MOVE?CW StringLabel,_SAddr ; Store address of StringLabel in SAddr
L?CALL SendIt ; Send the string.
endm
endasm
@SendIt
Readcode SAddr, char ' Read character
if Char then ' if not NULL, send it
ASM
MOVE?BB _Char,TXREG ; Load TXREG with Char
IsFull
BIT?GOTO 0, PIR1, 4, IsFull ; Loop while TXREG is full
; The above is the same as
; IF PIR1.4=0 THEN GOTO IsFull
;
INCF _SAddr,1 ; Point to the next character
GOTO SendIt ; Do it again
ENDASM
endif
return
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Start:
' /////////////////////////////////|\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
' Here we will send our data by using the above macro
'
@ SendString s1 ; Send string with label 's1'
@ SendString s2 ; Send string with label 's2'
@ SendString s3 ; Send string with label 's3'
@ SendString s4 ; Send string with label 's4'
pause 1500 ; wait a little bit
goto Start ; do it again
[/html]
Last edited by mister_e; - 27th August 2005 at 18:58.
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Bookmarks