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

📄 main.c

📁 基于ATMEGA161的CAN总线FIRMCORE
💻 C
字号:
/*
**  File:       Main.C
**
**  Purpose:    Demonstrate WiCAN LIB for SJA1000
**
**  Chip:       ATMega161 running at 7.3728MHz
**
**  Version:    1.0.3, 25:th of July 2002
**
**  Author:     Lars Wictorsson
**              LAWICEL / SWEDEN
**              http://www.lawicel.com   lars@lawicel.com
**
**  Copyright:  The copyright to the computer program(s) herein is the
**              property of LAWICEL HB, Sweden. The program(s) may be used
**              and/or copied only with the written permission of LAWICEL HB
**              in accordance with the terms and conditions stipulated in
**              the agreement/contract under which the program(s) have been
**              supplied.
**
**  Remarks:    This program was converted to CodeVisionAVR V1.23.6 or later
**              by Pavel Haiduc
**              HP InfoTech s.r.l.
**              http://www.hpinfotech.ro
**              e-mail: office@hpinfotech.ro
**
**  History:    2000-05-18  1.0.0   Created (LWI)
**              2001-05-06  1.0.1   Modified to test 29bit (LWI)
**              2001-05-14  1.0.2   Modified to test RTR (LWI)
**              2002-07-25  1.0.3   Converted to CVAVR (PH)
*/

#include <mega161.h>
#include <stdio.h>
#include "WiCAN.h"

WiCAN_Object MyFrame;

void main( void)
{
/*
**  Setup CAN controller
*/
    if ((WiCAN_Init(WiCAN_SPEED_20K, 0, 0, 0xDE)) == WiCAN_OK) {
        WiCAN_Start();

        MyFrame.id      = 0x500;                    // Set up a standard 11-bit ID Frame with
        MyFrame.len     = 1;                        // DLC = 1 (i.e. 1 byte)
        MyFrame.byte[0] = 0x01;                     // The first byte to '0x01'
        WiCAN_SendFrame(&MyFrame);                  // Send the frame

        MyFrame.id      = 0x510;                    // Set new ID 
        MyFrame.flags   = WiCAN_29;                 // Change the frame type to Extended
        MyFrame.byte[0]++;                          // Increase the value of byte 1
        WiCAN_SendFrame(&MyFrame);                  // Send the frame again

        MyFrame.id      = 0x520;                    // Set new ID 
        MyFrame.flags   = WiCAN_RTR;                // Change the STD frame type and set RTR bit
        WiCAN_SendFrame(&MyFrame);                  // Send the frame again (notice DLC is set to zero when sending)

        while(1) {                                  // Do a forever loop
            if (WiCAN_GetRxQueueSize() >= 4) {      // Wait until input FIFO has 4 messages or more
                while (WiCAN_GetFrame(&MyFrame) == WiCAN_OK) {
                    WiCAN_SendFrame(&MyFrame);      // Send all of them back as they came in.
                }
            }
        }
    }
}

⌨️ 快捷键说明

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