sub initusart
set TXtris on 'set TX port pin output
set RXtris on 'set RX port pin output
SPBRG = SPBRG_Val
TXSTA=0x24 'enable transmission and BRGH=1
RCSTA=0x90 'enable serial port and receive
end sub
sub HserTX (xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXREG = xmitdata 'transmit data
end sub
sub HserTX_Print(PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
for SysPrintTemp = 1 to PrintLen
HserTX(PrintData(SysPrintTemp))
next
end sub
function HserRX 'check if data received, and if so, return data
IF PIR1.RCIF OFF THEN GOTO endreceiveserial
HserRX = RCREG
GOTO successreceiveserial
endreceiveserial:
HserRX = 0
successreceiveserial:
end function
function HserIn
LoopRec:
IF PIR1.RCIF OFF THEN GOTO LoopRec
HserIn = RCREG
end function
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Am I wrong or is the usart.h library empty? All I see are routine prototypes. If it was there, what is UsartStatus?
usart.h is indeed empty.
Enclosed is a simple USART driver file that does not use error checking. These emulate the USART routines in Oshonsoft Pic_Sim_Ide Basic.
#define TXtris TRISC.6
#define RXtris TRISC.7
#define SPBRG_Val 64
sub initusart
set TXtris on 'set TX port pin output
set RXtris on 'set RX port pin output
SPBRG = SPBRG_Val
TXSTA=0x24 'enable transmission and BRGH=1
RCSTA=0x90 'enable serial port and receive
end sub
sub HserTX (xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXREG = xmitdata 'transmit data
end sub
sub HserTX_Print(PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
for SysPrintTemp = 1 to PrintLen
HserTX(PrintData(SysPrintTemp))
next
end sub
function HserRX 'check if data received, and if so, return data
IF PIR1.RCIF OFF THEN GOTO endreceiveserial
HserRX = RCREG
GOTO successreceiveserial
endreceiveserial:
HserRX = 0
successreceiveserial:
end function
function HserIn
LoopRec:
IF PIR1.RCIF OFF THEN GOTO LoopRec
HserIn = RCREG
end function