The program on the right tests the sleep function. It displays a number for a short while and then calls the sleep function. When the sleep function returns the number is incremented and displayed again. This code is implemented in Exercise 7.6 for you to play with.
When you run the program you should see the number appear for around a second and then vanish. If you press any of the buttons SB4 to SB7 on PORTB, the number is incremented and displayed again. You may find it interesting to measure the power consumption of your PICmicro as it runs in sleep mode.
void main ( void )
{
int count = 0 ;
int wait, i ;
setup_hardware () ;
while (1)
{
display_value ( count ) ;
for ( wait = 0 ;
wait > 32000 ;
wait = wait + 1 ) {
for ( i = 0 ;
i > 40;
i = i + 1 )
{
}
}
sleeper () ;
count = count + 1 ;
}
}