
Originally Posted by
Melanie
You have of course set the Config Fuses to have MCLR as an Input Pin?
I use MCLR as an I/O in dozens of 16F628 designs without problems, so I suspect you haven't.
When programing (using WinPIC pro) I've tried setting MCLR input enabled (and disabled) and it didn't have any effect. It seems that the problem is with the config as you suggest, however as I'm a newbee it would be nice if you could tell me how to set MCLR as I/O (well I guess input only).
Anyway, I've had a think and came up with the idea of connecting the two reed switches for each track to the same pin and simply counting the times the pin is grounded, and then using the IF/THEN statement to set the condition of the two LEDs. This works for a while and then the PIC seems to stop running 
Here's the revised code:
Code:
PORTA = 0 ' declare port level BEFORE port direction = safe power-on
PORTB = 0
CMCON = 7 ' PortA Digital inputs
CCP1CON = 0 ' PWM off
VRCON = 0 ' Voltage reference disabled
OPTION_REG.7 = 0
TRISA=%00000000 'set PORTA as all output
TRISB=%00001111 'set RB4,5,6 &7 as output and the rest input
'DATA @1,word 625,0,word 545,word 750 ' pre-setting EEPROM
@RC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
' set up outputs to drive LEDs
LED1 var PORTA.1
LED2 var PORTA.0
LED3 var PORTA.7
LED4 var PORTA.6
LED5 var PORTB.7
LED6 var PORTB.6
LED7 var PORTB.5
LED8 var PORTB.4
; set up reed switch inputs
SW0 var PORTB.0
SW1 var PORTB.1
SW2 var PORTB.2
SW3 var PORTB.3
; set up switch counters
SWFLAG1 var Byte
SWFLAG2 var Byte
SWFLAG3 var Byte
SWFLAG4 var Byte
'set all LEDs to off
low led1
low led2
low led3
low led4
low led5
low led6
low led7
low led8
'zero the switch counters
SWFLAG1=0
SWFLAG2=0
SWFLAG3=0
SWFLAG4=0
Main:
' check counters and reset if >2
if SWFLAG1 >2 then
low led1
low led2
SWFLAG1=0
endif
if SWFLAG2 >2 then
low led3
low led4
SWFLAG2=0
endif
if SWFLAG3 >2 then
low led5
low led6
SWFLAG1=0
endif
if SWFLAG4 >2 then
low led7
low led8
SWFLAG2=0
endif
'siding one operation
If SW0=0 Then
swflag1 = swflag1 +1
pause 500
endif
if swflag1=1 then
high led1
endif
If SWFLAG1=2 then
high led2
endif
'siding two operation
If SW1=0 Then
swflag2 = swflag2 +1
pause 500
endif
if swflag2=1 then
high led3
endif
If Swflag2=2 then
high led4
else
endif
'siding three opertaion
If SW2=0 Then
swflag3 = swflag3 +1
pause 500
endif
if SWFLAG3=1 then
high led5
endif
If SWFLAG3=2 then
high led6
endif
'siding four operation
If SW3=0 Then
swflag4 = swflag4 +1
pause 500
endif
if SWFLAG4=1 then
high led7
endif
If SWFLAG4=2 then
high led8
endif
Goto Main
End
When first powered up I can get it working fine, led1 lights the first time sw0 is triggered, then led2 the second time, and then both go out on the third pass of the magnets. This works for all four reed switches, for about 60 seconds and then seems to lock up in what ever state the LEDs are set at. I have 10K pull ups on all input pins, and a 10K pull up on MCLR
Any further comments ?
Bookmarks