piclist 2000\06\07\003821a >
Thread: 'F87xx Config Programming
face BY : Heinz Czychun email (remove spam text)

Hi All,

       Now that I've gotten one of the new Flash PIC chips (16F872), I
wanted to program it. As indicated by an email by Jim Robertson, my WARP-3
and MacPic will program the 'F872, by selecting the 'F84 as the chip to be
programmed. But it cannot program all the bits in the config register, and
I would like to put it into HVP mode to liberate RB3. So I looked at Tony
Nixon's RomZap, and saw that it used the PICs special address and data
registers to program the Flash Program Memory.

       I wrote a program that should have set the config reg to 0x3F3D.
But when I checked with TM4 it showed the bits still at 0x3FF1. I also then
loaded a flasher program that increments port B, and only pins RB0-2
oscillate as they should, the ones above these are low.

       Is what I'm trying to do possible or have I done something wrong in
the program ?

       The wording in DS30221 page 110 seems to preclude this, but then it
says "...LVP bit can only be charged when using high voltage on ~MCLR." So
this seems it might be possible since I am "discharging" the LVP bit, or is
this semantics?


My program follows.....

;======= Flash_PROM_Config_reg_Demo ===================== 6/6/2000 ==
; This program will use the special registers within the 'F872
; to set the Config register.
; This can be checked with TM4 on the Compaq
       list    p=16F84         ; used since there is no 16F872
                               ; this already means that MacPic
                               ; cannot be used to program the
                               ; config register, and may mean that
                               ; that the full 2K of the 'F872 may
                               ; not be accessable for programming
       radix   hex
;       cpu equates (memory map)
indf           equ     0x00     ; indirect addressing Reg
tmr0           equ     0x01     ; Timer/Counter register
pcl            equ     0x02     ; program counter (low byte)
status         equ     0x03     ; status reg
fsr            equ     0x04     ; file select register
porta          equ     0x05     ; port A
portb          equ     0x06     ; port B
portc          equ     0x07     ; port C
       ; Note these registers are on page 1
opt_reg        equ     0x01     ; MPU Option Register
trisa          equ     0x05     ; Data Direction Port A
trisb          equ     0x06     ; Data Direction Port B
trisc          equ     0x07     ; Data Direction Port C
       ; Note these registers are on page 2
EEData         equ     0x0C     ; EEPROM Data reg
EEDataH        equ     0x0E     ; EEPROM Data reg high byte
EEAdr          equ     0x0D     ; EEPROM Address reg
EEAdrH         equ     0x0F     ; EEPROM Address reg high byte
       ; Note these registers are on page 3
EECon1         equ     0x0C     ; EEPROM Control reg 1
EECon2         equ     0x0D     ; EEPROM Control reg 2
;       bit equates
rp0           equ     0x05      ; bank select low bit
rp1           equ     0x06      ; bank select high bit
zBit          equ     0x02      ; Zero flag
rd            equ     0x00      ; EEPROM read control bit
wr            equ     0x01      ; EEPROM write control bit
wren          equ     0x02      ; EEPROM write enable bit
eepgd         equ     0x07      ; Flash EPROM write enable bit
LED           equ     0x04      ; pin for LED
       org     0x000
       goto    main
       bsf     status,rp0      ; switch to bank 1
       movlw   b'00000000'     ; outputs
       movwf   trisa
       movwf   trisb
       movwf   trisc
       bcf     status,rp0      ; switch back to bank 0
       movlw   0xFF            ; all Port A & B outputs high
       movwf   porta           ;
       movwf   portb
       call    init
       ; setup Flash PROM to set config reg at 0x2007
       bsf     status,rp1      ; switch to bank 2
       movlw   0x20            ; initialize EEPROM address to
       movwf   EEAdrH          ; config register
       movlw   0x07
       movwf   EEAdr
       movlw   0x3F            ; initialize config register
       movwf   EEDataH         ; data to 0x3F3D
       movlw   0x3D            ; HV programming only
       movwf   EEData
       bcf     status,rp1      ; switch back to bank 0
       call    WriteEEPROM     ; load value into EEPROM
       bcf     portA, LED      ; turn LED on (diagnostic)
       goto    LoadDone        ; just wait here
; **** NOTE THIS STILL MUST BE UPDATED FOR 'F872 operation ***
; on entry addressPtr holds the address of the EEPROM to be read
; on exitdataPtr holds the data that was read
; Address and data already set-up
;       Note that normally the set-up would be done here from
;       a 16bit data buffer (actually 14bit), and a 16bit address pointer
       bsf     status, rp0     ; page select, page 3
       bsf     status, rp1     ;
       bsf     EECon1, eepgd   ; point to flash (program) memory
       bsf     EECon1, wren    ; enable write
       movlw   0x55            ; send 'magic' numbers to
       movwf   EECon2          ; EEPROM Control reg 2
       movlw   0xAA
       movwf   EECon2
       bsf     EECon1, wr      ; initiate write command
;       btfsc   EECon1, wr      ;Spec sheets show this as not necessary
;       goto    WriteCompl      ;
                               ; write is now complete
       bcf     status, rp0     ; switch back to page 0
       bcf     status, rp1
;at blast time, select:
;       memory                          unprotected
;       Debug                           disabled
;       Flash Program Memeory write     enabled
;       Data EE Code protection         off
;       Low Voltage Programming         disabled
;       Brown-out reset                 disabled
;       watchdog timer                  disabled (default is enabled)
;       standard crystal                XT
;       (using 4 MHz osc for test)
;       power-up timer                  on


See also: www.piclist.com/techref/microchip/devprogs.htm?key=programming
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) 'F87xx Config Programming

month overview.

new search...