基于TMS320F2812的三相逆变电源(3)

2018-11-22 18:19

//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff;

addr = receBuf[3]; //get address of ... tempAddr = addr; //temp var

//bitCount = (receBuf[4]<<8) + receBuf[5]; //get count of bits bitCount = receBuf[5];

byteCount = bitCount / 8; //get count of bytes if (bitCount % 8 != 0) byteCount++;

for (k = 0; k < byteCount; k++) {

position = k + 3; sendBuf[position] = 0; for (i = 0; i < 8; i++) {

getCoilVal(tempAddr, &tempData);

sendBuf[position] |= tempData << i; tempAddr++;

if (tempAddr >= addr + bitCount) {

exit = 1; break; } }

if (exit == 1) break; }

sendBuf[0] = localAddr; sendBuf[1] = 0x01; sendBuf[2] = byteCount; byteCount += 3;

crcData = crc16(sendBuf, byteCount); sendBuf[byteCount] = crcData >> 8; byteCount++;

sendBuf[byteCount] = crcData & 0xff; sendCount = byteCount + 1;

beginSend(); }

void readRegisters(void) {

static Uint8 kk = 0; Uint8 xkwy_temp; Uint8 addr; Uint8 tempAddr; Uint16 crcData; Uint8 readCount; Uint8 byteCount; Uint16 i;

Uint16 tempData = 0;

//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3]; tempAddr = addr;

xkwy_temp = M;

kk = ~kk; if (kk) {

if (xkwy_temp&0x08) {

if ((xkwy_temp&0x07) + testRegister2 >= testRegister2) testRegister0 = (xkwy_temp&0x07) + testRegister2; else

testRegister0 = 0xff; } else {

if (testRegister2-(xkwy_temp&0x07) <= testRegister2) testRegister0 = testRegister2 - (xkwy_temp&0x07); else

testRegister0 = 0x00; }

if (testRegister0 > 0xff) testRegister0 = 0xff; } else {

if (xkwy_temp&0x08) {

if ((xkwy_temp&0x07) + testRegister1 >= testRegister1) testRegister1 = (xkwy_temp&0x07) + testRegister1;

else

testRegister1 = 0xff; } else {

if (testRegister1-(xkwy_temp&0x07) <= testRegister1) testRegister1 = testRegister1 - (xkwy_temp&0x07); else

testRegister1 = 0x00; }

if (testRegister1 > 0xff) testRegister1 = 0xff; }

//readCount = (receBuf[4]<<8) + receBuf[5]; readCount = receBuf[5];

byteCount = readCount * 2;

for (i = 0; i < byteCount; i += 2, tempAddr++) { getRegisterVal(tempAddr, &tempData); sendBuf[i+3] = tempData >> 8; sendBuf[i+4] = tempData & 0xff; }

sendBuf[0] = localAddr; sendBuf[1] = 3;

sendBuf[2] = byteCount; byteCount += 3;

crcData = crc16(sendBuf, byteCount); sendBuf[byteCount] = crcData >> 8; byteCount++;

sendBuf[byteCount] = crcData & 0xff;

sendCount = byteCount + 1;

beginSend();

}//void readRegisters(void)

void forceSingleCoil(void) {

Uint8 addr; Uint8 tempAddr; Uint16 tempData;

Uint8 onOff; Uint8 i;

//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3]; tempAddr = addr;

//onOff = (receBuf[4]<<8) + receBuf[5]; onOff = receBuf[4];

//if(onOff == 0xff00) if (onOff == 0xff) {

tempData = 1; }

//else if(onOff == 0x0000) else if (onOff == 0x00) {

tempData = 0; }

setCoilVal(tempAddr, tempData);

for (i = 0; i < receCount; i++) { sendBuf[i] = receBuf[i]; }

sendCount = receCount;

beginSend(); }

void presetSingleRegister(void) {

Uint8 addr; Uint8 tempAddr; Uint8 setCount; Uint16 crcData; Uint16 tempData;

//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3];

tempAddr = addr; //& 0xff

tempData = ( receBuf[4]<<8 ) + receBuf[5]; setRegisterVal(tempAddr,tempData);

sendBuf[0] = localAddr; sendBuf[1] = 6;

sendBuf[2] = addr >> 8; sendBuf[3] = addr & 0xff; sendBuf[4] = receBuf[4]; sendBuf[5] = receBuf[5] ;

setCount = 6;

crcData = crc16(sendBuf,6); sendBuf[6] = crcData >> 8; sendBuf[7] = crcData & 0xff;

sendCount = 8; beginSend(); }

void presetMultipleRegisters(void) {

Uint8 addr; Uint8 tempAddr; Uint8 byteCount; Uint8 setCount; Uint16 crcData; Uint16 tempData; Uint8 i;

//addr = (receBuf[2]<<8) + receBuf[3]; //tempAddr = addr & 0xfff; addr = receBuf[3]; tempAddr = addr & 0xff;

//setCount = (receBuf[4]<<8) + receBuf[5]; setCount = receBuf[5]; byteCount = receBuf[6];

for (i = 0; i < setCount; i++, tempAddr++) { //SBUF = receBuf[i*2+7]; //SBUF = receBuf[i*2+8];

tempData = (receBuf[i*2+7] << 8) + receBuf[i*2+8];


基于TMS320F2812的三相逆变电源(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:军人抚恤优待条例释义

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: