********************************************************** * IRTester.asm * Frank Rudzicz Feb27, 2001 * * Short 68HC11 assembler to test and calibrate the * Sharp GP2D02 Digital IR sensor ********************************************************** *************************MAIN***************************** ORG $b600 ; use $F800 for an 'E2 bsr Initialize ; branch to subroutine ldaa #$ff ; fill accumulator a with all 1s (load a) staa $1007 ; set port C to be output, (store accumulator a) Top: bsr ReadDist stab $1003 ; ldx #$2000 ; Need for delay of IR timing. Delay dex ; decrement register x by 1 bne Delay ; branch if not zero jmp $b600 * END MAIN * *************************INITIALIZE***************************** Initialize: pshx ; push register x ldx #$1000 ; load x with $1000 (absolute) bset $26,x %10000000 ; Set PA7 as output bset 0,x %10000000 ; Set high pulx ; 'pop' x rts ; return from subroutine * END INITIALIZE * *************************READDIST***************************** ReadDist: pshx psha ldx #$1000 bclr 0,x %10000000 ; clear bits, w/mask Wait: brclr 0,x %00001000 Wait ; wait for IR input sei ; disable interrupts for timing clrb ; set register b to 0 bsr Get_Bit bsr Get_Bit bsr Get_Bit bsr Get_Bit bsr Get_Bit bsr Get_Bit bsr Get_Bit bsr Get_Bit bset 0,x %10000000 cmpb #$50 ; compare with b -> minimum good value bpl Good_Value ; branch if plus ldab #$00 ; too far, load 0 in b Good_Value: pula pulx cli ;clear interrupt mask rts * END READDIST * *************************GET_BIT***************************** Get_Bit: bset 0,x %10000000 ; hit 'em high bclr 0,x %10000000 ; hit 'em low nop ; no operation (delay for stabilization of data) nop ; add or remove as necssry nop nop ldaa 0,x ; load our data in A2 lsra ; logical shift right, data now in A1 lsra ; now it's in A0 lsra ; value from A2 is now in C rolb ; roll into B rts * END GET_BIT