Quote Originally Posted by skimask View Post
You know...I was thinking...
In this type of project, there's nothing that says the PIC has to turn itself completely off right away.
Why can't it stay running for, say 10 seconds, after the LED is powered off.
So, the process looks like this:

Initial power on with an initial mode...
LED lit, PIC waiting...
button pressed, LED off, PIC still waiting...
If one second passes without a button press, the PIC shuts itself off.
If a button press happen inside of one second, the mode changes and the 1 second timer is reset.
Requires a bit more thought with the single button power on/off circuit, but that's easy...
This is the circuit Im using:


With this code:
Code:
@ device pic12f683,INTRC_OSC_NOCLKOUT , wdt_on, mclr_off, protect_off, bod_on

CMCON0 = %00000111     ' Disable comparator
VRCON  = %00000000     ' disable


'       I/Os
TRISIO = %00000000      ' no inputs      

' definitions
 
' init values

if PCON.0=0 then
  gpio=%00000100        'Brown-out detected turn on LED on PIN5 (red)
else
  gpio=%00000010        'Brown-out NOT detected turn on LED on PIN6 (green)
endif

'main loop

loop:
pcon.0=1
goto loop
It does not work, the minute I give it power green lits and after 5 seconds¿?¿? it goes off and red lits.

Am I missing something?

I can use a 12F675 or even a 12F683 if a simpler / more efficient solution is possible.

Regarding flashlight operation, think of a flashlight without buttons, it goes on or off by twisting the body, and the battery electrical path to the LED/uC is done using the metal body. So this means when power is gone, is gone for everything. To be even more clear, here is a CAD drawing of my latest creation:


The green you see there is the uC/driver PCB that also serves as positive contact for the battery. Ground is attached inside the flashlight head.

To check more flashlights check: www.neoca.com.ar Thanks!