www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁 > 通信技術(shù) > 通信技術(shù)
[導(dǎo)讀] ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ; File Name: i2c_low.asm ; Author: Alan G. Smith ; Purpose: This code is borrowed from Microchip with all o

 

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;    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
   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

;************************************************************
GetData
   bsf    Rcv_Progress                   ; set Bus status for txmt progress
   bcf    Rcv_Success                    ; reset status bit
   movlw  0x08
   movwf  I2CBitCount
RcvNextBit
   bsf    STATUS, RP0                    ; page 1 for TRIS manipulation
   bcf    _SCL                           ; lower clock
   bcf    _SDA                           ; lower data line
   call   Delay47uSec                    ; guarantee min LOW TIME tLOW & setup time
   bsf    _SCL                           ; clock high, data sent by slave
   call   Delay40uSec                    ; guarantee min HIGH TIME tHIGH
   bcf    STATUS, RP0                    ; select page 0 to read Ports
   bcf    STATUS, C                      ; 0 out Status
   btfsc  SdaPin                         ; Check state of pin
   bsf    STATUS, C                      ; Pin was high, set status
   rlf    I2CData, F                     ; left Shift data (MSB first)
   decfsz I2CBitCount, F                 ; Are we done yet
   goto   RcvNextBit                     ; Nope, go get the next one
;
; Generate ACK bit if not last byte to be read,
; if last byte Gennerate NACK ; do not send ACK on last byte, main routine will send a STOP bit
;
   bsf    STATUS, RP0                    ; Page 1 for TRIS manipulation
   bcf    _SCL                           ; pull SCL low
   bcf    _SDA                           ; ACK by pulling SDA low
   btfsc  Last_Byte_Rcv                  ; Is it the last byte to receive
   bsf    _SDA                           ; If so, send NACK by setting SDA high
   call   Delay47uSec                    ; guarantee min LOW TIME tLOW & Setup time
   bsf    _SCL                           ; Raise Clock back up
   call   Delay40uSec                    ; guarantee min HIGH TIME tHIGH
RcvEnd:
   bcf    _SCL                           ; reset clock
   bcf    Rcv_Progress                   ; reset bit in Bus Status
   bsf    Rcv_Success                    ; transmission successful
   bcf    ACK_Error                      ; ACK OK
   return

Delay47uSec:
   movlw ((_47uS_Delay-5)/3 + 1)         ; move delay into W
DlyK
   movwf DelayCount                      ; move what is in W to DelayCount
   decfsz   DelayCount, F                ; Decrement DelayCount
   goto  $-1                             ; Loop until 0
   return                                ; return

Delay40uSec:
   movlw ((_40uS_Delay-8)/3 + 1)         ; move delay into W
   goto  DlyK                            ; goto DlyK loop


以下為測(cè)試程序(pic16f84)

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;                   Copyright (C) 1997 by Innovatus
;                        All Rights Reserved.
; 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.innovatu.com
s
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;    File Name: testI2C.asm
;       Author: Alan G. Smith
;      Purpose: This is testing out the I2C code.
;
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    LIST P=16f84, F=INHX8M, C=100, N=59

#include "p16f84.inc"

XTAL_FREQ       equ     10000000        ; the crystal frequency we are using
ClkOut          equ     XTAL_FREQ / 4   ; the number of cycles per second

_40uS_Delay set   (ClkOut/250000)
_47uS_Delay set   (ClkOut/212766)
_50uS_Delay set   (ClkOut/200000)

#define SclPin  PORTA, 0                ; Pin for SCL (I2C)
#define SdaPin  PORTA, 1                ; Pin for SDA (I2C)

#define _SCL    TRISA, 0                ; How do we toggle SCL
#define _SDA    TRISA, 1                ; How do we toggle SDA

#define MSB   7
#define LSB   0
#define TRUE  1
#define FALSE 0

InitTrisA       equ     0x07            ; The Initial state to TRIS port A.

#define  Bus_Busy      BusStatus,0
#define  Abort         BusStatus,1
#define  Txmt_Progress BusStatus,2
#define  Rcv_Progress  BusStatus,3
#define  Txmt_Success  BusStatus,4
#define  Rcv_Success   BusStatus,5
#define  Fatal_Error   BusStatus,6
#define  ACK_Error     BusStatus,7

#define  Slave_RW      BusControl,0
#define  Last_Byte_Rcv BusControl,1
#define  SlaveActive   BusControl,2

CBLOCK     0x0C                        ; I2C Ram needed
   BusStatus                            ; The I2C Status register
   BusControl                           ; The I2C Control register
   I2CBitCount                          ; Number of bits left to send (or receive)
   I2CData                              ; Data (note: This is DESTROYED when sending)
   SlaveAddr                            ; Slave Address
ENDC

CBLOCK
   DelayCount                           ; used to figure out precise time delays
ENDC


   org 0                                 ; Reset Vector
   goto   start                          ; Goto Start

start
   bcf    INTCON, GIE                    ; Turn off interrupts in this critical part of code!
   bcf    STATUS, RP0                    ; Select Page 0 of registers
   movlw  0x0C                           ; Make sure there are 0‘s on SCL and SDA
   movwf  PORTA                          ; We write 1‘s to TX since 0 is a start bit
   bsf    STATUS, RP0                    ; Select Page 1 of registers
   movlw  InitTrisA                      ; Load W with the value for TRIS A
   movwf  TRISA                          ; movw the value from W into TRIS A
;*************** DEBUG CODE (let us use LEDs) *******************
   clrf   TRISB
