SlideShare a Scribd company logo
;******************************************************************************;
;@Date 02/07/2009
;@Version 1.1
;@Author Pedro Pablo Plazas R.
;@@@ Communication between Serial EEPROM 24LC04B(Slave) and PIC16F84A(Master)
; using 2-wire serial interface bus, I2C.
;Bus timing Start/Stop and data for a frequency equal to 6Mhz
;*****************************************************************************
;**** Signals *****
SDA equ 2 ;Signal data
SCL equ 3 ;Signal clock
CONSTANT CODE_DEVICE_W = b'10100000' ;Control byte for writting operations.
CONSTANT CODE_DEVICE_R = b'10100001' ;Control byte for reading operations.
;*****************************************************************
;
;******************************************************************
EEPROM_init macro
call EEP_init
endm
;*****************************************************************************
;Rutine to write operation.
;Following the Start condition from the master, the device code(4 bits),
;the block address(3bits) and the R/W(-), bit which is a logic low is placed
;onto the bus by the master transmitter.
;*****************************************************************************
EEPROM_Write_Data macro word_Address, data_Write
call BIT_START ;//--Start bit
call SEND_CMD_Writting ;//--Command to write (10100000)
EEPROM_ACK
movlw word_Address ;//--Send Word Address
call SEND_Data_Or_Addr
EEPROM_ACK
movf data_Write,W ;//--Send byte to write.
call SEND_Data_Or_Addr
EEPROM_ACK ;//--ACK
call BIT_STOP ;//--Stop bit
endm
;*******************************************************************
;Page write. The write control byte, word address and the first data
;byte are transmitted to the 24XX04 in the same way as in a byte
;write. But instead of generating a Stop condition the master transmit
;up to 16 data bytes to the 24XX04.
;*******************************************************************
EEPROM_Page_Write_Data macro word_Address, data_Write1, data_Write2
call BIT_START ;//--Start bit
call SEND_CMD_Writting ;//--Command to write (10100000)
EEPROM_ACK
movlw word_Address ;//--Send Word Address
call SEND_Data_Or_Addr
EEPROM_ACK
movf data_Write1,W ;//--Send byte1 to write.
call SEND_Data_Or_Addr
EEPROM_ACK ;//--ACK
movf data_Write2,W ;//--Send byte2 to write.
call SEND_Data_Or_Addr
EEPROM_ACK ;//--ACK
call BIT_STOP ;//--Stop bit
endm
EEPROM_Read_Data macro word_Address
call BIT_START ;//--Start bit
call SEND_CMD_Writting ;//--Command to write (10100000)
EEPROM_ACK ;//--ACK
movlw word_Address ;//--Send Word Address
call SEND_Data_Or_Addr
EEPROM_ACK
call BIT_START ;//--Start bit
call SEND_CMD_Reading ;//--Command to read (10100001)
EEPROM_ACK ;//--ACK
call READ_DATA ;//--READ DATA BYTE
bcf EEPportB,SCL
nop
bsf EEPportB,SCL
nop
bcf EEPportB,SCL
nop
call BIT_STOP ;///Stop bit
endm
;*****************************************************************
;Init ports MAster(PIC16F84) for communication with Slave(EEPROM)
;*****************************************************************
EEP_init
BANK1
clrf EEPtrisA
clrf EEPtrisB
bsf EEPtrisB,0 ;Input to push key.
BANK0
clrf EEPportA
clrf EEPportB
bsf EEPportB,SDA
bsf EEPportB,SCL
RETURN
;*****************************************************************
;Generate Start o Stop bit
;*****************************************************************
BIT_START
bcf INTCON,GIE
BANK1
bcf EEPtrisB,SDA
BANK0
bsf INTCON,GIE
call SCLK_BIT_START
RETURN
BIT_STOP
bcf INTCON,GIE
BANK1
bcf EEPtrisB,SDA
BANK0
bsf INTCON,GIE
call SCLK_BIT_STOP
RETURN
;******************************************************************
;Generating acknowlegde signal
;******************************************************************
EEPROM_ACK macro
local ReadAck, EndAck
bcf INTCON,GIE
BANK1
bsf EEPtrisB,SDA
BANK0
bsf INTCON,GIE
ReadAck btfsc EEPportB,SDA
goto ReadAck
bsf EEPportB,SCL
nop
nop
bcf EEPportB,SCL
endm
;****************************************************************************
; Send one command or data(only to write) for writting or reading into EEPROM
;****************************************************************************
SEND_CMD_Writting movlw CODE_DEVICE_W ;Control byte to write
goto SEND_Data_Or_Addr
SEND_CMD_Reading movlw CODE_DEVICE_R ;Control byte to read
SEND_Data_Or_Addr movwf BYTE_TX
bcf INTCON,GIE
BANK1
bcf EEPtrisB,SDA
BANK0
bsf INTCON,GIE
movlw 0x08
movwf COUNT_BITS
SENDCtrl btfsc BYTE_TX,7
goto SEND_SB
bcf EEPportB,SDA
goto ROT_BITS
SEND_SB bsf EEPportB,SDA
ROT_BITS call SCLK_DATA
rlf BYTE_TX,1
decfsz COUNT_BITS,F
goto SENDCtrl
RETURN
;************************************************************
;Reading data from EEPROM
;************************************************************
READ_DATA
bcf INTCON,GIE
BANK1
bsf EEPtrisB,SDA
BANK0
bsf INTCON,GIE
movlw .8
movwf COUNT_BITS
ROT_DATA_BITS rlf REG_DATA,F
btfss EEPportB,SDA
bcf REG_DATA,0
btfsc EEPportB,SDA
bsf REG_DATA,0
call SCLK_DATA
decfsz COUNT_BITS,F
goto ROT_DATA_BITS
movf REG_DATA,W
RETURN
;*******************************************************
;Rutine to generate start condition setup time
;*******************************************************
SCLK_BIT_START
bcf EEPportB,SCL
bsf EEPportB,SDA
nop
nop
bsf EEPportB,SCL
nop
nop
bcf EEPportB,SDA
nop
nop
bcf EEPportB,SCL
nop
nop
RETURN
;*******************************************************
;Rutine to generate start condition setup time
;*******************************************************
SCLK_BIT_STOP bcf EEPportB,SDA
nop
nop
bsf EEPportB,SCL
nop
nop
bsf EEPportB,SDA
nop
nop
bcf EEPportB,SCL
nop
nop
RETURN
;**************************************************************
;Generating signal of clock for EEPROM(SCL), only one period
;**************************************************************
SCLK_DATA nop
nop
bsf EEPportB,SCL
nop
nop
nop
nop
bcf EEPportB,SCL
RETURN
;****************************************
;Routine to wait 100ms, to push any key
;****************************************
KeyWait movlw 0x96;--64(100ms)
movwf RS_TIMER1
;Delay of 1ms
T_Wait movlw 0xFA
movwf RS_TIMER2
T_Wx nop
nop
nop
nop
nop
decfsz RS_TIMER2
goto T_Wx
decfsz RS_TIMER1
goto T_Wait
RETURN

