デバッグ用V850データ表示
Fork of TextLCD_HelloWorld by
main.cpp@4:7ad4177061bb, 2016-11-05 (annotated)
- Committer:
- NT32
- Date:
- Sat Nov 05 10:09:38 2016 +0000
- Revision:
- 4:7ad4177061bb
- Parent:
- 3:ce52092b7a3a
?????V850??????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
simon | 0:334327d1a416 | 1 | #include "mbed.h" |
simon | 0:334327d1a416 | 2 | #include "TextLCD.h" |
simon | 0:334327d1a416 | 3 | |
NT32 | 3:ce52092b7a3a | 4 | I2CSlave i2cslave(dp5, dp27); |
NT32 | 3:ce52092b7a3a | 5 | |
NT32 | 4:7ad4177061bb | 6 | DigitalOut led1(dp14); |
NT32 | 3:ce52092b7a3a | 7 | |
NT32 | 3:ce52092b7a3a | 8 | TextLCD lcd(dp17, dp18, dp25, dp10, dp26, dp28, TextLCD::LCD20x4); // rs, e, d4-d7 |
NT32 | 3:ce52092b7a3a | 9 | |
NT32 | 4:7ad4177061bb | 10 | Serial pc(dp16, dp15); |
simon | 0:334327d1a416 | 11 | |
simon | 0:334327d1a416 | 12 | int main() { |
NT32 | 4:7ad4177061bb | 13 | char str[20], serBuff[64]; |
NT32 | 3:ce52092b7a3a | 14 | float SystemVoltage, AverageCellVoltage, MaxCellVoltage, MinimumCellVoltage, |
NT32 | 3:ce52092b7a3a | 15 | SystemCurrent, Motor1Current, Motor2Current, Motor3Current, |
NT32 | 3:ce52092b7a3a | 16 | Remain, PowerConsumption, IntegralPowerConsumption, IntegralCurrent; |
NT32 | 4:7ad4177061bb | 17 | |
NT32 | 4:7ad4177061bb | 18 | int measCurrent, currentCmd, accelVol, pwmDuty, mtrRpm; |
NT32 | 3:ce52092b7a3a | 19 | |
NT32 | 3:ce52092b7a3a | 20 | int MaxCellNumber, MinimumCellNumber; |
NT32 | 3:ce52092b7a3a | 21 | int32_t cellvol[12], mincell, maxcell; |
NT32 | 3:ce52092b7a3a | 22 | float realcellvol; /* real number of cell voltage */ |
NT32 | 3:ce52092b7a3a | 23 | |
NT32 | 4:7ad4177061bb | 24 | char rbuf[8]; |
NT32 | 3:ce52092b7a3a | 25 | char i2cbuf[32] = {0}; |
NT32 | 4:7ad4177061bb | 26 | char *endPtr; |
NT32 | 3:ce52092b7a3a | 27 | |
NT32 | 3:ce52092b7a3a | 28 | SystemVoltage = 120.5; //%4.1f システム電圧 |
NT32 | 3:ce52092b7a3a | 29 | AverageCellVoltage = 3.123; //%4.3f 平均セル電圧 |
NT32 | 3:ce52092b7a3a | 30 | MaxCellVoltage = 1.234; //%4.3f |
NT32 | 3:ce52092b7a3a | 31 | MinimumCellVoltage = 0.123; //%4.3f |
NT32 | 3:ce52092b7a3a | 32 | MaxCellNumber = 5; //%1d |
NT32 | 3:ce52092b7a3a | 33 | MinimumCellNumber = 3; //%1d |
NT32 | 3:ce52092b7a3a | 34 | SystemCurrent = 138.1235; //%3.0f |
NT32 | 3:ce52092b7a3a | 35 | Motor1Current = 11.1245; //%3.0f |
NT32 | 3:ce52092b7a3a | 36 | Motor2Current = 22.1245; //%3.0f |
NT32 | 3:ce52092b7a3a | 37 | Motor3Current = 33.1245; //%3.0f |
NT32 | 3:ce52092b7a3a | 38 | Remain = 85.435; //%3.0f |
NT32 | 3:ce52092b7a3a | 39 | PowerConsumption = 12.54; //%4.2f |
NT32 | 3:ce52092b7a3a | 40 | IntegralPowerConsumption = 1.54; //%3.2f |
NT32 | 3:ce52092b7a3a | 41 | IntegralCurrent = 43.21; //%4.2f |
NT32 | 3:ce52092b7a3a | 42 | |
NT32 | 4:7ad4177061bb | 43 | pc.baud(38400); |
NT32 | 4:7ad4177061bb | 44 | |
NT32 | 3:ce52092b7a3a | 45 | lcd.cls(); |
NT32 | 4:7ad4177061bb | 46 | led1 = 0; |
NT32 | 4:7ad4177061bb | 47 | lcd.locate( 0, 0); |
NT32 | 4:7ad4177061bb | 48 | lcd.printf("rcv start"); |
NT32 | 4:7ad4177061bb | 49 | wait(0.5); |
NT32 | 4:7ad4177061bb | 50 | led1 = 1; |
NT32 | 4:7ad4177061bb | 51 | |
NT32 | 4:7ad4177061bb | 52 | |
NT32 | 4:7ad4177061bb | 53 | |
NT32 | 3:ce52092b7a3a | 54 | while(1){ |
NT32 | 4:7ad4177061bb | 55 | //--------------------------------------------- |
NT32 | 4:7ad4177061bb | 56 | // 文字列受信=>数値変換 |
NT32 | 4:7ad4177061bb | 57 | //--------------------------------------------- |
NT32 | 4:7ad4177061bb | 58 | led1 = !led1; |
NT32 | 4:7ad4177061bb | 59 | pc.scanf("%s", serBuff); |
NT32 | 4:7ad4177061bb | 60 | if( 's' == serBuff[0] ){ |
NT32 | 4:7ad4177061bb | 61 | // 文字列解釈 |
NT32 | 4:7ad4177061bb | 62 | //電流計測値(AD10bit生データ) |
NT32 | 4:7ad4177061bb | 63 | strncpy( rbuf, &serBuff[1], 4 ); |
NT32 | 4:7ad4177061bb | 64 | measCurrent = ( strtol( rbuf, &endPtr, 10) ); |
NT32 | 4:7ad4177061bb | 65 | memset( rbuf, '\0', sizeof rbuf ); |
NT32 | 4:7ad4177061bb | 66 | //電流指令値(倍率が正しくないと思う) |
NT32 | 4:7ad4177061bb | 67 | strncpy( rbuf, &serBuff[5], 4 ); |
NT32 | 4:7ad4177061bb | 68 | currentCmd = ( strtol( rbuf, &endPtr, 10) ); |
NT32 | 4:7ad4177061bb | 69 | memset( rbuf, '\0', sizeof rbuf ); |
NT32 | 4:7ad4177061bb | 70 | //ボリューム(AD10bit生データ) |
NT32 | 4:7ad4177061bb | 71 | strncpy( rbuf, &serBuff[9], 4 ); |
NT32 | 4:7ad4177061bb | 72 | accelVol = ( strtol( rbuf, &endPtr, 10) ); |
NT32 | 4:7ad4177061bb | 73 | memset( rbuf, '\0', sizeof rbuf ); |
NT32 | 4:7ad4177061bb | 74 | //PWMデューティ(0~800:MAX800) |
NT32 | 4:7ad4177061bb | 75 | strncpy( rbuf, &serBuff[13], 4 ); |
NT32 | 4:7ad4177061bb | 76 | pwmDuty = ( strtol( rbuf, &endPtr, 10) ); |
NT32 | 4:7ad4177061bb | 77 | memset( rbuf, '\0', sizeof rbuf ); |
NT32 | 4:7ad4177061bb | 78 | //モータ回転数(RPM) |
NT32 | 4:7ad4177061bb | 79 | strncpy( rbuf, &serBuff[17], 6 ); |
NT32 | 4:7ad4177061bb | 80 | mtrRpm = ( strtol( rbuf, &endPtr, 10) ); |
NT32 | 4:7ad4177061bb | 81 | memset( rbuf, '\0', sizeof rbuf ); |
NT32 | 4:7ad4177061bb | 82 | // 数値表示 |
NT32 | 4:7ad4177061bb | 83 | lcd.cls(); //<=表示クリア |
NT32 | 4:7ad4177061bb | 84 | lcd.locate( 0, 0); //<= locate(列,行) |
NT32 | 4:7ad4177061bb | 85 | lcd.printf("SC =%04dA", measCurrent ); |
NT32 | 4:7ad4177061bb | 86 | lcd.locate( 0, 1); |
NT32 | 4:7ad4177061bb | 87 | lcd.printf("cmd =%04dA", ((measCurrent - currentCmd) / 4) ); |
NT32 | 4:7ad4177061bb | 88 | lcd.locate( 0, 2); |
NT32 | 4:7ad4177061bb | 89 | lcd.printf("vol =%04d", accelVol ); |
NT32 | 4:7ad4177061bb | 90 | lcd.locate( 0, 3); |
NT32 | 4:7ad4177061bb | 91 | lcd.printf("duty=%04.1f%", ((float)(pwmDuty))/8 ); |
NT32 | 4:7ad4177061bb | 92 | lcd.locate( 10, 0); |
NT32 | 4:7ad4177061bb | 93 | lcd.printf("%06drpm", mtrRpm ); |
NT32 | 3:ce52092b7a3a | 94 | } |
NT32 | 4:7ad4177061bb | 95 | // wait(0.1); |
NT32 | 4:7ad4177061bb | 96 | |
NT32 | 3:ce52092b7a3a | 97 | } |
NT32 | 3:ce52092b7a3a | 98 | } |