Code:
'*****************************************************************
'* Name : PRINT_18_TX_ASM_INT.pbp *
'* Author : richard *
'* Notice : *
'* : *
'* Date : *
'* Version : 18f26K22 *
'* Notes : *
'* : *
'* *
'*****************************************************************
#CONFIG
CONFIG FOSC=INTIO67, PLLCFG=OFF, PRICLKEN=OFF, FCMEN=OFF, IESO=OFF
CONFIG PWRTEN=OFF, BOREN=SBORDIS, BORV=190, WDTEN=ON, WDTPS=32768
CONFIG CCP2MX=PORTC1, PBADEN=OFF, CCP3MX=PORTB5, HFOFST=ON, T3CMX=PORTC0
CONFIG P2BMX=PORTB5, MCLRE=EXTMCLR, STVREN=ON, LVP=OFF, XINST=OFF, DEBUG=OFF
CONFIG CP0=OFF, CP1=OFF, CP2=OFF, CP3=OFF, CPB=OFF, CPD=OFF, WRT0=OFF
CONFIG WRT1=OFF, WRT2=OFF, WRT3=OFF, WRTC=OFF, WRTB=OFF, WRTD=OFF, EBTR0=OFF
CONFIG EBTR1=OFF, EBTR2=OFF, EBTR3=OFF, EBTRB=OFF
#ENDCONFIG
DEFINE OSC 64
DEFINE INTHAND do_tx
RCSTA = $90 ' Enable serial port & continuous receive
TXSTA = $24 ' Enable transmit, BRGH = 1
SPBRG = 130 ' 9600 Baud @ 64MHz, -0.02%
SPBRGH = 6
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
prnb var byte[256]
rpos VAR BYTE
empty VAR BYTE
TRISC=%11111111
OSCCON = $70 ; 64Mhz
OSCTUNE.6 = 1 ; Enable 4x PLL
while ! osccon2.7 :WEND ; to make sure the pll has stabilised before you run any other code
ANSELA=0
ANSELC=0
intcon=$c0
empty=1
pause 1000
hserout ["ready",13,10 ] ; PROOF OF LIFE
pause 1000
mainloop:
if empty then
;hserout [13,10]
arraywrite prnb[240],[13,10,0,"RTIOP12345678"]
gosub print
ENDIF
pause 2000
goto mainloop
' SAMPLE OF RAW BINARY OUTPUT FROM TX PIN IN HEX
' 0D 0A 00 52 54 49 4F 50 31 32 33 34 35 36 37 38
' 0D 0A 00 52 54 49 4F 50 31 32 33 34 35 36 37 38
' ..............
print:
rpos = 240 ;FOR TEST START AT INX 240 IE PRINT CHRS 240-255 IN BUFFER
empty=0
PIE1.4=1
return
asm
do_tx
LFSR 0, _prnb ; Store buffer ADDR to FSR0H
BANKSEL _rpos
MOVF _rpos,W ; Add rpos to pointer
ADDWF FSR0L,F ; Store Low byte in FSR0
BNC NOV
INCF FSR0H ,F
NOV
movf INDF0,W
movwf TXREG
INCFSZ _rpos,F ; Increment rpos
BRA exP ; if buffer empty turn ofF interrupt
bcf PIE1,TXIF
BANKSEL _empty ; AND SET FLAG
BSF _empty ,0
exP
BANKSEL 0
RETFIE
endasm
Bookmarks