More Related Content

What's hot

Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
Naoto MATSUMOTO
 
konfig routing paling cepat
konfig routing paling cepatkonfig routing paling cepat
konfig routing paling cepat
Belajar Konfig
 
Usage, Performance and Future Of PL1 at NRB Benoit Ebner
Usage, Performance and Future Of PL1 at NRB Benoit EbnerUsage, Performance and Future Of PL1 at NRB Benoit Ebner
Usage, Performance and Future Of PL1 at NRB Benoit Ebner
NRB
 
Eincop Netwax Lab: Lab 1 static route
Eincop Netwax Lab: Lab 1 static routeEincop Netwax Lab: Lab 1 static route
Eincop Netwax Lab: Lab 1 static route
Netwax Lab
 
Tiny Server Clustering using Vyatta/VyOS (MEMO)
Tiny Server Clustering using Vyatta/VyOS (MEMO)Tiny Server Clustering using Vyatta/VyOS (MEMO)
Tiny Server Clustering using Vyatta/VyOS (MEMO)
Naoto MATSUMOTO
 
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
Netwax Lab
 
3 g notes
3 g notes3 g notes
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
aryandi572
 
Ip sec vpn with dynamic routing mikrotik and cisco - mikro-tik wiki
Ip sec vpn with dynamic routing   mikrotik and cisco - mikro-tik wikiIp sec vpn with dynamic routing   mikrotik and cisco - mikro-tik wiki
Ip sec vpn with dynamic routing mikrotik and cisco - mikro-tik wiki
Huy Eav
 
