here is my test program:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
dir portc.7 in 'serial in
dir portc.6 out 'serial out
#define USART_BLOCKING
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call rec_data
dim temp as byte
dir portc.0 out 'opener
Start:
set portc.0 on
wait 1 s
set portc.0 off
wait 1 s
goto start
sub rec_data
If RCIF On Then
HSerReceive NewDataIn
temp = newdatain
if temp = 48 then display_data
end if
end sub
sub display_data
Transmitserial(49)
end sub
sub TransmitSerial_Print(PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
transmitSerial(PrintData(SysPrintTemp))
next
end sub
sub TransmitSerial(xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXDATA = xmitdata
' CalcParity(TXDATA) 'calculate parity
' rotate ParityByte RIGHT 'get parity bit into status.c
' SET TXSTA.TX9D OFF 'set parity bit to zero
' IF STATUS.C = 1 THEN SET TXSTA.TX9D ON 'if status.c is one, set parity bit
TXREG = TXDATA 'transmit data
end sub
it runs the main fine until i send it the "0" and then it just stops running the main and does nothing with no output on the serial?
why
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
in the "lowlevel" library GCBASIC>include>lowlevel>usart.h i'll bet the "blocking" statement is backwards. It was when I was using the usart a few weeks ago.
Search the forums. there are a couple fixes to the usart.h
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
here is my test program:
#chip 16F767, 12 'mhz
#config MCLRE=off, WDT=off
lcdcon = 0
dir portc.7 in 'serial in
dir portc.6 out 'serial out
#define USART_BLOCKING
#define USART_BAUD_RATE 9600 'the speed you want
InitUsart
On Interrupt UsartRX1Ready call rec_data
dim temp as byte
dir portc.0 out 'opener
Start:
set portc.0 on
wait 1 s
set portc.0 off
wait 1 s
goto start
sub rec_data
If RCIF On Then
HSerReceive NewDataIn
temp = newdatain
if temp = 48 then display_data
end if
end sub
sub display_data
Transmitserial(49)
end sub
sub TransmitSerial_Print(PrintData$)
PrintLen = PrintData(0)
if PrintLen = 0 then exit sub
'Write Data
for SysPrintTemp = 1 to PrintLen
transmitSerial(PrintData(SysPrintTemp))
next
end sub
sub TransmitSerial(xmitdata)
LoopTransmit:
IF PIR1.TXIF OFF THEN goto LoopTransmit 'check if transmitter is busy
TXDATA = xmitdata
' CalcParity(TXDATA) 'calculate parity
' rotate ParityByte RIGHT 'get parity bit into status.c
' SET TXSTA.TX9D OFF 'set parity bit to zero
' IF STATUS.C = 1 THEN SET TXSTA.TX9D ON 'if status.c is one, set parity bit
TXREG = TXDATA 'transmit data
end sub
it runs the main fine until i send it the "0" and then it just stops running the main and does nothing with no output on the serial?
why
in the "lowlevel" library GCBASIC>include>lowlevel>usart.h i'll bet the "blocking" statement is backwards. It was when I was using the usart a few weeks ago.
Search the forums. there are a couple fixes to the usart.h
in usart.h
Find
code
sub HSerSend(In SerData)
#ifdef PIC
#ifdef USART_BLOCKING
Wait While TXIF = Off
#endif
TXREG = SerData
#endif
#ifdef AVR
#ifdef USART_BLOCKING
Wait While UDRE = Off
#endif
UDR = SerData
#endif
end sub
code/
I bet "Wait While TXIF = Off" will say "=On"
73
m
thanks