;================================================
; PIC16C74B microcontroller and AT24C64 communication
The function implemented by this program is:
; Write I2C_A, I2C_B.....I2C_K contents to EEPROM
At the same time, the data is read out in the EEPROM and newly written to each register.
;================================================
LISTP=16C74B
#include
ERRORLEVEL-302
I2C_AEQU0X20
I2C_BEQU0X21
I2C_CEQU0X22
I2C_DEQU0X23
I2C_EEQU0X24
I2C_FEQU0X25
I2C_GEQU0X26
REG1EQU0X2B
REG2EQU0X2C
COUNTEQU0X71; I2C
BCOUNTEQU0X72; I2C
TXBUFEQU0X73; I2C
RXBUFEQU0X74; I2C
BUSCONEQU0X75; I2C
BUSSTAEQU0X76; I2C
I2CBUFEQU0X77; I2C
SLAVEADDREQU0XA0; I2C
DATAADDRHEQU0X01; I2C
DATAADDRLEQU0X00; I2C
;---------------------------------------
;BUSCON
;---------------------------------------
SLAVE_RWEQU7
LAST_BYTE_RXEQU6
SLAVE_ACTIVEEQU5
TIME_OUTEQU4
;---------------------------------------
;BUSSTA
;---------------------------------------
BUS_BUSYEQU7
TX_PROGRESSEQU6
RX_PROGRESSEQU5
TX_SUCCESSEQU4
RX_SUCCESSEQU3
FATAL_ERROREQU2; SLAVEEEPROM
ABORTEQU1
ACK_ERROREQU0
;---------------------------------------
R_NOT_WEQU0
TRUEEQU1
FALSEEQU0
SDAEQU0X04; I2C
SCLEQU0X03; I2C
;================================================
ORG0X00
GOTOSTART
ORG0X20
STARTBCFSTATUS, RP1
BCFSTATUS, RP0
CLRFRA
CLRFRB
CLRFRC
CLRFRD
CLRFRE
BSFSTATUS, RP0
CLRFTRISA
CLRFTRISB
CLRFTRISC
CLRFTRISD
CLRFTRISE
MOVLW0X02
MOVWFI2C_A
MOVLW0X04
MOVWFI2C_B
MOVLW0X03
MOVWFI2C_C
MOVLW0X03
MOVWFI2C_D
MOVLW0X05
MOVWFI2C_E
MOVLW0X06
MOVWFI2C_F
MOVLW0X04
MOVWFI2C_G
;================================================
START1
CALLI2CBUS_INIT
CALLREGTOI2CBUF
CALLI2CWRITE
CALLCLRI2CBUF
CALLD10
CALLI2CREAD
CALLI2CBUFTOREG
GOTOSTART1
;================================================
;CLRI2CBUF
;---------------------------------------
CLRI2CBUF
BCFSTATUS, RP0
MOVLWI2CBUF
MOVWFFSR
MOVLW0X08
MOVWFCOUNT
CLRLOOPCLRFINDF
INCFFSR, F
DECFSZCOUNT, F
GOTOCLRLOOP
RETURN
;---------------------------------------
; Write each REGSTER data to the I2CBUF buffer
;---------------------------------------
REGTOI2CBUF
BCFSTATUS, RP0
MOVLWI2CBUF
MOVWFFSR
MOVFI2C_A, W
MOVWFINDF
INCFFSR, F
MOVFI2C_B, W
MOVWFINDF
INCFFSR, F
MOVFI2C_C, W
MOVWFINDF
INCFFSR, F
MOVFI2C_D, W
MOVWFINDF
INCFFSR, F
MOVFI2C_E, W
MOVWFINDF
INCFFSR, F
MOVFI2C_F, W
MOVWFINDF
INCFFSR, F
MOVFI2C_G, W
MOVWFINDF
RETURN
;---------------------------------------
; Write I2CBUF buffer data to each REGSTER
;---------------------------------------
I2CBUFTOREG
BCFSTATUS, RP0
MOVLWI2CBUF
MOVWFFSR
MOVFINDF, W
MOVWFI2C_A
INCFFSR, F
MOVFINDF, W
MOVWFI2C_B
INCFFSR, F
MOVFINDF, W
MOVWFI2C_C
INCFFSR, F
MOVFINDF, W
MOVWFI2C_D
INCFFSR, F
MOVFINDF, W
MOVWFI2C_E
INCFFSR, F
MOVFINDF, W
MOVWFI2C_F
INCFFSR, F
MOVFINDF, W
MOVWFI2C_G
RETURN
;================================================
; Write data in the I2CBUF buffer to the EEPROM
;================================================
I2CWRITE
CALLI2CSTART
BTFSSBUSSTA, BUS_BUSY
GOTOTX_FAIL
BCFBUSCON, SLAVE_RW
CALLTX_SLAVE_ADDR
BTFSSBUSSTA, TX_SUCCESS; SUCESSFULL?
GOTOTX_FAIL
CALLTX_DATA_ADDR
BTFSSBUSSTA, TX_SUCCESS
GOTOTX_FAIL
MOVLWI2CBUF
MOVWFFSR
MOVLW07
MOVWFCOUNT
T_BYTE_LOOP
MOVFINDF, W
MOVWFTXBUF
CALLI2CTXB
BTFSSBUSSTA, TX_SUCCESS
GOTOTX_FAIL
INCFFSR, F
DECFSZCOUNT, F
GOTOT_BYTE_LOOP
GOTOTX_PASS
TX_FAILCALLI2CSTOP
BCFBUSSTA, TX_PROGRESS
BCFBUSSTA, TX_SUCCESS
RETLWFALSE
TX_PASS
CALLI2CSTOP
BCFBUSSTA, TX_PROGRESS
RETLWTRUE
;---------------------------------------
; read data from EEPROM to I2CBUF register
;---------------------------------------
I2CREADBCFSTATUS, RP0
BCFBUSSTA, RX_SUCCESS
CALLI2CSTART
BTFSSBUSSTA, BUS_BUSY
GOTORX_FAIL
BCFBUSCON, SLAVE_RW
CALLTX_SLAVE_ADDR
BTFSSBUSSTA, TX_SUCCESS
GOTORX_FAIL
CALLTX_DATA_ADDR
BTFSSBUSSTA, TX_SUCCESS
GOTORX_FAIL
CALLI2CSTART
BSFBUSCON, SLAVE_RW
CALLTX_SLAVE_ADDR
BTFSSBUSSTA, TX_SUCCESS
GOTORX_FAIL
BCFBUSSTA, LAST_BYTE_RX
MOVLWI2CBUF
MOVWFFSR
MOVLW07
MOVWFCOUNT
R_BYTE_LOOP
MOVLW0X01
XORWFCOUNT, W
BTFSCSTATUS, Z
BSFBUSSTA, LAST_BYTE_RX
CALLI2CRXB
BTFSSBUSSTA, RX_SUCCESS
GOTORX_FAIL
MOVFRXBUF, W
MOVWFINDF
INCFFSR, F
DECFSZCOUNT, F
GOTOR_BYTE_LOOP
GOTORX_PASS
RX_FAILCALLI2CSTOP
BCFBUSSTA, RX_PROGRESS
BCFBUSSTA, RX_SUCCESS
RETLWFALSE
RX_PASSCALLI2CSTOP
BCFSTATUS, RP0
BCFBUSSTA, TX_PROGRESS
BCFBUSSTA, RX_PROGRESS
BSFBUSSTA, RX_SUCCESS
RETLWTRUE
;================================================
;I2C initialization
;================================================
I2CBUS_INIT
BCFSTATUS, RP0
MOVFRC, W
ANDLW0X18
MOVWFRC
CLRFBUSSTA
CLRFBUSCON
RETURN
;================================================
; transfer device address
; entrance: BUSCON
;Export: BUSSTA
;================================================
TX_SLAVE_ADDR
BCFSTATUS, RP0
BCFBUSSTA, ACK_ERROR
MOVLWSLAVEADDR
MOVWFTXBUF
BTFSCBUSCON, SLAVE_RW
BSFTXBUF, R_NOT_W
CALLI2CTXB
BTFSCBUSSTA, TX_SUCCESS
GOTOTXADDR_SUCCESS
CLRWDT
BTFSSBUSSTA, ACK_ERROR
CALLI2CSTOP
GOTOTXADDR_END
TXADDR_SUCCESS
CLRWDT
TXADDR_END
RETURN
;================================================
; TX_DATA_ADDR sends the write/read address
;================================================
TX_DATA_ADDR
BCFSTATUS, RP0
MOVLWDATAADDRH
MOVWFTXBUF
CALLI2CTXB
BCFSTATUS, RP0
BTFSSBUSSTA, TX_SUCCESS
GOTOTX_DATA_ADDR_ERROR
MOVLWDATAADDRL
MOVWFTXBUF
CALLI2CTXB
BCFSTATUS, RP0
BTFSSBUSSTA, TX_SUCCESS
GOTOTX_DATA_ADDR_ERROR
GOTOTX_DATA_END
TX_DATA_ADDR_ERROR
BCFBUSSTA, TX_PROGRESS
BCFBUSSTA, TX_SUCCESS
BSFBUSSTA, ACK_ERROR
TX_DATA_END
RETURN
;================================================
; output an 8-bit data to the EEPROM and detect the ACK signal of the EEPROM
; Entry: TXBUF register
;BUSSTA register
;Export: EEPROM memory
;BUSSTA register
;===============================================
I2CTXBBCFSTATUS, RP0
BSFBUSSTA, TX_PROGRESS
BCFBUSSTA, TX_SUCCESS
MOVLW0X08
MOVWFBCOUNT
TXLOOPCLRWDT
BSFSTATUS, RP0
BCFTRISC, SCL
NOP
BCFTRISC, SDA
BCFSTATUS, RP0
RLFTXBUF, F
BSFSTATUS, RP0
BTFSCSTATUS, C
BSFTRISC, SDA
NOP
BSFTRISC, SCL
NOP
NOP
BCFSTATUS, RP0
DECFSZBCOUNT,F
GOTOTXLOOP
;---------------------------------------
Detection is EEPROM whether there is ACK signal generated, produced as normal
;Detection method:
; 1. Set the SCL.SDA of the RC port to the output and input states respectively.
; 2. Delay 2 instruction cycles, set SCL to high level
; 3. Delay 2 instruction cycles to detect the status of RC port SDA
; 4. If it is high, set the error status, return
; 5. If it is low, after delaying 2 instruction cycles, set RC port SCL to low level and continue execution.
;---------------------------------------
BSFSTATUS, RP0
BCFTRISC, SCL
BSFTRISC, SDA
NOP
NOP
BSFTRISC, SCL
NOP
BCFSTATUS, RP0
BTFSCRC, SDA
GOTOTX_ERR
BSFSTATUS, RP0
BCFTRISC, SCL
BCFSTATUS, RP0
BCFBUSSTA, TX_PROGRESS
BSFBUSSTA, TX_SUCCESS
BCFBUSSTA, ACK_ERROR
GOTOTX_END
TX_ERRBCFBUSSTA, TX_PROGRESS
BCFBUSSTA, TX_SUCCESS
BSFBUSSTA, ACK_ERROR
TX_ENDRETURN
;================================================
; read 8 bits of data from the EEPROM and send an ACK signal
; entry: EEPROM memory
;BUSCON register
;Export: RXBUF register
;BUSSTA register
;================================================
I2CRXBBCFSTATUS, RP0
BSFBUSSTA, RX_PROGRESS
BCFBUSSTA, RX_SUCCESS
MOVLW0X08
MOVWFBCOUNT
RXLOOPCLRWDT
BSFSTATUS, RP0
BCFTRISC, SCL; define TRISC
BSFTRISC, SDA; definition TRISC
NOP
NOP
BSFTRISC, SCL; TRISC
NOP
BCFSTATUS, RP0
BCFSTATUS, C
BTFSCRC, SDA; original instruction is BTFSCTRISC, SDA
BSFSTATUS, C
RLFRXBUF, F
DECFSZBCOUNT,F
GOTORXLOOP
;---------------------------------------
; send ACK signal to EEPROM
; determine whether the received byte is the last byte
;LAST_BYTE_RX is 1, is SDA send a high level, the end
;LAST_BYTE_RX is 0, not SDA sends a low ACK, continues to receive
;---------------------------------------
BSFSTATUS, RP0
BCFTRISC, SCL
BCFTRISC, SDA
BTFSCBUSCON, LAST_BYTE_RX; check if it is the last byte
BSFTRISC, SDA; is the last byte
NOP; send ACK signal
BSFTRISC, SCL
NOP
NOP
NOP
NOP
BCFTRISC, SCL
BCFSTATUS, RP0
BCFBUSSTA, RX_PROGRESS
BSFBUSSTA, RX_SUCCESS
RETURN
;================================================
; I2C start signal
; input: none
;Output: BUFSSTA
;================================================
I2CSTART
BSFSTATUS, RP0
BSFTRISC, SDA; 1US
NOP; 1US
BSFTRISC, SCL; 1US
NOP
NOP
BCFTRISC, SDA
NOP
NOP
BCFSTATUS, RP0
BSFBUSSTA, BUS_BUSY
RETURN
;================================================
;I2C end signal
; input: none
; Output: BUSSTA
;================================================
I2CSTOP
BSFSTATUS, RP0
BCFTRISC, SCL
BCFTRISC, SDA
BSFTRISC, SCL
NOP
NOP
BSFTRISC, SDA
NOP
BCFSTATUS, RP0
BCFBUSSTA, BUS_BUSY
RETURN
;================================================
;D10@
;cLOCkin4MHz
;delay10ms
;================================================
D10MOVLW0X0D
MOVWFREG1
LOOP2MOVLW0XFF
MOVWFREG2
LOOP1DECFSZREG2,f
GOTOLOOP1
DECFSZREG1,f
GOTOLOOP2
RETURN
;================================================
I2CERRCLRWDT
NOP
NOP
NOP
RETURN
END
FOLI has many types of disposables vape; FOLI BOX is one of popular Disposable Vape.
5000 Puffs, Mesh Coil, good cigarette oil, good, tasty and the price is reasonable. The minimum order quantity is 30 pieces, in stock, and delivered on the same day. It only takes 7-10 days from China to destination. Please take an order if you are interested.
Disposable Vape FOLI BOX 12ml 5000 Puffs Big Smoke rechargeable
Foli Vape is a hot vape brand in many countries. Foli Disposable Vape provides an innovative leak-resistant maze coil, ensuring security wherever you are and regardless of your daily activities.Foli Box disposable vape is rich in flavors, with 16 taste choices. The bottom suction resistance adjustment button can adjust the suction resistance according to personal preference.FOLI Box disposable vape is bright and colourful, and is deeply loved by young people.
600mah A-level battery
12ml eujice & 1.2ohm
16 flavors available Outstanding Flavor
Nicotin 3%
Puffs: 5000 Puffs
Volume:12ml
Battery Capacity:600mAh
Charging Port:Type-C
Suction resistance adjustment button
Flavor List:
MINT
LYCHEE STRAWBERRY
GREEN APPLE
WATERMELON
ORANGE MANGO
STRAWBERRYICECREAM
CRANBERRYGRAPE
GRAPE
BLUEBERRYRASPBERRY
LEMON TEA
BANANA LYCHEE
SKITTLES
GOLDEN FRUIT
BLUEBERRY
WATERMELON LYCHEE
STRAWBERRY
Features
1. No other carcinogenic substance.
2. Harmless to others and the environment. With no danger of second-hand smoking.
3. Smoke in public places, business, restaurants, planes etc. Does not emit any smell.
4. Enable smokers to abstain from smoking non-painfully.
5. Save the smoking cost of nearly 80% each year.
6. No ignition and no fire danger.
Foli Disposable Vape,Big Smoke High-Power Vape,E Cigarette Atomizer ,Disposable Vape Mash Coil
tsvape , https://www.tsecigarette.com