亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? i2c應用程序1.txt

?? 包括很多單片機開發用的元代碼
?? TXT
字號:

  ; File: an734.asm
; data: feb.23.2001
; Written By: 歌林電子制作實驗室www.nbglin.com 
; Functionality:
;
; This code implements the basic functions for an I2C slave device
; using the SSP module. All I2C functions are handled in an ISR.
; Bytes written to the slave are stored in a buffer. After a number
; of bytes have been written, the master device can then read the
; bytes back from the buffer.
;
; Variables and Constants used in the program:
;
; The start address for the receive buffer is stored in the variable
; 'RXBuffer'. The length of the buffer is denoted by the constant
; value 'RX_BUF_LEN'. The current buffer index is stored in the 
; variable 'Index'.
;
;--------------------------------------------------------------------
; 
; The following files should be included in the MPLAB project:
;
; an734.asm-- Main source code file
;
; 16f872.lkr-- Linker script file
; (change this file for the device
; you are using)
;---------------------------------------------------------------------
#include <p16f872.inc> ; Change to device that you are using.
;---------------------------------------------------------------------
;Constant Definitions
;---------------------------------------------------------------------
#define NODE_ADDR 0x02 ; I2C address of this node
; Change this value to address that
; you wish to use.
;---------------------------------------------------------------------
; Buffer Length Definition
;---------------------------------------------------------------------

#define RX_BUF_LEN 32 ; Length of receive buffer

;---------------------------------------------------------------------
; Variable declarations
;---------------------------------------------------------------------
udata

WREGsave res 1
STATUSsave res 1
FSRsave res 1
PCLATHsave res 1

Index res 1 ; Index to receive buffer
Temp res 1 ;
RXBuffer res RX_BUF_LEN ; Holds rec'd bytes from master
; device.

;---------------------------------------------------------------------
; Vectors
;---------------------------------------------------------------------

STARTUP code
nop 
goto Startup ; 
nop ; 0x0002
nop ; 0x0003
goto ISR ; 0x0004

PROG code

;---------------------------------------------------------------------
; Macros
;---------------------------------------------------------------------

memset macro Buf_addr,Value,Length

movlw Length ; This macro loads a range of data memory
movwf Temp ; with a specified value. The starting
movlw Buf_addr ; address and number of bytes are also 
movwf FSR ; specified.
SetNext movlw Value
movwf INDF
incf FSR,F
decfsz Temp,F
goto SetNext
endm


LFSR macro Address,Offset ; This macro loads the correct value
movlw Address ; into the FSR given an initial data 
movwf FSR ; memory address and offset value.
movf Offset,W
addwf FSR,F
endm

;---------------------------------------------------------------------
; Main Code
;---------------------------------------------------------------------

Startup
bcf STATUS,RP1
bsf STATUS,RP0
call Setup

Main clrwdt ; Clear the WDT 
goto Main ; Loop forever. 


;---------------------------------------------------------------------
; Interrupt Code
;---------------------------------------------------------------------

ISR
movwf WREGsave ; Save WREG
movf STATUS,W ; Get STATUS register
banksel STATUSsave ; Switch banks, if needed.
movwf STATUSsave ; Save the STATUS register
movf PCLATH,W ;
movwf PCLATHsave ; Save PCLATH
movf FSR,W ;
movwf FSRsave ; Save FSR

banksel PIR1
btfss PIR1,SSPIF ; Is this a SSP interrupt? 
goto $ ; No, just trap here.
bcf PIR1,SSPIF
call SSP_Handler ; Yes, service SSP interrupt.

banksel FSRsave
movf FSRsave,W ;
movwf FSR ; Restore FSR
movf PCLATHsave,W ; 
movwf PCLATH ; Restore PCLATH
movf STATUSsave,W ;
movwf STATUS ; Restore STATUS
swapf WREGsave,F ;
swapf WREGsave,W ; Restore WREG

retfie ; Return from interrupt.

;---------------------------------------------------------------------
Setup
;
; Initializes program variables and peripheral registers.
;---------------------------------------------------------------------

banksel PCON
bsf PCON,NOT_POR
bsf PCON,NOT_BOR

