END places the PIC in a tight loop executing SLEEP continuously.
With HSEROUT, PBP loads the outbound character, then issues a call to the
HSEROUT sub-routine. It doesn't wait for the last character to be sent.
Program execution returns to the next statement right after the call to
HSEROUT, lands on SLEEP, kills the CPU clock, and your last character is
never sent.
Here's how it works;
Code:
DEFINE OSC 4
HSEROUT ["AB"]
END
Which produces this in assembler;
Code:
0000 GOTO INIT
0001 HSEROUT CLRWDT
0002 BTFSS PIR1, 0x4
0003 GOTO HSEROUT
0004 MOVWF TXREG
0005 BSF STATUS, 0
0006 GOTO DONE
0007 DONE BCF STATUS, 0x7
0008 BCF STATUS, 0x6
0009 BCF STATUS, 0x5
000A CLRWDT
000B DONERET RETURN
000C INIT BSF STATUS, 0x5
000D MOVLW 0x19
000E MOVWF TXREG
000F MOVLW 0x20
0010 MOVWF RCSTA
0011 BCF STATUS, 0x5
0012 MOVLW 0x90
0013 MOVWF RCSTA
0014 MAIN MOVLW 0x41 ; <-- load 1st character
0015 CLRF PCLATH
0016 CALL HSEROUT ; <-- send it
0017 MOVLW 0x42 ; load 2nd character
0018 CLRF PCLATH
0019 CALL HSEROUT ; <-- send 2nd character
001A SLEEP <-- goes to sleep before 2nd character is sent
The PIC is executing instructions a lot faster than your 8-bit serial data can
be shifted out, so it returns and lands on the SLEEP instruction long before
data can be sent.
You need a pause after HSEROUT for a period of at least 1/baud rate*10 or
loop until the TX buffer flag indicates the last char has been sent.
Bookmarks