今测试C8051F340功耗,发现以下问题:
1、用内部震荡器无法进入空闲和停机模式,PCON=1/3,一执行到这系统就复位,直接芯片运行也是这样
2、系统使用内部80K震荡器并且8分频时,功耗非常大为2.6MA(各IO口不接任何器件),程序如下,请各位指教
#include <c8051f340.h> // SFR declarations //#define __SRC #include "main.h" //#undef __SRC #include "MacroDefine.h"
#include <string.h> #include <stdio.h> #include <absacc.h> #include <intrins.h>
#define uchar unsigned char #define uint unsigned int
sbit CARD_LED =P1^3; //2^0;
sfr16 TMR2RL = 0xca; // Timer2 reload value sfr16 TMR2 = 0xcc; // Timer2 counter
//----------------------------------------------------------------------------- // Global Constants //-----------------------------------------------------------------------------
#define SYSCLK 24500000 / 8 // SYSCLK frequency in Hz
#define BLINK_RATE 10 // Timer2 Interrupts per second
void OSCILLATOR_Init (void) { int i;
OSCICN |= 0;//0x03; // Configure internal oscillator for // its maximum frequency CLKMUL = 0x00; // Reset Clock Multiplier and select // internal oscillator as input source //CLKMUL &= 0x7f; CLKMUL |= 0x80; // Enable the Clock Multiplier
for(i = 0; i < 256; i++); // Delay at least 5us CLKMUL |= 0xC0; // Initialize the Clock Multiplier while(!(CLKMUL & 0x20)); // Wait for MULRDY => 1 RSTSRC = 0x06; // Enable missing clock detector // and VDD monitor FLSCL |= 0x10; // Set Flash Scale for 48MHz CLKSEL |= 0;//0x03; // Select output of clock multiplier // as the system clock. } void OSCILLATOR_Init_low (void) { OSCLCN |= 0x80; CLKSEL = 0x04; OSCICN = 0x00; } //*********************************** void delay_10ms(unsigned char cent) //12mhz { unsigned int j; unsigned char i,k; for(i=0;i<cent;i++); { for(k=0;k<10;k++) { for(j=0;j<20;j++); //_nop_(); } } }
void PORT_Init (void) { XBR0 = 0x01; // Enable UART on P0.4(RX) and P0.5(TX) XBR1 = 0x40; // Enable crossbar and enable // weak pull-ups P1MDOUT |= 0x8; // push-pull 1101 1111, RF_MISO=0 }
/////////////////////////////////////////////////////////////////////// // 主函数 /////////////////////////////////////////////////////////////////////// void main(void) { //设置变量 // uchar baud; uchar status,i;
//******************* PCA0MD &= ~0x40; // WDTE = 0 (clear watchdog timer EA=0; // enable) OSCILLATOR_Init (); // Initialize system clock to OSCILLATOR_Init_low(); // 24.5MHz PORT_Init (); // Initialize crossbar and GPIO for(i=0;i<3;i++) { CARD_LED=1; delay_10ms(1); CARD_LED=0; delay_10ms(1); }
P1MDOUT = 0; CARD_LED=1; //PCON |=1; while(1); }
|