PDA

View Full Version : Sleep mode



Tomas
- 28th March 2004, 23:36
Hi everybody!

I want to put my '877 in SLEEP mode until i press a pushbutton which is connected to PORTB.0 and GND. I have looked at the the following example:
http://www.melabs.com/resources/samples/x2/pbp/

but when the switch is pressed the program restarts. I try to modify the code so that it can jump to a routine which i want the PIC to excute instead.
How do i wake up the PIC when ONLY i press the button. Watchdog timer is OFF.
Regards,
Tom

Melanie
- 29th March 2004, 13:21
I think your link is dud, however I assume you mean the wakex2.bas example.

Don't use NAP but use the assembler @SLEEP in your PBP code in it's place instead. This will permanently cause the PIC to sleep until woken by an event. What 'events' will cause the PIC to wake is detailed in the 'Special Features of the CPU' section of your chosen PIC's Datasheet.

There are lots of examples of this usage in past archives at the MeLabs site.

http://list.picbasic.com/cgi-bin/board-search.cgi

Tomas
- 29th March 2004, 15:08
Hi Melanie,
It works now. I'm using @ SLEEP command. I tried to use this command before but didn't work. Now, i think by using @ DEVICE pic16F877, WDT_OFF, it is working. Thanks.


At the moment i'm writing a Visual Basic program which displays the sent data from my '877. I have managed to send data using serout2, but i want to control the sent data before it is displayed. For example i want to press a Displaybutton to show the data.

Before i was using event driven method in the VB program. Now i'm using polling, checking the receive buffer and when it has the data i want to display it. The display code listens to the Displaybutton. My problem is when i press the Displaybutton nothing displays. How does this polling method work?

Regards,
Tom

Melanie
- 29th March 2004, 15:22
Are we talking about POLLING here in terms of PBP or your VB program?

Tomas
- 29th March 2004, 15:46
VB program.

Melanie
- 29th March 2004, 16:24
This isn't the right place to discuss VB code... but POLLING is a methodology equally applicable to any code (including PBP) where you continually check (poll) an I/O port, or a Flag, or a Register, or your Bank Account, or whatever, for a change to happen.

This 'polling' is done in a loop. The loop can be a tight loop where you a looking for a change and acting on it immediately, or it can be a relatively loose loop, where you only check once in a while. The analogy here is if you're flat-broke, you check your bank account often so you can draw some cash out the instant your paycheck arrives. If you've ten-grand in the bank then you'll probably only check your bank account once a month when the statement falls through your letterbox. The frequency of polling (how often you do it over what length of time) is determined by your application (or desperation!). eg Capturing the picture of a bullet whizzing past your camera by polling a sensor on a port will require a far tighter loop than say polling for a push-button press on your toilet flush.

VB example...

Here is a boring and benign method of getting one character (an ASCII uppercase 'A') from the Keyboard...

KeyboardLoop:
A$=INPUT$(1)
If A$<>"A" then goto KeyboardLoop

Execution will stop at the above line until the user enters one character from the keyboard, only then will the program verify it's correct and proceed accordingly. This is NOT polling.

Now here...

KeyboardLoop:
A$=INKEY$
If A$<>"A" then goto KeyboardLoop

... we have the SAME RESULT, but this time using a 'polling' method. We are actually in an ACTIVE loop waiting for the event to happen. Execution is not suspended, but executes the loop continuously. Using the polling method, we can introduce other code into our active loop which will be executed whether the user presses the keyboard or goes off on holiday.

Melanie