?? i2c_eepr.asm
字號:
st7/ ; The first line is reserved
; for specifying the instruction set
; of the targetted processor
;+------------------------------------------------------------------------------+
;| |
;| I2C COMMUNICATION BETWEEN ST7 AND M24Cxx EEPROM |
;| |
;| Copyright (c), STMicroelectronics |
;| |
;+------------------------------------------------------------------------------+
;| The present source code which is for guidance only aims at providing |
;| customers with information regarding their products in order for them to save|
;| time. As a result, STMcroelectronics shall not be held liable for any direct,|
;| indirect or consequential damages with respect to any claims arising from the|
;| content of such a source code and/or the use made by customers of the |
;| information contained herein in connexion with their products. |
;+------------------------------------------------------------------------------+
;| |
;| File: i2c_eepr.asm |
;| |
;+----------------------+-----------------------+-------------------------------+
;| DATE | VERSION | HISTORY/CHANGES |
;| (MM/DD/YY) | VX.Y | |
;+----------------------+-----------------------+-------------------------------+
;| 01/03/02 | 2.0 | ST72251 ----> ST72264 |
;+----------------------+-----------------------+-------------------------------+
;|SOFTWARE DESCRIPTION: |
;|ST7 I2C single master peripheral software driver for a commmunication |
;|between an ST7 and an ST24C08 EEPROM. |
;|Polling software strategy without error management. |
;| |
;|PIN ALLOCATION: |
;| All I2C pins: SDA, SCL |
;+------------------------------------------------------------------------------+
TITLE "i2c_eepr.ASM"
; This title will appear on each
; page of the listing file
MOTOROLA ; This directive forces the Motorola
; format for the assembly (default)
;+------------------------------------------------------------------------------+
;| FILES INCLUSION |
;+------------------------------------------------------------------------------+
#INCLUDE "st72264.inc" ; Include st72264 registers and
; Memory mapping file
;+------------------------------------------------------------------------------+
;| MACRO DEFINITION |
;+------------------------------------------------------------------------------+
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2CCCR POSSIBLE SPEEDS |
;| |
;+------------------------------------------------------------------------------+
#DEFINE I2C_SPEED $26 ; 100.00 KHz
; #DEFINE I2C_SPEED $37 ; 70.00 KHz
; #DEFINE I2C_SPEED $4E ; 50.00 KHz
; #DEFINE I2C_SPEED $9E ; 25.00 KHz
; #DEFINE I2C_SPEED $EC ; 15.75 KHz
; #DEFINE I2C_SPEED $86 ; 333.00 KHz
; #DEFINE I2C_SPEED $8C ; 190.00 KHz
; #DEFINE I2C_SPEED $8E ; 167.00 KHz
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2CCR BIT DEFINITIONS |
;| |
;+------------------------------------------------------------------------------+
#DEFINE PE 5 ; Peripheral enable
#DEFINE ENGC 4 ; Enable general call
#DEFINE START 3 ; Start condition generation
#DEFINE ACK 2 ; Acknoledge level
#DEFINE STOP 1 ; Stop condition generation
#DEFINE ITE 0 ; Interrupt enable
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2CSR1 BIT DEFINITIONS |
;| |
;+------------------------------------------------------------------------------+
#DEFINE SR2F 7 ; Status register 2 flag
#DEFINE ADD10 6 ; 10bit master addressing mode
#DEFINE TRA 5 ; Transmitter / receiver
#DEFINE BUSY 4 ; Bus busy (between start and stop)
#DEFINE BTF 3 ; Byte transfer finished
#DEFINE ADSL 2 ; Addressed as slave
#DEFINE MSL 1 ; Master / slave
#DEFINE SB 0 ; Start bit generated (master mode)
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2CSR2 BIT DEFINITIONS |
;| |
;+------------------------------------------------------------------------------+
#DEFINE AF 4 ; Acknowledge failure
#DEFINE STOPF 3 ; Stop detection flag (slave mode)
#DEFINE ARLO 2 ; Arbitration lost
#DEFINE BERR 1 ; Bus error
#DEFINE GCAL 0 ; General call (slave mode)
;********************************************************************************
;+------------------------------------------------------------------------------+
;| DEFINES INCLUSION |
;+------------------------------------------------------------------------------+
#DEFINE CR_INIT_VALUE $24 ; I2C register initial values
; Control register: I2CCR
; --- --- PE ENGC START ACK STOP ITE
; 0 0 1 0 0 1 0 0
;+------------------------------------------------------------------------------+
;| RAM SEGMENT |
;+------------------------------------------------------------------------------+
BYTES ; Following addresses are 8 bit length
segment byte at 80-FF 'ram0'
.buff_in DS.B 8 ; Input buffer to read the EEPROM
.buff_out DS.B 8 ; Output buffer to write the EEPROM
;+------------------------------------------------------------------------------+
;| MAIN SECTION |
;+------------------------------------------------------------------------------+
WORDS ; Define subsequent addresses as words
segment 'rom'
.buff_data DC.B 0,1,2,3,4,5,6,7 ; Constant data value buffer
.main
ld X,#7 ; Input buffer initialization
.Inibuf clr (buff_in,X)
dec X
jrpl Inibuf
ld X,#7 ; Copy Constant data buffer in buff_out
.Cpybuf ld A,(buff_data,X)
ld (buff_out,X),A
dec X
jrpl Cpybuf
call I2Cm_Init ; Init I2C peripheral
; Write data from buff_out to the EEPROM
ld A,#$A0 ; EEPROM address parameter setting
ld X,#8 ; Number of byte to write in the EEPROM
ld Y,#$50 ; EEPROM internal data address
call I2Cm_Tx ; IN: Y=sub_add,X=nb,A=dest_add/OUT:None
clr A ; Waiting loop
.Wtloop jreq Wtloop ; To exit from this loop: break point and
; set A<>0: first, click on the Z flag;
; then change A value directly in the
; register (don't forget to press enter)
; Read data from the EE to the buff_in
ld A,#$A0 ; EEPROM address parameter setting
ld X,#8 ; Number of byte to write in the EEPROM
ld Y,#$50 ; EEPROM internal data address
call I2Cm_Rx ; IN: Y=sub_add,X=nb,A=dest_add/OUT:None
.end jra end ; Infinity main loop.
;+------------------------------------------------------------------------------+
;| SUB-ROUTINES SECTION |
;+------------------------------------------------------------------------------+
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2C INITIALISATION |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| I2C peripheral initialisation routine |
;| |
;|INPUT PARAMETERS: |
;| None |
;| |
;|INTERNAL PARAMETERS: |
;| A (Accumulator), CR_INIT_VALUE |
;| |
;|OUTPUT PARAMETERS: |
;| None |
;+------------------------------------------------------------------------------+
.I2Cm_Init
clr I2CCR ; Force reset status of the CR
ld A,#I2C_SPEED ; Set the selected I2C-bus speed
ld I2CCCR,A
tnz I2CDR ; Touch registers to remove pending its
tnz I2CSR1
tnz I2CSR2
ld A,#CR_INIT_VALUE ; Set initial control register value
ld I2CCR,A
ld I2CCR,A ; Write 2 times: PE=1 then other flag
; settings
ret
;********************************************************************************
;********************************************************************************
;+------------------------------------------------------------------------------+
;| |
;| I2C START ROUTINE |
;| |
;+------------------------------------------------------------------------------+
;|ROUTINE DESCRIPTION: |
;| This routine generates the I2C-Bus Start Condition |
;| |
;|INPUT PARAMETERS: |
;| None |
;| |
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -