PDA

View Full Version : PIC18F1220 locked up



eggman
- 7th April 2011, 14:43
Hi everyone,
I'm trying to make an 80 year countdown timer for an art project using a PIC18F1220. I'm using MPASM and PBP2.60.
When I copy the configs from P18F1220.INC file and paste them in my code it will compile fine and also my pickit2 does not complain. Only thing is that after programming the chip locks up and I cannot reprogram or erase it.
If I leave out the configs and use the ones in the PBP inc file it will program but my pickit2 says there's some config words not in the hex file.
I already lost three chips this way, anybody has an idea why? and is there a way to unlock the chips?
Thanks a lot



' 80 year countdown clock, thanks to Bill Legge for the MAX7221 code

@__CONFIG _CONFIG1H, _IESO_ON_1H & _FSCM_OFF_1H & _RC_OSC_1H
@__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
@__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_32K_2H
@__CONFIG _CONFIG3H, _MCLRE_OFF_3H
@__CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_ON_4L & _STVR_ON_4L

@__CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
@__CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
@__CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
@__CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
@__CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
@__CONFIG _CONFIG7H, _EBTRB_OFF_7H


include "modedefs.bas"

define OSC 4
PORTA = %00000000
PORTB = %00000000
TRISA = %00000000
TRISB = %00000000
OSCCON = %01100000 '4MHZ clock
ADCON0 = %00000000
ADCON1 = %11111111
INTCON = %11000000
T1CON = %00001101
PIE1.0 = 1
preset con 45543

CS_Max1 VAR PORTB.4 ' Chip select for MAX7221 IC1
CS_Max2 VAR PORTB.3 ' Chip select for MAX7221 IC2
CS_DS VAR PORTB.2 ' Chip select for DS1302 IC
clockpin VAR PORTB.0 ' Clock for SPI communication
datapin VAR PORTB.1 ' Serial Data Out for SPI communication
servo var PORTB.5


rtcyear VAR BYTE ' Allocate variables
rtcday VAR BYTE
rtcmonth VAR BYTE
rtcdate VAR BYTE
rtchr VAR BYTE
rtcmin VAR BYTE
rtcsec VAR BYTE
rtccontrol VAR BYTE
command var byte
counter var word
I var byte
temp var byte
temp2 var word
temp3 var long
temp4 var word
old_second var byte
servoCounter var word
flag1 var bit
flag2 var bit

clear

'GoSub settime

pause 100
init:

HIGH CS_Max1
HIGH CS_Max2
pause 100

low CS_Max2
shiftout datapin,clockpin,1,[1,%01001110] ' "S"
high CS_Max2

low CS_Max2
shiftout datapin,clockpin,1,[2,%01001111] ' "E"
high CS_Max2

low CS_Max2
shiftout datapin,clockpin,1,[3,%01011011] ' "C"
high CS_Max2

low CS_Max2
shiftout datapin,clockpin,1,[4,%00000000] ' blank digit
high CS_Max2

LOW CS_Max1
shiftout datapin,clockpin,1,[$09,%11111111] ' Decode register - all 8 digits
HIGH CS_Max1

LOW CS_Max2
shiftout datapin,clockpin,1,[$09,%11110000] ' Decode register - decode only 4 digits
HIGH CS_Max2

LOW CS_Max1
LOW CS_Max2
shiftout datapin,clockpin,1,[$0A, $0F] ' Intensity register - 32/32 brightness
HIGH CS_Max1
HIGH CS_Max2

low CS_Max1
low CS_Max2
shiftout datapin,clockpin,1,[$0B, $07] ' Scan limit register - display all digits
high CS_Max1
high CS_Max2 ' otherwise not equally bright

LOW CS_Max1
LOW CS_Max2
shiftout datapin,clockpin,1,[$0F, $00] ' test mode off
HIGH CS_Max1
HIGH CS_Max2

LOW CS_Max1
LOW CS_Max2
shiftout datapin,clockpin,1,[$0C, $01] ' normal operation
HIGH CS_Max1
HIGH CS_Max2


on interrupt goto myint



loop1
gosub calculate
pauseus 1000
goto loop1


calculate:
gosub gettime
if rtcsec <> old_second then
temp3 = 0
for counter = 1 to rtcmonth
lookup2 counter,[31,28,31,30,31,30,31,31,30,31,30,31],temp2
temp3 = temp3 + temp2
next
temp3 = ((60 - rtcyear) * 365) - temp3 'aantal dagen
temp3 = ((temp3 * 24)-rtchr) 'aantal uren
temp3 = (temp3 * 60) - rtcmin 'aantal minuten
temp3 = (temp3 * 60) - rtcsec 'aantal seconden
old_second = rtcsec
gosub display
endif

