⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iic_os2.asm

📁 i2c to os/2
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;        continue with program
;
;EXAMPLE using subdirective 'call_'
;++++++++++++++++++++++++++++++++++
;The 'call_' subdirective can be used with any of the four options outlined
;above.  The 'call_' subdirective is ORed with the memory space directive
;(the second byte of any command block).
;
;PROGRAM:
;        MOV    DPTR,#Option1_file_with_call
;        CALL   DO_IIC
;        JBC    IIC_failure,PROGRAM
;               .
;               .
;               .
;
;       ;
;       ;This example has 5 bytes read from 'slave1' and placed into DATA
;       ;space 'd_iic_data'.  A subroutine is then called to sum the 5 bytes
;       ;and the result is placed into 'd_iic_data'.  The second block writes
;       ;the sum to 'slave2'.
;       ;
;Option1_file_with_call:
;        DB      slave1_address OR iic_read_mask_   ;slave1 address + read bit
;        DB      ioD_ OR call_              ;indicate DATA target + subroutine
;        DB      5                                   ;indicate number of bytes
;        DB      d_iic_data       ;address of data (DATA are 1 byte addresses)
;        DB      LOW(Option1_sub)                       ;address of subroutine
;        DB      HIGH(Option1_sub)
;
;        DB      slave2_address OR iic_write_mask_ ;slave2 address + write bit
;        DB      ioD_                                    ;indicate DATA target
;        DB      1                                   ;indicate number of bytes
;        DB      d_iic_data                                   ;address of data
;
;        DB      iic_end_                                  ;end of iic session
;
;       ;
;       ;Subroutine sums five bytes read in from 'slave1'.
;       ;
;Option1_sub:
;        MOV    R0,#d_iic_data
;        MOV    R1,#5
;        CLR    C
;        CLR    A
;Op1_10:
;        ADDC   A,@R0
;        INC    R0
;        DJNZ   R1,Op1_10
;        MOV    d_iic_data,A
;        RET
;
;EXAMPLE using alternate address option 'use_aux_adrs_'
;++++++++++++++++++++++++++++++++++++++++++++++++++++++
;The alternative address option is used to tell "IIC_OS2" to get the slave
;address from the register 'aux_adrs'.  This is useful for writing generic
;Command File Blocks to deal with a family of IIC peripherals like I/O
;expandors, RAMs etc.
;
;In the following example, one implementation of a generic command file
;to read and write to PCF8570 RAMs is shown.  To use these generic command
;files, the user loads the address of the PCF8570 into 'aux_adrs' and the
;address of the byte in the RAM into 'IIC_data_buffer', then calls the
;command file "Read_RAM".  To write to RAM, repeat the same as above, and
;load the data to be sent into 'IIC_data_buffer + 1'.
;
;
;PROGRAM:
;        MOV    aux_adrs,#(PCF8570_1_adrs OR iic_write_mask_)   ;slave address
;        MOV    IIC_data_buffer,#12                ;address of target location
;        MOV    DPTR,#Read_RAM                  ;generic RAM read command file
;        CALL   DO_IIC
;        JBC    IIC_failure,PROGRAM
;
;        MOV    aux_adrs,#(PCF8570_2_adrs OR iic_read_mask_)   ;slave address
;        MOV    IIC_data_buffer,#36                ;address of target location
;        MOV    IIC_data_buffer+1,#7                             ;data to send
;        MOV    DPTR,#Write_RAM
;        CALL   DO_IIC
;        JBC    IIC_failure,PROGRAM
;
;               .
;               .
;               .
;       ;
;       ;
;       ;"Read_RAM" is a generic read PCF8570 command file.  It expects the
;       ;slave address of the PCF8570 to be loaded into 'aux_adrs'; the
;       ;address of the byte to read should be in 'IIC_data_buffer'.  The
;       ;byte read will be placed in 'IIC_data_buffer'.
;       ;
;       ;"Write_RAM" is a generic write PCF8570 command file.  It expects the
;       ;slave address of the PCF8570 to be loaded into 'aux_adrs'; the
;       ;address of the byte to read should be in 'IIC_data_buffer'; the data
;       ;to be sent should be loaded into 'IIC_data_buffer + 1'.
;       ;
;Read_RAM:
;        DB      use_aux_adrs_  ;slave address + R/W bit resides in 'aux_adrs'
;        DB      ioBuffer_ OR call_;indicate 'IIC_data_buffer' target and call
;        DB      1                                   ;indicate number of bytes
;        DB      LOW(reverse_RW)
;        DB      HIGH(reverse_RW)
;
;        DB      use_aux_adrs_  ;slave address + R/W bit resides in 'aux_adrs'
;        DB      ioBuffer_                  ;indicate 'IIC_data_buffer' target
;        DB      1                                            ;number of bytes
;
;        DB      iic_end_                                  ;end of iic session
;       =================================
;       The "reverse_RW" subroutine changes the read/write sense of the
;       'aux_adrs' contents.  This subroutine is called by the first block of
;       'Read_RAM' to change the write bit to a read bit.  The first block is
;       required to set the internal address pointer of the PCF8570 to the
;       desired value (as set by the user in 'IIC_data_buffer' by calling
;       routine "PROGRAM").
;
;reverse_RW:
;        XRL     aux_adrs,#00000001B
;        RET
;
;Write_RAM:
;        DB      use_aux_adrs_  ;slave address + R/W bit resides in 'aux_adrs'
;        DB      ioBuffer_                  ;indicate 'IIC_data_buffer' target
;        DB      2                                   ;indicate number of bytes
;
;        DB      iic_end_                                  ;end of iic session
;
;
;SYSTEM REQUIREMENTS:
;********************
;Data Bytes Used:  16
;Bit Addressable Bytes Used: 1
;Stack Penetration:  Approximately 17 bytes worst case
;Code Length:  Approximately 650 bytes of code.
;
;"IIC_OS2" register definitions:
;*******************************
;The following data bytes are required to run the full implementation of the
;IIC driver system.  In a microcontroller as large as the 80C552 or
;80C652, the requirement of these data bytes will not impose a great toll
;on the user's system.  Note that registers, bytes, equates and bit names are
;surrounded by ' ' in the description - routines, subroutines and procedure
;names are surrounded by " ".
;
;------------
;'IIC_status'
;
;LOADED BY: "DO_IIC" and "IIC_VECTOR"
;DESCRIPTION - holds the status of the requested IIC operations.  This data
;byte is loaded with 'status_DO_IIC' by "DO_IIC", which then
;monitors this byte, and determines if the IIC command file has been
;completed.  Completion of the IIC command file is known if the 'IIC_status'
;is equal to one of the following in it's lower nibble:
;
;  'status_OK_'                - operation complete, no problems
;  'status_arb_lost_'          - arbitration lost to another master
;  'status_attempt_data_'      - tried to send data 'max_data_attempts_' times
;  'status_attempt_adrs_'      - tried to find slave 'max_adrs_attempt_' times
;  'status_timeout_'           - waited 'max_wait_' time for activity
;  'status_buss_err_'          - a buss error (illegal start/stop)
;
;The upper nibble of the 'IIC_status' will be one of the following:
;
;  'status_master_'            - started&ended as a master
;  'status_slave_'             - addressed as slave (own address)
;  'status_arb_lost_slave_r_'  - arbitration lost to another master, this one
;                                addressed as a slave to be read from
;  'status_arb_lost_slave_w_'  - arbitration lost to another master, this one
;                                addressed as a slave to be written to
;  'status_general_slave_'     - addressed as slave (general call)
;  'status_arb_lost_general_'  - arbitration lost to a general call
;
;The upper nibble is useful since one could have called the IIC routine
;intending to be a master transmitter/receiver, but could be changed to a
;slave in mid-stream.  This information may be useful in some applications.
;
;The values 'max_data_attempts_', 'max_adrs_attempts_' and 'max_wait_' are
;equated in the main body below - these numbers define how many attempts
;should be made to send/receive data, locate a slave or wait for a response.
;
;------------------
;'IIC_final_status'
;
;This byte holds a copy of the 'IIC_status' at the end of the command file
;execution.  The calling routine should interrogate this byte if an
;'IIC_failure' is detected.
;
;
;----------------
;'IO_buffer_adrs'
;
;LOADED BY: "IIC_OS2"
;DESCRIPTION:  is loaded by the "IIC_OS2" operation and holds the address
;of the data to be trasmitted to a slave, or received from a slave.  The bit-
;addressable register 'Data?adrs?space' determines which memory space the
;'IO_buffer_adrs' targets.  The initial value for this register can come from
;the command file itself, or may be loaded from the 'indirect_adrs' register,
;depending on the actions directed from the 'Data?adrs?space' register.
;
;-----------------------
;'IIC_Command_File_adrs'
;
;LOADED BY: "DO_IIC" from the DPTR of the calling routine
;            manipulated by "IIC_OS2"
;DESCRIPTION: the calling routine loads the address of the command file to be
;executed by the "IIC_OS2" into the DPTR.  "DO_IIC" loads the DPTR into this
;register.  The "IIC_OS2" will modify this address register as the "IIC_OS2"
;operations proceed. If the command file resides in the DATA space, then only
;the LSByte of the address is used.
;
;----------------
;'indirect_adrs'
;'indirect_count'
;
;LOADED BY: calling routine or a command file called subroutine
;DESCRIPTION: the calling routine may use the 'indirect_' option as
;loaded in the 'Data?adrs?space' byte.  This option directs the "IIC_OS2"
;to get the 'IO_buffer_adrs' and the 'Multiple_count' from the calling routine
;(or called subroutine) loaded 'indirect_adrs' and 'indirect_count' registers.
;Both 'indirect_ registers are preserved.
;
;----------------
;'Multiple_count'
;
;LOADED BY: "IIC_OS2"
;DESCRIPTION: this register is a counter for the number of bytes to be
;received or transmitted. Received or transmitted bytes are sent to or read
;from the address space indicated in 'Data?adrs?space' and addressed by
;the 'IO_buffer_adrs'.  The initial value for this register can come from
;the command file itself, or may be loaded from the 'indirect_count' register,
;depending on the actions directed from the 'Data?adrs?space' register.  If
;this register is loaded with 0, the routines interpret this as 255 bytes.
;
;---------------
;'Attempt_count'
;
;LOADED BY: "IIC_OS2"
;DESCRIPTION: counts the number of failed attempts at sending/receiving data
;or addressing a slave.  If the number of tries in either case excedes
;'max_adrs_attempts_' or 'max_data_attempts_', the error status is reflected
;in 'IIC_status' and the "IIC_OS2" quits.
;
;-----------
;'last_data'
;
;LOADED BY: "IIC_OS2"
;DESCRIPTION: holds the value of the last data byte received or transmitted.
;Used in "IIC_OS2" as a look-back register so failed transmissions can be
;repeated.
;
;-----------
;'iic_timer'
;
;LOADED BY: "IIC_OS2"
;DESCRIPTION: used as a watchdog timer for the IIC operation.  Implemented as
;a up-counter in "DO_IIC", but ideally, this function should be in the
;hands of a real system timer.
;
;----------------------
;'Slave_in & Slave_out'
;
;LOADED BY: mainline routine
;DESCRIPTION: Buffers for Slave receiver and Transmitter modes.  Main routine
;loads 'Slave_out' with the 'SLVbytes_out_' number of bytes to be transmitted
;once addressed by another master.  'Slave_in' is filled by the 'SLVbytes_in_'
;number of bytes from another master.  If more or less bytes are to be received
;or sent when addressed as a slave, then the size of the buffers and the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -