* ****************************************************************** * By Andrew Chanler - FALL 2003 * Handyboard driver for using Devantech Magnetic Compass - CMPS03 * refer to http://www.cs.uml.edu/~achanler/robotics/ * ****************************************************************** * March 2005 * I modified the code to work on TIC2 which is connected to port 8 * 6811 registers ADCTL equ $1030 ; A/D Control/status Register ADR1 equ $1031 ; A/D Result Register 1 TCTL2 equ $1021 TFLG1 equ $1023 TMSK1 equ $1022 TCNT equ $100e org MAIN_START variable_start_time FDB 00 variable_compass_wrap FDB 00 * take analog reading with interrupts disabled subroutine_compass_driver: * turn off interrupts * sei clra clrb std variable_compass_wrap * Disable input capture interrupt on TIC2 * bit_clear(TMSK1, 0b00000010); ldaa TMSK1 anda #%11111101 staa TMSK1 * Disable input capture recording on TIC2 * bit_clear(TCTL2, 0b00001100); ldaa TCTL2 anda #%11110011 staa TCTL2 * Clear past input capture on TIC2 * poke(TFLG1, 0b00000010); ldaa #%00000010 staa TFLG1 * Enable rising edge input capture recording on TIC2 * bit_set(TCTL2, 0b00000100); ldaa TCTL2 ora #%00000100 staa TCTL2 cloop: ldaa TFLG1 anda #%00000010 beq cloop ldd 0x1012;TIC2 std variable_start_time sei * Disable input capture recording on TIC2 * bit_clear(TCTL2, 0b00001100); ldaa TCTL2 anda #%11110011 staa TCTL2 * Clear past input capture on TIC2 * poke(TFLG1, 0b00000010); ldaa #%00000010 staa TFLG1 * Enable falling edge input capture recording on TIC2 * bit_set(TCTL2, 0b00001000); ldaa TCTL2 ora #%00001000 staa TCTL2 wait: ldd TCNT ldab variable_start_time cba beq wait cloop2: ldd TCNT ldab variable_start_time cba bne no_wrap ldaa #1 staa variable_compass_wrap+1 no_wrap: ldaa TFLG1 anda #%00000010 beq cloop2 * Disable input capture recording on TIC2 * bit_clear(TCTL2, 0b00001100); ldaa TCTL2 anda #%11110011 staa TCTL2 cli ldd 0x1012;TIC2 subd variable_start_time rts ; d contains timer start value