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.
Fork of TextLCD_HelloWorld by
Revision 4:7ad4177061bb, committed 2016-11-05
- Comitter:
- NT32
- Date:
- Sat Nov 05 10:09:38 2016 +0000
- Parent:
- 3:ce52092b7a3a
- Commit message:
- ?????V850??????
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun May 24 08:11:04 2015 +0000 +++ b/main.cpp Sat Nov 05 10:09:38 2016 +0000 @@ -3,24 +3,27 @@ I2CSlave i2cslave(dp5, dp27); -DigitalOut led1(LED1); -DigitalOut led2(LED2); +DigitalOut led1(dp14); TextLCD lcd(dp17, dp18, dp25, dp10, dp26, dp28, TextLCD::LCD20x4); // rs, e, d4-d7 +Serial pc(dp16, dp15); int main() { - char str[20]; + char str[20], serBuff[64]; float SystemVoltage, AverageCellVoltage, MaxCellVoltage, MinimumCellVoltage, SystemCurrent, Motor1Current, Motor2Current, Motor3Current, Remain, PowerConsumption, IntegralPowerConsumption, IntegralCurrent; + + int measCurrent, currentCmd, accelVol, pwmDuty, mtrRpm; int MaxCellNumber, MinimumCellNumber; int32_t cellvol[12], mincell, maxcell; float realcellvol; /* real number of cell voltage */ - char rbuf[64]; + char rbuf[8]; char i2cbuf[32] = {0}; + char *endPtr; SystemVoltage = 120.5; //%4.1f システム電圧 AverageCellVoltage = 3.123; //%4.3f 平均セル電圧 @@ -37,40 +40,59 @@ IntegralPowerConsumption = 1.54; //%3.2f IntegralCurrent = 43.21; //%4.2f + pc.baud(38400); + 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); - + led1 = 0; + lcd.locate( 0, 0); + lcd.printf("rcv start"); + wait(0.5); + led1 = 1; + + + while(1){ - if(i2cslave.receive() != I2CSlave::NoData){ - i2cslave.read(i2cbuf, 7); - lcd.locate(0, 0); - led1 != led1; - lcd.printf("%s", i2cbuf); + //--------------------------------------------- + // 文字列受信=>数値変換 + //--------------------------------------------- + led1 = !led1; + pc.scanf("%s", serBuff); + if( 's' == serBuff[0] ){ + // 文字列解釈 + //電流計測値(AD10bit生データ) + strncpy( rbuf, &serBuff[1], 4 ); + measCurrent = ( strtol( rbuf, &endPtr, 10) ); + memset( rbuf, '\0', sizeof rbuf ); + //電流指令値(倍率が正しくないと思う) + strncpy( rbuf, &serBuff[5], 4 ); + currentCmd = ( strtol( rbuf, &endPtr, 10) ); + memset( rbuf, '\0', sizeof rbuf ); + //ボリューム(AD10bit生データ) + strncpy( rbuf, &serBuff[9], 4 ); + accelVol = ( strtol( rbuf, &endPtr, 10) ); + memset( rbuf, '\0', sizeof rbuf ); + //PWMデューティ(0~800:MAX800) + strncpy( rbuf, &serBuff[13], 4 ); + pwmDuty = ( strtol( rbuf, &endPtr, 10) ); + memset( rbuf, '\0', sizeof rbuf ); + //モータ回転数(RPM) + strncpy( rbuf, &serBuff[17], 6 ); + mtrRpm = ( strtol( rbuf, &endPtr, 10) ); + memset( rbuf, '\0', sizeof rbuf ); + // 数値表示 + lcd.cls(); //<=表示クリア + lcd.locate( 0, 0); //<= locate(列,行) + lcd.printf("SC =%04dA", measCurrent ); + lcd.locate( 0, 1); + lcd.printf("cmd =%04dA", ((measCurrent - currentCmd) / 4) ); + lcd.locate( 0, 2); + lcd.printf("vol =%04d", accelVol ); + lcd.locate( 0, 3); + lcd.printf("duty=%04.1f%", ((float)(pwmDuty))/8 ); + lcd.locate( 10, 0); + lcd.printf("%06drpm", mtrRpm ); } +// wait(0.1); + } } \ No newline at end of file