| ??? 05/28/10 23:53 Read: times |
#176275 - Again without the conditionals Responding to: ???'s previous message |
Interrupt handler:
serint1:
clr ES1 ; Disable further serial interrupts on port 1.
push ar2
push psw
push acc
push b
push DPL
push DPH
clr RI1
mov DPTR,#stop_drive+serintmon_pin
mov a,#1
movx @DPTR,a ; Output to ON coil every time we get an interrupt.
mov a,SBUF1 ; read the byte,
setb tr1_enab ; turn on driver,
mov r2,#0
djnz r2,$ ; Wait for 1/12us x 4 per cycle x 2 cycles x 256 = 0.17ms
mov SBUF1,a ; re-transmit the byte,
jnb TI1,$ ; wait for transmit complete bit (no timeout),
clr TI1
mov r2,#0
djnz r2,$ ; Wait for 1/12us x 4 per cycle x 2 cycles x 256 = 0.17ms
jmp ser1_1 ; and do nothing else.
ser1_1a:
mov a,SBUF1
jb transmit_flag,ser1_1 ; Ignore further characters while transmit flag is set (i.e. until the
; data - either remote or main - has been successfuly transmitted and acknowledged).
; This is simply because interrupting the send would cause a long delay which would
; probably cause the receiving unit to time out.
cjne a,#0FCh,ser1_1
mov DPTR,#keyboard2
jmp ser1_2
ser1_1:
clr tr1_enab ; Anything other than start marker, turn off driver.
pop DPH
pop DPL
pop b
pop acc
pop psw
pop ar2
setb ES1 ; Re-enable interrupt.
reti
ser1_2: ; FCh (start marker).
jnb RI1,$ ; Wait for byte (no timeout).
clr RI1
mov a,SBUF1
; cjne a,#0FAh,byte_update
cjne a,#0FAh,ser1_4 ; RSB100527 This change is because the code triggered by FBh seems to be unused, and dangerous.
jmp ser1_5
byte_update:
cjne a,#0FBh,ser1_4
jmp ser1_6
ser1_4: call send_error1
jmp ser1_1
ser1_6:
mov r2,#notes_64 ; FBh
again:
jnb RI1,$
clr RI1
mov a,SBUF1
movx @DPTR,a
inc DPTR
djnz r2,again
ser1_5: ; FAh (byte marker).
jnb RI1,$ ; Wait for byte (no timeout).
clr RI1
mov a,SBUF1
cjne a,#0FDh,ser1_7
jmp ser1_8
ser1_7:
anl a,#3fh
mov DPL,a
jnb RI1,$ ; Wait for byte (no timeout).
clr RI1
mov a,SBUF1
movx @DPTR,a ; Save the received byte in the correct location.
jmp ser1_5 ; Keep reading data until we see a checksum marker.
ser1_8: ; FDh (checksum marker).
jnb RI1,$
clr RI1
mov a,SBUF1
mov b,a
jnb RI1,$
clr RI1 ; Receive end_marker from remote unit.
mov a,SBUF1
cjne a,#0FEh,ser1_9
jmp ser1_10
ser1_9:
call send_error1
jmp ser1_1
ser1_10:
xcall check_sum
cjne a,b,ser1_9
call send_okay1
setb transmit2_flag ; This informs main loop to ignore local data and transmit keyboard2 array.
clr tr_enab ; Turn off RS485 driver.
mov r5,#00h ; Required to exit wait!
pop DPH
pop DPL
pop b
pop acc
pop psw
pop ar2
setb ES1 ; Re-enable interrupts.
reti
|