The propeller
The propellerThe propeller
74ls373
74ls37374ls373
74ls373
holinh7
 
Route Redistribution
Route RedistributionRoute Redistribution
Route Redistribution
Netwax Lab
 
Лекц 15
Лекц 15Лекц 15
Лекц 15
Muuluu
 
Nxll10 v lan and trunking
Nxll10 v lan and trunkingNxll10 v lan and trunking
Nxll10 v lan and trunking
Netwax Lab
 
Nxll28 ospf iii
Nxll28 ospf iiiNxll28 ospf iii
Nxll28 ospf iii
Netwax Lab
 
Gre tunnel pdf
Gre tunnel pdfGre tunnel pdf
Gre tunnel pdf
Rajesh Porwal
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
艾鍗科技
 
Juniper JNCIA – Juniper OSPF Route Configuration
Juniper JNCIA – Juniper OSPF Route ConfigurationJuniper JNCIA – Juniper OSPF Route Configuration
Juniper JNCIA – Juniper OSPF Route Configuration
Hamed Moghaddam
 
Skype file-transfer
Skype file-transferSkype file-transfer
Skype file-transfer
testdevm
 
Konfig routing eigrp
Konfig routing eigrpKonfig routing eigrp
Konfig routing eigrp
Ikhwanul Kurnia Rahman
 

What's hot (20)

Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
Large Scale L2TPv3 Overlay Networking with OSPFv3(DRAFT)
 
konfig routing paling cepat
konfig routing paling cepatkonfig routing paling cepat
konfig routing paling cepat
 
Usage, Performance and Future Of PL1 at NRB Benoit Ebner
Usage, Performance and Future Of PL1 at NRB Benoit EbnerUsage, Performance and Future Of PL1 at NRB Benoit Ebner
Usage, Performance and Future Of PL1 at NRB Benoit Ebner
 
Eincop Netwax Lab: Lab 1 static route
Eincop Netwax Lab: Lab 1 static routeEincop Netwax Lab: Lab 1 static route
Eincop Netwax Lab: Lab 1 static route
 
Tiny Server Clustering using Vyatta/VyOS (MEMO)
Tiny Server Clustering using Vyatta/VyOS (MEMO)Tiny Server Clustering using Vyatta/VyOS (MEMO)
Tiny Server Clustering using Vyatta/VyOS (MEMO)
 
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
Eincop Netwax Lab: HSRP (Hot Standby Router Protocol)
 
3 g notes
3 g notes3 g notes
3 g notes
 
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
Aryandi triyanto 10 (tugas cisco 1 router 3 pc)
 
Ip sec vpn with dynamic routing mikrotik and cisco - mikro-tik wiki
Ip sec vpn with dynamic routing   mikrotik and cisco - mikro-tik wikiIp sec vpn with dynamic routing   mikrotik and cisco - mikro-tik wiki
Ip sec vpn with dynamic routing mikrotik and cisco - mikro-tik wiki
 
The propeller
The propellerThe propeller
The propeller
 
74ls373
74ls37374ls373
74ls373
 
Route Redistribution
Route RedistributionRoute Redistribution
Route Redistribution
 
Лекц 15
Лекц 15Лекц 15
Лекц 15
 
