历史上的今天
今天是:2024年12月11日(星期三)
2019年12月11日 | PIC单片机的IIC接口程序
2019-12-11 来源:elecfans
PIC单片机的IIC接口程序
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 trueAddrSendFail 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 1TxmtNextBit: 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 returnTxmtErrorAck bsf STATUS,RP0 ; select page 1 bsf _SDA ; tristate SDA bsf _SCL ; tristate SCL bcf Txmt_Progress ; reset progress bit in Bus Status bcf Txmt_Success ; Transmission NOT successful bsf ACK_Error ; No ACK From Slave return
史海拾趣
|
各位老大,最近我刚开始研究6410的板子,手头上现有三星6410 PM 090416的BSP包,Nandflash型号是K9GAG08U0M 2G,用PM的包现在可以采用iRom方式从SD卡启动,但下载stepldr和Eboot不能从Nandflash启动,有谁知道都会有什么原因导致出现这个情况,我曾 ...… 查看全部问答> |
|
sqlce能在设备上直接创建和编辑数据库、或者sdf文件么?像access和sql server企业管理器一样的编辑数据库。如果行的话,应该怎么做?不行的话,能给我发一下创建数据库的代码么?谢谢!!!!… 查看全部问答> |
|
no input node cannot be assigned to input pin,我已有输入node不知道为什么会这么提示,还请各位大侠提示一下,谢谢… 查看全部问答> |
|
u-boot_smdkv210 分析三:启动代码lowlevel.s分析 u-boot_smdkv210 分析三:启动代码lowlevel.s分析_TEXT_BASE: .word TEXT_BASE .globl lowlevel_init lowlevel_init: push {lr} &n ...… 查看全部问答> |
|
对ADI的产品还算是比较了解的,之前用过他的DDS类的芯片,这个感觉不错,另外就是用过AD,DA,以及一个很快的比较器ADCMP600系列的,刚才太阳能伏光里面提到的有AD7606那个多通道的数模转换也很给力,ADI的前景很大,真的,就是芯片贵了点,另外指标 ...… 查看全部问答> |
|
各位大牛,最近硬件课设要做一个类似于名侦探柯南里的变声蝴蝶结的东西,就是把输入的声音fft变为频域上的,在频域上搬移后再放出去,计划用msp430f5529来做,但听老师说这个计算量偏大,估计很难实现,就算实现了也不实用。他给我的建议是用音频co ...… 查看全部问答> |




