Hi..how can i do a "sleep" mode for 8051?
Ya..I tried using PCON in my source code, but then i dont know how to check whether there's any effect on my program..i've connected the 8051 with LEDs and there is no difference if i add in PCON or not..how??
O.K. Most examples of sleep code have you do something like set the pcon bit and then just hang. An interrupt will awaken you and you process it, then go back to sleep and just hang. This was totally unsuitable for my project, as I needed to simply put the machine to sleep after some number of minutes of inactivity. I do not have to put it to sleep to save batteries. Here is how I did it. This is for a Silabs 320 Several specific things here. 1. Silabs 320 is running at 24 mhz, and to drop current consumption, I wanted to slow the processor down This assumes that the wakeup signals (in this case a pair of pushbuttons) are connected to int0 and int 1, and I wanted no other way to wake up. // // now disable all interrupts except for int0 and int1 // saved_ie=IE; // grab a copy of the interrupt enable register EA=0; // globally kill all of them saved_eie1=EIE1; // saved_eie2=EIE2; EIE1=0; EIE2=0; IE=0x85; // reenable global interrupts, and enable int0 and int1 CR=0; // disable the PCA TMR3CN=TMR3CN & 0xFB; // disable timer 3 // // slow the part down to slowest possible clockspeed in this mode // CLKSEL = 0x00; // Oscillator Clock Select Register ls bits 00 = CLKMUL=0; OSCICN=0x80; // sets system to internal oscliator /8 // // ensure that all the i/o pins are off // P1MDIN=0x00; // running value 0xFF // // shut down other ports the same way // PCON=PCON | 0x01; // suspend the processor // // we come out of sleep here // CR=1; // enable the PCA again EA=0; // // we are going to put code here to switch this to 24 mhz mode // OSCICN = 0x83; // system clock /1 CLKMUL = 0x80; // this sets the clock multiplyer to enabled mode delay=100; while (delay--); // wait at least 5 microseconds CLKMUL |= 0xC0; // initialize multiplier while ((CLKMUL & 0x20) != 0x20); // wait for multiplyer to be ready CLKSEL = 0x02; // system clock is 48mhz/2 i.e. 12 mhz * 4 /2
If the device is a SiLabs 80c51F3xx then it is better to just select the internal osc to the lowest posssible value. Don't go into the idle mode. I don't know the reason but these devices will have a HIGHER idle current in the sleep mode than running at a low osc value. Hope to spend more time on this myself later. Bradford
"I don't know the reason but these devices will have a HIGHER idle current in the sleep mode than running at a low osc value." Not being familiar with this device I don't know for sure, but I would guess that this is because the peripheral clocks are still running when in idle mode. Therefore, if you enter idle with a fast oscillator you may well see higher power consumption than just reducing the clock speed. If you reduce the clock and then enter idle you should get the lowest power consumption.