Nxll10 v lan and trunking
Nxll10 v lan and trunkingNxll10 v lan and trunking
Nxll10 v lan and trunking
 
Nxll28 ospf iii
Nxll28 ospf iiiNxll28 ospf iii
Nxll28 ospf iii
 
Gre tunnel pdf
Gre tunnel pdfGre tunnel pdf
Gre tunnel pdf
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
Juniper JNCIA – Juniper OSPF Route Configuration
Juniper JNCIA – Juniper OSPF Route ConfigurationJuniper JNCIA – Juniper OSPF Route Configuration
Juniper JNCIA – Juniper OSPF Route Configuration
 
Skype file-transfer
Skype file-transferSkype file-transfer
Skype file-transfer
 
Konfig routing eigrp
Konfig routing eigrpKonfig routing eigrp
Konfig routing eigrp
 

Similar to serialEEPROM

Spi (1)
Spi (1)Spi (1)
Spi (1)
sharmila B.S
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
Anurag Tomar
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
P sim.val
P sim.valP sim.val
P sim.val
Corneliu Modilca
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
Jens Siebert
 
Diseqc
DiseqcDiseqc
Diseqc
Jakab Zsolt
 
Laboratory Report Sample
Laboratory Report SampleLaboratory Report Sample
Laboratory Report Sample
Markus Flicke
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
BlackD10
 
Unit_I.pptx
Unit_I.pptxUnit_I.pptx
Unit_I.pptx
Prithiv9
 
Vista 1600 c epon olt quick start manual(r1.2)
Vista 1600 c epon olt quick start manual(r1.2)Vista 1600 c epon olt quick start manual(r1.2)
Vista 1600 c epon olt quick start manual(r1.2)
Shanxi Cai
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGA
Mafaz Ahmed
 