banksel Index ; Clear various program variables
clrf Index

clrf PORTB
clrf PIR1
banksel TRISB
clrf TRISB

movlw 0x36 ; Setup SSP module for 7-bit 
banksel SSPCON
movwf SSPCON ; address, slave mode
movlw NODE_ADDR
banksel SSPADD
movwf SSPADD
clrf SSPSTAT


banksel PIE1 ; Enable interrupts
bsf PIE1,SSPIE
bsf INTCON,PEIE ; Enable all peripheral interrupts
bsf INTCON,GIE ; Enable global interrupts

bcf STATUS,RP0
return

;---------------------------------------------------------------------
SSP_Handler
;---------------------------------------------------------------------
; The I2C code below checks for 5 states:
;---------------------------------------------------------------------
; State 1: I2C write operation, last byte was an address byte.
;
; SSPSTAT bits: S = 1, D_A = 0, R_W = 0, BF = 1
;
; State 2: I2C write operation, last byte was a data byte.
;
; SSPSTAT bits: S = 1, D_A = 1, R_W = 0, BF = 1
;
; State 3: I2C read operation, last byte was an address byte.
;
; SSPSTAT bits: S = 1, D_A = 0, R_W = 1, BF = 0
;
; State 4: I2C read operation, last byte was a data byte.
;
; SSPSTAT bits: S = 1, D_A = 1, R_W = 1, BF = 0
;
; State 5: Slave I2C logic reset by NACK from master.
; 
; SSPSTAT bits: S = 1, D_A = 1, R_W = 0, BF = 0
;
; For convenience, WriteI2C and ReadI2C functions have been used.
;----------------------------------------------------------------------

banksel SSPSTAT
movf SSPSTAT,W ; Get the value of SSPSTAT
andlw b'00101101' ; Mask out unimportant bits in SSPSTAT.
banksel Temp ; Put masked value in Temp
movwf Temp ; for comparision checking.

State1: ; Write operation, last byte was an
movlw b'00001001' ; address, buffer is full.
xorwf Temp,W ; 
btfss STATUS,Z ; Are we in State1?
goto State2 ; No, check for next state.....

memset RXBuffer,0,RX_BUF_LEN ; Clear the receive buffer.
clrf Index ; Clear the buffer index.
call ReadI2C ; Do a dummy read of the SSPBUF.
return

State2: ; Write operation, last byte was data,
movlw b'00101001' ; buffer is full.
xorwf Temp,W
btfss STATUS,Z ; Are we in State2?
goto State3 ; No, check for next state.....

LFSR RXBuffer,Index ; Point to the buffer.
call ReadI2C ; Get the byte from the SSP.
movwf INDF ; Put it in the buffer.
incf Index,F ; Increment the buffer pointer.
movf Index,W ; Get the current buffer index.
sublw RX_BUF_LEN ; Subtract the buffer length.
btfsc STATUS,Z ; Has the index exceeded the buffer length?
clrf Index ; Yes, clear the buffer index.
return

State3: ; Read operation, last byte was an
movlw b'00001100' ; address, buffer is empty.
xorwf Temp,W
btfss STATUS,Z ; Are we in State3?
goto State4 ; No, check for next state.....

clrf Index ; Clear the buffer index.
LFSR RXBuffer,Index ; Point to the buffer
movf INDF,W ; Get the byte from buffer.
call WriteI2C ; Write the byte to SSPBUF
incf Index,F ; Increment the buffer index.
return

State4: ; Read operation, last byte was data,
movlw b'00101100' ; buffer is empty.
xorwf Temp,W
btfss STATUS,Z ; Are we in State4?
goto State5 ; No, check for next state....

movf Index,W ; Get the current buffer index.
sublw RX_BUF_LEN ; Subtract the buffer length.
btfsc STATUS,Z ; Has the index exceeded the buffer length?
clrf Index ; Yes, clear the buffer index.
LFSR RXBuffer,Index ; Point to the buffer
movf INDF,W ; Get the byte
call WriteI2C ; Write to SSPBUF
incf Index,F ; Increment the buffer index.
return

