#include "p18f452.inc"
#define BAUD d'9600'
#define XTAL d'40'
#define X ((XTAL*d'1000000')/(d'64'*BAUD))-1
#define DATA_OUT 0x30 ; corresponds to 0 in ascii
org h'0'
goto MAIN
org h'8'
btfss PIR1, TXIF ; TX buffer is full?
retfie ; return from interrupt
TX_INT1 movf DATA_OUT, w
movwf TXREG ; put the data into the TX buf reg
retfie
MAIN
movlw X ; X is the calculated constant
movwf SPBRG ; set baud rate generator appropriately
bsf RCSTA, SPEN ; enable the serial port
bcf TRISC, 6 ; set pin 6 of port c as TX
bsf TRISC, 7 ; set pin 7 of port c as RX
bcf TXSTA, SYNC ; set the mode to asyhncronous
bsf TXSTA, TXEN ; enable the TX
; we want to enable to interrupts associated with TX and RX, so
bsf PIE1, TXIE ; enable the TX interrupts
bsf INTCON, GIE ; enable all unmasked interrupts
bsf INTCON, PEIE ; enable all unmasked peripheral ints
movf DATA_OUT
movwf TXREG
INF_LOOP goto INF_LOOP
END