;************************************************************************* ;** ** ;** A Simple program for erasing PIC16F628A ** ;** ** ;** * You can use this code for watever you wish, but I take no ** ;** responsability for any injury, damage to property or ** ;** copywrite breaches. ** ;** ** ;** Rev 1: 08/11/2003 -Added a delay loop during reset to let ** ;** the powersupply to have time to settle. ** ;** More info see: member.newsguy.com/~rhuang ** ;************************************************************************* include __config _XT_OSC & _WDT_OFF ;***************************************************************** ;** Variables Counter1 EQU 0ch OutData EQU 0dh DataH EQU 0eh DataL EQU 0fh Counter2 EQU 10h ORG 0 goto Start ORG 4 goto Interrupt ;***************************************************************** ;* RB0 - MCLR, active low ;* RB1 - LVP, active high ;* RB2 - VCC, active high ;* RB3 - DATA ;* RB4 - CLOCK ;******************** Program Start here Start: bsf PORTB, 0 ;Set first bsf STATUS, RP0 movlw 0x00 movwf TRISB ;Set port B to output clrf TRISA bcf STATUS, RP0 clrf PORTA call Delay ;******************** Program start bsf PORTA, 0 bcf PORTB, 0 ;12V on bsf PORTB, 2 ;Apply power bsf PORTB, 1 ;LVP on bsf PORTB, 3 bsf PORTB, 4 bsf PORTA, 1 ;Erase start ;-------------------- Move PC to 0x2000 movlw b'00000000' movwf OutData call SendCommand movlw 0xff movwf DataH movwf DataL call SendData movlw b'00000010' ;Set data for programming movwf OutData call SendCommand movlw 0xff movwf DataH movwf DataL call SendData movlw b'00001001' ;Bulk erase movwf OutData call SendCommand bcf PORTA, 1 ;Done EndProgram: goto EndProgram SendCommand: movlw 06h movwf Counter1 CommandLoop: bsf PORTB, 4 bcf PORTB, 3 btfsc OutData, 0 bsf PORTB, 3 rrf OutData bcf PORTB, 4 decfsz Counter1 goto CommandLoop return SendData: bcf DataL, 0 bcf DataH, 7 movlw 10h movwf Counter1 DataLoop: bsf PORTB, 4 bcf PORTB, 3 btfsc DataL, 0 bsf PORTB, 3 rrf DataH rrf DataL bcf PORTB, 4 decfsz Counter1 goto DataLoop return ;********************** A 197mS delay loop Delay: clrf Counter1 clrf Counter2 DelayLoop: DelayLoop2: decfsz Counter2 goto DelayLoop2 decfsz Counter1 goto DelayLoop return Interrupt: retfie end