Nice job Darrel, and thanks for the excellent resource. I've used several of
your routines on various projects.
Here's something similar for the 18F series.
Code:
DEFINE LOADER_USED 1
DEFINE OSC 4
ptr_pos VAR BYTE
temp VAR BYTE
x VAR BYTE
Main:
CALL USART_Init
ptr_pos = 0
CALL Start
ptr_pos = 16
CALL Start
ptr_pos = 48
CALL Start
ptr_pos = 176
CALL Start
Done:
GOTO Done
ASM
_USART_Init
movlw B'00100100' ;initialize USART
movwf TXSTA ;8-bit, Async, High Speed
movlw .25 ;value for 9600 bps @ 4MHz
movwf SPBRG ;set SPBRG for 9600 bps @ 4MHz
movlw B'10010000' ;enable USART
movwf RCSTA
return
;----Lookup & send text messages--------------------------
_Start
movlw UPPER msg_table
movwf TBLPTRU
movlw HIGH msg_table
movwf TBLPTRH
movlw LOW msg_table
movwf TBLPTRL
movf _ptr_pos,W ;prt_pos must hold message address
addwf TBLPTRL,F
clrf WREG
addwfc TBLPTRH,F
addwfc TBLPTRU,F
Next_Char
tblrd *+
movff TABLAT,_temp
bra Test_EOM ;test for EOM character
Continue
movf _temp,W ;move temp to w
movwf TXREG ;send it
btfss TXSTA,TRMT ;wait for data TX
goto $-2
bra Next_Char ;fetch next message character from table
Test_EOM
movlw "~" ;check for EOM character
cpfseq _temp, 1 ;compare temp with w, if temp = ~ then end
bra Continue ;no EOM, so continue
movlw "\r" ;move data into TXREG
movwf TXREG ;send carriage return
btfss TXSTA,TRMT ;wait for data TX
goto $-2
movlw "\n" ;move data into TXREG
movwf TXREG ;send line feed
btfss TXSTA,TRMT ;wait for data TX
goto $-2
return ;finished with message, return to caller
ENDASM
ASM
msg_table ; Message strings
data " Message #1~ ";Message #1 starts at msg_table 0
data " Message #2~ ";Message #2 starts at msg_table 16, etc,
data " Message #3~ ";32
data " Message #5~ ";48
data " Message #6~ ";64
data " Message #7~ ";80
data " Message #8~ ";96
data " Message #9~ ";112
data " Message #10~ ";128
data " Message #11~ ";144
data " Message #12~ ";160
data " Message #13~ ";176
ENDASM
Bookmarks