sush
Member level 4
pic16f628 eeprom
dear all
m trying to use internal eeprom of pic16f628 to read and write data .this is the code below .m not getting the correct output .please help me find the mistake
dear all
m trying to use internal eeprom of pic16f628 to read and write data .this is the code below .m not getting the correct output .please help me find the mistake
Code:
LIST p=16F628a ;tell assembler what chip we are using
include "P16F628a.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__CONFIG _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT & _PWRTE_ON & _LVP_OFF & _BODEN_OFF & _MCLRE_OFF
cblock 0x20 ;start of general purpose registers
count ;used in looping routines
count1 ;used in delay routine
counta ;used in delay routine
countb ;used in delay routine
prom_ADDR
prom_DATA
endc
org 0x0000
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
Initialise clrf count
clrf PORTA
clrf PORTB
clrf prom_ADDR
clrf prom_DATA
SetPorts bsf STATUS, RP0 ;select bank 1
movlw 0x00 ;make all pins outputs
movwf TRISA
movwf TRISB
bcf STATUS, RP0 ;select bank 0
call Delay255
call Delay255
call Delay255
call Delay255
movlw 0x50
movwf prom_ADDR
movlw 0x12
movwf prom_DATA
call write_eeprom
call Delay20
movlw 0x50
movwf prom_ADDR
call read_eeprom
movf prom_DATA, w
movwf PORTB
stop goto stop
;Subroutines
write_eeprom
BSF STATUS, RP0 ;Bank 1
movlw prom_ADDR
movwf EEADR
movf prom_DATA, w
movwf EEDATA
BSF EECON1, WREN ;Enable write
;BCF INTCON, GIE ;Disable INTs.
MOVLW 0x55 ;
MOVWF EECON2 ;Write 55h
MOVLW 0xAA ;
MOVWF EECON2 ;Write AAh
BSF EECON1,WR ;Set WR bit
;begin write
;BSF INTCON, GIE ;Enable INTs.
BCF STATUS, RP0 ;Bank 0
retlw 0x00
read_eeprom
BSF STATUS, RP0 ;Bank 1
MOVLW prom_ADDR ;
MOVWF EEADR ;Address to read
BSF EECON1, RD ;EE Read
MOVF EEDATA, W ;W = EEDATA
movwf prom_DATA
BCF STATUS, RP0 ;Bank 0
return
Delay255 movlw 0xff ;delay 255 mS
goto d0
Delay100 movlw d'100' ;delay 100mS
goto d0
Delay50 movlw d'50' ;delay 50mS
goto d0
Delay20 movlw d'20' ;delay 20mS
goto d0
Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
d0 movwf count1
d1 movlw 0xC7 ;delay 1mS
movwf counta
movlw 0x01
movwf countb
Delay_0
decfsz counta, f
goto $+2
decfsz countb, f
goto Delay_0
decfsz count1 ,f
goto d1
retlw 0x00
end