デバッグ用V850データ表示

Dependencies:   TextLCD mbed

Fork of TextLCD_HelloWorld by Simon Ford

main.cpp

Committer:
NT32
Date:
2015-05-24
Revision:
3:ce52092b7a3a
Parent:
2:ad0b044d0a10
Child:
4:7ad4177061bb

File content as of revision 3:ce52092b7a3a:

#include "mbed.h"
#include "TextLCD.h"

I2CSlave i2cslave(dp5, dp27);

DigitalOut led1(LED1);
DigitalOut led2(LED2);

TextLCD lcd(dp17, dp18, dp25, dp10, dp26, dp28, TextLCD::LCD20x4); // rs, e, d4-d7


int main() {
    char str[20];
        float SystemVoltage, AverageCellVoltage, MaxCellVoltage, MinimumCellVoltage,
    SystemCurrent, Motor1Current, Motor2Current, Motor3Current,
    Remain, PowerConsumption, IntegralPowerConsumption, IntegralCurrent;
    
    int MaxCellNumber, MinimumCellNumber;
    int32_t cellvol[12], mincell, maxcell;
    float realcellvol;  /* real number of cell voltage */

    char rbuf[64];
    char i2cbuf[32] = {0};

    SystemVoltage = 120.5;      //%4.1f システム電圧
    AverageCellVoltage = 3.123; //%4.3f 平均セル電圧
    MaxCellVoltage = 1.234;     //%4.3f 
    MinimumCellVoltage = 0.123; //%4.3f
    MaxCellNumber = 5;          //%1d
    MinimumCellNumber = 3;      //%1d
    SystemCurrent = 138.1235;   //%3.0f
    Motor1Current = 11.1245;    //%3.0f
    Motor2Current = 22.1245;    //%3.0f
    Motor3Current = 33.1245;    //%3.0f
    Remain = 85.435;            //%3.0f
    PowerConsumption = 12.54;   //%4.2f
    IntegralPowerConsumption = 1.54; //%3.2f
    IntegralCurrent = 43.21;    //%4.2f
    
    lcd.cls();
    lcd.locate(0, 0);
    lcd.locate(0, 1);
    lcd.printf("%4.3fV", AverageCellVoltage);
    lcd.locate(0, 2);
    lcd.printf("%4.3fV%d", MaxCellVoltage, MaxCellNumber);
    lcd.locate(0, 3);
    lcd.printf("%4.3fV%d", MinimumCellVoltage, MinimumCellNumber);
    lcd.locate(8, 0);
    lcd.printf("%3.0fA", SystemCurrent);
    lcd.locate(8, 1);
    lcd.printf("%3.0fA", Motor1Current);
    lcd.locate(8, 2);
    lcd.printf("%3.0fA", Motor2Current);
    lcd.locate(8, 3);
    lcd.printf("%3.0fA", Motor3Current);
    lcd.locate(16, 0);
    lcd.printf("%3.0fA", Remain);
    lcd.locate(13, 1);
    lcd.printf("%4.2fkW", PowerConsumption);
    lcd.locate(13, 2);
    lcd.printf("%3.2fkWh", IntegralPowerConsumption);
    lcd.locate(13, 3);
    lcd.printf("%4.2fAh", IntegralCurrent);
    
    i2cslave.address(0x33);
    i2cslave.frequency(100000);
    
    while(1){
        if(i2cslave.receive() != I2CSlave::NoData){
            i2cslave.read(i2cbuf, 7);
            lcd.locate(0, 0);
            led1 != led1;
            lcd.printf("%s", i2cbuf);
        }
    }
}