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

📄 can.lst

📁 基于MST-G240128点阵液晶的 状态机机制 人机界面四级滚屏菜单 源代码 ,带时间片机制模拟操作系统
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.02a   CAN                                                                  08/31/2006 08:52:05 PAGE 4   

 176          ** 函数名称: CAN_SendMsg()
 177          ** 功能描述: 发送msg.
 178          ** 入口参数: 无
 179          ** 出口参数: 无
 180          ** 全局变量: 无
 181          ** 调用模块: 无
 182          ** 说明: 
 183          ****************************************************************************/
 184          /*
 185          void CAN_SendMsg(int8 MsgNum, uint8 ByteNum)
 186          {
 187             uint8 i = 0;   
 188          
 189             SFRPAGE  = CAN0_PAGE;        // IF1 already set up for TX
 190             CAN0ADR  = IF1CMDMSK;        // Point to Command Mask 1
 191             CAN0DAT  = 0x0087;           // Config to WRITE to CAN RAM, write data bytes,
 192                                          // set TXrqst/NewDat, Clr IntPnd
 193          
 194             CAN0ADR   = IF1ARB2;         // Point to Arbitration2 register
 195             CAN0DATH |= 0x80;            // MsgVal = 1, Msg Valid.
 196             CAN0ADR   = IF1DATA1;        // Point to 1st byte of Data Field
 197          
 198             CAN0DATH = CAN_SendDATA[i];  // Autoincrement through IF data bytes
 199             if(i > ByteNum )             // DATA0 
 200               goto CAN_Send_DONE; 
 201          
 202             i++;
 203             CAN0DATL = CAN_SendDATA[i];  // DATA1 
 204             if(i > ByteNum )
 205               goto CAN_Send_DONE;
 206          
 207             i++;
 208             CAN0DATH = CAN_SendDATA[i];  // DATA2
 209             if(i > ByteNum )
 210               goto CAN_Send_DONE;
 211          
 212             i++;
 213             CAN0DATL = CAN_SendDATA[i];  // DATA3 
 214             if(i > ByteNum )
 215               goto CAN_Send_DONE;
 216          
 217             i++;
 218             CAN0DATH = CAN_SendDATA[i];  // DATA4 
 219             if(i > ByteNum )
 220               goto CAN_Send_DONE;
 221          
 222             i++;
 223             CAN0DATL = CAN_SendDATA[i];  // DATA5 
 224             if(i > ByteNum )
 225               goto CAN_Send_DONE;
 226          
 227             i++;
 228             CAN0DATH = CAN_SendDATA[i];  // DATA6 
 229             if(i > ByteNum )
 230               goto CAN_Send_DONE;
 231            
 232             i++;
 233             CAN0DATL = CAN_SendDATA[i];  // DATA7
 234             if(i > ByteNum )
 235               goto CAN_Send_DONE;
 236          
 237             CAN_Send_DONE:               // CAN_Send_DONE
C51 COMPILER V7.02a   CAN                                                                  08/31/2006 08:52:05 PAGE 5   

 238             CAN0ADR = IF1CMDRQST;        // Point to Command Request Reg.
 239             CAN0DATL = MsgNum;           // Move new data for TX to Msg Obj "MsgNum"
 240          }
 241          */
 242          
 243          
 244          /****************************************************************************
 245          ** 函数名称: CAN_RecvMsg()
 246          ** 功能描述: 接收msg.
 247          ** 入口参数: 无
 248          ** 出口参数: 无
 249          ** 全局变量: 无
 250          ** 调用模块: 无
 251          ** 说明: 
 252          ****************************************************************************/
 253          /*
 254          void CAN_RecvMsg(int8 MsgNum)
 255          {
 256             SFRPAGE  = CAN0_PAGE;       // IF1 already set up for RX
 257             CAN0ADR  = IF2CMDRQST;      // Point to Command Request Reg.
 258             CAN0DATL = MsgNum;          // Move new data for RX from Msg Obj "MsgNum"
 259                                         // Move new data to a
 260             CAN0ADR  = IF2DATA1;        // Point to 1st byte of Data Field
 261          
 262             CAN_RecvDATA[0] = CAN0DATH;
 263             CAN_RecvDATA[1] = CAN0DATL;
 264             CAN_RecvDATA[2] = CAN0DATH;
 265             CAN_RecvDATA[3] = CAN0DATL;
 266             CAN_RecvDATA[4] = CAN0DATH;
 267             CAN_RecvDATA[5] = CAN0DATL;
 268             CAN_RecvDATA[6] = CAN0DATH;
 269             CAN_RecvDATA[7] = CAN0DATL;
 270          }
 271          */
 272          
 273          
 274          /****************************************************************************
 275          ** 函数名称: CAN_ISR()
 276          ** 功能描述: CAN控制器中断服务程序.
 277          ** 入口参数: 无
 278          ** 出口参数: 无
 279          ** 全局变量: 无
 280          ** 调用模块: 无
 281          ** 说明: 
 282          ****************************************************************************/
 283          /*
 284          void CAN_ISR(void) interrupt 19
 285          {
 286             unsigned char CanSTATUS, ucTMP;
 287          
 288             CanSTATUS = CAN0STA;
 289             // Bit7: BOff:  Busoff Status; 
 290                  //  0/1: Not BusOff / BusOff.  
 291             // Bit6: EWarn: Warning Status;
 292                  //  0/1: BothEML < 96 / At Least OneEML > 96. 
 293             // Bit5: EPass: Error Passive; 
 294                  //   0/1: CAN Core IS Error Active / error passive state.
 295             // Bit4: RxOk:  Received    a Message Successfully, Cleared by SoftWare.
 296             // Bit3: TxOk:  Transmitted a Message Successfully, Cleared by SoftWare.
 297             // Bit[2..0]:   LEC[2..0]:  Last Error Code. Type of the last error to occur on the CAN bus
 298             // 0: No Error
 299             // 1: Stuff Error: 位填充错误 
C51 COMPILER V7.02a   CAN                                                                  08/31/2006 08:52:05 PAGE 6   

 300             // 2: Form Error:  接收帧格式错误
 301             // 3: AckError:    对方接收CAN控制器无应答
 302             // 4: Bit1Error:   发送隐性电平“1”,监测为“0” 
 303             // 5: Bit0Error:   发送显性电平“0”,监测为“1”,应答错误等
 304             // 6: CRCError:    接收数据的CRC校验码错误
 305             // 7: Unused:      无CAN事件发生
 306          
 307             if( (CanSTATUS&0x10) != 0 )           // RX OK.
 308             {                                  
 309                CAN0STA = (CAN0STA & 0xEF) | 0x07; // Reset RxOk, Set LEC to NoChange
 310                receive_data (0x01);               // Up to now, we have only one RX message
 311             }
 312             if( (CanSTATUS&0x08) != 0)            // Tx OK.
 313             {                                     
 314                CAN0STA = (CAN0STA & 0xF7) | 0x07; // Reset TxOk, set LEC to NoChange
 315             }
 316          
 317                  ucTMP = CanSTATUS & 0x07;
 318             if( ( ucTMP != 0) && ( ucTMP != 7) )  // Not Equal 0 AND Equal 7.
 319             {                                     // CAN Controllor Error Process.
 320                switch( ucTMP )                                   
 321                {
 322                             case 1: 
 323                                            break; 
 324                             case 2: 
 325                                            break; 
 326                             case 3: 
 327                                            break; 
 328                             case 4: 
 329                                            break; 
 330                             case 5: 
 331                                            break; 
 332                             case 6: 
 333                                            break; 
 334                             default: 
 335                                            break; 
 336                          }
 337                CAN0STA = CAN0STA | 0x07;         // Set LEC to NoChange
 338             }
 339          }
 340          */
 341          
 342          
 343          /*
 344             CAN0CN / CANCTRL   // CAN Control Register     
 345             // Configuration Change Enable CCE and INIT
 346             // Bit7: CAN Test Mode Enable bit.
 347             // Bit6: CAN Configuration Change Enable bit, "CCE".
 348             // Bit5: CAN Disable Automatic Retransmission bit.
 349             // Bit4: CAN Module Interrupt Flag.
 350             // Bit3: CAN Module Error Interrupt Enable Bit.
 351             // Bit2: CAN Status change Interrupt Enable Bit.
 352             // Bit1: CAN Module Interrupt Enable Bit, "INIT".
 353             // Bit0: CAN Initialization bit.
 354          
 355             CAN0STA / CANSTAT   // Status Register
 356             // Bit7: BOff:  Busoff Status; 0/1: Not BusOff   / BusOff.  
 357             // Bit6: EWarn: Warning Status;0/1: BothEML < 96 / At Least OneEML > 96. 
 358             // Bit5: EPass: Error Passive; 0/1: CAN Core IS Error Active / error passive state.
 359             // Bit4: RxOk:  Received a Message Successfully.   Cleared by SoftWare.
 360             // Bit3: TxOk:  Transmitted a Message Successfully.Cleared by SoftWare.
 361             // Bit[2..0]: LEC[2..0]: Last Error Code. Type of the last error to occur on the CAN bus

⌨️ 快捷键说明

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