Chip killer code - dont know why??

Status
Not open for further replies.

noel

New Member
Below is code for a programme i was mucking around with
basically using timers to flash led's on/off instead of loops

however anychip i burn the code too it prevents further erasing/reprogramming
i have tried 5 chips all with the same result - they are 16f628a / 16f648a

below is my code
i would like to know what the problem is that it 'kills' chips?????
Also how do i fix the code and how do ifix the chips if possible????
Many thanks
noel


;16f628A pin connections
; ra2 | | ra1 - output
; ra3 | | ra0 - output
; ra4 | | ra7
; ra5 | | ra6
; ground | | Supply
; rb0 | | rb7
; rb1 | | rb6
; rb2 | | rb5
; rb3 | | rb4




#DEFINE BANK0 BCF STATUS,5 ; define STATUS register bit 5 clear as BANK0
#DEFINE BANK1 BSF STATUS,5 ; define STATUS register bit 5 set as BANK1
#DEFINE T01F INTCON,2
#define T01E INTCON,5

#define TIMEROFF bcf T1CON,0
#define TIMERON bsf T1CON,0

list p=16f628a ; tell MPASM-type programmer to create a
; list (LST) file

include p16f628.inc ; bring in all standard register values

CBLOCK h'20'
BRIGHTNESS
ENDC

__config 0x3F18 ; internal 4MHz oscillator

ORG 0 ; reset vector

goto STARTIT
ORG 4 ;Interrupt Vector Address
;if an interrupt occurs the CPU will
;be directed to address $0004
;when the PIC is in programming mode it sets its
;internal counter to $0000 which is the reset
;vector address.The writer of the TASM
;programming toolkit decided to have
;it set this internal counter to $0005
;Thus .ORG $0004 must be used at the
;start of all TASM programs.
;Addresses $0001 to $0003 are not used with TASM
goto STARTIT
ORG 5 ; PIC program memory location at which to start
goto STARTIT




STARTIT BANK0
clrf PORTA ; clear PORTA's output if any
clrf PORTB ; clear PORTB's output if any
movlw 0x07 ; needed by some PICs, including PIC16F628
movwf CMCON ; so that PORTA is treated as digital port

BANK1
movlw b'00000000' ; all PORTA as output
movwf TRISA ; data direction register for PORTA
movlw b'00000000' ; PORTB as output
movwf TRISB ; data direction register for PORTB
bsf PIE1,0 ;enable interrupts
BANK0
movlw b'01111011' ; using compare tr2
movwf T2CON
movlw b'00111100'
movwf T1CON
movlw b'00001111'
movwf CCPR1L
movlw b'00001010'
movwf CCP1CON
;CLRWDT


movlw b'00000010'
movwf PORTA

goto LOOP

DELAY TIMEROFF
movlw 0xaa
movwf TMR1H
movwf TMR1L
bsf INTCON,6
bcf PIR1,0

TIMERON

btfsc PIR1,0
goto $+2
goto $-2
bcf PIR1,0
movlw b'00000001'
xorwf PORTA,f

return

LOOP bsf PORTA,3
call DELAY
bcf PORTA,3
call DELAY
goto LOOP



NOMORE goto NOMORE

END
 
You have configured the chip to use the internal oscillator and have disabled the mclr pin to use it as RA5 (configuration word bit5=0).

This causes some programmers to be unable to re-program the chip because it starts to run before the programmer has chance to put it into program mode.
It is a common problem that has been discussed several times in this forum, eg.
https://www.electro-tech-online.com/threads/p16f628a-w-p16pro-programming-problem.14248/
https://www.electro-tech-online.com/threads/oooops-think-i-killed-my-pic16f628a.38975/

To get your chips to program again, you either need to modify the software or hardware of your existing programmer depending on what it is, or change it for a compatible type.

What type of programmer are you using?
 
It is because you have !MCLR configured as a digital IO pin with an internal oscillator, rather than using the pin as a clear. This is not recommended by Microchip.
0x3F18 is binary 11 1111 0001 1000 When bit 5 is clear, this is how it works
Try 0x3F38 instead.

