?? senddata.c
字號:
/** \file
* MSP430FE427 Application Program Example
*
* This file send the data from the ESP430 via the serial communication
* port
*
* \author Stefan Schauer
* \date 04/29/2003
*/
//====================================================================
#include "device.h"
#include "comms_uart.h"
#include "SendData.h"
#include "fet4xx_rtclcd.h"
#include "emeter.h"
#include "parameter.h"
#include <stdio.h>
#include <math.h>
#ifdef withUARTComm
// const and var definition
unsigned int TX_Mode = tx_off; // Transmit mode
void SendData(void)
{
static unsigned int value;
static unsigned long lvalue;
static char strbuf[20];
switch (TX_Mode)
{
// static unsigned i =0;
case tx_off: break;
case tx_ch1:
_DINT();
SendResult((unsigned char*) &wfs1, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs1>>8));
SendChar((char)(wfs1&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_ch2:
_DINT();
SendResult((unsigned char*) &wfs2, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs2>>8));
SendChar((char)(wfs2&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_ch3:
_DINT();
SendResult((unsigned char*) &wfs3, 2);
SendString("\r");
_EINT(); // Enable Interrupts
/*
SendChar((char)(wfs3>>8));
SendChar((char)(wfs3&0xff));
i++;
if (i < 0x400) {;}
else if (i == 0x5400) { TX_Mode = tx_off; i = 0; }
*/
break;
case tx_temp:
SendString("\rTemp: ");
SendResult((unsigned char*) &temperature, 2);
SendString("\r");
break;
case tx_dump:
SendChar(0x0C);
SendString("Active Energy1: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = ACTENERGY2_LO;
energy.w[1] = ACTENERGY2_HI;
SendString("Active Energy2: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = REACTENERGY_LO;
energy.w[1] = REACTENERGY_HI;
SendString("Reactive Energy: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
energy.w[0] = APPENERGY_LO;
energy.w[1] = APPENERGY_HI;
SendString("Apparent Energy: ");
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
value = V1RMS;
SendString("V(RMS): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = IRMS_HI;
SendString("I(RMS): ");
SendResult((unsigned char*) &value, 2);
SendChar('.');
value = IRMS_LO;
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = VPEAK;
SendString("V(Peak): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = IPEAK;
SendString("I(Peak): ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = savedRET[20];//POWERFCT;
// value = POWERFCT;
SendString("PF: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
value = (unsigned int)((unsigned char)CAPIND);
SendString("CapInd: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
// value = MainsPeriod;
value = savedRET[22];
SendString("f: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
// lvalue = ((LineCyclCnt) + ((unsigned long)LineCyclCntHi << 16));
lvalue = ((savedRET[28]) + ((unsigned long)savedRET[29] << 16));
SendString("Cycles: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
lvalue = ((NMBMEAS_LO) + ((unsigned long)NMBMEAS_HI << 16));
SendString("Num of Meas.: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
SendChar('\r');
break;
case tx_energy:
lvalue = (unsigned long)((float) energy.l * (s_parameters.EnergyRatio/1000));
SendString("Active Energy1 (mW): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
break;
case tx_cal:
SendResult((unsigned char*) &energy, 4);
SendChar('\r');
TX_Mode = tx_off;
break;
case tx_values:
SendChar(0x0C);
SendString("Time: ");
SendResult((unsigned char*) &HOUR, 1);
SendString(":");
SendResult((unsigned char*) &MIN, 1);
SendString(":");
SendResult((unsigned char*) &SEC, 1);
SendString(" ");
SendResult((unsigned char*) &DAY, 1);
SendString(".");
SendResult((unsigned char*) &MONTH, 1);
SendString(".");
SendResult((unsigned char*) &YEAR, 1);
SendChar('\r');
lvalue = ((unsigned long) (V1RMS * (s_parameters.VRatio*1000))/1000);
SendString("V(RMS/mV): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (IRMS_HI * s_parameters.IRatio*1000))/1000;
SendString("I(RMS/mA): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (VPEAK * (s_parameters.VRatio*1000))/1000);
SendString("V(Peak/mV): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((unsigned long) (IPEAK * s_parameters.IRatio*1000))/1000;
SendString("I(peak/mA): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
value = savedRET[20];//POWERFCT;
value = (unsigned int)((((unsigned long)value*1000)/POW_2_14));
SendString("cosPhi(*1000): ");
if ((signed char)CAPIND > 0) SendChar('-');
//host_decu16(value);
sprintf(strbuf, "%d",value);
SendString(strbuf);
SendChar('\r');
value = (unsigned int)((unsigned char)CAPIND);
SendString("CapInd: ");
SendResult((unsigned char*) &value, 2);
SendString(" ");
value = savedRET[20];//POWERFCT;
SendString("PF: ");
SendResult((unsigned char*) &value, 2);
SendChar('\r');
// value = (unsigned int)((float)MainsPeriod/(float)((float)(1000000)/((float)(1048576))));
value = (unsigned int)((((float)savedRET[22]*(float)(1000000))/(float)(1048576)));
SendString("Main Period(us): ");
//host_decu16(value);
sprintf(strbuf, "%d",value);
SendString(strbuf);
SendChar('\r');
SendString("Frequency(mHz): ");
lvalue = (unsigned long)((float)(1000000*1000/((float)value)));
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = (unsigned long)((float) energy.l * (s_parameters.EnergyRatio/1000));
SendString("Active Energy1 (mW): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = (unsigned long)(((unsigned long)REACTENERGY_HI << 16) + REACTENERGY_LO);
lvalue = (unsigned long)((float) lvalue * (s_parameters.EnergyRatio/1000));
SendString("Reactive Energy1 (mVAR): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = (unsigned long)(((unsigned long)APPENERGY_HI << 16) + APPENERGY_LO);
lvalue = (unsigned long)((float) lvalue * (s_parameters.EnergyRatio/1000));
SendString("Apparent Energy1 (mVA): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = (unsigned long)((float) total_energy * (float)(s_parameters.EnergyRatio)/(float)((float)1000000*(float)3600));
SendString("Active TotalEnergy1 (Wh): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = (unsigned long) (((unsigned long)temperature * (TempGain*100)) - (TempOffset*100));
SendString("Temperature(*100/degree): ");
//host_decu32(lvalue);
sprintf(strbuf, "%ld",lvalue);
SendString(strbuf);
SendChar('\r');
lvalue = ((savedRET[28]) + ((unsigned long)savedRET[29] << 16));
SendString("Cycles: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
lvalue = ((NMBMEAS_LO) + ((unsigned long)NMBMEAS_HI << 16));
SendString("Num of Meas.: ");
SendResult((unsigned char*) &lvalue, 4);
SendChar('\r');
break;
default:
break;
}
}
#endif // withUARTComm
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -