'Use 8Mhz crystal
Define CLOCK_FREQUENCY = 8.0 '8 Mhz gives least error at 9600, 0.16%TX, 0.64%RX
.
.
.
Dim t1h As Byte 'Time high byte
Dim t1l As Byte 'Timer low byte
Dim tcon As Byte 'Timer prescalere and Set on
.
.
.
T1CON = 0 'make sure timer is off
.
.
.
.
'Set default loop of 50ms delay
t1h = 0x3c
t1l = 0xb0
tcon = 0x11
.
.
.
'Start 50ms timer
PIR1.TMR1IF = 0 'clear Timer1 flag
TMR1H = t1h '50ms high value as defined at start
TMR1L = t1l '50ms low value as defined at start
T1CON = tcon 'define 1:2 prescaler, enable timer1 to "on"
'In above, tcon variable happens to be 0x10 for prescaler, and 0x01 to start timer (TCON=0x11)
'for all times in the 40-60ms range. Other ranges may change tcon, hence it is now a variable defined
'in the initialization code near top. 80ms requires tcon=0x21
'Following loop is about 3.5 to 5us, faster than interrupt for RX checks
'due to fact interrupt routine saves registers, etc. before checking....
'Interrupt routine took about 9.5us, this is faster...
'NOTE:
'RCX is the serial input pin, and checked for change in polarity from idle.
'This value check is either 1 or 0, depending if the serial data is inverted or not
'What I do here is loop for the timer timeout (50ms), and if any data shows up (9600 baud)
'the system is fast enough to go do the serial read without missing anything.
' The 5uS delays in checking the bit is <0.5% error st 9600 baud (1mS/char)
lp:
If PIR1.TMR1IF = 1 Then Goto timeup '50ms timer
If rcx = 0 Then Goto lp
Goto readfreq 'data coming in, loop immediately to start read. Next readbyte is 5.5uS later
timeup:
T1CON = 0 'disable timer
PIR1.TMR1IF = 0 'clear flag
.
.
.