Edit: OK, I'm a bit slow, as picasm beat me to it.
 
Last edited:
below is my code
The other guys seem to have given you the answer, but I'm going to try to clarify things a bit more. You need to start using the mnemonics to set your config bits instead of just a number. With the number you can't tell at a glance what bits are set or cleared. With the mnemonics you can. You'll find them at the bottom of the P16F628.inc file, which is located (typically) in the c:\Program Files\Microchip\MPASM Suite directory.

Here's the list:
Code:
;==========================================================================
;
;       Configuration Bits
;
;==========================================================================

_BODEN_ON                    EQU     H'3FFF'
_BODEN_OFF                   EQU     H'3FBF'
_CP_ALL                      EQU     H'03FF'
_CP_75                       EQU     H'17FF'
_CP_50                       EQU     H'2BFF'
_CP_OFF                      EQU     H'3FFF'
_DATA_CP_ON                  EQU     H'3EFF'
_DATA_CP_OFF                 EQU     H'3FFF'
_PWRTE_OFF                   EQU     H'3FFF'
_PWRTE_ON                    EQU     H'3FF7'
_WDT_ON                      EQU     H'3FFF'
_WDT_OFF                     EQU     H'3FFB'
_LVP_ON                      EQU     H'3FFF'
_LVP_OFF                     EQU     H'3F7F'
_MCLRE_ON                    EQU     H'3FFF'
_MCLRE_OFF                   EQU     H'3FDF'
_ER_OSC_CLKOUT               EQU     H'3FFF'
_ER_OSC_NOCLKOUT             EQU     H'3FFE'
_INTRC_OSC_CLKOUT            EQU     H'3FFD'
_INTRC_OSC_NOCLKOUT          EQU     H'3FFC'
_EXTCLK_OSC                  EQU     H'3FEF'
_LP_OSC                      EQU     H'3FEC'
_XT_OSC                      EQU     H'3FED'
_HS_OSC                      EQU     H'3FEE'

Here's a typical __config line for a 16F628:
Code:
	__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _LVP_OFF


You should also always use the CODE tags when posting code here. The easy way is to click the # icon just before pasting your code. You can also do it manually by typing in [code] before your code and [/code] after it.

Here's your code looking much better:
Code:
	processor 16f628
	include "P16F628.inc"
	__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _LVP_OFF

	cblock	0x20
	BRIGHTNESS
	endc

	org	0
start	clrf	PORTA
	clrf	PORTB
	movlw	0x07		;disable comparators
	movwf	CMCON
	banksel	TRISA		;bank 1
	movlw	0		;all PORTA as output
	movwf	TRISA
	movwf	TRISB
	banksel	PORTA		;bank 0
	movlw	b'01111011'	; using compare tr2
	movwf	T2CON
	movlw	b'00111100'
	movwf	T1CON
	movlw	b'00001111'
	movwf	CCPR1L
	movlw	b'00001010'
	movwf	CCP1CON
	movlw	b'00000010'
	movwf	PORTA
	goto	LOOP

DELAY	bcf	T1CON,0
	movlw	0xaa
	movwf	TMR1H
	movwf	TMR1L
	bsf	INTCON,6
	bcf	PIR1,0
	bsf	T1CON,0
	btfsc	PIR1,0
	goto	$+2
	goto	$-2
	bcf	PIR1,0
	movlw	b'00000001'
	xorwf	PORTA,f
	return

LOOP	bsf	PORTA,3
	call	DELAY
	bcf	PORTA,3
	call	DELAY
	goto	LOOP
NOMORE	goto	NOMORE
	end
 
Last edited:
Even when you fix the config problem you still will have problems. You also have timer 1 setup to use the timer 1 oscillator and this can prevent chips from being erased. Either switch to the internal oscillator (T1CON.3=0) or switch to a chip where the timer 1 oscillator does not share the programming pins.

BTW, these chips can sometimes be erased using a Pickit2 by initialising the programmer with a good chip, swapping in the bad chip and immediately issuing an erase command.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…