return

disable

gettime:
CS_DS = 1
ShiftOut datapin, clockpin, LSBFIRST, [$BF]
ShiftIn datapin, clockpin, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
CS_DS = 0
temp = (rtcsec/16) * 10 + (rtcsec//16)
rtcsec = temp
temp = (rtcmin/16) * 10 + (rtcmin//16)
rtcmin = temp
temp = (rtchr/16) * 10 + (rtchr//16)
rtchr = temp
temp = (rtcyear/16) * 10 + (rtcyear//16)
rtcyear = temp
temp = (rtcday/16) * 10 + (rtcday//16)
rtcday = temp
temp = (rtcmonth/16) * 10 + (rtcmonth//16)
rtcmonth = temp
temp = (rtcdate/16) * 10 + (rtcdate//16)
rtcdate = temp
Return



display:
for I=0 to 3
low CS_Max2
shiftout datapin,clockpin,1,[I+5,temp3 dig I]
high CS_Max2
next I
for I=0 to 7 ' higher part of display
low CS_Max1
shiftout datapin,clockpin,1,[I+1,temp3 dig (I+2)]
high CS_Max1
next I
return

settime:
rtcyear = $11
rtcday = $01
rtcmonth = $4
rtcdate = $5
rtchr = $11
rtcmin = $07
rtcsec = 0
CS_DS = 1
ShiftOut datapin, clockpin, LSBFIRST, [$8E, 0]
CS_DS = 0
CS_DS = 1
ShiftOut datapin, clockpin, LSBFIRST, [$BE, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
CS_DS = 0
Return



myint:
if PIR1.0 = 1 then
PIR1.0 = 0
servo = 1
pauseus 1000 + servoCounter
servo = 0
temp4 = preset
TMR1H = temp4.highbyte
TMR1L = temp4.lowbyte
flag1 = 0
endif
if flag2 = 0 then
if servoCounter >= 1000 then
flag2 = 1
goto myint
endif
servoCounter = servoCounter + 5
else
if servoCounter <= 0 then
flag2 = 0
goto myint
endif
servoCounter = servoCounter - 5
endif

resume

end

Bruce
- 7th April 2011, 16:01
Try _LVP_OFF_4L

eggman
- 7th April 2011, 21:29
Thank you Bruce, tried it, and another chip locked up, good hint though.
Any other ideas?
Thanks

Bruce
- 7th April 2011, 21:44
More information would really help. You have _RC_OSC_1H, which configures the PIC for an external RC oscillator, and you have DEFINE OSC 4.

Are you using an external RC oscillator, crystal, resonator, or what?

Does it work as expected when you do NOT include config settings in your code?

Pickit2 may just be complaining that you don't have all config settings in your code, but if it actually works, when you don't, then it's pretty obvious what's causing the problem.

Just compare your config settings to the default settings in the PBP .INC file.

eggman
- 8th April 2011, 10:07
Okay, I compared all the fuses and found out this one locks it up:
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
It is hex 08, if I change it to hex 0F all is fine. Has to do with the brown-out settings. Could be the brown out voltage or the brown-out ON/OFF bit. Don't want to destroy another chip (my last one) so will leave it for now. But weird it is, is there any way to unlock these chips?
Thank you,
Kees

Dave
- 8th April 2011, 11:31
eggman , All configuration bits are re-programmable. I don't see why you call the chip destroyed? Just reconfigure it using MPLAB and the PIckit2...

Dave Purola,
N8NTA

Bruce
- 8th April 2011, 11:48
See #4 on this page: http://melabs.com/support/icsp.htm

If you previously programmed a few with LVP enabled, you may need to ground the LVP pin to reprogram them.

eggman
- 8th April 2011, 13:50
Well, I tried to program with RB5 (PGM) pulled low, still no luck. As soon as I try to start my Pickit2 with the PIC connected it reports: Device Error - hex file not loaded. So it will no longer recognize the wrongly programmed PICs, maybe I should try another programmer.
best,
Kees

Bruce
- 8th April 2011, 14:07
With the Pickit2 software running select Tools, and place a check next to Use VPP First Program Entry.

If it doesn't recognize the PIC with LVP at ground try it without this pin at ground.

eggman
- 8th April 2011, 14:57
Thank you Bruce,

You made my day!

regards,

Kees

Bruce
- 8th April 2011, 15:11
Cool...;)

Why not explain/post what you did that fixed it for other folks that may run into the same problem?