Changing the state of a pin and powering up the pic at the same time can cause problems because the pic has not initialized. A better approach would be to put the pic to sleep indefinately and wake it up via an interupt on portb or a single portb.0 input. The pic will normally draw 2 to 8 uAMPs depending on the pic. This can represent years of battery life. You would have to disable the wathdog timer to have the pic sleep indefinately. If your going to wake the pic up with any button pressed, you could gang the buttons to portb.0 with diodes. Oh, one other important point; I'm not sure about the PIC628A but I think it will operate down to 3 volts, perhaps less. This is important because you can avoid the use of a power wasting voltage regulator. You'll never get down to super low power consumption with a regulator unless there is something I'm not aware of. Of course you have to have a transmitter that operates on 3 volts too. All of the above is precisely what I did when I recently built an RF remote control. The pic is operating but asleep until a button is pressed. When a button is pressed, it wakes up the pic, enables the RF transmitter and sends the key command. The key command is delayed by 15ms until the transmitter is keyed up and steady. Then if no buttons are pressed after a few seconds, it goes back to sleep. I'm no expert like so many on these forums so I invite other to jumps in please. Here is a snippet of my code for a PIC16F876;
'MP3 Transmitter
'Program for PIC16F876
'-----------------------------------------------------------------------------------------
Include "modedefs,bas"
@ DEVICE pic16F876, HS_OSC
' System Clock Options
@ DEVICE pic16F876, WDT_OFF 'essential to be off to sleep permanently
' Watchdog Timer
@ DEVICE pic16F876, PWRT_OFF
' Power-On Timer
@ DEVICE pic16F876, BOD_OFF
' Brown-Out Detect
ADCON1 = 7 'turn off analogs
'PIN DESIGNATIONS
Dataout var porta.0 'Serial Data Out
TXEnable var porta.1 'Enable Transmitter
'Spare var porta.2 '
'Spare var porta.3 '
'Spare var porta.4 '
'Spare var porta.5 '
'Interuptpin var portb.0 'Interupt port where all buttons connect with diodes.
Prevbut var portb.1 'Play previous song
Playbut var portb.2 'Sort Playlist by Title
Upbut var portb.3 'Scroll up
Shufflebut var portb.4 'Play Random Song Next
Reversebut var portb.5 'Reverse Playlist
Randbut var portb.6 'Randomize Playlist
Titlebut var portb.7 'Sort Playlist by Title
'Spare var portc.0 '
'Spare var portc.1 '
Downbut var portc.2 'Scroll Down (need resistor here)
Volupbut var portc.3 'Increase Volume (need resistor here)
Voldnbut var portc.4 'Decrease Volume (need resistor here)
Qbut var portc.5 'Queue song (need resistor here)
Pausebut var portc.6 'Pause button (need resistor here)
Nextbut var portc.7 'Play next song (need resistor here)
'------------------------------------------------------------------------------------------
'SET VARIABLES
Timer var Word
Timer = 0
OPTION_REG.7 = 0 ' Enable PORTB pull-ups
OPTION_REG.6 = 0 ' Set RB.0 Interupt to detect falling edge on RB.0
TrisA = %11100
Trisb = %11111111
Trisc = %11111111
Scan: INTCON.4 = 0 'Disable interupt here
Timer = 0
Active: For Timer = 0 to 4000
Low TXEnable
Low Dataout
If Upbut = 0 then Upkey
If Downbut = 0 then Downkey
If Volupbut = 0 then Volupkey
If Voldnbut = 0 then Voldnkey
If Randbut = 0 then Randkey
If Titlebut = 0 then Titlekey
If Reversebut = 0 then Reversekey
If Shufflebut = 0 then Shufflekey
If Playbut = 0 then Playkey
If Prevbut = 0 then Prevkey
If Nextbut = 0 then Nextkey
If Pausebut = 0 then Pausekey
If Qbut = 0 then Qkey
pause 1 'Goes to sleep after about 5 seconds of inactivity
Next Timer
PORTA = 0
PORTB = 0 'turn off all outputs
PORTC = 0
INTCON.1 = 0
Goto LowPwr
LowPwr: INTCON.4 = 1 'Enable PORTB.0 Interupt
@ Sleep 'Go to sleep permanently until change to PORTB.0 Pin (must have Watchdog off)
Goto Scan 'wake up by an interupt (any button), go back to work
Titlekey:High TXEnable
Pause 15
Serout Dataout, N1200, ["A","Z",1]
pause 12
goto Scan
Bookmarks