Ospf Last Modified Eng
Ospf  Last Modified EngOspf  Last Modified Eng
Ospf Last Modified Eng
Alp isik
 
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
Felipe Prado
 
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
Program, Code of Program and  Screen Shot of Output (UNIVERSAL DRIVER USING µ...Program, Code of Program and  Screen Shot of Output (UNIVERSAL DRIVER USING µ...
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
Er. Ashish Pandey
 
COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520
Jon Fortman
 
MaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Code Examples
MaxBotix Code Examples
MaxBotix Inc
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
Simen Li
 
COBOL BATCH EXAMPLE-RPR6621F
COBOL BATCH EXAMPLE-RPR6621FCOBOL BATCH EXAMPLE-RPR6621F
COBOL BATCH EXAMPLE-RPR6621F
Jon Fortman
 
PIC16F877A C Programming.ppt
PIC16F877A C Programming.pptPIC16F877A C Programming.ppt
PIC16F877A C Programming.ppt
IlaiyarajaS1
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
nikhil dixit
 

Similar to serialEEPROM (20)

Spi (1)
Spi (1)Spi (1)
Spi (1)
 
SPI Protocol
SPI ProtocolSPI Protocol
SPI Protocol
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
P sim.val
P sim.valP sim.val
P sim.val
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
Diseqc
DiseqcDiseqc
Diseqc
 
Laboratory Report Sample
Laboratory Report SampleLaboratory Report Sample
Laboratory Report Sample
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
 
Unit_I.pptx
Unit_I.pptxUnit_I.pptx
Unit_I.pptx
 
Vista 1600 c epon olt quick start manual(r1.2)
Vista 1600 c epon olt quick start manual(r1.2)Vista 1600 c epon olt quick start manual(r1.2)
Vista 1600 c epon olt quick start manual(r1.2)
 
Real Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGAReal Time Clock Interfacing with FPGA
Real Time Clock Interfacing with FPGA
 
Ospf Last Modified Eng
Ospf  Last Modified EngOspf  Last Modified Eng
Ospf Last Modified Eng
 
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
DEF CON 27- SHEILA A BERTA - backdooring hardware devices by injecting malici...
 
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
Program, Code of Program and  Screen Shot of Output (UNIVERSAL DRIVER USING µ...Program, Code of Program and  Screen Shot of Output (UNIVERSAL DRIVER USING µ...
Program, Code of Program and Screen Shot of Output (UNIVERSAL DRIVER USING µ...
 
COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520COBOL DB2 BATCH EXAMPLE-RPR6520
COBOL DB2 BATCH EXAMPLE-RPR6520
 
MaxBotix Code Examples
MaxBotix Code ExamplesMaxBotix Code Examples
MaxBotix Code Examples
 
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
[嵌入式系統] MCS-51 實驗 - 使用 IAR (2)
 
COBOL BATCH EXAMPLE-RPR6621F
COBOL BATCH EXAMPLE-RPR6621FCOBOL BATCH EXAMPLE-RPR6621F
COBOL BATCH EXAMPLE-RPR6621F
 
PIC16F877A C Programming.ppt
PIC16F877A C Programming.pptPIC16F877A C Programming.ppt
PIC16F877A C Programming.ppt
 
Dam gate open close lpc prog
Dam gate open close lpc progDam gate open close lpc prog
Dam gate open close lpc prog
 

serialEEPROM

  • 1. ;******************************************************************************; ;@Date 02/07/2009 ;@Version 1.1 ;@Author Pedro Pablo Plazas R. ;@@@ Communication between Serial EEPROM 24LC04B(Slave) and PIC16F84A(Master) ; using 2-wire serial interface bus, I2C. ;Bus timing Start/Stop and data for a frequency equal to 6Mhz ;***************************************************************************** ;**** Signals ***** SDA equ 2 ;Signal data SCL equ 3 ;Signal clock CONSTANT CODE_DEVICE_W = b'10100000' ;Control byte for writting operations. CONSTANT CODE_DEVICE_R = b'10100001' ;Control byte for reading operations. ;***************************************************************** ; ;****************************************************************** EEPROM_init macro call EEP_init endm ;***************************************************************************** ;Rutine to write operation. ;Following the Start condition from the master, the device code(4 bits), ;the block address(3bits) and the R/W(-), bit which is a logic low is placed ;onto the bus by the master transmitter. ;***************************************************************************** EEPROM_Write_Data macro word_Address, data_Write call BIT_START ;//--Start bit call SEND_CMD_Writting ;//--Command to write (10100000) EEPROM_ACK movlw word_Address ;//--Send Word Address call SEND_Data_Or_Addr EEPROM_ACK movf data_Write,W ;//--Send byte to write. call SEND_Data_Or_Addr EEPROM_ACK ;//--ACK call BIT_STOP ;//--Stop bit endm ;******************************************************************* ;Page write. The write control byte, word address and the first data ;byte are transmitted to the 24XX04 in the same way as in a byte ;write. But instead of generating a Stop condition the master transmit ;up to 16 data bytes to the 24XX04. ;******************************************************************* EEPROM_Page_Write_Data macro word_Address, data_Write1, data_Write2 call BIT_START ;//--Start bit call SEND_CMD_Writting ;//--Command to write (10100000) EEPROM_ACK
  • 2. movlw word_Address ;//--Send Word Address call SEND_Data_Or_Addr EEPROM_ACK movf data_Write1,W ;//--Send byte1 to write. call SEND_Data_Or_Addr EEPROM_ACK ;//--ACK movf data_Write2,W ;//--Send byte2 to write. call SEND_Data_Or_Addr EEPROM_ACK ;//--ACK call BIT_STOP ;//--Stop bit endm EEPROM_Read_Data macro word_Address call BIT_START ;//--Start bit call SEND_CMD_Writting ;//--Command to write (10100000) EEPROM_ACK ;//--ACK movlw word_Address ;//--Send Word Address call SEND_Data_Or_Addr EEPROM_ACK call BIT_START ;//--Start bit call SEND_CMD_Reading ;//--Command to read (10100001) EEPROM_ACK ;//--ACK call READ_DATA ;//--READ DATA BYTE bcf EEPportB,SCL nop bsf EEPportB,SCL nop bcf EEPportB,SCL nop call BIT_STOP ;///Stop bit endm ;***************************************************************** ;Init ports MAster(PIC16F84) for communication with Slave(EEPROM) ;***************************************************************** EEP_init BANK1 clrf EEPtrisA clrf EEPtrisB bsf EEPtrisB,0 ;Input to push key. BANK0 clrf EEPportA clrf EEPportB bsf EEPportB,SDA bsf EEPportB,SCL RETURN ;***************************************************************** ;Generate Start o Stop bit ;***************************************************************** BIT_START bcf INTCON,GIE BANK1 bcf EEPtrisB,SDA BANK0 bsf INTCON,GIE call SCLK_BIT_START RETURN BIT_STOP
  • 3. bcf INTCON,GIE BANK1 bcf EEPtrisB,SDA BANK0 bsf INTCON,GIE call SCLK_BIT_STOP RETURN ;****************************************************************** ;Generating acknowlegde signal ;****************************************************************** EEPROM_ACK macro local ReadAck, EndAck bcf INTCON,GIE BANK1 bsf EEPtrisB,SDA BANK0 bsf INTCON,GIE ReadAck btfsc EEPportB,SDA goto ReadAck bsf EEPportB,SCL nop nop bcf EEPportB,SCL endm ;**************************************************************************** ; Send one command or data(only to write) for writting or reading into EEPROM ;**************************************************************************** SEND_CMD_Writting movlw CODE_DEVICE_W ;Control byte to write goto SEND_Data_Or_Addr SEND_CMD_Reading movlw CODE_DEVICE_R ;Control byte to read SEND_Data_Or_Addr movwf BYTE_TX bcf INTCON,GIE BANK1 bcf EEPtrisB,SDA BANK0 bsf INTCON,GIE movlw 0x08 movwf COUNT_BITS SENDCtrl btfsc BYTE_TX,7 goto SEND_SB bcf EEPportB,SDA goto ROT_BITS SEND_SB bsf EEPportB,SDA ROT_BITS call SCLK_DATA rlf BYTE_TX,1 decfsz COUNT_BITS,F goto SENDCtrl RETURN ;************************************************************ ;Reading data from EEPROM ;************************************************************
  • 4. READ_DATA bcf INTCON,GIE BANK1 bsf EEPtrisB,SDA BANK0 bsf INTCON,GIE movlw .8 movwf COUNT_BITS ROT_DATA_BITS rlf REG_DATA,F btfss EEPportB,SDA bcf REG_DATA,0 btfsc EEPportB,SDA bsf REG_DATA,0 call SCLK_DATA decfsz COUNT_BITS,F goto ROT_DATA_BITS movf REG_DATA,W RETURN ;******************************************************* ;Rutine to generate start condition setup time ;******************************************************* SCLK_BIT_START bcf EEPportB,SCL bsf EEPportB,SDA nop nop bsf EEPportB,SCL nop nop bcf EEPportB,SDA nop nop bcf EEPportB,SCL nop nop RETURN ;******************************************************* ;Rutine to generate start condition setup time ;******************************************************* SCLK_BIT_STOP bcf EEPportB,SDA nop nop bsf EEPportB,SCL nop nop bsf EEPportB,SDA nop nop bcf EEPportB,SCL nop nop RETURN ;************************************************************** ;Generating signal of clock for EEPROM(SCL), only one period ;************************************************************** SCLK_DATA nop
  • 5. nop bsf EEPportB,SCL nop nop nop nop bcf EEPportB,SCL RETURN ;**************************************** ;Routine to wait 100ms, to push any key ;**************************************** KeyWait movlw 0x96;--64(100ms) movwf RS_TIMER1 ;Delay of 1ms T_Wait movlw 0xFA movwf RS_TIMER2 T_Wx nop nop nop nop nop decfsz RS_TIMER2 goto T_Wx decfsz RS_TIMER1 goto T_Wait RETURN