;****************************************************************
   clrf   BusStatus                      ; Let‘s clear out busStatus before we start
   clrf   BusControl                     ; Let‘s clear out busControl before we start
;*************** TEST CODE *******************
   clrf   PORTB
main
   movlw  0xB0                           ; address of EEPROM
   movwf  SlaveAddr                      ; move into SlaveAddress register
   call   IsSlaveActive                  ; Check and see if the slave is active
   movlw  0xFF                           ; move FF into w (turn all LED‘s on)
   btfss  SlaveActive                    ; If the slave is active, leave it
   movlw  0xAA                           ; We didn‘t find it, turn off half.
   bcf    STATUS, RP0                    ; Select page 0 of registers
   movwf  PORTB                          ; move W to PortB

done                                     ; Game over man!
   goto   done                           ; endless loop

IsSlaveActive
   bcf    Slave_RW                       ; set for write operation
   call   TxmtStartBit                   ; Transmit Start Bit
   call   TxmtSlaveAddr                  ; Transmit Slave Address
   bcf    SlaveActive                    ; Assume not present
   btfss  ACK_Error                      ; skip if NACK, device is not present or not responding
   bsf    SlaveActive                    ; ACK received, device present & listening
   call   TxmtStopBit
   return

#include "i2c_low.asm"

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

舍弗勒以"專注驅(qū)動(dòng)技術(shù)的科技公司"為主題亮相IAA MOBILITY 2025(B3館B40展臺(tái)) 合并緯湃科技后首次亮相IAA MOBILITY,展示拓展后的汽車產(chǎn)品組合 憑借在軟件、...

關(guān)鍵字: 電氣 軟件 驅(qū)動(dòng)技術(shù) BSP

香港2025年 9月12日 /美通社/ -- 全球領(lǐng)先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡(luò)控股有限公司 ("網(wǎng)龍"或"本公司",香港交易所股票代碼:777)欣然宣布,其子公司My...

關(guān)鍵字: AI 遠(yuǎn)程控制 控制技術(shù) BSP

深圳2025年9月11日 /美通社/ -- 2025 年 9 月 10 日,第 26 屆中國國際光電博覽會(huì)(簡稱 "CIOE 中國光博會(huì)")在深圳盛大開幕。本屆展會(huì)吸引力再創(chuàng)新高,全球超3800家優(yōu)質(zhì)...

關(guān)鍵字: 自動(dòng)化 光電 CIO BSP

天津2025年9月11日 /美通社/ -- 國際能源署(IEA)數(shù)據(jù)顯示,2024 年全球數(shù)據(jù)中心電力消耗達(dá) 415 太瓦時(shí),占全球總用電量的 1.5%,預(yù)計(jì)到 2030 年,這一數(shù)字將飆升至 945 太瓦時(shí),近乎翻番,...

關(guān)鍵字: 模型 AI 數(shù)據(jù)中心 BSP

北京2025年9月11日 /美通社/ -- 國際9月11日上午,2025年中國國際服務(wù)貿(mào)易交易會(huì)(以下簡稱"服貿(mào)會(huì)")—體育賽事經(jīng)濟(jì)高質(zhì)量發(fā)展大會(huì)現(xiàn)場,北京經(jīng)濟(jì)技術(shù)開發(fā)區(qū)工委委員、管委會(huì)副主...

關(guān)鍵字: 5G BSP GROUP MOTOR

柏林2025年9月9日 /美通社/ -- 2025年9月5日,納斯達(dá)克上市公司優(yōu)克聯(lián)集團(tuán)(NASDAQ: UCL)旗下全球互聯(lián)品牌GlocalMe,正式亮相柏林國際消費(fèi)電子展(IFA 2025),重磅推出融合企...

關(guān)鍵字: LOCAL LM BSP 移動(dòng)網(wǎng)絡(luò)

深圳2025年9月9日 /美通社/ -- PART 01活動(dòng)背景 當(dāng)技術(shù)的鋒芒刺穿行業(yè)壁壘,萬物互聯(lián)的生態(tài)正重塑產(chǎn)業(yè)疆域。2025年,物聯(lián)網(wǎng)產(chǎn)業(yè)邁入?"破界創(chuàng)造"與"共生進(jìn)化"?的裂變時(shí)代——AI大模型消融感知邊界,...

關(guān)鍵字: BSP 模型 微信 AIOT

"出海無界 商機(jī)無限"助力企業(yè)構(gòu)建全球競爭力 深圳2025年9月9日 /美通社/ -- 2025年8月28日, 由領(lǐng)先商業(yè)管理媒體世界經(jīng)理人攜手環(huán)球資源聯(lián)合主辦、深圳?前海出海e站通協(xié)辦的...

關(guān)鍵字: 解碼 供應(yīng)鏈 AI BSP

柏林2025年9月9日 /美通社/ -- 柏林當(dāng)?shù)貢r(shí)間9月6日,在2025德國柏林國際電子消費(fèi)品展覽會(huì)(International Funkausstellung...

關(guān)鍵字: 掃地機(jī)器人 耳機(jī) PEN BSP

武漢2025年9月9日 /美通社/ -- 7月24日,2025慧聰跨業(yè)品牌巡展——湖北?武漢站在武漢中南花園酒店隆重舉辦!本次巡展由慧聰安防網(wǎng)、慧聰物聯(lián)網(wǎng)、慧聰音響燈光網(wǎng)、慧聰LED屏網(wǎng)、慧聰教育網(wǎng)聯(lián)合主辦,吸引了安防、...

關(guān)鍵字: AI 希捷 BSP 平板
關(guān)閉