*------------------------------------------------------------------------------ * * magnetometer.asm is the control program for the 68HC11 based magnetometer * circuitry for adapting an FGM-3h flux gate magnetometer to a serial line * interface. * * 01-DEC-2002, B. Ulmann fecit * *------------------------------------------------------------------------------ * The 68HC11 ports are mapped as follows to the surrounding electronics: * * PORT E: Input port for reading the values of the TTL-counter chips * PORT C: Input Port for reading the setting of the scan rate switch * PORT B: Output port for controlling the TTL circuitry * 0: RD0 Select LSB chip for reading * 1: RD1 Select next chip for reading * 2: RD2 Select MSB chip for reading * 3: STORE Copy counter to TTL register * 4: Activity LED Control front panel LED * 5: CLEAR Clear counter * * All of these control signals are active high. Note that setting two * RDx outputs to 0 simultaneously will damage the TTL circuitry! *------------------------------------------------------------------------------ PORT_A EQU $1000 ; First port, so use this as base address PORT_B EQU $4 ; Control outputs for TTL counter, etc. PORT_C EQU $3 ; Input port for scan rate select switch PORT_E EQU $A ; Input port for TTL counter BAUD EQU $2B ; serial baud register SCCR1 EQU $2C ; serial control register 1 SCCR2 EQU $2D ; serial control register 2 SCSR EQU $2E ; serial status register SCDR EQU $2F ; serial tx/rx data register TDRE EQU $80 ; Transmit Data Register Empty bit pattern *------------------------------------------------------------------------------ * Now it's time to start *------------------------------------------------------------------------------ ORG $B600 ; EEPROM resident program image * * Setup registers and ports * LDS #$00C3 ; Set up stack LDX #PORT_A ; Set base register CLR PORT_B,X ; Clear all PORT_B lines LDAA #$00100000 ; Set CLEAR control line STAA PORT_B,X ; Make change active CLR PORT_B,X ; And switch the line off again * * Initialise serial line interface to 9600, 8N1 * CLR SCCR1,X LDD #$300C STAA BAUD,X STAB SCCR2,X *------------------------------------------------------------------------------ * The main program starts here :-) *------------------------------------------------------------------------------ MAIN * * Now wait an appropiate amount of time as specified by the scan rate switch, * switch the activity LED off before waiting, and on after the DELAY call * returns. While doing this, toggle the STORE control line to copy the contents * of the TTL counter chips into the output buffers and clear the counters. * CLR PORT_B,X ; Set all control lines to off BSR DELAY ; Wait 100ms/1s/10s/100s, whatever is desired * JSR NIBOUT ; Write setting to serial line LDAA #$20 ; Write a blank JSR BYTOUT ; to the serial line * LDAA #%00011000 ; Set activity LED and STORE control lines STAA PORT_B,X ; and write this bit pattern to PORT_B LDAA #%00010000 ; Reset STORE control line STAA PORT_B,X LDAA #%00110000 ; Set CLEAR line STAA PORT_B,X ; and write this patter to PORT_B, too LDAA #%00010000 ; Reset CLEAR line STAA PORT_B,X ; Make change active * * Now it is time to read out the TTL counter chips successively * LDAA #%00010100 ; Set RD2 STAA PORT_B,X ; Write new bit pattern to PORT_B NOP LDAA PORT_E,X ; Get counter value from MSB chip BSR HEXOUT ; Write value as hex value to serial line * LDAA #%00010010 ; Set RD1 STAA PORT_B,X ; Write new bit pattern to PORT_B NOP LDAA PORT_E,X ; Get counter value from chip in the middle BSR HEXOUT ; Write value as hex value to the serial line * LDAA #%00010001 ; Set RD0 STAA PORT_B,X ; Write new bit pattern to PORT_B NOP LDAA PORT_E,X ; Get counter value from LSB chip BSR HEXOUT ; Write value as hex value to the serial line * LDAA #%00010000 ; Clear RD0 STAA PORT_B,X * LDAA #$0D ; Write a CR/LF to the serial line BSR BYTOUT LDAA #$0A BSR BYTOUT BRA MAIN ; Redo from start :-) *------------------------------------------------------------------------------ * DELAY waits an amount of time which is determined by the setting of the * scan rate select switch *------------------------------------------------------------------------------ DELAY PSHX ; Save port base address register LDAA PORT_C,X ; Get switch setting ANDA #$0F ; Only the four lower bits are used CMPA #$07 ; 100s selected? BNE DNEXT1 ; No LDX #$60000 ; Prepare first wait call BSR MSDELAY ; Now wait LDX #$48678 ; Prepare second wait call BSR MSDELAY ; Wait the remaining portion of time LDAA #$3 ; Save switch setting for later output PULX ; Restore port base address register RTS DNEXT1 CMPA #$0B ; 10s selected? BNE DNEXT2 ; No LDX #9994 ; Prepare to wait 9990ms BSR MSDELAY ; OK, wait LDAA #$2 ; Save switch setting for later output PULX ; Restore port base address register RTS DNEXT2 CMPA #$0D ; 1s selected? BNE DNEXT3 ; No LDX #992 ; Prepare to wait ca. 990ms BSR MSDELAY ; Start the delay routine LDAA #$1 ; Save switch setting for later output PULX ; Restore port base address register RTS DNEXT3 LDX #92 ; Wait ca. 90 ms since main takes about 10ms BSR MSDELAY ; Falling through is not an option :-) CLRA ; Save switch setting for later output PULX ; Restore port base address register RTS *------------------------------------------------------------------------------ * The routine MSDELAY is stolen from Pascal Niklaus and Lukas Zimmermann, * Institute of Botany, University of Basel/Switzerland. :-) The content of * X determines the number of ms, this routine will need to complete. *------------------------------------------------------------------------------ MSDELAY LDAA #196 NOP NOP BRN DLY1 BRA DLY4 DLY1 LDAA #199 DLY4 NOP DLY2 NOP BRN DLY1 DECA BNE DLY2 DEX BNE DLY1 RTS *------------------------------------------------------------------------------ * HEXOUT writes the value of the byte stored in accumulator as two character * hex value to the serial line *------------------------------------------------------------------------------ HEXOUT PSHA ; Save byte for processing of the second nibble LSRA ; Get upper nibble LSRA LSRA LSRA BSR NIBOUT ; Write upper nibble to the serial line PULA ; Restore original value BSR NIBOUT ; Write lower nibble to the serial line RTS *------------------------------------------------------------------------------ * NIBOUT writes a hex nibble as ASCII character to the serial line *------------------------------------------------------------------------------ NIBOUT ANDA #$0F ; Use only the lower four bits CMPA #$09 ; Digit or letter? BGT NIBLTR ; Letter ADDA #$30 ; Add ASCII offset to '0' BRA NIB1 ; Continue output operation NIBLTR ADDA #$37 ; ASCII offset to 'A' NIB1 BSR BYTOUT ; Write byte contained in A to the serial line RTS *------------------------------------------------------------------------------ * BYTOUT writes the byte contained in accumulator A to the serial line *------------------------------------------------------------------------------ BYTOUT BRCLR SCSR,X TDRE BYTOUT; Loop until transmit register is empty STAA SCDR,X ; Output the byte RTS