Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Lab9-01_All_transmit Lab9-03_Thermal_chamber 3daf572bcae1 Team ... more
Fork of HeptaBattery by
HeptaBattery.cpp@0:1682fa22a51e, 2017-07-21 (annotated)
- Committer:
- hepta2ume
- Date:
- Fri Jul 21 06:41:37 2017 +0000
- Revision:
- 0:1682fa22a51e
- Child:
- 2:821f36c03e26
HeptaBattery
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| hepta2ume | 0:1682fa22a51e | 1 | #include "HeptaBattery.h" | 
| hepta2ume | 0:1682fa22a51e | 2 | #include "mbed.h" | 
| hepta2ume | 0:1682fa22a51e | 3 | |
| hepta2ume | 0:1682fa22a51e | 4 | HeptaBattery::HeptaBattery(PinName bat, PinName bat_ct) : _bat(bat),_bat_ct(bat_ct) | 
| hepta2ume | 0:1682fa22a51e | 5 | { | 
| hepta2ume | 0:1682fa22a51e | 6 | _bat_ct = 0; | 
| hepta2ume | 0:1682fa22a51e | 7 | PHY_PowerDown();//Ethernet PHYchip停止 | 
| hepta2ume | 0:1682fa22a51e | 8 | } | 
| hepta2ume | 0:1682fa22a51e | 9 | |
| hepta2ume | 0:1682fa22a51e | 10 | void HeptaBattery::vol(float* bt) | 
| hepta2ume | 0:1682fa22a51e | 11 | { | 
| hepta2ume | 0:1682fa22a51e | 12 | *bt = (_bat.read()*1.431*3.3);//バッテリー電圧読み出し | 
| hepta2ume | 0:1682fa22a51e | 13 | } | 
| hepta2ume | 0:1682fa22a51e | 14 | |
| hepta2ume | 0:1682fa22a51e | 15 | void HeptaBattery::fast_charge() | 
| hepta2ume | 0:1682fa22a51e | 16 | { | 
| hepta2ume | 0:1682fa22a51e | 17 | //Peripheral_PowerDown(0x7DFEDFEE);怪しい | 
| hepta2ume | 0:1682fa22a51e | 18 | _bat_ct = 1; | 
| hepta2ume | 0:1682fa22a51e | 19 | } | 
| hepta2ume | 0:1682fa22a51e | 20 | |
| hepta2ume | 0:1682fa22a51e | 21 | void HeptaBattery::vol_u16(char* bt_u16, int *dsize) | 
| hepta2ume | 0:1682fa22a51e | 22 | { | 
| hepta2ume | 0:1682fa22a51e | 23 | unsigned short bt_datas; | 
| hepta2ume | 0:1682fa22a51e | 24 | char bt1[8]= {0x00},bt2[8]= {0x00}; | 
| hepta2ume | 0:1682fa22a51e | 25 | bt_datas=_bat.read_u16()>>4; | 
| hepta2ume | 0:1682fa22a51e | 26 | sprintf( bt1, "%02X", (bt_datas >> 8) & 0x0F); | 
| hepta2ume | 0:1682fa22a51e | 27 | sprintf( bt2, "%02X", (bt_datas) & 0xFF); | 
| hepta2ume | 0:1682fa22a51e | 28 | bt_u16[0]=bt1[0]; | 
| hepta2ume | 0:1682fa22a51e | 29 | bt_u16[1]=bt1[1]; | 
| hepta2ume | 0:1682fa22a51e | 30 | bt_u16[2]=bt2[0]; | 
| hepta2ume | 0:1682fa22a51e | 31 | bt_u16[3]=bt2[1]; | 
| hepta2ume | 0:1682fa22a51e | 32 | *dsize = 4; | 
| hepta2ume | 0:1682fa22a51e | 33 | } | 
| hepta2ume | 0:1682fa22a51e | 34 | |
| hepta2ume | 0:1682fa22a51e | 35 | void HeptaBattery::power_saving_mode() | 
| hepta2ume | 0:1682fa22a51e | 36 | { | 
| hepta2ume | 0:1682fa22a51e | 37 | float Bat; | 
| hepta2ume | 0:1682fa22a51e | 38 | Bat = _bat.read()*1.431*3.3; | 
| hepta2ume | 0:1682fa22a51e | 39 | //4.2以上 | 
| hepta2ume | 0:1682fa22a51e | 40 | if(Bat>=4.2) { | 
| hepta2ume | 0:1682fa22a51e | 41 | _bat_ct = 0; | 
| hepta2ume | 0:1682fa22a51e | 42 | Peripheral_PowerUp(0xFDFF6FF7); | 
| hepta2ume | 0:1682fa22a51e | 43 | LPC_SC->CCLKCFG = 2; | 
| hepta2ume | 0:1682fa22a51e | 44 | SystemCoreClockUpdate(); | 
| hepta2ume | 0:1682fa22a51e | 45 | } | 
| hepta2ume | 0:1682fa22a51e | 46 | //3.7 < Voltage < 4.1 | 
| hepta2ume | 0:1682fa22a51e | 47 | else if(Bat<=4.1 && Bat>=3.7) { | 
| hepta2ume | 0:1682fa22a51e | 48 | Peripheral_PowerUp(0xFDFF6FF7); | 
| hepta2ume | 0:1682fa22a51e | 49 | LPC_SC->CCLKCFG = 2; | 
| hepta2ume | 0:1682fa22a51e | 50 | SystemCoreClockUpdate(); | 
| hepta2ume | 0:1682fa22a51e | 51 | _bat_ct = 1; | 
| hepta2ume | 0:1682fa22a51e | 52 | } | 
| hepta2ume | 0:1682fa22a51e | 53 | //3.5V以下 | 
| hepta2ume | 0:1682fa22a51e | 54 | else if(Bat<=3.5) { | 
| hepta2ume | 0:1682fa22a51e | 55 | Peripheral_PowerDown(0x7D7E6DF1); | 
| hepta2ume | 0:1682fa22a51e | 56 | LPC_SC->CCLKCFG = 5; | 
| hepta2ume | 0:1682fa22a51e | 57 | SystemCoreClockUpdate(); | 
| hepta2ume | 0:1682fa22a51e | 58 | _bat_ct = 1; | 
| hepta2ume | 0:1682fa22a51e | 59 | } | 
| hepta2ume | 0:1682fa22a51e | 60 | |
| hepta2ume | 0:1682fa22a51e | 61 | } | 
