📄 main_mm.c
字号:
/**************************************************************************
MODULE: MAIN
CONTAINS: Example application using MicroCANopen
For PEAK System Tehnik MicroMod Module
www.peak-system.com
Compiled with Fujitsu Softune Workbench
COPYRIGHT: Embedded Systems Academy, Inc. 2002 - 2007
All rights reserved. www.microcanopen.com
This software was written in accordance to the guidelines at
www.esacademy.com/software/softwarestyleguide.pdf
DISCLAIM: Read and understand our disclaimer before using this code!
www.esacademy.com/disclaim.htm
LICENSE: THIS IS THE EDUCATIONAL VERSION OF MICROCANOPEN
See file license_educational.txt or
www.microcanopen.com/license_educational.txt
A commercial MicroCANopen license is available at
www.CANopenStore.com
VERSION: 3.30, ESA 30-JAN-07
$LastChangedDate: 2007-01-30 20:50:41 -0800 (Tue, 30 Jan 2007) $
$LastChangedRevision: 235 $
***************************************************************************/
#include "inc\compiler.h"
#include "inc\mb90495.h"
#include "inc\vectors.h"
#include "inc\can.h"
#include "inc\hardware.h"
#include "inc\uart.h"
#include "inc\timer.h"
#include "inc\i2c.h"
#include "inc\eeprom.h"
#include "inc\adi.h"
#include "inc\pwm.h"
#include "..\mco\mco.h"
// external declaration for the process image array
extern UNSIGNED8 MEM_NEAR gProcImg[];
/**************************************************************************
DOES: Execute an A to D conversion
RETURNS: Converted value
**************************************************************************/
UNSIGNED16 read_poti(
void
)
{
return AD_Read(0);
}
/**************************************************************************
DOES: The main function
RETURNS: nothing
**************************************************************************/
void main(
void
)
{
UNSIGNED32 pot;
UNSIGNED8 b;
InitIrqLevels();
__set_il(7); // allow all levels
Hardware_Init();
UART_Init(SER_BAUD_19200);
puts("\n\r\n\rMicroCANopen for PEAK MicroMOD V2.10");
Timer_Init();
AD_Init();
for(b=0;b<4;b++)
{
AD_SetTimeConstant(b, 20); // Passfilter of 20ms
}
// Reset/Initialize CANopen communication
MCOUSER_ResetCommunication();
CAN_RegisterMsg(0);
__EI(); // Enable Interrupts
// foreground loop
while(1)
{
// Trigger watchdog
WATCHDOG;
// Update process data
// Output first digital byte
Set_DOUTByte(gProcImg[P620001_DIGOUTPUT8_]);
// Echo all digital data
gProcImg[P600001_DIGINPUT8_] = gProcImg[P620001_DIGOUTPUT8_];
gProcImg[P600001_DIGINPUT8_] = gProcImg[P620002_DIGOUTPUT8_];
gProcImg[P600001_DIGINPUT8_] = gProcImg[P620003_DIGOUTPUT8_];
gProcImg[P600001_DIGINPUT8_] = gProcImg[P620004_DIGOUTPUT8_];
// first analog input is real I/O
pot = read_poti();
gProcImg[P640101_ANALOGINPUT16_] = pot & 0x000000FF; // lo byte
gProcImg[P640101_ANALOGINPUT16_+1] = (pot >> 8) & 0x000000FF; // hi byte
// echo all other I/O values from input to output
// analog
gProcImg[P640102_ANALOGINPUT16_] = gProcImg[P641102_ANALOGOUTPUT16_];
gProcImg[P640102_ANALOGINPUT16_+1] = gProcImg[P641102_ANALOGOUTPUT16_+1];
// Operate on CANopen protocol stack
MCO_ProcessStack();
} // end of while(1)
} // end of main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -