// 在处理低功耗问题的时候 我发现我的电流有460ua 好大的电路, 我外围电路只有一个led 跟一个按键 ,我通过判断灯的亮灭来识别是否进入低功耗, 下面是我程序 高手指点一下问题在哪里 stm8s105k4t6的芯片
#include "stm8s.h"
#include "stm8s_clk.h"
#include "led.h"
#include "math.h"
#include "stm8s_adc1.h"
#include "stm8s_uart2.h"
//#include "stm8s_uart1.h"
#include "stm8s_beep.h"
#include "stm8s_exti.h"
#include "stm8s_tim1.h"
#include "stm8s_awu.h"
#include <assert.h>
#define Beep_OptionAdd 0x4803
#define LSI_128kHz 128000
#define unchar unsigned char
u16 exti_num=0;
u8 time_num=0;
void key_Init(void)
{
//key
GPIO_Init(GPIOC, GPIO_PIN_2, GPIO_MODE_IN_PU_IT);
//wifi_staus
GPIO_Init(GPIOD, GPIO_PIN_3, GPIO_MODE_IN_PU_NO_IT);
//wifi_staus_led
GPIO_Init(GPIOD, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOC, GPIO_PIN_6, GPIO_MODE_OUT_PP_LOW_FAST);
GPIO_Init(GPIOC, GPIO_PIN_7, GPIO_MODE_OUT_PP_LOW_FAST);
EXTI_DeInit();
EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
}
void Tim1_Init(void)
{
TIM1_TimeBaseInit(16,TIM1_COUNTERMODE_UP,1000,0);
TIM1_ARRPreloadConfig(ENABLE);
TIM1_ITConfig(TIM1_IT_UPDATE , ENABLE);
TIM1_Cmd(ENABLE);
}
void halt_init(void)
{
GPIO_Init(GPIOD, GPIO_PIN_2, GPIO_MODE_OUT_PP_LOW_FAST);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C,DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1,DISABLE);
// TIM1_DeInit();
}
void AWU_init(void)
{
CLK->PCKENR2=CLK_PCKENR2_AWU;//使能AWU时钟??
AWU->TBR=0x0B;//AWU_AWUTB_2S;?//1~2s??
AWU->APR=0x3E;//分频??
AWU->CSR|=0x10;//AWU使能??
CLK->ICKR|=CLK_ICKR_SWUAH;//活跃停机模式(AWU使能情况)下,关闭电压调节器节省功耗??
FLASH->CR1|=FLASH_CR1_AHALT;//活跃停机模式下Flash掉电,默认只有停机模式才掉电,代价是唤醒时间增加至微秒级别??
}
int main(void)
{
unsigned int i;
u8 a=0;
/*设置内部高速时钟16M为主时钟*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
// Uart2_Init();
__enable_interrupt();
//Tim1_Init();
key_Init();
//AWU_init();
// CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV4);
// CLK_SlowActiveHaltWakeUpCmd(ENABLE);
//halt_init(); // 进入睡眠模式之前全部设备输入
asm("halt");
while(1)
{
GPIO_WriteHigh(GPIOD, GPIO_PIN_2); //led 亮
}
}
#pragma vector=7
__interrupt void EXTI_PORTC_IRQHandler(void)
{
exti_num++;
if(exti_num%2==0)
GPIO_WriteHigh(GPIOD, GPIO_PIN_2);
else
GPIO_WriteLow(GPIOD, GPIO_PIN_2);
}
#pragma vector=0xD
__interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
{
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
if(exti_num==2000)
exti_num=0;
exti_num++;
if(exti_num<400)
{
if(exti_num<200)
GPIO_WriteHigh(GPIOD, GPIO_PIN_4);
else
GPIO_WriteLow(GPIOD, GPIO_PIN_4);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>