* ******************************************************************* * by Andrew Chanler - Oct 2003 * Cricket bus interface for handybaord using port A pin 7 which is (digital input 9) as bus line * please refer to http://www.cs.uml.edu/~achanler/robotics/ * ******************************************************************* #include "6811regs.asm" ORG MAIN_START ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_initialize_module: rts ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_install_PAI_interrupt: * ;; enable the interrupt #include "ldxibase.asm" ldd #interrupt_cbus_PAI std PAIINT,X ;; setup pulse accumulator interrupt vector ldaa PACTL oraa #%01000000 anda #%01001111 staa PACTL ;; turn on pulse accumulator with high to low trigger rts ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; variable_is_cbus_cmd FDB 0x00 variable_cbus_byte FDB 0x00 variable_my_cbus_id FDB 0x00 ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; interrupt_cbus_PAI: sei clrb ldaa #8 ldx #0x1000 clr variable_is_cbus_cmd clr variable_is_cbus_cmd+1 * wait for begining of start bit pai_waithere: brclr 0,x 0x80 pai_waithere ;7 * ;; at best, 7 eclocks have gone by since start of start bit * ;; at worst, 15 eclocks have gone by since start of start bit * ;; and first data bit will be from eclock 20 to eclock 40 * ;; try to read in middle of bit(around eclock 30), if best 7 + 19 = 26; if worst 15 + 19 = 34 * ;; therefore 19 e clocks must pass before bits are read. * wait 19 eclocks for start bit to pass and to get into the middle of bit zero pshx ;4 pulx ;5 nop ;2 nop ;2 nop ;2 nop ;2 nop ;2 * read one bit every 10us pai_next_bit: brset 0,x 0x80 pai_sc ;7 pai_cc: clc ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne pai_next_bit ;3 brset 0,x 0x80 pai_done ;; check command bit inc variable_is_cbus_cmd+1 bra pai_done pai_sc: sec ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne pai_next_bit ;3 brset 0,x 0x80 pai_done ;; check command bit inc variable_is_cbus_cmd+1 bra pai_done pai_done: ldaa #%00010000 staa TFLG2 ;; clear pai flag clra std variable_cbus_byte cli rti ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_ignore_cbus: ldaa TMSK2 anda #%11101111 ;; disable PAI interrupt staa TMSK2 rts subroutine_listen_to_cbus: ldab #%00010000 stab TFLG2 ;; clear pai flag ldab TMSK2 orab #%00010000 ;; enable PAI interrupt stab TMSK2 rts ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_cbus_send_cmd: sei ;2 ldaa PACTL oraa #0x80 ;; set porta pin 7 to output; staa PACTL tba ; put b in a ldab #8 ldx #0x1000 * ;; line low for 100 us bclr 0,x %10000000 ;;7 ldx #31 ;3 scb_delay: * ;; 200 - 14 = 186 e clocks ;; note 6 * 31 = 186 eclocks dex ;3 bne scb_delay ;3 ldx #0x1000 ;3 * ;; start bit for 10us bset 0,x %10000000 ;7 start bit ldx #0x1000 ;3 ldx #0x1000 ;3 nop ;2 * ;; each data bit for 10us scb_bit_loop: rora ;2 bcs scb_bs ;3 scb_bc: bclr 0,x %10000000 ;7 ldx #0x1000 ;3 decb ;2 bne scb_bit_loop ;3 bra scb_byte_done ;3 scb_bs: bset 0,x %10000000 ;7 ldx #0x1000 ;3 decb ;2 bne scb_bit_loop ;3 bra scb_byte_done ;3 scb_byte_done: * ;; command bit for 10us bclr 0,x %10000000 ;7 bclr 0,x %10000000 ;7 ldx #0x1000 ;3 ldx #0x1000 ;3 * ;; line goes high when done: bset 0,x %10000000 ldab PACTL andb #0x7F ;; make porta pin 7 be an input stab PACTL ldaa #%00010000 staa TFLG2 ;; clear pai flag cli rts ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_cbus_send_data: sei ;2 ldaa PACTL oraa #0x80 ;; set porta pin 7 to output; staa PACTL tba ; put b in a ldab #8 ldx #0x1000 * ;; line low for 100 us bclr 0,x %10000000 ;;7 ldx #31 ;3 sdb_delay: * ;; 200 - 14 = 186 e clocks ;; note 6 * 31 = 186 eclocks dex ;3 bne sdb_delay ;3 ldx #0x1000 ;3 * ;; start bit for 10us bset 0,x %10000000 ;7 start bit ldx #0x1000 ;3 ldx #0x1000 ;3 nop ;2 * ;; each data bit for 10us sdb_bit_loop: rora ;2 bcs sdb_bs ;3 sdb_bc: bclr 0,x %10000000 ;7 ldx #0x1000 ;3 decb ;2 bne sdb_bit_loop ;3 bra sdb_byte_done ;3 sdb_bs: bset 0,x %10000000 ;7 ldx #0x1000 ;3 decb ;2 bne sdb_bit_loop ;3 bra sdb_byte_done ;3 sdb_byte_done: * ;; data bit for 10us bset 0,x %10000000 ;7 bset 0,x %10000000 ;7 ldx #0x1000 ;3 ldx #0x1000 ;3 * ;; line goes high when done: bset 0,x %10000000 ldab PACTL andb #0x7F ;; make porta pin 7 be an input stab PACTL ldaa #%00010000 staa TFLG2 ;; clear pai flag cli rts ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ** ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; subroutine_read_cbus: * ;; set port a pin 7 to input (HB digital in 9 = port a pin 7) sei ;2 clrb ldaa #8 ldx #0x1000 clr variable_is_cbus_cmd clr variable_is_cbus_cmd+1 * wait for bus signal to go low: DEBUG MODE rb_waithere1: brset 0,x 0x80 rb_waithere1 * wait for begining of start bit rb_waithere2: brclr 0,x 0x80 rb_waithere2 * wait 19 eclocks for start bit to pass and to get into the middle of bit zero pshx ;4 pulx ;5 nop ;2 nop ;2 nop ;2 nop ;2 nop ;2 * read one bit every 10us rb_next_bit: brset 0,x 0x80 rb_sc ;7 rb_cc: clc ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne rb_next_bit ;3 brset 0,x 0x80 rb_done ;; check command bit inc variable_is_cbus_cmd+1 bra rb_done rb_sc: sec ;2 rorb ;2 nop ;2 nop ;2 deca ;2 bne rb_next_bit ;3 brset 0,x 0x80 rb_done ;; check command bit inc variable_is_cbus_cmd+1 bra rb_done rb_done: ldaa #%00010000 staa TFLG2 ;; clear pai flag clra cli rts