⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hpi.i

📁 单片机和DSP之间的hpi模块程序,实现单片机和dsp的数据传输,单片机是华邦单片机
💻 I
📖 第 1 页 / 共 3 页
字号:
 ucByteHigh=*pDataWrite; ucByteLow=*(pDataWrite+1);  EA = 0;                                      bHPI_HCS= 0;                                                                                                   ((unsigned char volatile xdata *) 0)[unAddress]=ucByteHigh;                                             unCounter=0;                                                 bHPI_RDY=1;                                               while((bHPI_RDY==0)&&(unCounter<1000))      unCounter++; if(bHPI_RDY==0)                                           return(1);    ((unsigned char volatile xdata *) 0)[unAddress+0x0200]=ucByteLow;                                      bHPI_HCS= 1;                                              EA = 1;                                      return(0);  }     unsigned char  HPIWordWrite(unsigned int unAddress, unsigned int unDataWrite) {  unsigned int    idata unCounter;  unsigned char idata ucByteHigh;  unsigned char idata ucByteLow; union UINTandBYTE idata  WordData;  WordData.unData=unDataWrite;  ucByteHigh=WordData.DataByte.ucDataH; ucByteLow=WordData.DataByte.ucDataL;  EA = 0;                                      bHPI_HCS= 0;                                                                                                    ((unsigned char volatile xdata *) 0)[unAddress]=ucByteHigh;                                             unCounter=0;                                                 bHPI_RDY=1;                                               while((bHPI_RDY==0)&&(unCounter<1000))      unCounter++; if(bHPI_RDY==0)                                           return(1);    ((unsigned char volatile xdata *) 0)[unAddress+0x0200]=ucByteLow;                                      bHPI_HCS= 1;                                              EA = 1;                                      return(0);  }     unsigned char   HPITwoByteRead(unsigned int unAddress, unsigned char *pDataRead) {  unsigned int    idata unCounter;  unsigned char idata ucByteHigh;  unsigned char idata ucByteLow;  EA = 0;                                      bHPI_HCS= 0;                                                                                ucByteHigh=((unsigned char volatile xdata *) 0)[unAddress+0x0100];                                       unCounter=0;                                                bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0)                                          return(1);  ucByteLow=((unsigned char volatile xdata *) 0)[unAddress+0x0300];                              bHPI_HCS= 1;                                             *pDataRead=ucByteHigh; *(pDataRead+1)=ucByteLow;  EA = 1;                                      return(0);  }    unsigned char   HPIWordRead(unsigned int unAddress, unsigned int *pDataRead) {  unsigned int    idata unCounter;  unsigned char idata ucByteHigh;  unsigned char idata ucByteLow; union UINTandBYTE idata  WordData;  EA = 0;                                      bHPI_HCS= 0;                                                                                ucByteHigh=((unsigned char volatile xdata *) 0)[unAddress+0x0100];                                       unCounter=0;                                                bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0)                                          return(1);  ucByteLow=((unsigned char volatile xdata *) 0)[unAddress+0x0300];                              bHPI_HCS= 1;                                             EA = 1;                                      WordData.DataByte.ucDataH=ucByteHigh; WordData.DataByte.ucDataL=ucByteLow; *pDataRead= WordData.unData;  return(0);  }   void  HPIInit() { HPIWordWrite(0xF000,0xE8E8); }     unsigned char   HPIBlockWrite(unsigned int unAddress, unsigned char *DataBuffer, unsigned int unLength ) {  unsigned int  idata unIndex;  unsigned int  idata unCounter;  unsigned char idata ucError;  unsigned char idata ucByteHigh;  unsigned char idata ucByteLow;  ucError=HPIWordWrite(0xF800, unAddress-1);                  if(ucError==1)                                                                 return(1);  EA = 0;                                      for(unIndex=0;unIndex<unLength;unIndex++)                      { ucByteHigh=*(DataBuffer + unIndex++);                         ucByteLow=*(DataBuffer + unIndex);  bHPI_HCS= 0;  unCounter=0; bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);    ((unsigned char volatile xdata *) 0)[0xF400]=ucByteHigh;                                   unCounter=0; bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);    ((unsigned char volatile xdata *) 0)[0xF600]=ucByteLow;  bHPI_HCS= 1;  }  EA = 1;                                      return(0); }    unsigned char   HPIBlockRead(unsigned int unAddress, unsigned char *DataBuffer, unsigned int unLength ) {  unsigned int   idata unCounter;  unsigned int  idata   unIndex;  unsigned char idata ucError;  unsigned char idata ucByteHigh;  unsigned char idata ucByteLow;  ucError=HPIWordWrite(0xF800, unAddress);               if(ucError==1) return(1);  EA = 0;                                      for(unIndex=0;unIndex<unLength;unIndex++)   { bHPI_HCS= 0; unCounter=0; bHPI_RDY=1;  while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);   ucByteHigh=((unsigned char volatile xdata *) 0)[0xF500];                                   unCounter=0; bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);  ucByteLow=((unsigned char volatile xdata *) 0)[0xF700];  bHPI_HCS= 1; *(DataBuffer + unIndex++)=ucByteHigh; *(DataBuffer + unIndex)=ucByteLow; }  EA = 1;                                      return(0); }       void MCUMotionWrite()     { if(eAlarm!=NoAlarm) { if((eAlarm<ParameterError)||(!bDSPStart)) return;  if((eAlarm>=YPLimtP)&&(eAlarm<=ZPLimtN)) { if(((eAlarm == YPLimtP) && (MCUOutputBuffer.lYIncrement<0))  ||((eAlarm == YPLimtN) && (MCUOutputBuffer.lYIncrement>0)) ||((eAlarm == ZPLimtP) && (MCUOutputBuffer.lZIncrement<0)) ||((eAlarm == ZPLimtN) && (MCUOutputBuffer.lZIncrement>0))) { ; } else return; } }  ProgramStartPoint.lY = CurrentProgramPoint.lY; ProgramStartPoint.lZ = CurrentProgramPoint.lZ;   ucOutputBufferBusy=0x55; OperateStateWrite();  MCUOutputBuffer.ucCommandStatus=ucOutputOperateState; HPIBlockWrite(0x0088, (unsigned char *)&MCUOutputBuffer, 48);  ucOutputBufferBusy=0xAA; OperateStateWrite();  }     void MCUIOOutputWrite()     {  if((eAlarm<ParameterError)||(!bDSPStart)) return;  MCUOutputBuffer.ucMCUOperateMode= ucbOperateMode; MCUOutputBuffer.ucCommandStatus= ucOutputOperateState; MCUOutputBuffer.ucF[1]=ucOUTPUT[0]; MCUOutputBuffer.ucF[3]=ucOUTPUT[1];  HPIBlockWrite(0x009B, &MCUOutputBuffer.ucReserve2, 30);  }    void MCUParameterWrite()     { if((eAlarm<ParameterError)||(!bDSPStart)) return;  HPIBlockWrite(0x00AA, (unsigned char *)&ParameterValue, 102);   }      void MCUInputRead()     { if(!bDSPStart) return;  HPIBlockRead(0x0300, (unsigned char *)&MCUInputBuffer, 56);  ucINPUT[0]=MCUInputBuffer.ucG[1]; ucINPUT[1]=MCUInputBuffer.ucG[3]; ucINPUT[2]=MCUInputBuffer.ucG[5];  ucDSPAlarm=MCUInputBuffer.ucAlarmCode;    ucMotionComplete=MCUInputBuffer.ucMotionStatus;  if(((MCUInputBuffer.lProgramY-MachineProgramPonitOld.lY)<20000)&& ((MCUInputBuffer.lProgramY-MachineProgramPonitOld.lY)>-20000))     {      CurrentProgramPoint.lY = MCUInputBuffer.lProgramY -ProgramOrigin.lY; lMacroValue[58] = CurrentProgramPoint.lY ; }  if(((MCUInputBuffer.lProgramZ-MachineProgramPonitOld.lZ)<20000)&& ((MCUInputBuffer.lProgramZ-MachineProgramPonitOld.lZ)>-20000))        {        CurrentProgramPoint.lZ = MCUInputBuffer.lProgramZ - ProgramOrigin.lZ; lMacroValue[59] = CurrentProgramPoint.lZ;   }  CurrentActualPoint.lY = MCUInputBuffer.lMachineY; CurrentActualPoint.lZ = MCUInputBuffer.lMachineZ;  CurrentLeave.lY=MCUInputBuffer.lLeaveY; CurrentLeave.lZ=MCUInputBuffer.lLeaveZ;    MachineProgramPonitOld.lY = MCUInputBuffer.lProgramY; MachineProgramPonitOld.lZ = MCUInputBuffer.lProgramZ;  }     void OperateStateRead()  {  unsigned char idata ucByteTemp[2];  if(!bDSPStart) return;  HPIWordWrite(0xF800, 0x0080); HPITwoByteRead(0xFC00, ucByteTemp);  ucOutputBufferBusy=ucByteTemp[1]; }    void OperateStateWrite()  {  unsigned char idata ucByteTemp[2];  if((eAlarm<ParameterError)||(!bDSPStart)) return;  ucByteTemp[0]=0;    ucByteTemp[1]=ucOutputBufferBusy;  HPIWordWrite(0xF800, 0x0080); HPITwoByteWrite(0xFC00, ucByteTemp);  }     void  FastMultipleWrite()  { if(!bDSPStart) return;  HPIWordWrite(0xF800,0x00B4); HPITwoByteWrite(0xFC00, &ParameterValue.ucReserve0);  }     void  FeedMultipleWrite()  { if(!bDSPStart) return;  HPIWordWrite(0xF800,0x00B5); HPITwoByteWrite(0xFC00, &ParameterValue.ucReserve1);  }     void  HWMultipleWrite()  { if(!bDSPStart) return;  HPIWordWrite(0xF800,0x00B6); HPITwoByteWrite(0xFC00, &ParameterValue.ucReserve2);  }         void YHomeGridRead() {  if(!bDSPStart) return;  HPIWordWrite(0xF800,0x031C); HPIWordRead(0xFC00, &ParameterValue.unYHomeGrid); }     void ZHomeGridRead() {  if(!bDSPStart) return;  HPIWordWrite(0xF800,0x031D); HPIWordRead(0xFC00, &ParameterValue.unZHomeGrid); }     void ZeroOffsetRead() {  if(!bDSPStart) return;  if((ParameterValue.ucBitParameter3&0x01)!=0) { HPIWordWrite(0xF800,0x031E); HPIWordRead(0xFC00, &ParameterValue.unYZeroOffset);  if((ParameterValue.unYZeroOffset<PARAMETERTABLE[26].lMin)||(ParameterValue.unYZeroOffset>PARAMETERTABLE[26].lMax)) ParameterValue.unYZeroOffset=2048; }  if((ParameterValue.ucBitParameter3&0x02)!=0)	 {    HPIWordWrite(0xF800,0x031F); HPIWordRead(0xFC00, &ParameterValue.unZZeroOffset); if((ParameterValue.unZZeroOffset<PARAMETERTABLE[27].lMin)||(ParameterValue.unZZeroOffset>PARAMETERTABLE[27].lMax)) ParameterValue.unZZeroOffset=2048;  } }     void  PitchOffsetWrite()  {  if(!bDSPStart) return;  HPIBlockWrite(0x0100, (unsigned char *)&nYPitchOffset,512);  HPIBlockWrite(0x0200, (unsigned char *)&nZPitchOffset,512);    }     void PLCDiagnoseSignelRead()     { if(!bDSPStart) return;  HPIBlockRead(0x0380, (unsigned char *)&PLCDiagnoseSignel, 114);  }      unsigned char  PLCProgramWrite()  {  unsigned int  idata unLength;		  unsigned int  idata unIndex;  unsigned int  idata unCounter;  unsigned char idata ucError;  unsigned char idata ucByteLow;  if((eAlarm<ParameterError)||((!bDSPStart))) return(1);  unLength=unPLCProgramCodeUsed*3; ucError=HPIWordWrite(0xF800, (0x0400-1));                  if(ucError==1)                                                                 return(1);  EA = 0;                                      for(unIndex=0;unIndex<unLength;unIndex++)                      {                                                     ucByteLow=*((unsigned char *)PLC_Code+ unIndex);                  bHPI_HCS= 0;  unCounter=0; bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);    ((unsigned char volatile xdata *) 0)[0xF400]=0x00;                                   unCounter=0; bHPI_RDY=1; while((bHPI_RDY==0)&&(unCounter<1000)) unCounter++; if(bHPI_RDY==0) return(1);    ((unsigned char volatile xdata *) 0)[0xF600]=ucByteLow;  bHPI_HCS= 1;  }  EA = 1;                                      return(0); }      unsigned char HandShakeRead() {  unsigned char idata ucByteTemp[8];  unsigned char idata ucCounter;  HPIBlockRead(0x0082, ucByteTemp, 8);  ucCounter=0; while((ucCounter<8)&&(ucByteTemp[ucCounter++]==0x55));  if(ucCounter==8) return(0x55);  ucCounter=0; while((ucCounter<8)&&(ucByteTemp[ucCounter++]==0xAA));  if(ucCounter==8) return(0xAA); else return(0);  }     void  HandShakeWrite(unsigned char ucByteHigh,unsigned char ucByteLow) {  unsigned char idata ucByteTemp[8];  unsigned char idata ucCounter;  ucCounter=0;  while(ucCounter<8) { ucByteTemp[ucCounter++]=ucByteHigh; ucByteTemp[ucCounter++]=ucByteLow; }  HPIBlockWrite(0x0082, ucByteTemp, 8);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -