*------------------------------------------------------------------------------ * * adconverter.asm is the control program for the 68HC11A1 and ADS7807 based * 8 channel, 16 bit analog digital converter for seismic applications. * * 14-APR-2003, B. Ulmann fecit * *------------------------------------------------------------------------------ * The 68HC11 ports are mapped as follows to the surrounding electronics: * * PORT_E: Input port for reading the 8 bit output of the ADS7807. * PORT_C: Input port: * 0: Scan rate switch position 1 * 1: Scan rate switch position 2 * 2: Scan rate switch position 3 * 3: Scan rate switch position 4 * 4: External trigger input, TRIG_IN * 5: /BUSY from the ADS7807 * PORT_B: Output port for controlling the surrounding circuitry: * 0: READ,/CONVERT control line to the ADS7807 * 1: BYTE control line to the ADS7807 * 2: SAMPLE_LED * 3: TRIG_OUT * 4: MUX_ADDR_0 * 5: MUX_ADDR_1 * 6: MUX_ADDR_2 *------------------------------------------------------------------------------ PORT_A EQU $1000 ; Base address of port a register PORT_B EQU $4 ; Relative position of port b register PORT_C EQU $3 PORT_E EQU $A BAUD EQU $2B SCCR1 EQU $2C SCCR2 EQU $2D SCSR EQU $2E SCDR EQU $2F TDRE EQU $80 BUSY EQU $20 ; Bit position of ADS 7807 /BUSY line TRIG EQU $10 ; Bit position of external trigger input SCAN0 EQU $1 ; Bit positions of the scan rate select switch SCAN1 EQU $2 SCAN2 EQU $4 SCAN3 EQU $8 * ORG $B600 * * Setup registers * LDS #$00C3 ; Set up stack LDX #PORT_A ; Set base register * * Initialize serial line interface to 9600, 8N1 * CLR SCCR1,X LDD #$300C STAA BAUD,X STAB SCCR2,X *------------------------------------------------------------------------------ * Main program *------------------------------------------------------------------------------ MAIN LDAA #%00001101 ; TOUT low, SAMPLE_LED on STAA PORT_B,X LDAA #%00000000 ; Read channel 0 BSR GETVAL ; Read value and output four hex nibbles LDAA #%00010000 ; Read channel 1 BSR GETVAL LDAA #%00100000 ; Read channel 2 BSR GETVAL LDAA #%00110000 ; Read channel 3 BSR GETVAL LDAA #%01000000 ; Read channel 4 BSR GETVAL LDAA #%01010000 ; Read channel 5 BSR GETVAL LDAA #%01100000 ; Read channel 6 BSR GETVAL LDAA #%01110000 ; Read channel 7 BSR GETVAL * * Send CR-LF to denote the end of one complete conversion cycle * LDAB #$0D BSR BYTOUT LDAB #$0A BSR BYTOUT LDAA #%00000001 ; Switch off SAMPLE_LED, etc. STAA PORT_B,X BSR DELAY ; Wait for next conversion cycle BRA MAIN *------------------------------------------------------------------------------ * GETVAL reads one converted value from the ADS7807. It expects A to contain * the address of the analog line in bits 4..6. The value read is written to * the serial line. *------------------------------------------------------------------------------ GETVAL ORA #%00001101 ; Set MUX to selected channel STAA PORT_B,X BRN GETVAL ; Wait a moment BRN GETVAL BRN GETVAL BRN GETVAL ANDA #%11111100 ; Start conversion cycle STAA PORT_B,X ORA #%00000001 ; Switch to read mode STAA PORT_B,X BSYLOOP BRCLR PORT_C,X BUSY BSYLOOP; Loop until /BUSY is set LDAB PORT_E,X ; Get high byte of data BSR HEXOUT ; Write data to serial line ORA #%00000010 ; Set BYTE control line STAA PORT_B,X LDAB PORT_E,X ; Get low byte BSR HEXOUT ; Write data to serial line RTS *------------------------------------------------------------------------------ * HEXOUT writes the value of the byte stored in the accumulator B as two * character string to the serial line. *------------------------------------------------------------------------------ HEXOUT PSHB ; Save byte for processing of the second nibble LSRB ; Get upper nibble LSRB LSRB LSRB BSR NIBOUT PULB BSR NIBOUT RTS *------------------------------------------------------------------------------ * NIBOUT writes the LSB hex nibble of accumulator B as ASCII character to the * serial line. The entry BYTOUT write a single byte to the serial line. *------------------------------------------------------------------------------ NIBOUT ANDB #$0F ; Use only the lower four bits ADDB #$30 ; Add ASCII offset to '0' CMPB #$39 ; Digit or letter? BLE BYTOUT ; Digit ADDB #$07 ; Add remaining offset BYTOUT BRCLR SCSR,X TDRE BYTOUT; Loop until transmit register is empty STAB SCDR,X ; Write character to the serial line RTS *------------------------------------------------------------------------------ * DELAY waits an amount of time which is determined by the setting of the * sample rate select switch *------------------------------------------------------------------------------ DELAY PSHX ; Save port base address register BRSET PORT_C,X SCAN0 NOSCAN0; Position 0 not selected GODOT BRCLR PORT_C,X TRIG GODOT; Wait for external trigger going low BRA DELEND ; Continue with main program NOSCAN0 BRSET PORT_C,X SCAN1 NOSCAN1; Position 1 not selected LDX #7 BSR MSDELAY BRA DELEND NOSCAN1 BRSET PORT_C,X SCAN2 NOSCAN2; Position 2 not selected LDX #67 BSR MSDELAY BRA DELEND NOSCAN2 LDX #167 BSR MSDELAY DELEND PULX RTS *------------------------------------------------------------------------------ * The routine MSDELAY is stolen from Pascal Niklaus and Lukas Zimmermann, * Institute of Botany, Unversity of Basel/Switzerland. :-) The content of * X determines the number of ms this routine will need to complete. *------------------------------------------------------------------------------ MSDELAY PSHA LDAA #120 NOP NOP BRN DLY1 BRA DLY4 DLY1 LDAA #199 DLY4 NOP DLY2 NOP BRN DLY1 DECA BNE DLY2 DEX BNE DLY1 PULA RTS