View Full Version : How to go to sleep
savnik
- 13th September 2006, 13:30
I have this :
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE I2C_SCLOUT 1
SCL var PORTA.1
SDA var PORTA.0
UP var PORTB.6
DOWN var PORTB.7
CH_PAS var PORTB.5
Input UP
Input DOWN
Input CH_PAS
b1 var Byte
b2 var Byte
b3 var Byte
b5 var Byte
F1 var Word
F2 var Word
F3 var Word
ADDR1 VAR Byte
ADDR2 VAR Byte
LOCK VAR Byte
TMP VAR Word
TMP_LO VAR TMP.LowByte
TMP_HI VAR TMP.HighByte
PLLBASE VAR Word
PLL VAR Word
LO VAR PLL.LowByte
HI VAR PLL.HighByte
PAS VAR Byte
loop:
Button UP,1,10,2,b1,1,MONTE
Button DOWN,1,10,2,b2,1,DESCEND
Button CH_PAS,1,255,0,b3,1, CHOIX
PAUSE 100
I2CREAD SDA,SCL,ADDR2,[LOCK]
GoSub AFFICHAGE
GoTo loop
and i want the pic to go to sleep if no button is pushed.And awake if i push any button.
I have read the datasheet but i don't know how to make
Pic is 16f84a
blainecf
- 13th September 2006, 15:33
You don't mention why you want the MCU to sleep. I'm assuming power consumption based on battery drain.
If so, then you need to state how crucial the power draw is to your design, and what response time you need.
If power draw is not crucial, then why do you want the MCU to sleep? Or, do you just want it to pause.
bcf
savnik
- 13th September 2006, 19:45
I use the pic to control a TSA5511 (i2c) for a pll for UHF , but the counter of pic is modulate the rf (vco) , so i want to sleep until i push any button and after some time to go again to sleep.
savnik
- 16th September 2006, 09:47
I change the code but i don't know if it is correct
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 0
DEFINE LCD_RSREG PORTA
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG PORTA
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE I2C_SCLOUT 1
SCL var PORTA.1
SDA var PORTA.0
UP var PORTB.6
DOWN var PORTB.7
CH_PAS var PORTB.5
Input UP
Input DOWN
Input CH_PAS
b1 var Byte
b2 var Byte
b3 var Byte
b5 var Byte
F1 var Word
F2 var Word
F3 var Word
ADDR1 VAR Byte
ADDR2 VAR Byte
LOCK VAR Byte
TMP VAR Word
TMP_LO VAR TMP.LowByte
TMP_HI VAR TMP.HighByte
PLLBASE VAR Word
PLL VAR Word
LO VAR PLL.LowByte
HI VAR PLL.HighByte
PAS VAR Byte
' Initialize interrupts
On Interrupt Goto loop
INTCON = $88 ' enable interrupts on RB4 through RB7
MAIN:
PLL = PLLBASE + TMP
I2CWRITE SDA,SCL,ADDR1,[HI,LO,$8E] 'Sending of the data to the module
GoSub CALCUL 'calculate the frequency for posting
GoSub AFFICHAGE 'post the frequency
PAUSE 200
@SLEEP
loop:
Button UP,1,10,2,b1,1,MONTE
Button DOWN,1,10,2,b2,1,DESCEND
Button CH_PAS,1,255,0,b3,1, CHOIX
PAUSE 100
I2CREAD SDA,SCL,ADDR2,[LOCK]
GoSub AFFICHAGE
INTCON.1 = 0 ' clear the interrupt flag
Resume ' end of interrupt service routine
Enable ' allow interrupts again
GoTo loop
MONTE:
.....
.....
GoTo MAIN
DESCEND:
.....
.....
GoTo MAIN
CHOIX:
.....
.....
GoTo MAIN
savnik
- 18th September 2006, 17:47
Button UP,1,10,2,b1,1,MONTE
Button DOWN,1,10,2,b2,1,DESCEND
Button CH_PAS,1,255,0,b3,1, CHOIX
BUTTON Pin,Down,Delay,Rate,BVar,Action,Label
Because the 'down' in my code is 1 the pic go to interrupt continues (loop)
How to change the code (not the button);
peterdeco1
- 18th September 2006, 18:09
I've used something like this in the past & it worked fine:
START:
IF PORTA.1 = 0 THEN WORK 'BUTTON PUSHED
PAUSE 100
LET X = X + 1
IF X > 250 THEN RELAX 'SHUT DOWN AFTER 25 SEC
GOTO START
WORK:
DO WHATEVER
LET X = 0
GOTO START
RELAX:
NAP 0
IF PORTA.1 = 1 THEN RELAX
LET X = 0
GOTO START
savnik
- 18th September 2006, 20:59
I don't know if the
INTCON = $88 ' enable interrupts on RB4 through RB7
is right
savnik
- 22nd September 2006, 06:42
some one to help me;
ErnieM
- 22nd September 2006, 14:44
INTCON=$88 looks good to me. You've got the interupts enabled, and Port B change enables also.
Keeping in mind I've not done interupts in PBP (raw assembler yeah) I'd put the button handeling code inside the interupt handler. However, this would be a problem with the BUTTON command as that wants to be inside a loop, so maybe wake up for a while every time you see a keychange.
savnik
- 22nd September 2006, 18:38
However, this would be a problem with the BUTTON command as that wants to be inside a loop.
Maybe this is the my problem and i don't know how to solve.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.