summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2013-07-11 02:11:50 +0000
committerChristian Pointner <equinox@spreadspace.org>2013-07-11 02:11:50 +0000
commit57b3981d45149f747e820290cdfe296eb026b041 (patch)
tree27a3e5d5c4dba626f144cc1f90ca87daba87dfb5
parentflash write address checks work (diff)
writing flash works now for 16f1847
git-svn-id: https://svn.spreadspace.org/pic/trunk@79 a09c6847-51d9-44de-8ef2-e725cf50f3c7
-rw-r--r--bootloader/cmds-16f1847.inc97
1 files changed, 55 insertions, 42 deletions
diff --git a/bootloader/cmds-16f1847.inc b/bootloader/cmds-16f1847.inc
index bb51298..d5be38d 100644
--- a/bootloader/cmds-16f1847.inc
+++ b/bootloader/cmds-16f1847.inc
@@ -76,50 +76,63 @@ cmd_w_flash
andwf combuff + .2,w
btfss STATUS,Z
goto address_invalid
-;; movlw FSS ; initialize EEADR:EEADRH and FSR
-;; movwf cnt
-;; movlw b'01011000'
-;; movwf STATUS
-;; movlw combuff + .2
-;; movwf FSR
-;; movf INDF,w
-;; movwf EEADR
-;; incf FSR,f
-;; movf INDF,w
-;; movwf EEADRH
+ movlw FSS ; initialize EEADR:EEADRH and FSR
+ movwf cnt
+ movlb .3
+ movlw combuff + .2
+ movwf FSR
+ movf INDF,w
+ movwf EEADRL
+ incf FSR,f
+ movf INDF,w
+ movwf EEADRH
+ bcf EECON1,CFGS
+ bsf EECON1,EEPGD
+ bsf EECON1,WREN
+
+write_flash_segment_loop
+ incf FSR,f ; load code word into EEDAT:EEDATH
+ movf INDF,w
+ movwf EEDATL
+ incf FSR,f
+ movf INDF,w
+ movwf EEDATH
-;; write_flash_segment_loop
-;; incf FSR,f ; load code word into EEDAT:EEDATH
-;; movf INDF,w
-;; movwf EEDAT
-;; incf FSR,f
-;; movf INDF,w
-;; movwf EEDATH
+ bsf EECON1,FREE ; erase row before writing
+ movlw H'55'
+ movwf EECON2
+ movlw H'AA'
+ movwf EECON2
+ bsf EECON1,WR
+ nop
+ nop
+ bcf EECON1,FREE ; now start the acutal write sequence
+ movf EEADRL,w
+ andlw FLASH_BOUNDARY
+ xorlw FLASH_BOUNDARY
+ btfss STATUS,Z
+ bsf EECON1,LWLO
+ btfsc STATUS,Z
+ bcf EECON1,LWLO
+ movlw H'55'
+ movwf EECON2
+ movlw H'AA'
+ movwf EECON2
+ bsf EECON1,WR
+ nop
+ nop
+ incfsz EEADRL,f ; increment flash address
+ goto write_flash_segment_next
+ incf EEADRH,f
+write_flash_segment_next
+ decfsz cnt,f
+ goto write_flash_segment_loop
-;; bsf STATUS,RP0 ; now start the acutal write sequence
-;; bsf EECON1,EEPGD
-;; bsf EECON1,WREN
-;; movlw H'55'
-;; movwf EECON2
-;; movlw H'AA'
-;; movwf EECON2
-;; bsf EECON1,WR
-;; nop
-;; nop
-;; bcf EECON1,WREN
-;; bcf STATUS,RP0
-;; incfsz EEADR,f ; increment flash address
-;; goto write_flash_segment_next
-;; incf EEADRH,f
-;; write_flash_segment_next
-;; decfsz cnt,f
-;; goto write_flash_segment_loop
-;; bsf STATUS,RP0
-;; clrw ; check if a write error occured
-;; btfsc EECON1,WRERR
-;; movlw E_FLASH_WERR
-;; bcf STATUS,RP1
-;; bcf STATUS,RP0
+ bcf EECON1,WREN
+ clrw ; check if a write error occured
+ btfsc EECON1,WRERR
+ movlw E_FLASH_WERR
+ movlb .0
movwf combuff + .2 ; = E_OK
movlw .1 ; bytes to send
call send_answer