qingkong 发表于 2020-3-17 10:01:42

在家用lgt8f328p的休眠功能做了个表

本帖最后由 qingkong 于 2020-3-17 10:05 编辑



只是显示时间的时候可以到3ma左右


这个东西是双主机I2C总线
ESP8266 自己忙自己的,NTP更新了时间后就去睡觉。图片上那个就是它睡着后拍的
我这个没有弘老大的库,因为他那个库没法调lgt8f328p的运行速度

github找 dbuezas lgt8fx/master/package_lgt8fx_index.json



ESP8266的就是个NTP表加了个deepsleep,就不上了。。。。

下面是lgt8f328p的代码,上传时选择CPU频率是1MHZ LDO是AMS1117

//使用的库 timerone; Grove 4Digit Display; Grove - RTC DS1307;
//从DS1307读RTC时间 显示到数码管
//建议使用lg8f328p 这个国产兼容芯,因为这货3.3V也是16MHZ 电压范围是5.5-3V 啥也不用管,直接用18650电池供电就行
/*
Power consumption @ 5v
Clock   Pro mini style w/o power LEDPro mini styleNano style
32MHz12.7mA15.0mA32.6mA
16MHz9.2mA   11.5mA27.8mA
8MHz   7.1mA   9.4mA   25.4mA
4MHz   5.9mA   8.2mA   23.3mA
2MHz   5.3mA   7.6mA   23.4mA
1MHz   5.0mA   7.3mA   22.8mA

*/

/*******************************************************************************/
//#include<TimerOne.h>
#include <TM1637.h>
#define ON 1
#define OFF 0
#include <DS1307.h>
//#include <WDT.h>
#include <PMU.h>

int8_t TimeDisp[] = { 0x00, 0x00, 0x00, 0x00 };
volatile unsigned char ClockPoint = 1;
//unsigned char Update= ON;
//unsigned char halfsecond = 0;
unsigned char second;
unsigned char minute = 0;
unsigned char hour = 12;

//#define CLK 6 //pins definitions for TM1637 and can be changed to other ports
//#define DIO 7

#define CLK 10 //pins definitions for TM1637 and can be changed to other ports
#define DIO 9
TM1637 tm1637(CLK, DIO);
DS1307 clock1307; //define a object of DS1307 class

void setup() {

//pinMode(0, OUTPUT);

// delay to check wdt reset condition
delay(1000);
/*
   #if defined(__LGT8FX8P__)
   wdt_enable(WTO_2S);
   #else
   wdt_enable(WTO_512MS);
   #endif
   */

uint32_t guid = (GUID3 << 24) | (GUID2 << 16) | (GUID1 << 8) | GUID0; // 给guid赋值唯一ID
// Serial.println(guid); // 串口输出唯一ID
tm1637.set(BRIGHT_DARKEST); //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;

tm1637.init();

//Timer1.initialize(2*500000);         //timing for 500ms
// Timer1.attachInterrupt(TimingISR); //declare the interrupt serve routine:TimingISR
clock1307.begin();
clock1307.startClock();

   
ADCSRA = 0; // disable ADC

}
void loop() {
// put your main code here, to run repeatedly:
//wdt_reset();
//digitalToggle(0);

//delay(1);
//if (Update == ON) {
TimingISR();
TimeUpdate();
tm1637.display(TimeDisp);

// }

/*
   *休眠模式 功能说明
   空闲模式(IDLE) 仅仅关闭内核时钟,其他外设模块正常工作,所有有效中断源均可 以将内核唤醒
   省电模式(Save) 与 DPS0 模式相同,Save 模式为与 LGT8FX8D 保持兼容
   掉电模式(DPS0) 与 Save 模式相同,支持唤醒源包括:
    所有引脚电平变化
    看门狗定时唤醒
    异步模式的 TMR2 唤醒
   掉电模式(DPS1) 关闭所有内外部振荡器, 支持唤醒源包括:
    所有引脚外部电平变化
    外部中断 0/1
    工作于 32K LFRC 的看门狗定时器
   掉电模式(DPS2) 关闭内核电源, 最低功耗模式,支持的唤醒源包括:
    外部复位
    PORTD 引脚电平变化
    LPRC 定时唤醒(128ms/256ms/512ms/1s)
   需要注意,从 DPS2 唤醒的过程与上电复位相同

   PM_IDLE,
   PM_POWERDOWN = 2,
   PM_POFFS1 = 3,
   PM_POFFS0 = 6
   */

//ADCSRA = 0; // disable ADC
PMU.sleep(PM_POWERDOWN, SLEEP_1S);
//delay(1000);
}
void TimingISR() {
//halfsecond++;
//Update = ON;

// Serial.println(second);
ClockPoint = !ClockPoint;

// if (halfsecond == 2) {
//   halfsecond = 0;

// }
}

void printTime() {
clock1307.getTime();//delay(100);
//Serial.print(clock1307.hour, DEC);
hour = clock1307.hour;
//Serial.print(":");
//Serial.print(clock1307.minute, DEC);
minute = clock1307.minute;
//Serial.print(":");
//Serial.print(clock1307.second, DEC);
//Serial.print("");
//Serial.print(clock1307.month, DEC);
//Serial.print("/");
//Serial.print(clock1307.dayOfMonth, DEC);
//Serial.print("/");
//Serial.print(clock1307.year + 2000, DEC);
//Serial.print(" ");
//Serial.print(clock1307.dayOfMonth);
//Serial.print("*");
//switch (clock1307.dayOfWeek) // Friendly printout the weekday
//{
//case MON:
//    Serial.print("MON");
//    break;
//case TUE:
//    Serial.print("TUE");
//    break;
//case WED:
//    Serial.print("WED");
//    break;
//case THU:
//    Serial.print("THU");
//    break;
//case FRI:
//    Serial.print("FRI");
//    break;
//case SAT:
//    Serial.print("SAT");
//    break;
//case SUN:
//    Serial.print("SUN");
//    break;
//}
//Serial.println(" ");
}
void TimeUpdate(void) {
if (ClockPoint)
    tm1637.point(POINT_ON);
else
    tm1637.point(POINT_OFF);
printTime(); //设置数据 准备显示时间
// Update = OFF;

TimeDisp = hour / 10;
TimeDisp = hour % 10;
TimeDisp = minute / 10;
TimeDisp = minute % 10;

}



最后。。。。
弘老大OCROBOT的做工的确是很不错的,我当年测试就是用的他的板子
但是 那个也太大了。。。真到了做个小东西就不方便了

能否做个这种类似arduino mini pro的,然后ldo换成微盟那个me6118a也行啊800ma 静态电流50ua 总是比ams1117 强多了。。。而且还是全国产。。。
体积下来了,很多东西都好用啊,而且没了串口芯片,也能便宜点不是 :lol

建议搞3.3V的,这个东西与ESP8266啥的都友善。。。虽然ADC可能受影响。。。

qingkong 发表于 2020-3-17 14:11:53

:lol 或者出一个不带LDO的也成啊 控制好体积:$

allen727hk 发表于 2020-3-19 23:04:18

paobo99 发表于 2022-2-22 14:39:37

真正需要休眠的板子因为用电池供电,可以去掉LDO
页: [1]
查看完整版本: 在家用lgt8f328p的休眠功能做了个表