历史上的今天
今天是:2024年10月15日(星期二)
2019年10月15日 | pic单片机的模拟I2C通信
2019-10-15 来源:eefocus
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Copyright (C) 1997 by Innovatus
; This code may be distributed and used freely provided that this
; copyright notice stays intact and that any modifications are noted.
; For more information about Innovatus: http://www.innovatus.com
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; File Name: i2c_low.asm
; Author: Alan G. Smith
; Purpose: This code is borrowed from Microchip with all of the fancy
; stuff taken out.
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
InitI2CBusMaster
;************************************************************
TxmtStartBit
bsf Bus_Busy ; on a start condition bus is busy
bsf STATUS, RP0 ; Select page 1
bsf _SDA ; set SDA high
bsf _SCL ; clock is high
call Delay40uSec ; This is necessary for setup time
bcf _SDA ; This gives a falling edge on SDA while clock is high
call Delay47uSec ; Necessary for START HOLD time
return
;************************************************************
TxmtStopBit
bsf STATUS, RP0 ; Select page 1
bcf _SCL ; clock is low
bcf _SDA ; set SDA low
bsf _SCL ; clock is pulled up
call Delay40uSec ; Setup time for STOP condition
bsf _SDA ; rising edge on SDA while CLOCK is high
call Delay47uSec ; makes sure a START isn't sent immediately after a STOP
bcf Bus_Busy ; The bus isn't busy anymore
return
;************************************************************
AbortI2C
call TxmtStopBit ; Send a stop bit
bsf Abort ; set the abort bit
return
;************************************************************
TxmtSlaveAddr
movf SlaveAddr, w ; Move slave address to W
bcf ACK_Error ; reset Acknowledge error bit
movwf I2CData ; move W to I2C Data
bcf I2CData, LSB ; Set for write
btfsc Slave_RW ; If skip then write operation
bsf I2CData, LSB ; Clear for read
call SendData ; send the address
btfss Txmt_Success ; skip if successful
goto AddrSendFail ; Oops, we failed
retlw TRUE ; return true
AddrSendFail
btfss ACK_Error ; was there an error acknowledging
retlw FALSE ; No, so return 0
call TxmtStopBit ; Address not acknowleged, so send STOP bit
retlw FALSE ; Unsuccessful, so return 0
;************************************************************
SendData
; We might should make a copy of the data here, the example does but I don't see why!!!
bsf Txmt_Progress ; We are in the middle of transmitting
bcf Txmt_Success ; reset success bit
movlw 0x08
movwf I2CBitCount ; Set I2C Bit Count to 8
bsf STATUS, RP0 ; Select page 1
TxmtNextBit:
bcf _SCL ; Set clock Low
rlf I2CData, F ; MSB First, Note that I2CData is Destroyed
bcf _SDA ; Set clock based on what the MSB is
btfsc STATUS,C ; Was the MSB a 1
bsf _SDA ; Nope set it high
call Delay47uSec ; guarantee min LOW TIME tLOW & Setup time
bsf _SCL ; set clock high
call Delay40uSec ; guarantee min HIGH TIME tHIGH
decfsz I2CBitCount, F ; are we done yet
goto TxmtNextBit ; nope, send the next bit
;
; Check For Acknowledge
;
bcf _SCL ; reset clock
bsf _SDA ; Release SDA line for Slave to pull down
call Delay47uSec ; guarantee min LOW TIME tLOW & Setup time
bsf _SCL ; clock for slave to ACK
call Delay40uSec ; guarantee min HIGH TIME tHIGH
bcf STATUS, RP0 ; Select PAGE 0 to test SDA pin
btfsc SdaPin ; SDA should be pulled low by slave if OK
goto TxmtErrorAck ; Uh oh, slave isn't behaving (or isn't there)
bsf STATUS, RP0 ; Select PAGE 1
bcf _SCL ; reset clock
bcf Txmt_Progress ; reset progress bit in Bus Status
bsf Txmt_Success ; Transmission successful
bcf ACK_Error ; ACK OK
return
TxmtErrorAck
bsf STATUS,RP0 ; select page 1
bsf _SDA ; tristate SDA
史海拾趣
|
4-20mA 电流环路隔离器(ISO 4-20mA)低成本、小体积,两线制4-20mA电流环路隔离 IC说 明: ISO 4-20mA电流环隔离芯片是单片两线制隔离接口芯片,该IC内部包含有电流信号调制解调电路、信号耦合隔离变换电路等。很小的输入等效电阻,使该IC的输入电 ...… 查看全部问答> |
|
Unix下的一个程序,我想把它移植到Vxworks上,编译的时候系统提示 找不到 我知道这是Unix下的 头文件,如何才能在Vxworks下编译通过。… 查看全部问答> |
|
首先,我们在arm下开发wince4.2系统 我们的系统打算用键盘控制,键盘上有F1-F10功能键与0-9数字键复用, 上下左右方向键,回车键等,打算自己做键盘,用一个单片机控制键盘,用串口将键盘的键码传输到arm。功能键用来实现一些功能界面的转换,数字 ...… 查看全部问答> |
|
1.了解培训机构的师资情况。这一点对参加培训的学员来说是最重要的,每个机构都会说自己师资很好,但实际能不能在短期的培训过程中让学员学到有用的知识,虽然有个人主观学目前,关于嵌入式的培训机构多如牛毛,想学习嵌入式,我们必须要学会选择, ...… 查看全部问答> |
|
从开始搜集资料到现在,已有一段时日了,虽是断断续续在做,但最终还是有结果的了。我在这里用的是CM3微控器,就用了我手头上有的这块从eeworld申请到得stellaris 8962评估板。显示是用1602,因评估板上自带OLED屏,我就先用它作显示,它用着 ...… 查看全部问答> |
|
DSP烧录到Flash中去了,仿真可运行,拔掉仿真器,开电重启不能运行 DSP烧录到Flash中去了,仿真可运行,不掉电拔掉仿真器可运行,但是断电重启,不能运行,这时候只要把仿真器(connect)连接起来,程式运行。求解???????????????… 查看全部问答> |




