Define CONF_WORD = 0x3ff2
Dim x As Bit
Dim y As Byte
init:
AllDigital
x = 1
main:
Serout RB0, 9600, "Hello world!", CrLf
While x = 1
Call serin_timeout(100)
Wend
End
Proc serin_timeout(t As Byte)
Dim serin_flag As Bit
serin_flag = 0
'enable prescaler for tmr0
OPTION.PSA = 0
'set tmr0 prescaler for 8
OPTION.PS2 = 0
OPTION.PS1 = 1
OPTION.PS0 = 0
'enable tmr0
OPTION.T0CS = 0
'clear tmr0
TMR0 = 0
While TMR0 < t
If PORTB.1 = 0 Then
Serin RB1, 9600, y
Serout RB0, 9600, y, CrLf
serin_flag = 1
Endif
Wend
If serin_flag = 0 Then
Serout RB0, 9600, "TIMEOUT", CrLf
Endif
'clear tmr0
TMR0 = 0
'disable TMR0
OPTION.T0CS = 1
End Proc