Serial eeprom to PIC16F84 interface
This programm send first a data (F0h) to eeprom at address 00FFh and then data from address 00FFh it's read from eeprom and displayed to portB.
;=======eeprom_i2c / Version 1.0====================17/01/03== ; st24c64w ; ra0,ra1 sdata,sclock ; rb0 to rb7 ; internal clock ; standard crystal 4.000 MHz XT - 1us pe instructiune ; Program realizat de Ing. Bergthaller Iulian-Alexandru ;------------------------------------------------------------ list p=16f84A;f=inhx8m _CP_OFF equ H'3FFF' ;code protect off _PWRTE_ON equ H'3FFF' ;Power on timer on _WDT_OFF equ H'3FFB' ;watch dog timer off _XT_OSC equ H'3FFD' ;crystal oscillator __CONFIG _CP_OFF & _PWRTE_ON & _WDT_OFF & _XT_OSC ;------------------------------------------------------------ ; cpu init status equ 03 porta equ 05 portb equ 06 count1 equ 0C count2 equ 0D count3 equ 0E transo equ 0F count4 equ 10 trisa equ 85 trisb equ 86 #DEFINE sclk porta,1 #DEFINE sdta porta,0 ;------------------------------------------------------------ ; bit init rp0 equ 5 devicew equ 0xA0 devicer equ 0xA1 ;------------------------------------------------------------ org 0 ; ;------------------------------------------------------------ init bsf status,rp0 ;switch to bank 1 movlw 0 ;outputs movwf trisb bcf status,rp0 ;switch back to bank 0 movlw 0 movwf portb ;*************************************************** start movlw 0xFF movwf portb call pause call scrie call pause weit nop call lesen call pause goto weit ;*************************************************** scrie call sout; write datas to address adresl+adresh movlw 0x00 movwf portb call alos bsf portb,0 movlw devicew movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf portb,1 movlw 0x00 movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf portb,2 movlw 0xFF movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf portb,3 movlw 0xF0 movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf porta,3 call ahalt call pause bcf porta,3 retlw 00 ;*************************************************** lesen call sout movlw 0x00 movwf portb call alos bsf portb,0 movlw devicew movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf portb,1 movlw 0x00 movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause call sout bcf portb,7 bsf portb,2 movlw 0xFF movwf transo call varsa bsf portb,7 call srin call antwt ; antwort aus eeprom call pause bcf portb,7 bsf portb,3 call sout; current address read call alos bsf porta,2 movlw devicer movwf transo call varsa bcf porta,2 call srin call antwt ; antwort aus eeprom call scana ; eeprom lesen call sout bsf porta,3 call ahalt call pause bcf porta,3 retlw 00 ;*************************************************** sout bsf status,rp0 ;switch to bank 1 movlw 0 ;outputs movwf trisa bcf status,rp0 ;switch back to bank 0 movlw 0 movwf porta retlw 00 ;*************************************************** srin bsf status,rp0 ;switch to bank 1 movlw 01 ;input movwf trisa; set sda as input bcf status,rp0 ;switch back to bank 0 retlw 00 ;*************************************************** alos bsf sdta; start condition module bcf sclk call pause bsf sclk call pause bcf sdta; comanda start call pause bcf sclk call pause retlw 00 ;*************************************************** ahalt bcf sdta; stop condition module call pause bsf sclk call pause bsf sdta; comanda stop call pause bcf sclk call pause retlw 00 ;*************************************************** varsa bcf sclk call pause btfsc transo,7 ;bit0(MSB) bsf sdta btfss transo,7 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,6 ;bit1 bsf sdta btfss transo,6 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,5 ;bit2 bsf sdta btfss transo,5 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,4 ;bit3 bsf sdta btfss transo,4 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,3 ;bit4 bsf sdta btfss transo,3 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,2 ;bit5 bsf sdta btfss transo,2 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,1 ;bit6 bsf sdta btfss transo,1 bcf sdta call pause bsf sclk call pause bcf sclk call pause btfsc transo,0 ;bit7(LSB) bsf sdta btfss transo,0 bcf sdta call pause bsf sclk call pause bcf sclk retlw 00 ;*************************************************** scana call pause bsf sclk btfsc sdta ;bit0(MSB) bsf portb,7 btfss sdta bcf portb,7 bcf sclk call pause bsf sclk btfsc sdta ;bit1 bsf portb,6 btfss sdta bcf portb,6 bcf sclk call pause bsf sclk btfsc sdta ;bit2 bsf portb,5 btfss sdta bcf portb,5 bcf sclk call pause bsf sclk btfsc sdta ;bit3 bsf portb,4 btfss sdta bcf portb,4 bcf sclk call pause bsf sclk btfsc sdta ;bit4 bsf portb,3 btfss sdta bcf portb,3 bcf sclk call pause bsf sclk btfsc sdta ;bit5 bsf portb,2 btfss sdta bcf portb,2 bcf sclk call pause bsf sclk btfsc sdta ;bit6 bsf portb,1 btfss sdta bcf portb,1 bcf sclk call pause bsf sclk btfsc sdta ;bit7(LSB) bsf portb,0 btfss sdta bcf portb,0 bcf sclk call pause bsf sclk call pause bcf sclk retlw 00 ;*************************************************** antwt movlw 0x04 movwf count4 bsf sclk call pause ackts btfss sdta ;sda=0 ? goto eprok decfsz count4 goto ackts call fails eprok bcf sclk retlw 00 ;*************************************************** fails movlw 0 movwf portb call pause movlw 0xFF movwf portb call pause movlw 0 movwf portb call pause retlw 00 ;*************************************************** pause movlw 0x02 movwf count3 d3 movlw 0xF0 movwf count1 d1 movlw 0xF0 movwf count2 d2 decfsz count2 goto d2 decfsz count1 goto d1 decfsz count3 goto d3 retlw 00 ;------------------------------------------------------------ end ;============================================================
The hex code can be download from here.
The last version it's now available.