State5:
movlw b'00101000' ; A NACK was received when transmitting
xorwf Temp,W ; data back from the master. Slave logic
btfss STATUS,Z ; is reset in this case. R_W = 0, D_A = 1
goto I2CErr ; and BF = 0
return ; If we aren抰 in State5, then something is 
; wrong.

I2CErr nop
banksel PORTB ; Something went wrong! Set LED
bsf PORTB,7 ; and loop forever. WDT will reset
goto $ ; device, if enabled.
return

;---------------------------------------------------------------------
; WriteI2C
;---------------------------------------------------------------------

WriteI2C
banksel SSPSTAT
btfsc SSPSTAT,BF ; Is the buffer full?
goto WriteI2C ; Yes, keep waiting.
banksel SSPCON ; No, continue.
DoI2CWrite
bcf SSPCON,WCOL ; Clear the WCOL flag.
movwf SSPBUF ; Write the byte in WREG
btfsc SSPCON,WCOL ; Was there a write collision?
goto DoI2CWrite
bsf SSPCON,CKP ; Release the clock.
return

;---------------------------------------------------------------------
ReadI2C
;---------------------------------------------------------------------

banksel SSPBUF
movf SSPBUF,W ; Get the byte and put in WREG
return

end ; End of file


 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色狠狠色狠狠综合| 亚洲欧洲成人精品av97| 奇米精品一区二区三区在线观看 | 麻豆91免费看| 欧美精品久久久久久久多人混战| 一卡二卡三卡日韩欧美| www.欧美精品一二区| 亚洲国产成人自拍| 国产精品综合一区二区三区| 精品人伦一区二区色婷婷| 亚洲图片欧美色图| 欧美日韩国产另类不卡| 精品一区二区三区的国产在线播放 | 精品国产乱码久久久久久久| 九九精品一区二区| 中文字幕精品一区二区精品绿巨人 | 欧美午夜电影一区| 亚洲自拍另类综合| 欧美一级一区二区| 国产一区免费电影| 国产欧美一区二区在线观看| 国产在线一区二区综合免费视频| 精品久久五月天| 国产成人在线观看| 亚洲三级小视频| 欧美在线一二三| 亚洲国产精品麻豆| 日韩写真欧美这视频| 麻豆成人久久精品二区三区红| 中文字幕乱码久久午夜不卡| 欧美猛男男办公室激情| 国产成人精品1024| 午夜欧美大尺度福利影院在线看| 精品国产伦一区二区三区观看方式 | 尤物av一区二区| 欧美日精品一区视频| 日韩av中文字幕一区二区三区| 91精品国产91久久久久久最新毛片| 免费成人结看片| 亚洲视频每日更新| 欧美三级资源在线| 1区2区3区欧美| 欧美午夜影院一区| 国产高清久久久久| 一区二区三区在线免费| 日韩一区二区三区视频在线| 99精品国产99久久久久久白柏| 亚洲一区二区三区四区在线免费观看 | 国产日韩视频一区二区三区| 色综合天天天天做夜夜夜夜做| 三级在线观看一区二区| 26uuu亚洲| 色系网站成人免费| 国产麻豆精品在线| 日韩二区三区在线观看| 国产欧美精品区一区二区三区| 欧洲精品一区二区三区在线观看| 久久国产福利国产秒拍| 天天综合天天做天天综合| 一区二区三区四区精品在线视频 | av在线不卡电影| 国产精品亚洲а∨天堂免在线| 蜜桃av噜噜一区| 日韩福利电影在线观看| 亚洲18女电影在线观看| 一区二区视频在线| 亚洲免费观看高清完整版在线观看| 久久久99精品久久| 久久综合999| 日韩三区在线观看| 日韩视频国产视频| 欧美一二三区在线观看| 4438x亚洲最大成人网| 欧美精品色综合| 欧美精品日韩一区| 在线播放一区二区三区| 717成人午夜免费福利电影| 欧美久久免费观看| 欧美一级高清片| 精品奇米国产一区二区三区| 精品久久五月天| 国产亚洲精品7777| 国产精品欧美一级免费| 国产精品不卡一区二区三区| 国产精品福利影院| 亚洲精品国产精品乱码不99| 亚洲精品一二三| 亚洲一区二区三区中文字幕| 亚洲成人在线网站| 免费av网站大全久久| 精品在线播放免费| 从欧美一区二区三区| 成人动漫一区二区三区| 成人a免费在线看| 色先锋aa成人| 91精品国产一区二区三区蜜臀| 精品久久久久99| 国产精品午夜电影| 一区二区三区视频在线观看| 亚洲一区二区三区中文字幕| 日韩av在线播放中文字幕| 久久99这里只有精品| 国产a久久麻豆| 99久久久久久99| 7777精品伊人久久久大香线蕉| 26uuu国产电影一区二区| 国产欧美精品日韩区二区麻豆天美| 亚洲欧美综合另类在线卡通| 亚洲成人免费在线| 国产精品一二三四五| 99在线热播精品免费| 欧美三级在线看| 欧美精品一区二区三区久久久| |精品福利一区二区三区| 丝袜亚洲精品中文字幕一区| 高清免费成人av| 欧美精品色一区二区三区| 日本一区二区三区dvd视频在线| 亚洲一卡二卡三卡四卡五卡| 精品一区二区三区在线观看| 91一区二区三区在线观看| 日韩一区二区三区视频在线观看| 中文字幕一区二区三中文字幕| 香蕉成人伊视频在线观看| 粉嫩蜜臀av国产精品网站| 欧美色综合影院| 国产精品美女一区二区| 日韩专区中文字幕一区二区| av成人动漫在线观看| 欧美一区二区福利视频| 自拍偷在线精品自拍偷无码专区| 另类综合日韩欧美亚洲| 在线观看国产一区二区| 国产亲近乱来精品视频| 日韩影视精彩在线| 日本精品一级二级| 欧美国产一区二区在线观看| 日本不卡一二三区黄网| 欧美影视一区在线| 日本一区二区三区免费乱视频| 另类小说视频一区二区| 欧美在线影院一区二区| 成人欧美一区二区三区黑人麻豆| 久久99精品国产.久久久久久| 欧美性生活影院| 亚洲欧美成aⅴ人在线观看| 国产成人精品免费看| 日韩美女天天操| 秋霞成人午夜伦在线观看| 欧美色倩网站大全免费| 亚洲免费在线视频| 99国产精品视频免费观看| 中文成人综合网| 国产成人亚洲综合a∨婷婷图片| 欧美成人a视频| 美女性感视频久久| 日韩一区和二区| 日日摸夜夜添夜夜添国产精品| 欧美亚洲图片小说| 一区二区成人在线| 色综合 综合色| 亚洲乱码精品一二三四区日韩在线| 国产91富婆露脸刺激对白| 久久久久久久久岛国免费| 国内精品伊人久久久久av影院| 日韩欧美成人激情| 久久www免费人成看片高清| 欧美精品一区二区三区很污很色的 | 亚洲精品写真福利| 日本高清无吗v一区| 亚洲综合丝袜美腿| 欧美日韩一区成人| 日本免费在线视频不卡一不卡二| 欧美福利视频一区| 免费在线欧美视频| 精品女同一区二区| 国产精品一区二区免费不卡| 国产色一区二区| 菠萝蜜视频在线观看一区| 亚洲色图丝袜美腿| 91久久奴性调教| 天堂一区二区在线| 欧美成人免费网站| 99久久综合99久久综合网站| 亚洲欧美韩国综合色| 欧美日韩亚洲另类| 精品一区免费av| 欧美日韩在线播放三区| 蜜臀精品一区二区三区在线观看 | 久久se精品一区二区| 国产日韩欧美制服另类| 91丨九色丨蝌蚪丨老版| 亚洲成人动漫av| 精品国产乱码久久久久久浪潮 | 国产剧情在线观看一区二区| 国产精品美女久久久久高潮 | 91精品国产综合久久精品图片 | 三级一区在线视频先锋| 337p日本欧洲亚洲大胆精品| 99久久99久久精品国产片果冻|