Hi all,
My first post so be gentile with me 
My first project using PBP is for my 12 year old son's model railway. I'm using a 16F628A with the internal 4Mhz OSC as timing is not an issue (and the internal OSC is claimed to be very precise anyway). The project is not rocket science, simply to detect a train via the momentarly activation of a reed switch. This pulse then turns on an LED which is latched on until the same reed switch is activated again.
I have two problems:
1) - The latching is not clean, in that sometimes the LED brightens and remains on when it should be off, or when off it is turned on by the reed switch, but fails to latch
2) - I'm using WinPIC pro to program the PIC. I have set the PIC up for internal OSC no clock out in the code, but I have to change the settings from XT to RC noClockout in the Winpic application. Is the an issue with the Winpic application, or the code (which compiles OK)
Anyway, here is my code.
Code:
@INTRC_OSC_NOCLKOUT
@WDT_ON
@PWRT_ON
@MCLR_OFF
@BOD_ON
@LVP_OFF
@CPD_OFF
@PROTECT_OFF
CMCON=7
TRISB=%11101111 'set RB6 as output and the rest input
SW var PORTB.0 'switch input pin 6 (RB0)
LED1 var PORTB.4 'LED1 on pin 10 (RB4)
Swset var bit
low led1 'RB4 set to LOW (LED1 is off)
Swset=0 'Var swset is set low
Main:
if SW=0 then 'If switch is LOW (Grounded) then
Toggle Swset 'change swset from 0 to 1
pauseus 200 'debounce delay
endif
If Swset=1 then 'if swset is 1
high led1 'then turn on RB4 (and hence the LED)
else
low led1 'else, LED is off
endif
Goto Main 'go back and keep checking
End
The reason I've only configured one output on port B is purely for testing..once I have this sorted, RB0, RB1, RB2 and RB3 will all be switch inpts, with RB4 - RB7 their coresponding outputs (we have 4 sidings to monitor )
TIA
Malcolm
Bookmarks